DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::snbmodules::NotificationInterface Class Referenceabstract

#include <notification_interface.hpp>

Inheritance diagram for dunedaq::snbmodules::NotificationInterface:
[legend]

Public Member Functions

 NotificationInterface (std::string connection_prefix="snbmodules", int timeout_send=10, int timeout_receive=100)
 
 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)
 
virtual ~NotificationInterface ()=default
 
std::optional< NotificationDatalisten_for_notification (const std::string &id, const std::string &expected_from="", int timeout=-1, int tries=-1)
 Listen for a notification.
 
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.
 
virtual bool action_on_receive_notification (NotificationData notif)=0
 Action to do when receiving a notification.
 
void lookups_connections ()
 Get the list of every connections, must have the prefix first in the name of the connection and the name of the connection must be in the format: prefix.*bookkeeper.* or prefix.*client.*.
 
const std::vector< std::string > & get_bookkeepers_conn () const
 Init the connection interface, Only used for standalone application.
 
const std::set< std::string > & get_clients_conn () const
 

Private Attributes

std::vector< std::string > m_bookkeepers_conn
 List of bookkeepers connections.
 
std::set< std::string > m_clients_conn
 List of clients connections.
 
int m_timeout_send = 10
 Timeout for sending a notification in ms.
 
int m_timeout_receive = 100
 Timeout for receiving a notification in ms.
 
std::string m_connection_prefix = "snbmodules"
 Prefix for the connection name.
 
int m_max_tries = 3
 

Detailed Description

Definition at line 67 of file notification_interface.hpp.

Constructor & Destructor Documentation

◆ NotificationInterface() [1/2]

dunedaq::snbmodules::NotificationInterface::NotificationInterface ( std::string connection_prefix = "snbmodules",
int timeout_send = 10,
int timeout_receive = 100 )
inlineexplicit

Definition at line 71 of file notification_interface.hpp.

74 : m_timeout_send(timeout_send)
75 , m_timeout_receive(timeout_receive)
76 , m_connection_prefix(std::move(connection_prefix))
77 {
78 }
int m_timeout_send
Timeout for sending a notification in ms.
int m_timeout_receive
Timeout for receiving a notification in ms.
std::string m_connection_prefix
Prefix for the connection name.

◆ NotificationInterface() [2/2]

dunedaq::snbmodules::NotificationInterface::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 )
inline

Definition at line 80 of file notification_interface.hpp.

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 }
std::set< std::string > m_clients_conn
List of clients connections.
std::vector< std::string > m_bookkeepers_conn
List of bookkeepers connections.
#define TLOG(...)
Definition macro.hpp:22

◆ ~NotificationInterface()

virtual dunedaq::snbmodules::NotificationInterface::~NotificationInterface ( )
virtualdefault

Member Function Documentation

◆ action_on_receive_notification()

virtual bool dunedaq::snbmodules::NotificationInterface::action_on_receive_notification ( NotificationData notif)
pure virtual

Action to do when receiving a notification.

Parameters
notifNotification received
Returns
true if the notification was handled, false otherwise

Implemented in dunedaq::snbmodules::Bookkeeper, dunedaq::snbmodules::TransferClient, and dunedaq::snbmodules::TransferSession.

◆ get_bookkeepers_conn()

const std::vector< std::string > & dunedaq::snbmodules::NotificationInterface::get_bookkeepers_conn ( ) const
inline

Init the connection interface, Only used for standalone application.

Parameters
session_nameName of the session
use_connectivity_serviceUse the connectivity service
ipIP of the connectivity service

Definition at line 189 of file notification_interface.hpp.

189{ return m_bookkeepers_conn; }

◆ get_clients_conn()

const std::set< std::string > & dunedaq::snbmodules::NotificationInterface::get_clients_conn ( ) const
inline

Definition at line 190 of file notification_interface.hpp.

190{ return m_clients_conn; }

◆ listen_for_notification()

std::optional< NotificationData > dunedaq::snbmodules::NotificationInterface::listen_for_notification ( const std::string & id,
const std::string & expected_from = "",
int timeout = -1,
int tries = -1 )

Listen for a notification.

Parameters
idID of the connection
expected_fromExpected source of the notification, if empty, accept any source
timeoutTimeout for receiving the notification in ms, if -1, use the default timeout
Returns
std::optional<NotificationData> Notification received or not

Definition at line 21 of file notification_interface.cpp.

25{ // NOLINT
26 // Default value for tries
27 if (tries == -1) {
28 tries = m_max_tries;
29 }
30 // TLOG() << "debug : Listening for request from " << id;
31
32 if (timeout == -1) {
33 timeout = m_timeout_receive;
34 }
35
36 TLOG() << "AAA " << __LINE__ << " getting receiver for UID \"" << id << "\"";
37 std::optional<NotificationData> msg =
38 iomanager::IOManager::get()->get_receiver<NotificationData>(id)->try_receive(std::chrono::milliseconds(timeout));
39
40 if (msg.has_value()) {
41 TLOG() << "debug : Received request " << msg->m_notification << " for " << msg->m_target_id;
42
43 if (expected_from != "" && expected_from.find(msg.value().m_source_id) == std::string::npos) {
44 TLOG() << "debug : Received request from " << msg->m_source_id << " but expected from " << expected_from
45 << " ignoring";
46 if (tries <= 1) {
47 return std::nullopt;
48 }
49 tries--;
50 return listen_for_notification(id, expected_from, timeout, tries);
51 }
52 }
53 return msg;
54}
static std::shared_ptr< IOManager > get()
Definition IOManager.hpp:40
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.

◆ lookups_connections()

void dunedaq::snbmodules::NotificationInterface::lookups_connections ( )
inline

Get the list of every connections, must have the prefix first in the name of the connection and the name of the connection must be in the format: prefix.*bookkeeper.* or prefix.*client.*.

Definition at line 126 of file notification_interface.hpp.

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 {
133 iomanager::ConnectionResponse result = IOManagerWrapper::get().lookups_connection(id, false);
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;
145 iomanager::ConnectionResponse result = IOManagerWrapper::get().lookups_connection(id, false);
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 }
iomanager::ConnectionResponse lookups_connection(const iomanager::ConnectionId &conn_id, bool restrict_single)
init IOManager instance, Only used for stand alone application

◆ send_notification()

bool dunedaq::snbmodules::NotificationInterface::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.

Parameters
notifType of the notification
srcname of the source or uuid of the connection
dstname of the destination or uuid of the connection
id_connID of the connection
dataData of the notification (optional)
Returns

Definition at line 57 of file notification_interface.cpp.

63{
64 // Default value for tries
65 if (tries == -1) {
66 tries = m_max_tries;
67 }
68
69 // find connection with dst in it
70 std::string real_conn_id = id_conn;
71 for (const auto& conn : m_bookkeepers_conn) {
72 if (conn.find(id_conn) != std::string::npos) {
73 real_conn_id = conn;
74 break;
75 }
76 }
77 for (const auto& conn : m_clients_conn) {
78 if (conn.find(id_conn) != std::string::npos) {
79 real_conn_id = conn;
80 break;
81 }
82 }
83
84 TLOG() << "debug : Sending request " << notification_type::notification_to_string(notif) << " to " << dst << " via "
85 << real_conn_id;
86
87 NotificationData notif_data(src, dst, notification_type::notification_to_string(notif), data);
88
89 bool result = iomanager::IOManager::get()
90 ->get_sender<NotificationData>(real_conn_id)
91 ->try_send(std::move(notif_data), std::chrono::milliseconds(m_timeout_send));
92
93 if (result == false) {
94 ers::error(NotificationSendError(ERS_HERE, real_conn_id));
95 if (tries <= 1) {
96 return false;
97 }
98
99 // wait
100 std::this_thread::sleep_for(std::chrono::milliseconds(m_timeout_send));
101 TLOG() << "debug : Retrying send notification";
102 tries--;
103 return send_notification(notif, src, dst, real_conn_id, data, tries);
104 }
105
106 return result;
107}
#define ERS_HERE
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.
void error(const Issue &issue)
Definition ers.hpp:81
static std::string notification_to_string(e_notification_type e)

Member Data Documentation

◆ m_bookkeepers_conn

std::vector<std::string> dunedaq::snbmodules::NotificationInterface::m_bookkeepers_conn
private

List of bookkeepers connections.

Definition at line 194 of file notification_interface.hpp.

◆ m_clients_conn

std::set<std::string> dunedaq::snbmodules::NotificationInterface::m_clients_conn
private

List of clients connections.

Definition at line 196 of file notification_interface.hpp.

◆ m_connection_prefix

std::string dunedaq::snbmodules::NotificationInterface::m_connection_prefix = "snbmodules"
private

Prefix for the connection name.

Definition at line 203 of file notification_interface.hpp.

◆ m_max_tries

int dunedaq::snbmodules::NotificationInterface::m_max_tries = 3
private

Definition at line 205 of file notification_interface.hpp.

◆ m_timeout_receive

int dunedaq::snbmodules::NotificationInterface::m_timeout_receive = 100
private

Timeout for receiving a notification in ms.

Definition at line 201 of file notification_interface.hpp.

◆ m_timeout_send

int dunedaq::snbmodules::NotificationInterface::m_timeout_send = 10
private

Timeout for sending a notification in ms.

Definition at line 199 of file notification_interface.hpp.


The documentation for this class was generated from the following files: