Classes | Public Types | Public Member Functions | Static Public Attributes

CxUtils::MessageClient Class Reference

Client interface to subscribe to/get messages from the MessageServer class. All messages are received through shared memory and can work between processes. More...

#include <messageclient.h>

List of all members.

Classes

class  Callback
 Callback class used for getting messages received by the client. More...

Public Types

typedef MappedMemory::ID ID
 ID Field.

Public Member Functions

 MessageClient ()
 Constructor.
 ~MessageClient ()
 Destructor.
int Initialize (const std::string &serverID, const ID clientID=AnyID, const unsigned int messageBoxSize=MappedMessageBox::DefaultSize, const bool mustConnect=true)
 Initializes the client by making a connection to a message server.
int Initialize (const ID serverID, const ID clientID, const unsigned int messageBoxSize=MappedMessageBox::DefaultSize, const bool mustConnect=true)
 Initializes the client by making a connection to a message server.
int Initialize (const ID clientID, const unsigned int messageBoxSize=MappedMessageBox::DefaultSize)
 Initializes a MessageBox that does not connect to a server. This is useful because this method will create a MessageBox with a thread continuously reading from it.
void Shutdown ()
 Closes client connection and removes from Message Server registry.
bool IsInitialized () const
bool ReadMessage (Packet &message) const
 Reads the next message received by the client.
bool ReadMessage (std::string &message) const
 Reads the next message received by the client.
bool RegisterCallback (Callback *callback)
 Register a callback to be run whenever a new message is received.
bool RegisterCallback (const Callback::Function &callback)
 Register a function callback to be run whenever a new message is received.
void RemoveCallback (Callback *callback)
 Remove a registered callback.
void RemoveCallback (const Callback::Function &callback)
 Remove a registered callback.
bool IsConnected (const unsigned int thresholdMs=500) const
 Check if we are connected to an active server.
void SetUpdateDelayMs (const unsigned int delayTimeMs=0)
 Sets how quickly to check for data (0) is default.
ID GetID () const

Static Public Attributes

static const ID AnyID = 0
 Use any available ID.

Detailed Description

Client interface to subscribe to/get messages from the MessageServer class. All messages are received through shared memory and can work between processes.

Definition at line 60 of file messageclient.h.


Member Typedef Documentation

ID Field.

Definition at line 63 of file messageclient.h.


Constructor & Destructor Documentation

MessageClient::MessageClient (  )

Constructor.

Definition at line 138 of file messageclient.cpp.

MessageClient::~MessageClient (  )

Destructor.

Definition at line 151 of file messageclient.cpp.


Member Function Documentation

ID CxUtils::MessageClient::GetID (  ) const [inline]

Definition at line 121 of file messageclient.h.

int MessageClient::Initialize ( const ID  serverID,
const ID  clientID,
const unsigned int  messageBoxSize = MappedMessageBox::DefaultSize,
const bool  mustConnect = true 
)

Initializes the client by making a connection to a message server.

Parameters:
[in]serverIDThe ID of the server to try and connect to.
[in]clientIDThe ID to assign to your client, set to AnyID if you don't care.
[in]messageBoxSizeSize in bytes to make your internal receive buffer in shared memory. Make this value larger or smaller depending on the volume and size of messages you expect to receive.
[in]mustConnectIf true, then we must successfully open a connection to a MessageServer. If false, then the client will try to connect on it's own as soon as the server is available.
Returns:
1 on success, 0 on failure.

Definition at line 176 of file messageclient.cpp.

int MessageClient::Initialize ( const std::string &  serverID,
const ID  clientID = AnyID,
const unsigned int  messageBoxSize = MappedMessageBox::DefaultSize,
const bool  mustConnect = true 
)

Initializes the client by making a connection to a message server.

Parameters:
[in]serverIDThe ID of the server to try and connect to.
[in]clientIDThe ID to assign to your client, set to AnyID if you don't care.
[in]messageBoxSizeSize in bytes to make your internal receive buffer in shared memory. Make this value larger or smaller depending on the volume and size of messages you expect to receive.
[in]mustConnectIf true, then we must successfully open a connection to a MessageServer. If false, then the client will try to connect on it's own as soon as the server is available.
Returns:
1 on success, 0 on failure.

Definition at line 206 of file messageclient.cpp.

int MessageClient::Initialize ( const ID  clientID,
const unsigned int  messageBoxSize = MappedMessageBox::DefaultSize 
)

Initializes a MessageBox that does not connect to a server. This is useful because this method will create a MessageBox with a thread continuously reading from it.

Parameters:
[in]clientIDThe ID to use for the creation of a MessageBox.
[in]messageBoxSizeSize in bytes to make your internal receive buffer in shared memory. Make this value larger or smaller depending on the volume and size of messages you expect to receive.
Returns:
1 on success, 0 on failure.

Definition at line 309 of file messageclient.cpp.

bool CxUtils::MessageClient::IsConnected ( const unsigned int  thresholdMs = 500 ) const [inline]

Check if we are connected to an active server.

Definition at line 119 of file messageclient.h.

bool MessageClient::IsInitialized (  ) const
Returns:
True if initialized, false otherwise.

Definition at line 374 of file messageclient.cpp.

bool MessageClient::ReadMessage ( std::string &  message ) const

Reads the next message received by the client.

Parameters:
[in]messageThe message contents read.
Returns:
True on success, false on failure.

Definition at line 413 of file messageclient.cpp.

bool MessageClient::ReadMessage ( Packet message ) const

Reads the next message received by the client.

Parameters:
[in]messageThe message contents read.
Returns:
True on success, false on failure.

Definition at line 389 of file messageclient.cpp.

bool MessageClient::RegisterCallback ( const Callback::Function callback )

Register a function callback to be run whenever a new message is received.

Parameters:
[in]callbackFunction callback data.
Returns:
True on success, false on failure.

Definition at line 464 of file messageclient.cpp.

bool MessageClient::RegisterCallback ( Callback callback )

Register a callback to be run whenever a new message is received.

Parameters:
[in]callbackPointer to callback to be run.
Returns:
True on success, false on failure.

Definition at line 438 of file messageclient.cpp.

void MessageClient::RemoveCallback ( Callback callback )

Remove a registered callback.

Parameters:
[in]callbackCallback data to remove.

Definition at line 496 of file messageclient.cpp.

void MessageClient::RemoveCallback ( const Callback::Function callback )

Remove a registered callback.

Parameters:
[in]callbackCallback data to remove.

Definition at line 516 of file messageclient.cpp.

void MessageClient::SetUpdateDelayMs ( const unsigned int  delayTimeMs = 0 )

Sets how quickly to check for data (0) is default.

Sets the polling frequency for Interprocess Communication.

Parameters:
[in]delayTimeMsHow long to wait in ms between checks for new data. Set to 0 for no wait.

Definition at line 543 of file messageclient.cpp.

void MessageClient::Shutdown (  )

Closes client connection and removes from Message Server registry.

Callbacks are not cleared by this method.

Definition at line 352 of file messageclient.cpp.


Member Data Documentation

const ID CxUtils::MessageClient::AnyID = 0 [static]

Use any available ID.

Definition at line 64 of file messageclient.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines