Wrapper class for basic ZeroMQ context and socket management.
This singleton class wraps a couple of basic ZeroMQ tasks:
For convenience, it offers a number of template overloads that automatically encode all kinds of data types in ZeroMQ message objects.
Definition at line 122 of file ZeroMQSvc.h.
Public Types | |
enum | Encoding { Text = 0 , Binary } |
Public Member Functions | |
void | close_context () const |
zmq::context_t & | context () const |
Get context. | |
template<class T , typename std::enable_if<!std::is_pointer< T >::value &&ZMQ::Detail::is_trivial< T >::value, T >::type * = nullptr> | |
T | decode (const zmq::message_t &msg) const |
decode message with ZMQ, POD version | |
template<class T , typename std::enable_if< std::is_same< T, std::string >::value, T >::type * = nullptr> | |
std::string | decode (const zmq::message_t &msg) const |
decode ZMQ message, string version | |
zmq::message_t | encode (const char *item) const |
Encode string as a ZeroMQ message object. | |
zmq::message_t | encode (const std::string &item) const |
template<class T , typename std::enable_if<!std::is_pointer< T >::value &&ZMQ::Detail::is_trivial< T >::value, T >::type * = nullptr> | |
zmq::message_t | encode (const T &item, std::function< size_t(const T &t)> sizeFun=ZMQ::defaultSizeOf< T >) const |
encode message to ZMQ | |
Encoding | encoding () const |
template<class T , typename std::enable_if<!(std::is_same< zmq::message_t, T >::value), T >::type * = nullptr> | |
T | receive (zmq::socket_t &socket, zmq::recv_flags flags=zmq::recv_flags::none, bool *more=nullptr) const |
receive message with ZMQ, general version | |
template<class T , typename std::enable_if< std::is_same< zmq::message_t, T >::value, T >::type * = nullptr> | |
T | receive (zmq::socket_t &socket, zmq::recv_flags flags=zmq::recv_flags::none, bool *more=nullptr) const |
receive message with ZMQ | |
zmq::send_result_t | send (zmq::socket_t &socket, const char *item, zmq::send_flags flags=zmq::send_flags::none) const |
Send message over a socket. | |
template<class T , typename std::enable_if<!std::is_same< T, zmq::message_t >::value, T >::type * = nullptr> | |
zmq::send_result_t | send (zmq::socket_t &socket, const T &item, zmq::send_flags flags=zmq::send_flags::none) const |
Send message with ZMQ. | |
zmq::send_result_t | send (zmq::socket_t &socket, zmq::message_t &&msg, zmq::send_flags flags=zmq::send_flags::none) const |
zmq::send_result_t | send (zmq::socket_t &socket, zmq::message_t &msg, zmq::send_flags flags=zmq::send_flags::none) const |
void | setEncoding (const Encoding &e) |
Set encoding mode. | |
zmq::socket_t | socket (zmq::socket_type type) const |
Create and return a new socket. | |
zmq::socket_t * | socket_ptr (zmq::socket_type type) const |
Create and return a new socket by pointer. | |
Private Attributes | |
zmq::context_t * | m_context = nullptr |
Encoding | m_enc = Text |
enum ZeroMQSvc::Encoding |
Enumerator | |
---|---|
Text | |
Binary |
Definition at line 128 of file ZeroMQSvc.h.
void ZeroMQSvc::close_context | ( | ) | const |
Definition at line 114 of file ZeroMQSvc.cpp.
zmq::context_t & ZeroMQSvc::context | ( | ) | const |
Get context.
Creates a context if it has not yet been created and returns a reference to it.
Definition at line 63 of file ZeroMQSvc.cpp.
|
inline |
decode message with ZMQ, POD version
Definition at line 140 of file ZeroMQSvc.h.
|
inline |
decode ZMQ message, string version
Definition at line 149 of file ZeroMQSvc.h.
zmq::message_t ZeroMQSvc::encode | ( | const char * | item | ) | const |
Encode string as a ZeroMQ message object.
[in] | item | String. |
Definition at line 128 of file ZeroMQSvc.cpp.
zmq::message_t ZeroMQSvc::encode | ( | const std::string & | item | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 137 of file ZeroMQSvc.cpp.
|
inline |
encode message to ZMQ
Definition at line 192 of file ZeroMQSvc.h.
ZeroMQSvc::Encoding ZeroMQSvc::encoding | ( | ) | const |
Definition at line 43 of file ZeroMQSvc.cpp.
|
inline |
receive message with ZMQ, general version
Definition at line 159 of file ZeroMQSvc.h.
|
inline |
receive message with ZMQ
Definition at line 176 of file ZeroMQSvc.h.
zmq::send_result_t ZeroMQSvc::send | ( | zmq::socket_t & | socket, |
const char * | item, | ||
zmq::send_flags | flags = zmq::send_flags::none |
||
) | const |
Send message over a socket.
[in] | socket | Socket. |
[in] | item | Message to send over. |
[in] | flags | Flags to send. See http://api.zeromq.org/master:zmq-send for possible flags and the cppzmq API for the type-safe equivalents in the zmq::send_flags enum class. |
Definition at line 153 of file ZeroMQSvc.cpp.
|
inline |
Send message with ZMQ.
Definition at line 205 of file ZeroMQSvc.h.
zmq::send_result_t ZeroMQSvc::send | ( | zmq::socket_t & | socket, |
zmq::message_t && | msg, | ||
zmq::send_flags | flags = zmq::send_flags::none |
||
) | const |
Definition at line 170 of file ZeroMQSvc.cpp.
zmq::send_result_t ZeroMQSvc::send | ( | zmq::socket_t & | socket, |
zmq::message_t & | msg, | ||
zmq::send_flags | flags = zmq::send_flags::none |
||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 161 of file ZeroMQSvc.cpp.
Set encoding mode.
[in] | e | Encoding mode; either Text or Binary. |
Definition at line 53 of file ZeroMQSvc.cpp.
zmq::socket_t ZeroMQSvc::socket | ( | zmq::socket_type | type | ) | const |
Create and return a new socket.
[in] | type | Type of the socket. See http://api.zeromq.org/master:zmq-socket for possible values. |
Definition at line 84 of file ZeroMQSvc.cpp.
zmq::socket_t * ZeroMQSvc::socket_ptr | ( | zmq::socket_type | type | ) | const |
Create and return a new socket by pointer.
[in] | type | Type of the socket. See http://api.zeromq.org/master:zmq-socket for possible values. |
Definition at line 102 of file ZeroMQSvc.cpp.
|
mutableprivate |
Definition at line 219 of file ZeroMQSvc.h.
Definition at line 218 of file ZeroMQSvc.h.