artdaq_mfextensions  v1_02_02
msgserver.cc
1 #include "messagefacility/MessageLogger/MessageLogger.h"
2 #include "messagefacility/Utilities/MessageFacilityMsg.h"
3 
4 #include <boost/program_options.hpp>
5 #include <boost/bind.hpp>
6 
7 #include <iostream>
8 #include <string>
9 #include "mfextensions/Binaries/ReceiverManager.hh"
10 #include "fhiclcpp/make_ParameterSet.h"
11 
12 namespace po = boost::program_options;
13 
14 bool cmdline = false;
15 int z = 0;
16 
17 void printmsg(mf::MessageFacilityMsg const& mfmsg)
18 {
19  // No display of received messages in command line mode
20  if (cmdline) return;
21 
22  // First archive the received message
23  // have to do it this way because LogErrorObj() takes a pointer
24  // to ErrorObj and take over the ownership (it will deal with
25  // with deletion), plus the fact ErrorObj doesn't have a copy
26  // assignment operator
27  mf::ErrorObj* eop = new mf::ErrorObj(mfmsg.ErrorObject());
28  mf::LogErrorObj(eop);
29 
30  // Show received message on screen
31  std::cout << "severity: " << mfmsg.severity() << "\n";
32  std::cout << "timestamp: " << mfmsg.timestr() << "\n";
33  std::cout << "hostname: " << mfmsg.hostname() << "\n";
34  std::cout << "hostaddr(ip): " << mfmsg.hostaddr() << "\n";
35 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
36  std::cout << "process: " << mfmsg.process() << "\n";
37 # endif
38  std::cout << "process_id: " << mfmsg.pid() << "\n";
39  std::cout << "application: " << mfmsg.application() << "\n";
40  std::cout << "module: " << mfmsg.module() << "\n";
41  std::cout << "context: " << mfmsg.context() << "\n";
42  std::cout << "category(id): " << mfmsg.category() << "\n";
43  std::cout << "file: " << mfmsg.file() << "\n";
44  std::cout << "line: " << mfmsg.line() << "\n";
45  std::cout << "message: " << mfmsg.message() << "\n";
46  std::cout << std::endl;
47 }
48 
49 void printnull(mf::MessageFacilityMsg const& mfmsg)
50 {
51  mf::ErrorObj* eop = new mf::ErrorObj(mfmsg.ErrorObject());
52  mf::LogErrorObj(eop);
53 }
54 
55 int main(int argc, char* argv[])
56 {
57  // checking options
58  std::string filename;
59  std::string configFile;
60 
61  try
62  {
63  po::options_description cmdopt("Allowed options");
64  cmdopt.add_options()
65  ("help,h", "display help message")
66  ("config,c", po::value<std::string>(&configFile)->default_value(""),"Specify the FHiCL configuration file to use")
67  ("filename,f",
68  po::value<std::string>(&filename)->default_value("msg_archive"),
69  "specify the message archive file name");
70 
71  po::options_description desc;
72  desc.add(cmdopt);
73 
74  po::variables_map vm;
75  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
76  po::notify(vm);
77 
78  if (vm.count("help"))
79  {
80  std::cout << "Usage: msglogger [options] <message text>\n";
81  std::cout << cmdopt;
82  return 0;
83  }
84  }
85  catch (std::exception& e)
86  {
87  std::cerr << "error: " << e.what() << "\n";
88  return 1;
89  }
90  catch (...)
91  {
92  std::cerr << "Exception of unknown type!\n";
93  return 1;
94  }
95 
96 
97  // Start MessageFacility Service
98 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
99  std::ostringstream descstr;
100  descstr << "";
101  fhicl::ParameterSet main_pset;
102  mf::StartMessageFacility( main_pset );
103 # else
104  mf::StartMessageFacility(
105  mf::MessageFacilityService::SingleThread,
106  mf::MessageFacilityService::logArchive(filename));
107 # endif
108 
109  fhicl::ParameterSet pset;
110  auto maker = cet::filepath_maker();
111  fhicl::make_ParameterSet(configFile, maker, pset);
112  mfviewer::ReceiverManager rm(pset);
113 
114 
115  // Welcome message
116  std::cout << "Message Facility MsgServer is up and listening to configured Receivers" <<std::endl;
117 
118  // Command line message loop
119  std::string cmd;
120 
121  while (true)
122  {
123  if (cmdline) std::cout << "> ";
124  getline(std::cin, cmd);
125 
126  if (cmd.empty())
127  {
128  cmdline = true;
129  }
130  else if (cmdline && (cmd == "r" || cmd == "resume"))
131  {
132  cmdline = false;;
133  }
134  else if (cmdline && (cmd == "q" || cmd == "quit"))
135  {
136  //dds.stop();
137  return 0;
138  }
139  else if (cmdline && (cmd == "h" || cmd == "help"))
140  {
141  std::cout << "MessageFacility DDS server available commands:\n"
142  << " (h)elp display this help message\n"
143  << " (s)tat summary of received messages\n"
144  << " (r)esume resume to message listening mode\n"
145  //<< " (p)artition listen to a new partition\n"
146  << " (q)uit exit MessageFacility DDS server\n"
147  << " ... more interactive commands on the way.\n";
148  }
149  else if (cmdline && (cmd == "s" || cmd == "stat"))
150  {
151  std::cout << "Currently listening, " << z << " messages have been received." << std::endl;
152  }
153  else if (cmdline)
154  {
155  std::cout << "Command " << cmd << " not found. "
156  << "Type \"help\" or \"h\" for a list of available commands.\n";
157  }
158  } // end of command line message loop
159 
160 
161  return 0;
162 }
The ReceiverManager loads one or more receiver plugins and displays messages received by those plugin...