DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DaphneV3Interface.hpp
Go to the documentation of this file.
1
13#ifndef DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
14#define DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
15
16#include <ers/ers.hpp>
17#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
18
19#include <zmq.hpp>
22
23#include <memory>
24#include <mutex>
25#include <functional>
26#include <string>
27
28
29
30namespace dunedaq {
31
32 ERS_DECLARE_ISSUE( daphnemodules,
33 SocketCreationError,
34 "Failed to create a socket",
36 )
37
38 ERS_DECLARE_ISSUE( daphnemodules,
40 "Failed to ping daphne board at " << ip << ':' << port,
41 ((std::string)ip)((int)port)
42 )
43
44 ERS_DECLARE_ISSUE( daphnemodules,
45 FailedSend,
46 "Failed to send message of type " << type,
47 ((std::string)type)
48 )
49
50 ERS_DECLARE_ISSUE( daphnemodules,
51 FailedReceive,
52 "Failed to receive message from " << connection,
53 ((std::string)connection)
54 )
55
56 ERS_DECLARE_ISSUE( daphnemodules,
57 EmptyPayload,
58 "Empty payload received from " << connection,
59 ((std::string)connection)
60 )
61
62 ERS_DECLARE_ISSUE( daphnemodules,
63 TypeMismatch,
64 "Received message of type " << type << " instead of " << expected,
65 ((std::string)type)((std::string)expected)
66 )
67
68
69 ERS_DECLARE_ISSUE( daphnemodules,
70 FailedDecoding,
71 "Failed to de-serialise to " << type << ". Message: " << message,
72 ((std::string)type)((std::string)message)
73 )
74
75 ERS_DECLARE_ISSUE( daphnemodules,
76 UnexpectedDirection,
77 "Message received with unexpeted properties. Version: " << version << ", direction " << ". Message: " << message,
78 ((uint32_t)version)((std::string)direction)((std::string)message)
79 )
80
81
82
83 } // namespace dunedaq
84
85
86namespace dunedaq::daphnemodules {
87
89
90 public:
91 DaphneV3Interface( std::string address, // it can contain the port or not
92 std::string routing, // this should be the name of the controller module
93 std::chrono::milliseconds timeout = std::chrono::milliseconds(500));
94
95
97
102
103 // this takes the serilised message and encodes it into the envelope
104 // It returns the serialised reply
105
106 daphne::ControlEnvelopeV2 send( std::string && message, daphne::MessageTypeV2 );
107
108 // this takes the serilised message and encodes it into the envelope
109 // It returns the de-serialised objects
110 template<class T>
111 T send( std::string && message, daphne::MessageTypeV2 sent_type, daphne::MessageTypeV2 received_type );
112
113 bool validate_connection();
114
115 protected:
116 void _send( std::string && message, daphne::MessageTypeV2 );
118
119 void close();
120
121 private:
122 zmq::context_t m_context;
123
124 zmq::socket_t m_socket;
125 mutable std::mutex m_access_mutex;
126
127 std::string m_connection;
128
129 std::chrono::milliseconds m_timeout{1000};
130
131 uint64_t m_message_counter = 0;
132
133 inline static const size_t s_default_control_port = 40001;
134 };
135
136
137} // namespce dunedaq::daphnemodules
138
139#include <DaphneV3Interface.hxx>
140
141#endif // DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
#define ERS_EMPTY
DaphneV3Interface(std::string address, std::string routing, std::chrono::milliseconds timeout=std::chrono::milliseconds(500))
DaphneV3Interface(DaphneV3Interface &&)=delete
daphne::ControlEnvelopeV2 send(std::string &&message, daphne::MessageTypeV2)
DaphneV3Interface & operator=(const DaphneV3Interface &)=delete
void _send(std::string &&message, daphne::MessageTypeV2)
DaphneV3Interface(const DaphneV3Interface &)=delete
The DUNE-DAQ namespace.
Invalid address