tdaq-develop-2025-02-12
ots_mm_udp_interface.h
1 #ifndef _ots_mm_udp_interface_h_
2 #define _ots_mm_udp_interface_h_
3 
4 #include <arpa/inet.h>
5 #include <errno.h>
6 #include <netdb.h>
7 #include <netinet/in.h>
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <sys/socket.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15 
16 #include <string.h> //for strstr (not the same as <string>)
17 #include <iostream>
18 #include <map>
19 #include <set>
20 #include <sstream>
21 #include <string> //for string
22 #include <vector>
23 
24 #define __COUT_HDR__ ""
25 
26 #define Q(X) #X
27 #define QUOTE(X) Q(X)
28 
29 #define __FILENAME__ \
30  (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
31 #define __MF_SUBJECT__ __FILENAME__
32 #define __MF_DECOR__ (__MF_SUBJECT__)
33 
34 #define __COUT_HDR_L__ ":" << std::dec << __LINE__ << " |\t"
35 #define __COUT_HDR_FL__ __FILENAME__ << "" << __COUT_HDR_L__
36 #define TLOG(X) std::cout << QUOTE(X) << ": " << __COUT_HDR_FL__ //__LINE__ << ": "
37 #define __COUT_ERR__ TLOG(TLVL_ERROR) << __COUT_HDR__
38 #define __COUT_WARN__ TLOG(TLVL_WARN) << __COUT_HDR__
39 #define __COUT_INFO__ TLOG(TLVL_INFO) << __COUT_HDR__
40 #define __COUT__ \
41  if(0) \
42  TLOG(TLVL_DEBUG) << __COUT_HDR__
43 #define __COUTT__ \
44  if(0) \
45  TLOG(TLVL_TRACE) << __COUT_HDR__
46 
47 #define __SS__ \
48  std::stringstream ss; \
49  ss << "|" << __MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
50 #define __SS_THROW__ \
51  { \
52  __COUT_ERR__ << "\n" << ss.str(); \
53  throw std::runtime_error(ss.str()); \
54  } //put in {}'s to prevent surprises, e.g. if ... else __SS_THROW__;
55 #define __SS_THROW_ONLY__ \
56  { \
57  throw std::runtime_error(ss.str()); \
58  } //put in {}'s to prevent surprises, e.g. if ... else __SS_THROW__;
59 #define __E__ std::endl
60 
61 #define __COUTV__(X) __COUT__ << QUOTE(X) << " = " << X << __E__
62 #define __COUTVS__(LVL, X) \
63  TLOG(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << X << __E__
64 
65 std::string vectorToString(const std::vector<std::string>& setToReturn,
66  const std::string& delimeter = ", ");
67 void getVectorFromString(const std::string& inputString,
68  std::vector<std::string>& listToReturn,
69  const std::set<char>& delimiter = {',', '|', '&'},
70  const std::set<char>& whitespace = {' ', '\t', '\n', '\r'},
71  std::vector<char>* listOfDelimiters = 0,
72  bool decodeURIComponents = false);
73 std::vector<std::string> getVectorFromString(
74  const std::string& inputString,
75  const std::set<char>& delimiter = {',', '|', '&'},
76  const std::set<char>& whitespace = {' ', '\t', '\n', '\r'},
77  std::vector<char>* listOfDelimiters = 0,
78  bool decodeURIComponents = false);
79 
80 //==============================================================================
82 {
83  public:
84  ots_mm_udp_interface(const char* mm_ip, int mm_port);
85  ~ots_mm_udp_interface(void);
86 
87  const std::string& getFrontendMacroInfo(void);
88  std::string getFrontendList(void);
89  std::string getCommandList(const std::string& targetFE);
90  int getCommandInputCount(const std::string& targetFE, const std::string& command);
91  int getCommandOutputCount(const std::string& targetFE, const std::string& command);
92  std::string getCommandInputName(const std::string& targetFE,
93  const std::string& command,
94  int inputIndex);
95  std::string getCommandOutputName(const std::string& targetFE,
96  const std::string& command,
97  int outputIndex);
98  std::string runCommand(const std::string& targetFE,
99  const std::string& command,
100  const std::string& inputs);
101 
102  // static const int MAXBUFLEN = 5000;
103 
104  static std::string decodeURIComponent(const std::string& data);
105  static std::string encodeURIComponent(const std::string& data);
106  static std::string decodeHTMLEntities(const std::string& data);
107 
108  private:
109  int mm_sock_;
110  struct sockaddr_in mm_ai_addr;
111  std::string buffer_;
112  std::string fullXML_;
116 }; //end ots_mm_udp_interface class declaration
117 
118 #endif
std::string getFrontendList(void)
returns CSV list of Front-end interface UIDs
ots_mm_udp_interface(const char *mm_ip, int mm_port)
static std::string decodeURIComponent(const std::string &data)
std::string runCommand(const std::string &targetFE, const std::string &command, const std::string &inputs)
const std::string & getFrontendMacroInfo(void)
returns CSV list of Front-end interface UIDs
std::string getCommandOutputName(const std::string &targetFE, const std::string &command, int outputIndex)
Note: if std::map does not complicate interface too much for ROOT/pyton, could make this const std::s...