Belle II Software development
ZMQRawConnection.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <framework/pcore/zmq/connections/ZMQConnection.h>
11#include <framework/pcore/zmq/utils/ZMQParent.h>
12
13#include <zmq.hpp>
14
15#include <string>
16#include <memory>
17
18namespace Belle2 {
42 public:
44 ZMQRawInput(const std::string& inputAddress, unsigned int maximalBufferSize, bool receiveEventMessages,
45 const std::shared_ptr<ZMQParent>& parent);
46
54 std::vector<zmq::message_t> handleIncomingData();
55
57 void clear();
58
59 private:
61 unsigned int m_maximalBufferSize;
63 std::vector<char> m_buffer;
65 size_t m_writeAddress = 0;
67 unsigned int m_currentSize = 0;
71 std::string m_inputIdentity = "";
72 };
73
88 public:
90 ZMQRawOutput(const std::string& outputAddress, bool addEventSize, const std::shared_ptr<ZMQParent>& parent);
91
93 virtual void handleEvent(zmq::message_t message);
95 void handleIncomingData();
97 bool isReady() const final;
98
99 private:
101 std::string m_dataIdentity = "";
103 bool m_addEventSize = false;
104 };
106}
Specialized connection over a ZMQ socket.
Definition: ZMQConnection.h:63
Input connection allowing to speak with non-zmq sockets via a ZMQ_STREAM socket.
unsigned int m_maximalBufferSize
Parameter for the maximal buffer size. If this size is reached, a FATAL will be issued.
size_t m_writeAddress
Where in the buffer are we currently writing to.
std::vector< char > m_buffer
Internal storage for the buffer.
unsigned int m_currentSize
How large should the full message be? The information is from the first int of the message.
bool m_receiveEventMessages
Parameter to receive event messages (see above)
void clear()
Reset the internal buffer and counter.
std::vector< zmq::message_t > handleIncomingData()
Block until a TCP packet can be received from the socket.
std::string m_inputIdentity
Internal storage of the connected socket to check if we get messages from multiple ones.
Output connection to speak to non-zmq sockets via a ZMQ_STREAM socket.
bool m_addEventSize
Parameter to add the event size to a message.
void handleIncomingData()
Handle incoming data: a socket (dis)connect.
virtual void handleEvent(zmq::message_t message)
Pass on the message - maybe by prefixing it with a htonl-converted data size in bytes.
bool isReady() const final
If no socket is connected, this connection is not ready.
std::string m_dataIdentity
Internal storage of the connected identity to no have multiple connections.
Abstract base class for different kinds of events.