Line data Source code
1 : /**
2 : *
3 : * @file ZmqUri.cpp ZmqUri struct method implementations
4 : *
5 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 :
10 : #include "utilities/ZmqUri.hpp"
11 : #include "utilities/Issues.hpp"
12 : #include "utilities/get_ips.hpp"
13 :
14 : #include <string>
15 : #include <vector>
16 :
17 : // ZMQ URIs are formatted as follows: tcp://{host}:{port}
18 46 : dunedaq::utilities::ZmqUri::ZmqUri(std::string connection_string)
19 : {
20 46 : if (connection_string.find("://") == std::string::npos) {
21 3 : throw InvalidUri(ERS_HERE, connection_string);
22 : }
23 :
24 43 : scheme = connection_string.substr(0, connection_string.find("://"));
25 43 : connection_string = connection_string.substr(connection_string.find("://") + 3);
26 :
27 43 : if (connection_string.find(":") != std::string::npos) {
28 13 : port = connection_string.substr(connection_string.find(":") + 1);
29 13 : connection_string = connection_string.substr(0, connection_string.find(":"));
30 : }
31 43 : host = connection_string;
32 52 : }
33 :
34 : std::vector<std::string>
35 41 : dunedaq::utilities::ZmqUri::get_uri_ip_addresses()
36 : {
37 41 : if (scheme == "tcp") {
38 14 : auto output = get_hostname_ips(host);
39 :
40 26 : for (size_t ii = 0; ii < output.size(); ++ii) {
41 12 : output[ii] = "tcp://" + output[ii] + ":" + port;
42 : }
43 : return output;
44 0 : } else {
45 54 : return { to_string() };
46 : }
47 27 : }
|