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