Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ZeroMQSvc Class Reference

Wrapper class for basic ZeroMQ context and socket management.

This singleton class wraps a couple of basic ZeroMQ tasks:

  1. Creating, storing and eventually closing a ZeroMQ context.
  2. Creating new sockets in the context.
  3. Sending, receiving, encoding and decoding messages over sockets.

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

#include </home/sftnight/build/workspace/root-makedoc-v630/rootspi/rdoc/src/v6-30-00-patches/roofit/roofitZMQ/res/RooFit_ZMQ/ZeroMQSvc.h>

Member Enumeration Documentation

◆ Encoding

Enumerator
Text 
Binary 

Definition at line 128 of file ZeroMQSvc.h.

Member Function Documentation

◆ close_context()

void ZeroMQSvc::close_context ( ) const

Definition at line 114 of file ZeroMQSvc.cpp.

◆ context()

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.

◆ decode() [1/2]

template<class T , typename std::enable_if<!std::is_pointer< T >::value &&ZMQ::Detail::is_trivial< T >::value, T >::type * = nullptr>
T ZeroMQSvc::decode ( const zmq::message_t &  msg) const
inline

decode message with ZMQ, POD version

Definition at line 140 of file ZeroMQSvc.h.

◆ decode() [2/2]

template<class T , typename std::enable_if< std::is_same< T, std::string >::value, T >::type * = nullptr>
std::string ZeroMQSvc::decode ( const zmq::message_t &  msg) const
inline

decode ZMQ message, string version

Definition at line 149 of file ZeroMQSvc.h.

◆ encode() [1/3]

zmq::message_t ZeroMQSvc::encode ( const char *  item) const

Encode string as a ZeroMQ message object.

Parameters
[in]itemString.

Definition at line 128 of file ZeroMQSvc.cpp.

◆ encode() [2/3]

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.

◆ encode() [3/3]

template<class T , typename std::enable_if<!std::is_pointer< T >::value &&ZMQ::Detail::is_trivial< T >::value, T >::type * = nullptr>
zmq::message_t ZeroMQSvc::encode ( const T &  item,
std::function< size_t(const T &t)>  sizeFun = ZMQ::defaultSizeOf<T> 
) const
inline

encode message to ZMQ

Definition at line 192 of file ZeroMQSvc.h.

◆ encoding()

ZeroMQSvc::Encoding ZeroMQSvc::encoding ( ) const

Definition at line 43 of file ZeroMQSvc.cpp.

◆ receive() [1/2]

template<class T , typename std::enable_if<!(std::is_same< zmq::message_t, T >::value), T >::type * = nullptr>
T ZeroMQSvc::receive ( zmq::socket_t &  socket,
zmq::recv_flags  flags = zmq::recv_flags::none,
bool more = nullptr 
) const
inline

receive message with ZMQ, general version

Definition at line 159 of file ZeroMQSvc.h.

◆ receive() [2/2]

template<class T , typename std::enable_if< std::is_same< zmq::message_t, T >::value, T >::type * = nullptr>
T ZeroMQSvc::receive ( zmq::socket_t &  socket,
zmq::recv_flags  flags = zmq::recv_flags::none,
bool more = nullptr 
) const
inline

receive message with ZMQ

Definition at line 176 of file ZeroMQSvc.h.

◆ send() [1/4]

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.

Parameters
[in]socketSocket.
[in]itemMessage to send over.
[in]flagsFlags 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.
Returns
An optional of type zmq::send_result_t that contains the number of bytes sent if successful, and is empty if EAGAIN was received, which probably means you should try again.

Definition at line 153 of file ZeroMQSvc.cpp.

◆ send() [2/4]

template<class T , typename std::enable_if<!std::is_same< T, zmq::message_t >::value, T >::type * = nullptr>
zmq::send_result_t ZeroMQSvc::send ( zmq::socket_t &  socket,
const T &  item,
zmq::send_flags  flags = zmq::send_flags::none 
) const
inline

Send message with ZMQ.

Definition at line 205 of file ZeroMQSvc.h.

◆ send() [3/4]

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.

◆ send() [4/4]

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.

◆ setEncoding()

void ZeroMQSvc::setEncoding ( const Encoding e)

Set encoding mode.

Parameters
[in]eEncoding mode; either Text or Binary.

Definition at line 53 of file ZeroMQSvc.cpp.

◆ socket()

zmq::socket_t ZeroMQSvc::socket ( zmq::socket_type  type) const

Create and return a new socket.

Parameters
[in]typeType of the socket. See http://api.zeromq.org/master:zmq-socket for possible values.
Returns
The socket object.

Definition at line 84 of file ZeroMQSvc.cpp.

◆ socket_ptr()

zmq::socket_t * ZeroMQSvc::socket_ptr ( zmq::socket_type  type) const

Create and return a new socket by pointer.

Parameters
[in]typeType of the socket. See http://api.zeromq.org/master:zmq-socket for possible values.
Returns
A raw pointer to the socket object. Note: the caller must take ownership!

Definition at line 102 of file ZeroMQSvc.cpp.

Member Data Documentation

◆ m_context

zmq::context_t* ZeroMQSvc::m_context = nullptr
mutableprivate

Definition at line 219 of file ZeroMQSvc.h.

◆ m_enc

Encoding ZeroMQSvc::m_enc = Text
private

Definition at line 218 of file ZeroMQSvc.h.

  • roofit/roofitZMQ/res/RooFit_ZMQ/ZeroMQSvc.h
  • roofit/roofitZMQ/src/ZeroMQSvc.cpp