Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

PlayerClient Class Reference
[Core functionality]

#include <playerclient.h>

List of all members.


Detailed Description

One PlayerClient object is used to control each connection to a Player server. Contained within this object are methods for changing the connection parameters and obtaining access to devices, which we explain next.


Public Member Functions

 PlayerClient (const char *hostname=NULL, const int port=PLAYER_PORTNUM, const int protocol=PLAYER_TRANSPORT_TCP)
 PlayerClient (const struct in_addr *hostaddr, const int port, const int protocol=PLAYER_TRANSPORT_TCP)
 ~PlayerClient ()
int Connect (const char *hostname="localhost", int port=PLAYER_PORTNUM)
int Connect (const struct in_addr *addr, int port)
int ConnectRNS (const char *robotname, const char *hostname="localhost", int port=PLAYER_PORTNUM)
int Disconnect ()
bool Connected ()
int Peek (int timeout=0)
int Read (bool await_sync=true, ClientProxy **dev=NULL)
int Write (player_device_id_t device_id, const char *command, size_t commandlen)
int Request (player_device_id_t device_id, const char *payload, size_t payloadlen, player_msghdr_t *replyhdr, char *reply, size_t replylen)
int Request (player_device_id_t device_id, const char *payload, size_t payloadlen)
int RequestDeviceAccess (player_device_id_t device_id, unsigned char req_access, unsigned char *grant_access, char *driver_name=NULL, int driver_name_len=0)
int SetFrequency (unsigned short freq)
int SetDataMode (unsigned char mode)
int RequestData ()
int Authenticate (char *key)
int LookupPort (const char *name)
void AddProxy (ClientProxy *proxy)
void RemoveProxy (ClientProxy *proxy)
int GetDeviceList ()

Public Attributes

player_connection_t conn
bool connected
bool fresh
char hostname [256]
int port
in_addr hostaddr
timeval timestamp
int id_count
player_device_id_t ids [PLAYER_MAX_DEVICES]
char drivernames [PLAYER_MAX_DEVICES][PLAYER_MAX_DEVICE_STRING_LEN]


Constructor & Destructor Documentation

PlayerClient::PlayerClient const char *  hostname = NULL,
const int  port = PLAYER_PORTNUM,
const int  protocol = PLAYER_TRANSPORT_TCP
 

Make a client and connect it as indicated. If hostname is omitted (or NULL) then the client will not be connected. In that cast, call Connect() yourself later.

PlayerClient::PlayerClient const struct in_addr *  hostaddr,
const int  port,
const int  protocol = PLAYER_TRANSPORT_TCP
 

Make a client and connect it as indicated, using a binary IP instead of a hostname

PlayerClient::~PlayerClient  ) 
 


Member Function Documentation

int PlayerClient::Connect const char *  hostname = "localhost",
int  port = PLAYER_PORTNUM
 

Connect to the indicated host and port. Returns 0 on success; -1 on error.

int PlayerClient::Connect const struct in_addr *  addr,
int  port
 

Connect to the indicated host and port, using a binary IP. Returns 0 on success; -1 on error.

int PlayerClient::ConnectRNS const char *  robotname,
const char *  hostname = "localhost",
int  port = PLAYER_PORTNUM
 

Connect to a robot, based on its name, by using the Player robot name service (RNS) on the indicated host and port. Returns 0 on success; -1 on error.

int PlayerClient::Disconnect  ) 
 

Disconnect from server. Returns 0 on success; -1 on error.

bool PlayerClient::Connected  )  [inline]
 

Check if we are connected.

int PlayerClient::Peek int  timeout = 0  ) 
 

Check whether there is data waiting on the connection, blocking for up to timeout milliseconds (set to 0 to not block).

Returns:

  • 0 if there is no data waiting
  • 1 if there is data waiting
  • -1 if something went wrong

int PlayerClient::Read bool  await_sync = true,
ClientProxy **  dev = NULL
 

Use this method to read data from the server, blocking until at least one message is received. Use PlayerClient::Peek() to check whether any data is currently waiting.

If await_sync is true, Read() will read one round of data; that is, it will read until a SYNC packet is received from the server. If await_sync is false, then Read() will return after reading one message, which could be either a data message or a SYNC.

Depending on which data delivery mode is in use, new data may or may not be received for each open device. The data that is received for each device device will be processed by the appropriate device proxy and stored there for access by your program. If no errors occurred 0 is returned. Otherwise, -1 is returned and diagnostic information is printed to stderr (you should probably close the connection!).

int PlayerClient::Write player_device_id_t  device_id,
const char *  command,
size_t  commandlen
 

Write a command to the server. This method is not intended for direct use. Rather, device proxies should implement higher-level methods atop this one. Returns 0 on success, -1 otherwise.

int PlayerClient::Request player_device_id_t  device_id,
const char *  payload,
size_t  payloadlen,
player_msghdr_t replyhdr,
char *  reply,
size_t  replylen
 

Send a request to the server. This method is not intended for direct use. Rather, device proxies should implement higher-level methods atop this one. Returns 0 on success, -1 otherwise.

int PlayerClient::Request player_device_id_t  device_id,
const char *  payload,
size_t  payloadlen
 

Another form of Request(), this one can be used if the caller is not interested in the reply. This method is not intended for direct use. Rather, device proxies should implement higher-level methods atop this one. Returns 0 if an ACK is received, -1 otherwise.

int PlayerClient::RequestDeviceAccess player_device_id_t  device_id,
unsigned char  req_access,
unsigned char *  grant_access,
char *  driver_name = NULL,
int  driver_name_len = 0
 

Request access to a device; meant mostly for use by client-side device proxy constructors. req_access is requested access. grant_access, if non-NULL, will be filled with the granted access. Returns 0 if everything went OK or -1 if something went wrong.

int PlayerClient::SetFrequency unsigned short  freq  ) 
 

You can change the rate at which your client receives data from the server with this method. The value of freq is interpreted as Hz; this will be the new rate at which your client receives data (when in continuous mode). On error, -1 is returned; otherwise 0.

int PlayerClient::SetDataMode unsigned char  mode  ) 
 

You can toggle the mode in which the server sends data to your client with this method. The mode should be one of

  • PLAYER_DATAMODE_PUSH_ALL (all data at fixed frequency)
  • PLAYER_DATAMODE_PULL_ALL (all data on demand)
  • PLAYER_DATAMODE_PUSH_NEW (only new new data at fixed freq)
  • PLAYER_DATAMODE_PULL_NEW (only new data on demand)
  • PLAYER_DATAMODE_PUSH_ASYNC (new data, as fast as it is produced) On error, -1 is returned; otherwise 0.

int PlayerClient::RequestData  ) 
 

When in a PULL data delivery mode, you can request a single round of data using this method. On error -1 is returned; otherwise 0.

int PlayerClient::Authenticate char *  key  ) 
 

Attempt to authenticate your client using the provided key. If authentication fails, the server will close your connection.

int PlayerClient::LookupPort const char *  name  ) 
 

Documentation on LookupPort goes here

void PlayerClient::AddProxy ClientProxy proxy  ) 
 

void PlayerClient::RemoveProxy ClientProxy proxy  ) 
 

int PlayerClient::GetDeviceList  ) 
 


Member Data Documentation

player_connection_t PlayerClient::conn
 

bool PlayerClient::connected
 

bool PlayerClient::fresh
 

Flag set if data has just been read into one or more of this clients' open devices. If you use it, you must set it to false yourself after examining the data.

char PlayerClient::hostname[256]
 

The host of the Player server to which we are connected.

int PlayerClient::port
 

The port of the Player server to which we are connected.

struct in_addr PlayerClient::hostaddr
 

struct timeval PlayerClient::timestamp
 

The latest time received from the server.

int PlayerClient::id_count
 

List of ids for available devices. This list is villed in by GetDeviceList()

player_device_id_t PlayerClient::ids[PLAYER_MAX_DEVICES]
 

char PlayerClient::drivernames[PLAYER_MAX_DEVICES][PLAYER_MAX_DEVICE_STRING_LEN]
 


The documentation for this class was generated from the following file:
Generated on Tue May 3 14:16:05 2005 for Player by doxygen 1.3.6