DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
notification_interface.hpp
Go to the documentation of this file.
1
10#ifndef SNBMODULES_INCLUDE_SNBMODULES_NOTIFICATION_INTERFACE_HPP_
11#define SNBMODULES_INCLUDE_SNBMODULES_NOTIFICATION_INTERFACE_HPP_
12
16
20
21#include <set>
22#include <string>
23#include <utility>
24#include <vector>
25
26namespace dunedaq {
27namespace snbmodules {
30{
32 std::string m_source_id;
34 std::string m_target_id;
36 std::string m_notification;
38 std::string m_data;
39
40 NotificationData() = default;
41 NotificationData(std::string source_id, std::string target_id, std::string notification, std::string data = "")
42 : m_source_id(std::move(source_id))
43 , m_target_id(std::move(target_id))
44 , m_notification(std::move(notification))
45 , m_data(std::move(data))
46 {
47 }
48 NotificationData(std::string source_id,
49 std::string target_id,
51 std::string data = "")
52 : m_source_id(std::move(source_id))
53 , m_target_id(std::move(target_id))
54 , m_notification(notification_type::notification_to_string(notification))
55 , m_data(std::move(data))
56 {
57 }
58 virtual ~NotificationData() = default;
63
65};
66
68{
69
70public:
71 explicit NotificationInterface(std::string connection_prefix = "snbmodules",
72 int timeout_send = 10,
73 int timeout_receive = 100)
74 : m_timeout_send(timeout_send)
75 , m_timeout_receive(timeout_receive)
76 , m_connection_prefix(std::move(connection_prefix))
77 {
78 }
79
80 NotificationInterface(std::vector<std::string> bk_conn,
81 std::set<std::string> client_conn,
82 const std::string& connection_prefix = "snbmodules",
83 int timeout_send = 10,
84 int timeout_receive = 100)
85 : m_timeout_send(timeout_send)
86 , m_timeout_receive(timeout_receive)
87 , m_connection_prefix(connection_prefix)
88 {
89 m_bookkeepers_conn = std::move(bk_conn);
90 TLOG() << "CCC " << __LINE__ << " client_conn size=" << client_conn.size();
91 m_clients_conn = std::move(client_conn);
92 }
93 virtual ~NotificationInterface() = default;
94
100 std::optional<NotificationData> listen_for_notification(const std::string& id,
101 const std::string& expected_from = "",
102 int timeout = -1,
103 int tries = -1);
104
113 const std::string& src,
114 const std::string& dst,
115 const std::string& id_conn,
116 const std::string& data = "",
117 int tries = -1);
118
123
127 {
128
129 iomanager::ConnectionId id = { m_connection_prefix + ".*bookkeeper.*", "notification_t", "" };
130 TLOG() << "LAB " << __LINE__ << " " << id.uid << " " << id.data_type << " " << id.session;
131
132 try {
134 for (const auto& conn : result.connections) {
135 TLOG() << "CCC " << __LINE__ << " adding bookkeeper conn.uid=" << conn.uid;
136 m_bookkeepers_conn.push_back(conn.uid);
137 }
138 } catch (...) // Ignore if no connection found
139 {
140 TLOG() << "LAB " << __LINE__;
141 }
142 try {
143 id = { m_connection_prefix + ".*transfer.*", "notification_t", "" };
144 TLOG() << "LAB " << __LINE__ << " " << id.uid << " " << id.data_type << " " << id.session;
146 for (const auto& conn : result.connections) {
147 TLOG() << "CCC " << __LINE__ << " adding transfer conn.uid=" << conn.uid;
148 m_clients_conn.insert(conn.uid);
149 }
150 } catch (...) // Ignore if no connection found
151 {
152 TLOG() << "LAB " << __LINE__;
153 }
154 }
155
156#if 0
162 virtual inline void add_connection(const IPFormat &ip, const std::string &connection_name, const std::string &data_type, bool is_client)
163 {
164 IOManagerWrapper::get().add_connection(ip, connection_name, data_type);
165
166 if (is_client)
167 {
168 TLOG() << "CCC " << __LINE__ << " adding connection_name=" << connection_name;
169 m_clients_conn.insert(connection_name);
170 }
171 else
172 {
173 m_bookkeepers_conn.push_back(connection_name);
174 }
175 }
176#endif
177
183 // TEMP_REMOVED//void init_connection_interface(const std::string &session_name = "SNBMODULES", bool
184 // use_connectivity_service = false, const IPFormat &ip = IPFormat("localhost", 5000)) TEMP_REMOVED//{
185 // TEMP_REMOVED//IOManagerWrapper::get().init_connection_interface(session_name, use_connectivity_service, ip);
186 // TEMP_REMOVED//}
187
188 // Getters
189 inline const std::vector<std::string>& get_bookkeepers_conn() const { return m_bookkeepers_conn; }
190 inline const std::set<std::string>& get_clients_conn() const { return m_clients_conn; }
191
192private:
194 std::vector<std::string> m_bookkeepers_conn;
196 std::set<std::string> m_clients_conn;
197
203 std::string m_connection_prefix = "snbmodules";
204
205 int m_max_tries = 3;
206};
207
208} // namespace snbmodules
209
210// Must be in dunedaq namespace only
212
213} // namespace dunedaq
214
215#endif // SNBMODULES_INCLUDE_SNBMODULES_NOTIFICATION_INTERFACE_HPP_
#define DUNE_DAQ_SERIALIZABLE(Type, typestring)
Macro to define a type as serializable, so it can be sent over the network.
iomanager::ConnectionResponse lookups_connection(const iomanager::ConnectionId &conn_id, bool restrict_single)
init IOManager instance, Only used for stand alone application
Class that represents an IP address and a port TODO: should be replaced by something better ?
Definition ip_format.hpp:26
std::optional< NotificationData > listen_for_notification(const std::string &id, const std::string &expected_from="", int timeout=-1, int tries=-1)
Listen for a notification.
int m_timeout_send
Timeout for sending a notification in ms.
std::set< std::string > m_clients_conn
List of clients connections.
NotificationInterface(std::string connection_prefix="snbmodules", int timeout_send=10, int timeout_receive=100)
int m_timeout_receive
Timeout for receiving a notification in ms.
void lookups_connections()
Get the list of every connections, must have the prefix first in the name of the connection and the n...
bool send_notification(const notification_type::e_notification_type &notif, const std::string &src, const std::string &dst, const std::string &id_conn, const std::string &data="", int tries=-1)
Send a notification during m_timeout_send ms.
const std::vector< std::string > & get_bookkeepers_conn() const
Init the connection interface, Only used for standalone application.
std::vector< std::string > m_bookkeepers_conn
List of bookkeepers connections.
virtual bool action_on_receive_notification(NotificationData notif)=0
Action to do when receiving a notification.
NotificationInterface(std::vector< std::string > bk_conn, std::set< std::string > client_conn, const std::string &connection_prefix="snbmodules", int timeout_send=10, int timeout_receive=100)
const std::set< std::string > & get_clients_conn() const
std::string m_connection_prefix
Prefix for the connection name.
#define TLOG(...)
Definition macro.hpp:22
The DUNE-DAQ namespace.
std::vector< ConnectionInfo > connections
NotificationData class, represent a notification.
NotificationData(NotificationData const &)=default
NotificationData(NotificationData &&)=default
NotificationData(std::string source_id, std::string target_id, notification_type::e_notification_type notification, std::string data="")
std::string m_data
Data of the notification, can be empty.
NotificationData(std::string source_id, std::string target_id, std::string notification, std::string data="")
NotificationData & operator=(NotificationData &&)=default
NotificationData & operator=(NotificationData const &)=default
std::string m_notification
Notification type.
DUNE_DAQ_SERIALIZE(NotificationData, m_source_id, m_target_id, m_notification, m_data)
e_notification_type
Different type of notifications possible to send.