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>
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. |
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.
ID Field.
Definition at line 63 of file messageclient.h.
MessageClient::MessageClient | ( | ) |
Constructor.
Definition at line 138 of file messageclient.cpp.
MessageClient::~MessageClient | ( | ) |
Destructor.
Definition at line 151 of file messageclient.cpp.
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.
[in] | serverID | The ID of the server to try and connect to. |
[in] | clientID | The ID to assign to your client, set to AnyID if you don't care. |
[in] | messageBoxSize | Size 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] | mustConnect | If 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. |
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.
[in] | serverID | The ID of the server to try and connect to. |
[in] | clientID | The ID to assign to your client, set to AnyID if you don't care. |
[in] | messageBoxSize | Size 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] | mustConnect | If 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. |
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.
[in] | clientID | The ID to use for the creation of a MessageBox. |
[in] | messageBoxSize | Size 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. |
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 |
Definition at line 374 of file messageclient.cpp.
bool MessageClient::ReadMessage | ( | std::string & | message ) | const |
Reads the next message received by the client.
[in] | message | The message contents read. |
Definition at line 413 of file messageclient.cpp.
bool MessageClient::ReadMessage | ( | Packet & | message ) | const |
Reads the next message received by the client.
[in] | message | The message contents read. |
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.
[in] | callback | Function callback data. |
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.
[in] | callback | Pointer to callback to be run. |
Definition at line 438 of file messageclient.cpp.
void MessageClient::RemoveCallback | ( | Callback * | callback ) |
Remove a registered callback.
[in] | callback | Callback data to remove. |
Definition at line 496 of file messageclient.cpp.
void MessageClient::RemoveCallback | ( | const Callback::Function & | callback ) |
Remove a registered callback.
[in] | callback | Callback 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.
[in] | delayTimeMs | How 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.
const ID CxUtils::MessageClient::AnyID = 0 [static] |
Use any available ID.
Definition at line 64 of file messageclient.h.