artdaq_mfextensions  v1_04_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/Binaries/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"))
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) std::cout << "> ";
77  getline(std::cin, cmd);
78 
79  if (cmd.empty())
80  {
81  cmdline = true;
82  }
83  else if (cmdline && (cmd == "r" || cmd == "resume"))
84  {
85  cmdline = false;
86  ;
87  }
88  else if (cmdline && (cmd == "q" || cmd == "quit"))
89  {
90  // dds.stop();
91  return 0;
92  }
93  else if (cmdline && (cmd == "h" || cmd == "help"))
94  {
95  std::cout << "MessageFacility DDS server available commands:\n"
96  << " (h)elp display this help message\n"
97  << " (s)tat summary of received messages\n"
98  << " (r)esume resume to message listening mode\n"
99  //<< " (p)artition listen to a new partition\n"
100  << " (q)uit exit MessageFacility DDS server\n"
101  << " ... more interactive commands on the way.\n";
102  }
103  else if (cmdline && (cmd == "s" || cmd == "stat"))
104  {
105  std::cout << "Currently listening, " << z << " messages have been received." << std::endl;
106  }
107  else if (cmdline)
108  {
109  std::cout << "Command " << cmd << " not found. "
110  << "Type \"help\" or \"h\" for a list of available commands.\n";
111  }
112  } // end of command line message loop
113 
114  return 0;
115 }
The ReceiverManager loads one or more receiver plugins and displays messages received by those plugin...