00001 #include "messagefacility/MessageLogger/MessageLogger.h"
00002 #include "messagefacility/Utilities/MessageFacilityMsg.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 void printmsg(mf::MessageFacilityMsg const& mfmsg)
00018 {
00019
00020 if (cmdline) return;
00021
00022
00023
00024
00025
00026
00027 mf::ErrorObj* eop = new mf::ErrorObj(mfmsg.ErrorObject());
00028 mf::LogErrorObj(eop);
00029
00030
00031 std::cout << "severity: " << mfmsg.severity() << "\n";
00032 std::cout << "timestamp: " << mfmsg.timestr() << "\n";
00033 std::cout << "hostname: " << mfmsg.hostname() << "\n";
00034 std::cout << "hostaddr(ip): " << mfmsg.hostaddr() << "\n";
00035 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00036 std::cout << "process: " << mfmsg.process() << "\n";
00037 # endif
00038 std::cout << "process_id: " << mfmsg.pid() << "\n";
00039 std::cout << "application: " << mfmsg.application() << "\n";
00040 std::cout << "module: " << mfmsg.module() << "\n";
00041 std::cout << "context: " << mfmsg.context() << "\n";
00042 std::cout << "category(id): " << mfmsg.category() << "\n";
00043 std::cout << "file: " << mfmsg.file() << "\n";
00044 std::cout << "line: " << mfmsg.line() << "\n";
00045 std::cout << "message: " << mfmsg.message() << "\n";
00046 std::cout << std::endl;
00047 }
00048
00049 void printnull(mf::MessageFacilityMsg const& mfmsg)
00050 {
00051 mf::ErrorObj* eop = new mf::ErrorObj(mfmsg.ErrorObject());
00052 mf::LogErrorObj(eop);
00053 }
00054
00055 int main(int argc, char* argv[])
00056 {
00057
00058 std::string filename;
00059 std::string configFile;
00060
00061 try
00062 {
00063 po::options_description cmdopt("Allowed options");
00064 cmdopt.add_options()
00065 ("help,h", "display help message")
00066 ("config,c", po::value<std::string>(&configFile)->default_value(""),"Specify the FHiCL configuration file to use")
00067 ("filename,f",
00068 po::value<std::string>(&filename)->default_value("msg_archive"),
00069 "specify the message archive file name");
00070
00071 po::options_description desc;
00072 desc.add(cmdopt);
00073
00074 po::variables_map vm;
00075 po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
00076 po::notify(vm);
00077
00078 if (vm.count("help"))
00079 {
00080 std::cout << "Usage: msglogger [options] <message text>\n";
00081 std::cout << cmdopt;
00082 return 0;
00083 }
00084 }
00085 catch (std::exception& e)
00086 {
00087 std::cerr << "error: " << e.what() << "\n";
00088 return 1;
00089 }
00090 catch (...)
00091 {
00092 std::cerr << "Exception of unknown type!\n";
00093 return 1;
00094 }
00095
00096
00097
00098 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00099 std::ostringstream descstr;
00100 descstr << "";
00101 fhicl::ParameterSet main_pset;
00102 mf::StartMessageFacility( main_pset );
00103 # else
00104 mf::StartMessageFacility(
00105 mf::MessageFacilityService::SingleThread,
00106 mf::MessageFacilityService::logArchive(filename));
00107 # endif
00108
00109 fhicl::ParameterSet pset;
00110 auto maker = cet::filepath_maker();
00111 fhicl::make_ParameterSet(configFile, maker, pset);
00112 mfviewer::ReceiverManager rm(pset);
00113
00114
00115
00116 std::cout << "Message Facility MsgServer is up and listening to configured Receivers" <<std::endl;
00117
00118
00119 std::string cmd;
00120
00121 while (true)
00122 {
00123 if (cmdline) std::cout << "> ";
00124 getline(std::cin, cmd);
00125
00126 if (cmd.empty())
00127 {
00128 cmdline = true;
00129 }
00130 else if (cmdline && (cmd == "r" || cmd == "resume"))
00131 {
00132 cmdline = false;;
00133 }
00134 else if (cmdline && (cmd == "q" || cmd == "quit"))
00135 {
00136
00137 return 0;
00138 }
00139 else if (cmdline && (cmd == "h" || cmd == "help"))
00140 {
00141 std::cout << "MessageFacility DDS server available commands:\n"
00142 << " (h)elp display this help message\n"
00143 << " (s)tat summary of received messages\n"
00144 << " (r)esume resume to message listening mode\n"
00145
00146 << " (q)uit exit MessageFacility DDS server\n"
00147 << " ... more interactive commands on the way.\n";
00148 }
00149 else if (cmdline && (cmd == "s" || cmd == "stat"))
00150 {
00151 std::cout << "Currently listening, " << z << " messages have been received." << std::endl;
00152 }
00153 else if (cmdline)
00154 {
00155 std::cout << "Command " << cmd << " not found. "
00156 << "Type \"help\" or \"h\" for a list of available commands.\n";
00157 }
00158 }
00159
00160
00161 return 0;
00162 }