PlayerCc::PlayerClient Class Reference

The PlayerClient is used for communicating with the player server. More...

#include <playerclient.h>

Collaboration diagram for PlayerCc::PlayerClient:
Collaboration graph

Detailed Description

The PlayerClient is used for communicating with the player server.

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.

Since the threading functionality of the PlayerClient is built on Boost, these options are conditionally available based on the Boost threading library being present on the system. The StartThread() and StopThread() are the only functions conditionally available based on this.

Public Member Functions

 PlayerClient (const std::string aHostname=PLAYER_HOSTNAME, uint32_t aPort=PLAYER_PORTNUM, int transport=PLAYERC_TRANSPORT_TCP)
 Make a client and connect it as indicated.
 
 ~PlayerClient ()
 destructor
 
bool Connected ()
 Query connection to Player server. More...
 
void StartThread ()
 Start the run thread.
 
void StopThread ()
 Stop the run thread.
 
void Run (uint32_t aTimeout=10)
 This starts a blocking loop on Read()
 
void Stop ()
 Stops the Run() loop.
 
bool Peek (uint32_t timeout=0)
 Check whether there is data waiting on the connection, blocking for up to timeout milliseconds (set to 0 to not block). More...
 
void SetRequestTimeout (uint32_t seconds)
 Set the timeout for client requests.
 
void SetRetryLimit (int limit)
 Set connection retry limit, which is the number of times that we'll try to reconnect to the server after a socket error. More...
 
int GetRetryLimit ()
 Get connection retry limit, which is the number of times that we'll try to reconnect to the server after a socket error. More...
 
void SetRetryTime (double time)
 Set connection retry time, which is number of seconds to wait between reconnection attempts. More...
 
double GetRetryTime ()
 Get connection retry time, which is number of seconds to wait between reconnection attempts. More...
 
void Read ()
 A blocking Read. More...
 
void ReadIfWaiting ()
 A nonblocking Read. More...
 
void SetDataMode (uint32_t aMode)
 Set whether the client operates in Push/Pull modes. More...
 
void SetReplaceRule (bool aReplace, int aType=-1, int aSubtype=-1, int aInterf=-1)
 Set a replace rule for the clients queue on the server. More...
 
void RequestDeviceList ()
 Get the list of available device ids. More...
 
std::list< playerc_device_info_tGetDeviceList ()
 
std::string GetHostname () const
 Returns the hostname.
 
uint32_t GetPort () const
 Returns the port.
 
int LookupCode (std::string aName) const
 Get the interface code for a given name.
 
std::string LookupName (int aCode) const
 Get the name for a given interface code.
 
uint32_t GetOverflowCount ()
 Get count of the number of discarded messages on the server since the last call to this method.
 

Public Attributes

mutex_t mMutex
 A mutex for handling synchronization.
 

Private Types

typedef boost::thread thread_t
 
typedef boost::mutex mutex_t
 

Private Member Functions

void Connect (const std::string aHostname, uint32_t aPort)
 
void Disconnect ()
 
void RunThread ()
 

Private Attributes

std::list< PlayerCc::ClientProxy * > mProxyList
 
std::list< playerc_device_info_tmDeviceList
 
playerc_client_tmClient
 
std::string mHostname
 
uint32_t mPort
 
unsigned int mTransport
 
bool mIsStop
 
thread_tmThread
 

Member Function Documentation

◆ Connected()

bool PlayerCc::PlayerClient::Connected ( )
inline

Query connection to Player server.

Check if the PlayerClient is currently connected to the server.

Returns
true if connected, false if not.

References _playerc_client_t::connected.

◆ GetRetryLimit()

int PlayerCc::PlayerClient::GetRetryLimit ( )
inline

Get connection retry limit, which is the number of times that we'll try to reconnect to the server after a socket error.

References _playerc_client_t::retry_limit.

◆ GetRetryTime()

double PlayerCc::PlayerClient::GetRetryTime ( )
inline

Get connection retry time, which is number of seconds to wait between reconnection attempts.

References _playerc_client_t::retry_time.

◆ Peek()

bool PlayerCc::PlayerClient::Peek ( uint32_t  timeout = 0)

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

Returns
  • false if there is no data waiting
  • true if there is data waiting

◆ Read()

void PlayerCc::PlayerClient::Read ( )

A blocking Read.

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. In pull mode, this will block until all data waiting on the server has been received, ensuring as up to date data as possible.

◆ ReadIfWaiting()

void PlayerCc::PlayerClient::ReadIfWaiting ( )

A nonblocking Read.

Use this method if you want to read in a nonblocking manner. This is the equivalent of checking if Peek is true and then reading

◆ RequestDeviceList()

void PlayerCc::PlayerClient::RequestDeviceList ( )

Get the list of available device ids.

The data is written into the proxy structure rather than retured to the caller.

◆ SetDataMode()

void PlayerCc::PlayerClient::SetDataMode ( uint32_t  aMode)

Set whether the client operates in Push/Pull modes.

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

Exceptions
throwsPlayerError if unsuccessfull

◆ SetReplaceRule()

void PlayerCc::PlayerClient::SetReplaceRule ( bool  aReplace,
int  aType = -1,
int  aSubtype = -1,
int  aInterf = -1 
)

Set a replace rule for the clients queue on the server.

If a rule with the same pattern already exists, it will be replaced with the new rule (i.e., its setting to replace will be updated).

Parameters
aReplaceShould we replace these messages? true/false
aTypetype of message to set replace rule for (-1 for wildcard). See Message types.
aSubtypemessage subtype to set replace rule for (-1 for wildcard).
aInterfInterface to set replace rule for (-1 for wildcard). This can be used to set the replace rule for all members of a certain interface type. See Interface specifications.
Exceptions
throwsPlayerError if unsuccessful
See also
ClientProxy::SetReplaceRule, PlayerClient::SetDataMode

◆ SetRetryLimit()

void PlayerCc::PlayerClient::SetRetryLimit ( int  limit)
inline

Set connection retry limit, which is the number of times that we'll try to reconnect to the server after a socket error.

Set to -1 for inifinite retry.

References playerc_client_set_retry_limit().

Here is the call graph for this function:

◆ SetRetryTime()

void PlayerCc::PlayerClient::SetRetryTime ( double  time)
inline

Set connection retry time, which is number of seconds to wait between reconnection attempts.

References playerc_client_set_retry_time().

Here is the call graph for this function:

The documentation for this class was generated from the following file: