Obsidian
Probabilistic Geophysical Joint Inversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
stateline::comms::SocketRouter Class Reference

Implements polling and configurable routing between an arbitrary number of (pre-constructed) zeromq sockets. Functionality is attached through a signal interface. More...

#include <router.hpp>

Public Member Functions

 SocketRouter ()
 Create a new socket router.
 
 ~SocketRouter ()
 Clean up resources used by the socket router.
 
void add_socket (SocketID idx, std::unique_ptr< zmq::socket_t > &socket)
 Add a socket to be controlled by the router. More...
 
void start ()
 Start the router polling with blocking. More...
 
void start (int msPerPoll)
 Start the router polling with a polling loop frequency. More...
 
SocketHandleroperator() (const SocketID &id)
 Access the handler (ie the signal interface) for a particular socket. More...
 
void stop ()
 Stop the router from polling.
 
void send (const SocketID &id, const Message &msg)
 Send a message through a socket. More...
 
Message receive (const SocketID &id)
 Receive a message from a socket. More...
 

Detailed Description

Implements polling and configurable routing between an arbitrary number of (pre-constructed) zeromq sockets. Functionality is attached through a signal interface.

Member Function Documentation

void stateline::comms::SocketRouter::add_socket ( SocketID  idx,
std::unique_ptr< zmq::socket_t > &  socket 
)

Add a socket to be controlled by the router.

Parameters
idxThe SocketID index that will refer to the socket
socketThe unique_ptr holding the socket (we'll take it)
SocketHandler & stateline::comms::SocketRouter::operator() ( const SocketID id)

Access the handler (ie the signal interface) for a particular socket.

Parameters
idThe socket ID of the socket.
Returns
A reference to the socket callback struct.
Message stateline::comms::SocketRouter::receive ( const SocketID id)

Receive a message from a socket.

Warning
Do not use this once polling has started except from attached function callbacks (which run in the same thread as the polling loop).
Parameters
idThe socket ID.
Returns
The message received.
void stateline::comms::SocketRouter::send ( const SocketID id,
const Message msg 
)

Send a message through a socket.

Warning
Do not use this once polling has started except from attached function callbacks (which run in the same thread as the polling loop).
Parameters
idThe socket ID.
msgThe message to send.
void stateline::comms::SocketRouter::start ( )

Start the router polling with blocking.

It is critical that the send and receive calls are only used from functions connected to the signals once polling is started. This is because the sockets themselves are not thread safe.

void stateline::comms::SocketRouter::start ( int  msPerPoll)

Start the router polling with a polling loop frequency.

It is critical that the send and receive calls are only used from functions connected to the signals once polling is started. This is because the sockets themselves are not thread safe.


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