DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::utilities Namespace Reference

Classes

class  Named
 A Named is a DAQ object (Queue or DAQModule) which has an instance name. More...
 
class  NamedObject
 Implements the Named interface. More...
 
class  ReusableThread
 
class  TimestampEstimator
 TimestampEstimator is an implementation of TimestampEstimatorBase that uses TimeSync messages from an input queue to estimate the current timestamp. More...
 
class  TimestampEstimatorBase
 TimestampEstimatorBase is the base class for timestamp-based logic in test systems where the current timestamp must be estimated somehow (eg, because there is no hardware timing system). More...
 
class  TimestampEstimatorSystem
 TimestampEstimatorSystem is an implementation of TimestampEstimatorBase that uses the system clock to give the current timestamp. More...
 
struct  ZmqUri
 

Functions

std::vector< std::string > get_ips_from_hostname (std::string hostname)
 
std::vector< std::string > resolve_uri_hostname (std::string connection_string)
 
ZmqUri parse_connection_string (std::string connection_string)
 

Function Documentation

◆ get_ips_from_hostname()

std::vector< std::string > dunedaq::utilities::get_ips_from_hostname ( std::string hostname)

Definition at line 13 of file Resolver.cpp.

14{
15 std::vector<std::string> output;
16
17 TLOG_DEBUG(12) << "Name is " << hostname;
18
19 struct addrinfo* result;
20 auto s = getaddrinfo(hostname.c_str(), nullptr, nullptr, &result);
21
22 if (s != 0) {
23 ers::error(NameNotFound(ERS_HERE, hostname, std::string(gai_strerror(s))));
24 return output;
25 }
26
27 for (auto rp = result; rp != nullptr; rp = rp->ai_next) {
28 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
29
30 // Let's skip all the IPv6 here
31 if (rp->ai_family == AF_INET6)
32 continue;
33
34 getnameinfo(rp->ai_addr, rp->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
35 auto result = std::string(hbuf);
36 bool duplicate = false;
37 for (auto& res : output) {
38 if (res == result) {
39 duplicate = true;
40 break;
41 }
42 }
43 if (!duplicate) {
44 TLOG_DEBUG(13) << "Found address " << result << " for hostname " << hostname;
45 output.push_back(result);
46 }
47 }
48
49 freeaddrinfo(result);
50
51 return output;
52}
#define ERS_HERE
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
NameNotFound
Definition Issues.hpp:29
void error(const Issue &issue)
Definition ers.hpp:81

◆ parse_connection_string()

dunedaq::utilities::ZmqUri dunedaq::utilities::parse_connection_string ( std::string connection_string)

Definition at line 72 of file Resolver.cpp.

73{
74 // ZMQ URIs are formatted as follows: tcp://{host}:{port}
75 ZmqUri output;
76
77 if (connection_string.find("://") == std::string::npos) {
78 throw InvalidUri(ERS_HERE, connection_string);
79 }
80
81 output.scheme = connection_string.substr(0, connection_string.find("://"));
82 connection_string = connection_string.substr(connection_string.find("://") + 3);
83
84 if (connection_string.find(":") != std::string::npos) {
85 output.port = connection_string.substr(connection_string.find(":") + 1);
86 connection_string = connection_string.substr(0, connection_string.find(":"));
87 }
88 output.host = connection_string;
89
90 return output;
91}

◆ resolve_uri_hostname()

std::vector< std::string > dunedaq::utilities::resolve_uri_hostname ( std::string connection_string)

Definition at line 55 of file Resolver.cpp.

56{
57 auto uri = parse_connection_string(connection_string);
58
59 if(uri.scheme == "tcp") {
60 auto output = get_ips_from_hostname(uri.host);
61
62 for (size_t ii = 0; ii < output.size(); ++ii) {
63 output[ii] = "tcp://" + output[ii] + ":" + uri.port;
64 }
65 return output;
66 } else {
67 return { connection_string };
68 }
69}
ZmqUri parse_connection_string(std::string connection_string)
Definition Resolver.cpp:72
std::vector< std::string > get_ips_from_hostname(std::string hostname)
Definition Resolver.cpp:13
Unsupported std::string uri Execution of command std::string error Failed to create CommandFacility uri
Definition Issues.hpp:77