Belle II Software development
ZMQMessageFactory Class Reference

Helper class for creating new ID/No-ID messages. More...

#include <ZMQMessageFactory.h>

Static Public Member Functions

static auto createMessage (const std::string &msgIdentity, const EMessageTypes msgType, const std::unique_ptr< EvtMessage > &eventMessage)
 Create an ID Message out of an identity, the type and an event message.
 
static auto createMessage (const std::string &msgIdentity, const EMessageTypes msgType, const std::string &msgData="")
 Create an ID Message out of an identity, the type and a string.
 
static auto createMessage (const std::string &msgIdentity, const EMessageTypes msgType, zmq::message_t msgData)
 Create an ID Message out of an identity, the type and another zmq message.
 
static auto createMessage (const std::string &msgIdentity, std::unique_ptr< ZMQNoIdMessage > shortMessage)
 Create an ID Message out of an identity and an already received message.
 
static auto createMessage (const EMessageTypes msgType, const std::string &msgData="")
 Create a No-ID Message out of an identity, the type and a string.
 
static auto createMessage (const EMessageTypes msgType, int msgData)
 Create a No-ID Message out of an identity, the type and an int.
 
static auto createMessage (const EMessageTypes msgType, const StoreObjPtr< EventMetaData > &evtMetaData)
 Create a No-ID Message out of an identity, the type and an event meta data.
 
static auto createMessage (const EMessageTypes msgType, zmq::message_t msgData)
 Create a No-ID Message out of the type and another zmq message.
 
static auto createMessage (const EMessageTypes msgType, zmq::message_t msgData, zmq::message_t additionalData)
 Create a No-ID Message out of the type, another zmq message and an additional message.
 
static auto createMessage (zmq::message_t msgType, zmq::message_t msgData)
 Create a No-ID Message out of an identity, the type and another zmq message.
 
static auto createMessage (const EMessageTypes msgType, const std::unique_ptr< EvtMessage > &eventMessage)
 Create a No-ID Message out of an identity, the type and an event message.
 
static auto createMessage (const EMessageTypes msgType, const std::unique_ptr< EvtMessage > &eventMessage, zmq::message_t additionalData)
 Create a No-ID Message out of an identity, the type, an event message, and and additional message.
 
static auto stripIdentity (std::unique_ptr< ZMQIdMessage > message)
 Create a No-ID Message out of an ID message.
 
template<class AMessage >
static std::unique_ptr< AMessage > fromSocket (const std::unique_ptr< zmq::socket_t > &socket)
 Create a message of the given type by receiving a message from the socket.
 

Static Private Member Functions

template<class T , class... Args>
static std::unique_ptr< T > createMessage (Args &&... args)
 Small helper constructor to create a unique_ptr out of some arguments, as std::make_unique is not working with protected constructors.
 

Detailed Description

Helper class for creating new ID/No-ID messages.

Definition at line 24 of file ZMQMessageFactory.h.

Member Function Documentation

◆ createMessage() [1/13]

static std::unique_ptr< T > createMessage ( Args &&...  args)
inlinestaticprivate

Small helper constructor to create a unique_ptr out of some arguments, as std::make_unique is not working with protected constructors.

Definition at line 143 of file ZMQMessageFactory.h.

144 {
145 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
146 }

◆ createMessage() [2/13]

static auto createMessage ( const EMessageTypes  msgType,
const std::string &  msgData = "" 
)
inlinestatic

Create a No-ID Message out of an identity, the type and a string.

Definition at line 59 of file ZMQMessageFactory.h.

61 {
62 return createMessage<ZMQNoIdMessage>(msgType, msgData);
63 }

◆ createMessage() [3/13]

static auto createMessage ( const EMessageTypes  msgType,
const std::unique_ptr< EvtMessage > &  eventMessage 
)
inlinestatic

Create a No-ID Message out of an identity, the type and an event message.

Definition at line 102 of file ZMQMessageFactory.h.

104 {
105 return createMessage<ZMQNoIdMessage>(msgType, eventMessage);
106 }

◆ createMessage() [4/13]

static auto createMessage ( const EMessageTypes  msgType,
const std::unique_ptr< EvtMessage > &  eventMessage,
zmq::message_t  additionalData 
)
inlinestatic

Create a No-ID Message out of an identity, the type, an event message, and and additional message.

Definition at line 109 of file ZMQMessageFactory.h.

112 {
113 return createMessage<ZMQNoIdMessage>(msgType, eventMessage, std::move(additionalData));
114 }

◆ createMessage() [5/13]

static auto createMessage ( const EMessageTypes  msgType,
const StoreObjPtr< EventMetaData > &  evtMetaData 
)
inlinestatic

Create a No-ID Message out of an identity, the type and an event meta data.

Definition at line 73 of file ZMQMessageFactory.h.

75 {
76 return createMessage<ZMQNoIdMessage>(msgType, evtMetaData);
77 }

◆ createMessage() [6/13]

static auto createMessage ( const EMessageTypes  msgType,
int  msgData 
)
inlinestatic

Create a No-ID Message out of an identity, the type and an int.

Definition at line 66 of file ZMQMessageFactory.h.

68 {
69 return createMessage<ZMQNoIdMessage>(msgType, msgData);
70 }

◆ createMessage() [7/13]

static auto createMessage ( const EMessageTypes  msgType,
zmq::message_t  msgData 
)
inlinestatic

Create a No-ID Message out of the type and another zmq message.

Definition at line 80 of file ZMQMessageFactory.h.

82 {
83 return createMessage<ZMQNoIdMessage>(msgType, std::move(msgData));
84 }

◆ createMessage() [8/13]

static auto createMessage ( const EMessageTypes  msgType,
zmq::message_t  msgData,
zmq::message_t  additionalData 
)
inlinestatic

Create a No-ID Message out of the type, another zmq message and an additional message.

Definition at line 87 of file ZMQMessageFactory.h.

90 {
91 return createMessage<ZMQNoIdMessage>(msgType, std::move(msgData), std::move(additionalData));
92 }

◆ createMessage() [9/13]

static auto createMessage ( const std::string &  msgIdentity,
const EMessageTypes  msgType,
const std::string &  msgData = "" 
)
inlinestatic

Create an ID Message out of an identity, the type and a string.

Definition at line 35 of file ZMQMessageFactory.h.

38 {
39 return createMessage<ZMQIdMessage>(msgIdentity, msgType, msgData);
40 }

◆ createMessage() [10/13]

static auto createMessage ( const std::string &  msgIdentity,
const EMessageTypes  msgType,
const std::unique_ptr< EvtMessage > &  eventMessage 
)
inlinestatic

Create an ID Message out of an identity, the type and an event message.

Definition at line 27 of file ZMQMessageFactory.h.

30 {
31 return createMessage<ZMQIdMessage>(msgIdentity, msgType, eventMessage);
32 }

◆ createMessage() [11/13]

static auto createMessage ( const std::string &  msgIdentity,
const EMessageTypes  msgType,
zmq::message_t  msgData 
)
inlinestatic

Create an ID Message out of an identity, the type and another zmq message.

Definition at line 43 of file ZMQMessageFactory.h.

46 {
47 return createMessage<ZMQIdMessage>(msgIdentity, msgType, std::move(msgData));
48 }

◆ createMessage() [12/13]

static auto createMessage ( const std::string &  msgIdentity,
std::unique_ptr< ZMQNoIdMessage shortMessage 
)
inlinestatic

Create an ID Message out of an identity and an already received message.

Definition at line 51 of file ZMQMessageFactory.h.

53 {
54 return createMessage<ZMQIdMessage>(msgIdentity, std::move(shortMessage->getMessagePart<0>()),
55 std::move(shortMessage->getMessagePart<1>()));
56 }

◆ createMessage() [13/13]

static auto createMessage ( zmq::message_t  msgType,
zmq::message_t  msgData 
)
inlinestatic

Create a No-ID Message out of an identity, the type and another zmq message.

Definition at line 95 of file ZMQMessageFactory.h.

97 {
98 return createMessage<ZMQNoIdMessage>(std::move(msgType), std::move(msgData));
99 }

◆ fromSocket()

static std::unique_ptr< AMessage > fromSocket ( const std::unique_ptr< zmq::socket_t > &  socket)
inlinestatic

Create a message of the given type by receiving a message from the socket.

Definition at line 126 of file ZMQMessageFactory.h.

127 {
128 auto newMessage = std::unique_ptr<AMessage>(new AMessage());
129 auto& messageParts = newMessage->getMessageParts();
130 for (unsigned int i = 0; i < AMessage::c_messageParts; i++) {
131 B2ASSERT("The next part does not belong to the same message",
132 socket->get(zmq::sockopt::rcvmore) == 1 or i == 0);
133 auto received = socket->recv(messageParts[i], zmq::recv_flags::none);
134 B2ASSERT("No message received", received);
135 }
136 B2ASSERT("There should not be more than the retrieved parts", socket->get(zmq::sockopt::rcvmore) == 0);
137 return newMessage;
138 }

◆ stripIdentity()

static auto stripIdentity ( std::unique_ptr< ZMQIdMessage message)
inlinestatic

Create a No-ID Message out of an ID message.

Definition at line 117 of file ZMQMessageFactory.h.

118 {
119 return createMessage<ZMQNoIdMessage>(std::move(message->getMessagePart<1>()),
120 std::move(message->getMessagePart<2>()),
121 std::move(message->getMessagePart<3>()));
122 }

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