Belle II Software light-2405-quaxo
ZMQConnection.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/utils/ZMQLogger.h>
11#include <framework/pcore/zmq/utils/ZMQParent.h>
12
13#include <zmq.hpp>
14
15#include <memory>
16
17namespace Belle2 {
30 class ZMQConnection : public ZMQLogger {
31 public:
33 using ReactorFunction = std::function<void(void)>;
34
44 static bool poll(const std::map<const ZMQConnection*, ReactorFunction>& connectionList, int timeout);
45
47 static bool hasMessage(const ZMQConnection* connection);
48
50 virtual ~ZMQConnection() = default;
51
53 virtual bool isReady() const;
55 virtual std::vector<zmq::socket_t*> getSockets() const = 0;
56 };
57
63 public:
65 explicit ZMQConnectionOverSocket(const std::shared_ptr<ZMQParent>& parent);
66
68 std::vector<zmq::socket_t*> getSockets() const final;
69
71 std::string getEndPoint() const;
72 protected:
74 std::shared_ptr<ZMQParent> m_parent;
76 std::unique_ptr<zmq::socket_t> m_socket;
77 };
79}
Specialized connection over a ZMQ socket.
Definition: ZMQConnection.h:62
std::string getEndPoint() const
Return the connection string for this socket.
std::shared_ptr< ZMQParent > m_parent
The shared ZMQParent instance.
Definition: ZMQConnection.h:74
std::unique_ptr< zmq::socket_t > m_socket
The memory of the socket. Needs to be initialized in a derived class.
Definition: ZMQConnection.h:76
std::vector< zmq::socket_t * > getSockets() const final
The socket used for polling is just the stored socket.
Base class for every connection with virtual functions to be implemented:
Definition: ZMQConnection.h:30
virtual bool isReady() const
Return true of this connection is able to send messages right now. Can be overloaded in derived class...
virtual ~ZMQConnection()=default
Virtual default destructor.
std::function< void(void)> ReactorFunction
Typedef of a function which will be called if a connection has a message.
Definition: ZMQConnection.h:33
static bool hasMessage(const ZMQConnection *connection)
Check if the given connection as an incoming message (right now, no waiting).
virtual std::vector< zmq::socket_t * > getSockets() const =0
Return the list of sockets which should be polled on to check for incoming messages....
static bool poll(const std::map< const ZMQConnection *, ReactorFunction > &connectionList, int timeout)
Poll on the given connections and call the attached function if a messages comes in.
Base class for the ZMQ connection to help monitor and log certain values.
Definition: ZMQLogger.h:35
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24