artdaq_mfextensions  v1_05_00
msgserver.cc
1 #include "messagefacility/MessageLogger/MessageLogger.h"
2 #include "messagefacility/Utilities/ErrorObj.h"
3 
4 #include <boost/bind.hpp>
5 #include <boost/program_options.hpp>
6 
7 #include <iostream>
8 #include <string>
9 #include "fhiclcpp/make_ParameterSet.h"
10 #include "mfextensions/Receivers/ReceiverManager.hh"
11 
12 namespace po = boost::program_options;
13 
14 bool cmdline = false;
15 int z = 0;
16 
17 int main(int argc, char* argv[])
18 {
19  // checking options
20  std::string filename;
21  std::string configFile;
22 
23  try
24  {
25  po::options_description cmdopt("Allowed options");
26  cmdopt.add_options()("help,h", "display help message")("config,c",
27  po::value<std::string>(&configFile)->default_value(""),
28  "Specify the FHiCL configuration file to use")(
29  "filename,f", po::value<std::string>(&filename)->default_value("msg_archive"),
30  "specify the message archive file name");
31 
32  po::options_description desc;
33  desc.add(cmdopt);
34 
35  po::variables_map vm;
36  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
37  po::notify(vm);
38 
39  if (vm.count("help") != 0u)
40  {
41  std::cout << "Usage: msglogger [options] <message text>\n";
42  std::cout << cmdopt;
43  return 0;
44  }
45  }
46  catch (std::exception& e)
47  {
48  std::cerr << "error: " << e.what() << "\n";
49  return 1;
50  }
51  catch (...)
52  {
53  std::cerr << "Exception of unknown type!\n";
54  return 1;
55  }
56 
57  // Start MessageFacility Service
58  std::ostringstream descstr;
59  descstr << "";
60  fhicl::ParameterSet main_pset;
61  mf::StartMessageFacility(main_pset);
62 
63  fhicl::ParameterSet pset;
64  auto maker = cet::filepath_maker();
65  fhicl::make_ParameterSet(configFile, maker, pset);
67 
68  // Welcome message
69  std::cout << "Message Facility MsgServer is up and listening to configured Receivers" << std::endl;
70 
71  // Command line message loop
72  std::string cmd;
73 
74  while (true)
75  {
76  if (cmdline)
77  {
78  std::cout << "> ";
79  }
80  getline(std::cin, cmd);
81 
82  if (cmd.empty())
83  {
84  cmdline = true;
85  }
86  else if (cmdline && (cmd == "r" || cmd == "resume"))
87  {
88  cmdline = false;
89  ;
90  }
91  else if (cmdline && (cmd == "q" || cmd == "quit"))
92  {
93  // dds.stop();
94  return 0;
95  }
96  else if (cmdline && (cmd == "h" || cmd == "help"))
97  {
98  std::cout << "MessageFacility DDS server available commands:\n"
99  << " (h)elp display this help message\n"
100  << " (s)tat summary of received messages\n"
101  << " (r)esume resume to message listening mode\n"
102  //<< " (p)artition listen to a new partition\n"
103  << " (q)uit exit MessageFacility DDS server\n"
104  << " ... more interactive commands on the way.\n";
105  }
106  else if (cmdline && (cmd == "s" || cmd == "stat"))
107  {
108  std::cout << "Currently listening, " << z << " messages have been received." << std::endl;
109  }
110  else if (cmdline)
111  {
112  std::cout << "Command " << cmd << " not found. "
113  << "Type \"help\" or \"h\" for a list of available commands.\n";
114  }
115  } // end of command line message loop
116 
117  return 0;
118 }
The ReceiverManager loads one or more receiver plugins and displays messages received by those plugin...