DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaUtils.hpp
Go to the documentation of this file.
1
11#ifndef IOMANAGER_INCLUDE_IOMANAGER_SCHEMAUTILS_HPP_
12#define IOMANAGER_INCLUDE_IOMANAGER_SCHEMAUTILS_HPP_
13
16#include "confmodel/Service.hpp"
17
18#include <cerrno>
19#include <functional>
20#include <ifaddrs.h>
21#include <netdb.h>
22#include <regex>
23#include <sstream>
24
25namespace dunedaq {
26namespace iomanager {
27
29{
30 std::string uid{ "" };
31 std::string data_type{ "" };
32 std::string tag{ "" };
33 std::string session{ "" };
34
36
37 ConnectionId(std::string uid, std::string data_type, std::string tag = "", std::string session = "")
38 : uid(uid)
40 , tag(tag)
42 {
43 }
44
46 : uid(cfg->UID())
47 , data_type(cfg->get_data_type())
48 {
49 }
50};
51
52inline bool
53operator<(ConnectionId const& l, ConnectionId const& r)
54{
55 if (l.session == r.session || l.session == "" || r.session == "") {
56 if (l.data_type == r.data_type) {
57 if (l.uid == r.uid) {
58 return l.tag < r.tag;
59 }
60 return l.uid < r.uid;
61 }
62 return l.data_type < r.data_type;
63 }
64 return l.session < r.session;
65}
66inline bool
68{
69 return (l.session == "" || r.session == "" || l.session == r.session) && l.uid == r.uid && l.tag == r.tag &&
70 l.data_type == r.data_type;
71}
72
73inline bool
75{
76 if (search.data_type != check.data_type)
77 return false;
78
79 if (search.session != check.session && search.session != "" && check.session != "")
80 return false;
81
82 std::regex search_ex(search.uid);
83 return std::regex_match(check.uid, search_ex);
84}
85
86inline std::string
87to_string(const ConnectionId& conn_id)
88{
89 if (conn_id.session != "") {
90 return conn_id.session + "/" + conn_id.uid + (conn_id.tag != "" ? "+" + conn_id.tag : "") + "@@" +
91 conn_id.data_type;
92 }
93 return conn_id.uid + (conn_id.tag != "" ? "+" + conn_id.tag : "") + "@@" + conn_id.data_type;
94}
95
96inline std::string
98{
99 std::string uri = "";
100 if (netCon) {
101 TLOG_DEBUG(45) << "Getting URI for network connection " << netCon->UID();
102 auto service = netCon->get_associated_service();
103 if (service->get_protocol() == "tcp") {
104
105 std::string port = "*";
106 if (service->get_port() && service->get_port() != 0) {
107 port = std::to_string(service->get_port());
108 }
109 std::string ipaddr = "0.0.0.0";
110 char hostname[256];
111 if (gethostname(&hostname[0], 256) == 0) {
112 ipaddr = std::string(hostname);
113 }
114 auto iface = service->get_eth_device_name();
115 if (iface != "") {
116 // Work out which ip address goes with this device
117 struct ifaddrs* ifaddr;
118 getifaddrs(&ifaddr);
119 for (auto ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
120 if (ifa->ifa_addr == NULL) {
121 continue;
122 }
123 if (std::string(ifa->ifa_name) == iface) {
124 char ip[NI_MAXHOST];
125 int status =
126 getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
127 if (status != 0) {
128 continue;
129 }
130 ipaddr = std::string(ip);
131 break;
132 }
133 }
134 freeifaddrs(ifaddr);
135 }
136 uri = std::string(service->get_protocol() + "://" + ipaddr + ":" + port);
137 } else if (service->get_protocol() == "inproc") {
138 uri = std::string(service->get_protocol() + "://" + service->get_path());
139 }
140 }
141 return uri;
142}
143
144} // namespace iomanager
145
146} // namespace dunedaq
147
148namespace std {
149
150template<>
151struct hash<dunedaq::iomanager::ConnectionId>
152{
153 std::size_t operator()(const dunedaq::iomanager::ConnectionId& conn_id) const
154 {
155 return std::hash<std::string>()(conn_id.session + conn_id.uid + conn_id.tag + conn_id.data_type);
156 }
157};
158
159}
160
161#endif // IOMANAGER_INCLUDE_IOMANAGER_SCHEMAUTILS_HPP_
static void check(std::vector< conffwk::ConfigurationChange * > &changes, const InheritanceData &inheritance, const std::set< std::string > &class_names, const OksConfiguration::SMap &objects, const std::string &obj_class, const std::string &obj_id, const char action)
const std::string & UID() const noexcept
const dunedaq::confmodel::Service * get_associated_service() const
Get "associated_service" relationship value. Service provided by this connection.
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
bool is_match(ConnectionId const &search, ConnectionId const &check)
std::string to_string(const ConnectionId &conn_id)
bool operator<(ConnectionRegistration const &l, ConnectionRegistration const &r)
std::string get_uri_for_connection(const confmodel::NetworkConnection *netCon)
bool operator==(ConnectionId const &l, ConnectionId const &r)
Including Qt Headers.
Unsupported std::string uri Execution of command std::string error Failed to create CommandFacility uri
Definition Issues.hpp:77
ConnectionId(std::string uid, std::string data_type, std::string tag="", std::string session="")
ConnectionId(const confmodel::Connection *cfg)
std::size_t operator()(const dunedaq::iomanager::ConnectionId &conn_id) const