Belle II Software development
|
A helper class for communicating over ZMQ. Includes a multicast and (if needed) also a data socket. More...
#include <ZMQClient.h>
Public Member Functions | |
template<int AZMQType> | |
void | initialize (const std::string &pubSocketAddress, const std::string &subSocketAddress, const std::string &socketAddress, bool bind) |
Initialize the multicast and a data socket of the given type. | |
void | initialize (const std::string &pubSocketAddress, const std::string &subSocketAddress) |
Initialize only the multicast. | |
void | terminate (bool sendGoodbye=true) |
Terminate the sockets properly. | |
void | reset () |
Reset the sockets. ATTENTION: this does not close the sockets! Use only after forks to not clean up to times. | |
void | subscribe (EMessageTypes messageType) |
Subscribe to the given multicast message type. | |
template<class AZMQMessage > | |
void | send (AZMQMessage message) const |
Send a message over the data socket. | |
void | send (zmq::message_t &message) const |
Send a zmq message over the data socket. ATTENTION: we are taking ownership here! | |
template<class AZMQMessage > | |
void | publish (AZMQMessage message) const |
Publish the message to the multicast. | |
bool | isOnline () const |
Check if the client was initialized and not terminated. | |
template<class AMulticastAnswer , class ASocketAnswer > | |
int | poll (unsigned int timeout, AMulticastAnswer multicastAnswer, ASocketAnswer socketAnswer) const |
Poll both the multicast and the data socket until, either: | |
template<class ASocketAnswer > | |
int | pollSocket (unsigned int timeout, ASocketAnswer socketAnswer) const |
Poll method to only the data socket. | |
template<class AMulticastAnswer > | |
int | pollMulticast (unsigned int timeout, AMulticastAnswer multicastAnswer) const |
Poll method to only the multicast socket. | |
Static Private Member Functions | |
static int | pollSocketVector (const std::vector< zmq::socket_t * > &socketList, int timeout) |
Internal poll function. | |
Private Attributes | |
std::unique_ptr< zmq::context_t > | m_context |
ZMQ context. | |
std::vector< zmq::socket_t * > | m_pollSocketPtrList |
Will use this vector for polling. | |
std::unique_ptr< zmq::socket_t > | m_pubSocket |
ZMQ Pub socket. | |
std::unique_ptr< zmq::socket_t > | m_subSocket |
ZMQ sub socket. | |
std::unique_ptr< zmq::socket_t > | m_socket |
ZMQ socket. | |
A helper class for communicating over ZMQ. Includes a multicast and (if needed) also a data socket.
Definition at line 22 of file ZMQClient.h.
void initialize | ( | const std::string & | pubSocketAddress, |
const std::string & | subSocketAddress | ||
) |
Initialize only the multicast.
Definition at line 79 of file ZMQClient.cc.
template void initialize< ZMQ_PUB > | ( | const std::string & | pubSocketAddress, |
const std::string & | subSocketAddress, | ||
const std::string & | socketAddress, | ||
bool | bind | ||
) |
Initialize the multicast and a data socket of the given type.
Definition at line 53 of file ZMQClient.cc.
|
inline |
Check if the client was initialized and not terminated.
Definition at line 59 of file ZMQClient.h.
|
staticprivate |
Internal poll function.
Definition at line 118 of file ZMQClient.cc.
|
inline |
Publish the message to the multicast.
Definition at line 53 of file ZMQClient.h.
void reset | ( | ) |
Reset the sockets. ATTENTION: this does not close the sockets! Use only after forks to not clean up to times.
Definition at line 43 of file ZMQClient.cc.
|
inline |
Send a message over the data socket.
Definition at line 43 of file ZMQClient.h.
void send | ( | zmq::message_t & | message | ) | const |
Send a zmq message over the data socket. ATTENTION: we are taking ownership here!
Definition at line 108 of file ZMQClient.cc.
void subscribe | ( | EMessageTypes | messageType | ) |
Subscribe to the given multicast message type.
Definition at line 99 of file ZMQClient.cc.
void terminate | ( | bool | sendGoodbye = true | ) |
Terminate the sockets properly.
Definition at line 18 of file ZMQClient.cc.
|
private |
ZMQ context.
Definition at line 99 of file ZMQClient.h.
|
private |
Will use this vector for polling.
Definition at line 102 of file ZMQClient.h.
|
private |
ZMQ Pub socket.
Definition at line 105 of file ZMQClient.h.
|
private |
ZMQ socket.
Definition at line 109 of file ZMQClient.h.
|
private |
ZMQ sub socket.
Definition at line 107 of file ZMQClient.h.