artdaq_mfextensions  v1_03_03a
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  // checking options
19  std::string filename;
20  std::string configFile;
21 
22  try {
23  po::options_description cmdopt("Allowed options");
24  cmdopt.add_options()("help,h", "display help message")("config,c",
25  po::value<std::string>(&configFile)->default_value(""),
26  "Specify the FHiCL configuration file to use")(
27  "filename,f", po::value<std::string>(&filename)->default_value("msg_archive"),
28  "specify the message archive file name");
29 
30  po::options_description desc;
31  desc.add(cmdopt);
32 
33  po::variables_map vm;
34  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
35  po::notify(vm);
36 
37  if (vm.count("help")) {
38  std::cout << "Usage: msglogger [options] <message text>\n";
39  std::cout << cmdopt;
40  return 0;
41  }
42  } catch (std::exception& e) {
43  std::cerr << "error: " << e.what() << "\n";
44  return 1;
45  } catch (...) {
46  std::cerr << "Exception of unknown type!\n";
47  return 1;
48  }
49 
50  // Start MessageFacility Service
51  std::ostringstream descstr;
52  descstr << "";
53  fhicl::ParameterSet main_pset;
54  mf::StartMessageFacility(main_pset);
55 
56  fhicl::ParameterSet pset;
57  auto maker = cet::filepath_maker();
58  fhicl::make_ParameterSet(configFile, maker, pset);
60 
61  // Welcome message
62  std::cout << "Message Facility MsgServer is up and listening to configured Receivers" << std::endl;
63 
64  // Command line message loop
65  std::string cmd;
66 
67  while (true) {
68  if (cmdline) std::cout << "> ";
69  getline(std::cin, cmd);
70 
71  if (cmd.empty()) {
72  cmdline = true;
73  } else if (cmdline && (cmd == "r" || cmd == "resume")) {
74  cmdline = false;
75  ;
76  } else if (cmdline && (cmd == "q" || cmd == "quit")) {
77  // dds.stop();
78  return 0;
79  } else if (cmdline && (cmd == "h" || cmd == "help")) {
80  std::cout << "MessageFacility DDS server available commands:\n"
81  << " (h)elp display this help message\n"
82  << " (s)tat summary of received messages\n"
83  << " (r)esume resume to message listening mode\n"
84  //<< " (p)artition listen to a new partition\n"
85  << " (q)uit exit MessageFacility DDS server\n"
86  << " ... more interactive commands on the way.\n";
87  } else if (cmdline && (cmd == "s" || cmd == "stat")) {
88  std::cout << "Currently listening, " << z << " messages have been received." << std::endl;
89  } else if (cmdline) {
90  std::cout << "Command " << cmd << " not found. "
91  << "Type \"help\" or \"h\" for a list of available commands.\n";
92  }
93  } // end of command line message loop
94 
95  return 0;
96 }
The ReceiverManager loads one or more receiver plugins and displays messages received by those plugin...