#include <notification_interface.hpp>
|
| | 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< NotificationData > | listen_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 ¬if, 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 |
| |
Definition at line 67 of file notification_interface.hpp.
◆ 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.
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.
88 {
90 TLOG() <<
"CCC " << __LINE__ <<
" client_conn size=" << client_conn.size();
92 }
std::set< std::string > m_clients_conn
List of clients connections.
std::vector< std::string > m_bookkeepers_conn
List of bookkeepers connections.
◆ ~NotificationInterface()
| virtual dunedaq::snbmodules::NotificationInterface::~NotificationInterface |
( |
| ) |
|
|
virtualdefault |
◆ action_on_receive_notification()
| virtual bool dunedaq::snbmodules::NotificationInterface::action_on_receive_notification |
( |
NotificationData | notif | ) |
|
|
pure virtual |
◆ 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_name | Name of the session |
| use_connectivity_service | Use the connectivity service |
| ip | IP of the connectivity service |
Definition at line 189 of file notification_interface.hpp.
◆ get_clients_conn()
| const std::set< std::string > & dunedaq::snbmodules::NotificationInterface::get_clients_conn |
( |
| ) |
const |
|
inline |
◆ 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
-
| id | ID of the connection |
| expected_from | Expected source of the notification, if empty, accept any source |
| timeout | Timeout 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{
26
27 if (tries == -1) {
29 }
30
31
32 if (timeout == -1) {
34 }
35
36 TLOG() <<
"AAA " << __LINE__ <<
" getting receiver for UID \"" <<
id <<
"\"";
37 std::optional<NotificationData> msg =
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--;
51 }
52 }
53 return msg;
54}
static std::shared_ptr< IOManager > get()
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 {
134 for (const auto& conn : result.connections) {
135 TLOG() <<
"CCC " << __LINE__ <<
" adding bookkeeper conn.uid=" << conn.uid;
137 }
138 } catch (...)
139 {
140 TLOG() <<
"LAB " << __LINE__;
141 }
142 try {
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;
149 }
150 } catch (...)
151 {
152 TLOG() <<
"LAB " << __LINE__;
153 }
154 }
static IOManagerWrapper & get()
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
-
| notif | Type of the notification |
| src | name of the source or uuid of the connection |
| dst | name of the destination or uuid of the connection |
| id_conn | ID of the connection |
| data | Data of the notification (optional) |
- Returns
Definition at line 57 of file notification_interface.cpp.
63{
64
65 if (tries == -1) {
67 }
68
69
70 std::string real_conn_id = id_conn;
72 if (conn.find(id_conn) != std::string::npos) {
73 real_conn_id = conn;
74 break;
75 }
76 }
78 if (conn.find(id_conn) != std::string::npos) {
79 real_conn_id = conn;
80 break;
81 }
82 }
83
85 << real_conn_id;
86
88
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) {
95 if (tries <= 1) {
96 return false;
97 }
98
99
100 std::this_thread::sleep_for(std::chrono::milliseconds(
m_timeout_send));
101 TLOG() <<
"debug : Retrying send notification";
102 tries--;
104 }
105
106 return result;
107}
bool send_notification(const notification_type::e_notification_type ¬if, 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)
static std::string notification_to_string(e_notification_type e)
◆ m_bookkeepers_conn
| std::vector<std::string> dunedaq::snbmodules::NotificationInterface::m_bookkeepers_conn |
|
private |
◆ m_clients_conn
| std::set<std::string> dunedaq::snbmodules::NotificationInterface::m_clients_conn |
|
private |
◆ m_connection_prefix
| std::string dunedaq::snbmodules::NotificationInterface::m_connection_prefix = "snbmodules" |
|
private |
◆ m_max_tries
| int dunedaq::snbmodules::NotificationInterface::m_max_tries = 3 |
|
private |
◆ m_timeout_receive
| int dunedaq::snbmodules::NotificationInterface::m_timeout_receive = 100 |
|
private |
◆ m_timeout_send
| int dunedaq::snbmodules::NotificationInterface::m_timeout_send = 10 |
|
private |
The documentation for this class was generated from the following files: