00001 #include "messagefacility/MessageLogger/MessageLogger.h"
00002 #include "messagefacility/Utilities/ErrorObj.h"
00003
00004 #include <boost/program_options.hpp>
00005 #include <boost/bind.hpp>
00006
00007 #include <iostream>
00008 #include <string>
00009 #include "mfextensions/Binaries/ReceiverManager.hh"
00010 #include "fhiclcpp/make_ParameterSet.h"
00011
00012 namespace po = boost::program_options;
00013
00014 bool cmdline = false;
00015 int z = 0;
00016
00017 int main(int argc, char* argv[])
00018 {
00019
00020 std::string filename;
00021 std::string configFile;
00022
00023 try
00024 {
00025 po::options_description cmdopt("Allowed options");
00026 cmdopt.add_options()
00027 ("help,h", "display help message")
00028 ("config,c", po::value<std::string>(&configFile)->default_value(""),"Specify the FHiCL configuration file to use")
00029 ("filename,f",
00030 po::value<std::string>(&filename)->default_value("msg_archive"),
00031 "specify the message archive file name");
00032
00033 po::options_description desc;
00034 desc.add(cmdopt);
00035
00036 po::variables_map vm;
00037 po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
00038 po::notify(vm);
00039
00040 if (vm.count("help"))
00041 {
00042 std::cout << "Usage: msglogger [options] <message text>\n";
00043 std::cout << cmdopt;
00044 return 0;
00045 }
00046 }
00047 catch (std::exception& e)
00048 {
00049 std::cerr << "error: " << e.what() << "\n";
00050 return 1;
00051 }
00052 catch (...)
00053 {
00054 std::cerr << "Exception of unknown type!\n";
00055 return 1;
00056 }
00057
00058
00059
00060 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00061 std::ostringstream descstr;
00062 descstr << "";
00063 fhicl::ParameterSet main_pset;
00064 mf::StartMessageFacility( main_pset );
00065 # else
00066 mf::StartMessageFacility(
00067 mf::MessageFacilityService::SingleThread,
00068 mf::MessageFacilityService::logArchive(filename));
00069 # endif
00070
00071 fhicl::ParameterSet pset;
00072 auto maker = cet::filepath_maker();
00073 fhicl::make_ParameterSet(configFile, maker, pset);
00074 mfviewer::ReceiverManager rm(pset);
00075
00076
00077
00078 std::cout << "Message Facility MsgServer is up and listening to configured Receivers" <<std::endl;
00079
00080
00081 std::string cmd;
00082
00083 while (true)
00084 {
00085 if (cmdline) std::cout << "> ";
00086 getline(std::cin, cmd);
00087
00088 if (cmd.empty())
00089 {
00090 cmdline = true;
00091 }
00092 else if (cmdline && (cmd == "r" || cmd == "resume"))
00093 {
00094 cmdline = false;;
00095 }
00096 else if (cmdline && (cmd == "q" || cmd == "quit"))
00097 {
00098
00099 return 0;
00100 }
00101 else if (cmdline && (cmd == "h" || cmd == "help"))
00102 {
00103 std::cout << "MessageFacility DDS server available commands:\n"
00104 << " (h)elp display this help message\n"
00105 << " (s)tat summary of received messages\n"
00106 << " (r)esume resume to message listening mode\n"
00107
00108 << " (q)uit exit MessageFacility DDS server\n"
00109 << " ... more interactive commands on the way.\n";
00110 }
00111 else if (cmdline && (cmd == "s" || cmd == "stat"))
00112 {
00113 std::cout << "Currently listening, " << z << " messages have been received." << std::endl;
00114 }
00115 else if (cmdline)
00116 {
00117 std::cout << "Command " << cmd << " not found. "
00118 << "Type \"help\" or \"h\" for a list of available commands.\n";
00119 }
00120 }
00121
00122
00123 return 0;
00124 }