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

CxUtils::MessageServer Class Reference

Class to create a server that can detect clients processes and distribute messages to them using mapped/shared memory. More...

#include <messageserver.h>

List of all members.

Classes

class  Registry
 Registry to keep track of clients who want to receive data from the Message Server. Message Clients must register themselves to receive data from the Message Server. More...

Public Types

typedef MappedMemory::ID ID
 ID Field.
typedef std::set< IDList
 Client/Registry list information.

Public Member Functions

 MessageServer ()
 Constructor.
 ~MessageServer ()
 Destructor.
int Initialize (const ID serverID, const unsigned int maxClients=DefaultMaxClients)
 Initializes the MessageServer.
int Initialize (const std::string &serverID, const unsigned int maxClients=DefaultMaxClients)
 Initializes the MessageServer.
void Shutdown ()
 Stops the server and releases all connections to clients and registry.
bool CreateConnection (const ID id)
 Optional method to force a connection attempt to a specific ID number.
bool SendToClient (const ID id, const std::string &message)
 Sends a message to a specific subscribing client ID.
bool SendToClient (const ID id, const Packet &message)
 Sends a message to a specific subscribing client ID.
bool SendToAllClients (const std::string &message)
 Sends a message to all subscribing clients.
bool SendToAllClients (const Packet &message)
 Sends a message to all subscribing clients.
bool GetClientList (List &clients) const
 Get a list of all connected client IDs.
unsigned int GetNumClients () const
bool IsInitialized () const

Static Public Member Functions

static bool IsServerPresent (const std::string &serverID)
 Method used to check if a server is running on the host machine.

Static Public Attributes

static const unsigned int DefaultMaxClients = 25
 Default value for max num of clients.

Detailed Description

Class to create a server that can detect clients processes and distribute messages to them using mapped/shared memory.

The Message Server acts as the single point of entry for message data that needs to be distributed. Message Clients (MessageClient class) can register to receive these message as they arrive.

Definition at line 62 of file messageserver.h.


Member Typedef Documentation

ID Field.

Definition at line 66 of file messageserver.h.

typedef std::set<ID> CxUtils::MessageServer::List

Client/Registry list information.

Definition at line 67 of file messageserver.h.


Constructor & Destructor Documentation

MessageServer::MessageServer (  )

Constructor.

Definition at line 496 of file messageserver.cpp.

MessageServer::~MessageServer (  )

Destructor.

Definition at line 506 of file messageserver.cpp.


Member Function Documentation

bool MessageServer::CreateConnection ( const ID  id )

Optional method to force a connection attempt to a specific ID number.

The MessageServer class will automatically find and connect to MessageClients running on the host machine, however if it has not detected the connection yet, it is possible to force one using this interface.

Parameters:
[in]idThe ID of the MessageClient to try create a connection to.
Returns:
True on success, false on failure.

Definition at line 627 of file messageserver.cpp.

bool MessageServer::GetClientList ( List clients ) const

Get a list of all connected client IDs.

Parameters:
[in]clientsList of active client connections.
Returns:
True on success, false on failure.

Definition at line 768 of file messageserver.cpp.

unsigned int MessageServer::GetNumClients (  ) const
Returns:
Number of active client connections.

Definition at line 791 of file messageserver.cpp.

int MessageServer::Initialize ( const ID  serverID,
const unsigned int  maxClients = DefaultMaxClients 
)

Initializes the MessageServer.

Parameters:
[in]serverIDName of server to use (all clients must use this name to connect). For maximum portability between Windows and Linux, use an integer (in Windows you can use any string).
[in]maxClientsMaximum number of clients to allow connections to server (default is 25).
Returns:
1 on success, 0 on failure.

Definition at line 525 of file messageserver.cpp.

int MessageServer::Initialize ( const std::string &  serverID,
const unsigned int  maxClients = DefaultMaxClients 
)

Initializes the MessageServer.

Parameters:
[in]serverIDName of server to use (all clients must use this name to connect). For maximum portability between Windows and Linux, use an integer (in Windows you can use any string).
[in]maxClientsMaximum number of clients to allow connections to server (default is 25).
Returns:
1 on success, 0 on failure.

Definition at line 548 of file messageserver.cpp.

bool MessageServer::IsInitialized (  ) const
Returns:
True if the server is initialized and running, otherwise false.

Definition at line 806 of file messageserver.cpp.

bool MessageServer::IsServerPresent ( const std::string &  serverID ) [static]

Method used to check if a server is running on the host machine.

Parameters:
[in]serverIDThe name/ID of the server to check for.
Returns:
True if the server is active and running, false otherwise.

Definition at line 825 of file messageserver.cpp.

bool MessageServer::SendToAllClients ( const Packet message )

Sends a message to all subscribing clients.

Parameters:
[in]messageThe message data to send.
Returns:
True on success, false on failure.

Definition at line 718 of file messageserver.cpp.

bool MessageServer::SendToAllClients ( const std::string &  message )

Sends a message to all subscribing clients.

Parameters:
[in]messageThe message data to send.
Returns:
True on success, false on failure.

Definition at line 743 of file messageserver.cpp.

bool MessageServer::SendToClient ( const ID  id,
const std::string &  message 
)

Sends a message to a specific subscribing client ID.

Parameters:
[in]idThe ID of the client to send the message to.
[in]messageThe message data to send.
Returns:
True on success, false on failure.

Definition at line 694 of file messageserver.cpp.

bool MessageServer::SendToClient ( const ID  id,
const Packet message 
)

Sends a message to a specific subscribing client ID.

Parameters:
[in]idThe ID of the client to send the message to.
[in]messageThe message data to send.
Returns:
True on success, false on failure.

Definition at line 669 of file messageserver.cpp.

void MessageServer::Shutdown (  )

Stops the server and releases all connections to clients and registry.

Definition at line 590 of file messageserver.cpp.


Member Data Documentation

const unsigned int CxUtils::MessageServer::DefaultMaxClients = 25 [static]

Default value for max num of clients.

Definition at line 65 of file messageserver.h.


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