RSB
0.7.0
|
A wrapper class providing an object-oriented interface to the Spread API. More...
#include <SpreadConnection.h>
Public Member Functions | |
SpreadConnection (const std::string &prefix, const std::string &host=defaultHost(), unsigned int port=defaultPort()) | |
virtual | ~SpreadConnection () |
void | interruptReceive () |
Interrupts a potential receiver blocking in the read call some time after this call. | |
bool | isActive () |
Tells if this instance is connected to spread daemon. | |
unsigned long | getMsgCount () |
Returns number of messages sent. | |
mailbox * | getMailbox () |
Returns the internally used mailbox for other low-level functions. | |
connection state management | |
| |
void | activate () |
Activates the connection and thereby connects to the spread daemon as configured in the constructor. | |
void | deactivate () |
Disconnects from the daemon. | |
fundamental message exchange | |
void | send (const SpreadMessage &msg) |
Sends a message on spread. | |
void | receive (SpreadMessagePtr sm) |
Tries to receive the next message from this connection and blocks until it is available. |
Private Member Functions | |
std::string | generateId (const std::string &prefix) |
Private Attributes | |
rsc::logging::LoggerPtr | logger |
volatile bool | connected |
A flag to indicate whether we are connected to spread. | |
mailbox | con |
Handle to the internal spread connection. | |
std::string | host |
Host for the spread daemon. | |
unsigned int | port |
Port for the spread daemon. | |
std::string | spreadname |
The name of the daemon. | |
std::string | spreadpg |
Private name of this connection. | |
std::string | conId |
User-defined name to be used for this spread connection. | |
unsigned long | msgCount |
Number of message sent via this connection. |
A wrapper class providing an object-oriented interface to the Spread API.
Definition at line 58 of file SpreadConnection.h.
rsb::spread::SpreadConnection::SpreadConnection | ( | const std::string & | prefix, |
const std::string & | host = defaultHost() , |
||
unsigned int | port = defaultPort() |
||
) |
Definition at line 53 of file SpreadConnection.cpp.
References conId, logger, and spreadname.
|
virtual |
Definition at line 69 of file SpreadConnection.cpp.
References connected, deactivate(), and logger.
void rsb::spread::SpreadConnection::activate | ( | ) |
Activates the connection and thereby connects to the spread daemon as configured in the constructor.
CommException | error connecting to the daemon |
rsc::misc::IllegalStateException | already activated |
Definition at line 76 of file SpreadConnection.cpp.
References con, conId, connected, logger, spreadname, and spreadpg.
void rsb::spread::SpreadConnection::deactivate | ( | ) |
Disconnects from the daemon.
rsc::misc::IllegalStateException | already deactivated |
Definition at line 134 of file SpreadConnection.cpp.
References conId, and connected.
Referenced by ~SpreadConnection().
|
private |
Definition at line 321 of file SpreadConnection.cpp.
mailbox * rsb::spread::SpreadConnection::getMailbox | ( | ) |
unsigned long rsb::spread::SpreadConnection::getMsgCount | ( | ) |
Returns number of messages sent.
Definition at line 330 of file SpreadConnection.cpp.
References msgCount.
void rsb::spread::SpreadConnection::interruptReceive | ( | ) |
Interrupts a potential receiver blocking in the read call some time after this call.
The receiver may receive all queued messages before being interrupted.
rsc::misc::IllegalStateException | connection was not active |
Definition at line 310 of file SpreadConnection.cpp.
bool rsb::spread::SpreadConnection::isActive | ( | ) |
Tells if this instance is connected to spread daemon.
true
if connected Definition at line 145 of file SpreadConnection.cpp.
References connected.
void rsb::spread::SpreadConnection::receive | ( | SpreadMessagePtr | sm | ) |
Tries to receive the next message from this connection and blocks until it is available.
sm | out parameter with the message to fill with the read contents |
rsc::misc::IllegalStateException | connection was not active |
CommException | communication error receiving a message |
boost::thread_interrupted | if receiving was interrupted using interruptReceive |
Definition at line 149 of file SpreadConnection.cpp.
References con, conId, connected, logger, rsb::spread::SpreadMessage::MEMBERSHIP, rsb::spread::SpreadMessage::REGULAR, SPREAD_MAX_GROUPS, SPREAD_MAX_MESSLEN, and spreadpg.
void rsb::spread::SpreadConnection::send | ( | const SpreadMessage & | msg | ) |
Sends a message on spread.
msg | message to send |
rsc::misc::IllegalStateException | connection was not active |
CommException | communication error sending the message |
Definition at line 246 of file SpreadConnection.cpp.
References con, conId, connected, rsb::spread::SpreadMessage::getData(), rsb::spread::SpreadMessage::getGroupCount(), rsb::spread::SpreadMessage::getGroupsBegin(), rsb::spread::SpreadMessage::getGroupsEnd(), rsb::spread::SpreadMessage::getQOS(), rsb::spread::SpreadMessage::getSize(), logger, and msgCount.
|
private |
Handle to the internal spread connection.
Definition at line 166 of file SpreadConnection.h.
Referenced by activate(), getMailbox(), interruptReceive(), receive(), and send().
|
private |
User-defined name to be used for this spread connection.
Definition at line 188 of file SpreadConnection.h.
Referenced by activate(), deactivate(), getMailbox(), interruptReceive(), receive(), send(), and SpreadConnection().
|
private |
A flag to indicate whether we are connected to spread.
Definition at line 162 of file SpreadConnection.h.
Referenced by activate(), deactivate(), getMailbox(), interruptReceive(), isActive(), receive(), send(), and ~SpreadConnection().
|
private |
Host for the spread daemon.
Definition at line 170 of file SpreadConnection.h.
|
private |
Definition at line 158 of file SpreadConnection.h.
Referenced by activate(), receive(), send(), SpreadConnection(), and ~SpreadConnection().
|
private |
Number of message sent via this connection.
Definition at line 192 of file SpreadConnection.h.
Referenced by getMsgCount(), and send().
|
private |
Port for the spread daemon.
Definition at line 174 of file SpreadConnection.h.
|
private |
The name of the daemon.
Can consists of port and host, e.g. 4803@localhost or only a port. See SP_connect(3) man-page for details.
Definition at line 180 of file SpreadConnection.h.
Referenced by activate(), and SpreadConnection().
|
private |
Private name of this connection.
Definition at line 184 of file SpreadConnection.h.
Referenced by activate(), interruptReceive(), and receive().