10#include <framework/logging/Logger.h>
11#include <framework/pcore/zmq/messages/ZMQNoIdMessage.h>
12#include <framework/pcore/zmq/messages/ZMQIdMessage.h>
13#include <framework/pcore/zmq/messages/ZMQDefinitions.h>
29 const std::unique_ptr<EvtMessage>& eventMessage)
31 return createMessage<ZMQIdMessage>(msgIdentity, msgType, eventMessage);
37 const std::string& msgData =
"")
39 return createMessage<ZMQIdMessage>(msgIdentity, msgType, msgData);
45 zmq::message_t msgData)
47 return createMessage<ZMQIdMessage>(msgIdentity, msgType, std::move(msgData));
52 std::unique_ptr<ZMQNoIdMessage> shortMessage)
54 return createMessage<ZMQIdMessage>(msgIdentity, std::move(shortMessage->getMessagePart<0>()),
55 std::move(shortMessage->getMessagePart<1>()));
60 const std::string& msgData =
"")
62 return createMessage<ZMQNoIdMessage>(msgType, msgData);
69 return createMessage<ZMQNoIdMessage>(msgType, msgData);
76 return createMessage<ZMQNoIdMessage>(msgType, evtMetaData);
81 zmq::message_t msgData)
83 return createMessage<ZMQNoIdMessage>(msgType, std::move(msgData));
88 zmq::message_t msgData,
89 zmq::message_t additionalData)
91 return createMessage<ZMQNoIdMessage>(msgType, std::move(msgData), std::move(additionalData));
96 zmq::message_t msgData)
98 return createMessage<ZMQNoIdMessage>(std::move(msgType), std::move(msgData));
103 const std::unique_ptr<EvtMessage>& eventMessage)
105 return createMessage<ZMQNoIdMessage>(msgType, eventMessage);
110 const std::unique_ptr<EvtMessage>& eventMessage,
111 zmq::message_t additionalData)
113 return createMessage<ZMQNoIdMessage>(msgType, eventMessage, std::move(additionalData));
119 return createMessage<ZMQNoIdMessage>(std::move(message->getMessagePart<1>()),
120 std::move(message->getMessagePart<2>()),
121 std::move(message->getMessagePart<3>()));
125 template <
class AMessage>
126 static std::unique_ptr<AMessage>
fromSocket(
const std::unique_ptr<zmq::socket_t>& socket)
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);
136 B2ASSERT(
"There should not be more than the retrieved parts", socket->get(zmq::sockopt::rcvmore) == 0);
142 template <
class T,
class... Args>
145 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
Type-safe access to single objects in the data store.
Helper class for creating new ID/No-ID messages.
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 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 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 StoreObjPtr< EventMetaData > &evtMetaData)
Create a No-ID Message out of an identity, the type and an event meta data.
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 wor...
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 stripIdentity(std::unique_ptr< ZMQIdMessage > message)
Create a No-ID Message out of an ID message.
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(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, int msgData)
Create a No-ID Message out of an identity, the type and an int.
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 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 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, 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 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.
EMessageTypes
Type the messages can have.
Abstract base class for different kinds of events.