RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rsb::spread::SpreadConnection Class Reference

A wrapper class providing an object-oriented interface to the Spread API. More...

#include <SpreadConnection.h>

Collaboration diagram for rsb::spread::SpreadConnection:
Collaboration graph

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.
mailboxgetMailbox ()
 Returns the internally used mailbox for other low-level functions.
connection state management
Todo:
is this really necessary?
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.

Detailed Description

A wrapper class providing an object-oriented interface to the Spread API.

Note
this class is not thread-safe! Use it only single-threaded! The only exception to this rule is interruptReceive. It can be used to kill an asynchronously operating receiver thread on the connection.
Author
swrede
jwienke

Definition at line 58 of file SpreadConnection.h.

Constructor & Destructor Documentation

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.

rsb::spread::SpreadConnection::~SpreadConnection ( )
virtual

Definition at line 69 of file SpreadConnection.cpp.

References connected, deactivate(), and logger.

Here is the call graph for this function:

Member Function Documentation

void rsb::spread::SpreadConnection::activate ( )

Activates the connection and thereby connects to the spread daemon as configured in the constructor.

Exceptions
CommExceptionerror connecting to the daemon
rsc::misc::IllegalStateExceptionalready 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.

Precondition
there must be no more reader blocking in receive
Exceptions
rsc::misc::IllegalStateExceptionalready deactivated

Definition at line 134 of file SpreadConnection.cpp.

References conId, and connected.

Referenced by ~SpreadConnection().

Here is the caller graph for this function:

string rsb::spread::SpreadConnection::generateId ( const std::string &  prefix)
private

Definition at line 321 of file SpreadConnection.cpp.

mailbox * rsb::spread::SpreadConnection::getMailbox ( )

Returns the internally used mailbox for other low-level functions.

Returns
mailbox
Todo:
why pointer? mailbox is a typedef to int? If pointer is required use a shared ptr

Definition at line 334 of file SpreadConnection.cpp.

References con, conId, and connected.

unsigned long rsb::spread::SpreadConnection::getMsgCount ( )

Returns number of messages sent.

Returns
number of sent messages

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.

Note
this method may explicitly be called from a different thread than the one blocking in receive. Nevertheless only one other thread at a time is allowed call this method.
Exceptions
rsc::misc::IllegalStateExceptionconnection was not active

Definition at line 310 of file SpreadConnection.cpp.

References con, conId, connected, and spreadpg.

bool rsb::spread::SpreadConnection::isActive ( )

Tells if this instance is connected to spread daemon.

Returns
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.

Parameters
smout parameter with the message to fill with the read contents
Note
not all readers in different threads receive all messages, one message is only received by one thread
Exceptions
rsc::misc::IllegalStateExceptionconnection was not active
CommExceptioncommunication error receiving a message
boost::thread_interruptedif 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.

Parameters
msgmessage to send
Exceptions
rsc::misc::IllegalStateExceptionconnection was not active
CommExceptioncommunication 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.

Here is the call graph for this function:

Member Data Documentation

mailbox rsb::spread::SpreadConnection::con
private

Handle to the internal spread connection.

Definition at line 166 of file SpreadConnection.h.

Referenced by activate(), getMailbox(), interruptReceive(), receive(), and send().

std::string rsb::spread::SpreadConnection::conId
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().

volatile bool rsb::spread::SpreadConnection::connected
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().

std::string rsb::spread::SpreadConnection::host
private

Host for the spread daemon.

Definition at line 170 of file SpreadConnection.h.

rsc::logging::LoggerPtr rsb::spread::SpreadConnection::logger
private

Definition at line 158 of file SpreadConnection.h.

Referenced by activate(), receive(), send(), SpreadConnection(), and ~SpreadConnection().

unsigned long rsb::spread::SpreadConnection::msgCount
private

Number of message sent via this connection.

Definition at line 192 of file SpreadConnection.h.

Referenced by getMsgCount(), and send().

unsigned int rsb::spread::SpreadConnection::port
private

Port for the spread daemon.

Definition at line 174 of file SpreadConnection.h.

std::string rsb::spread::SpreadConnection::spreadname
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().

std::string rsb::spread::SpreadConnection::spreadpg
private

Private name of this connection.

Definition at line 184 of file SpreadConnection.h.

Referenced by activate(), interruptReceive(), and receive().


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