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... | |
SocketHandler & | operator() (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... | |
Implements polling and configurable routing between an arbitrary number of (pre-constructed) zeromq sockets. Functionality is attached through a signal interface.
void stateline::comms::SocketRouter::add_socket | ( | SocketID | idx, |
std::unique_ptr< zmq::socket_t > & | socket | ||
) |
Add a socket to be controlled by the router.
idx | The SocketID index that will refer to the socket |
socket | The 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.
id | The socket ID of the socket. |
Receive a message from a socket.
id | The socket ID. |
Send a message through a socket.
id | The socket ID. |
msg | The 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.