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