#include #include #include #include #include #include "JNet/JControlHost.hh" #include "JSystem/JDateAndTime.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Auxiliary program to receive messages from ControlHost server. * * The option -H \[:port] correponds to the hostname and the port of the server, respectively.\n * The options -t and -T correspond to the ControlHost tag(s), * with subscriptions any and all, respectively.\n * Each message tag will be printed and for the latter also the message content.\n * The program will terminate when it receives message \. * \author mdejong */ int main(int argc, const char *argv[]) { using namespace std; using namespace JPP; string hostname; set tagList; set TagList; bool date; int debug; try { JParser<> zap("Auxiliary program to receive messages from ControlHost server."); zap['H'] = make_field(hostname, "host name of message srver") = "localhost"; zap['t'] = make_field(tagList, "list of tags with subscription any") = JPARSER::initialised(); zap['T'] = make_field(TagList, "list of tags with subscription all") = JPARSER::initialised(); zap['D'] = make_field(date, "print date and time of message receipt"); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (tagList.empty() && TagList.empty()) { FATAL("No tags specified."); } JControlHost::Throw(true); try { JControlHost in(hostname); { JSubscriptionList buffer; for (set::const_iterator i = tagList.begin(); i != tagList.end(); ++i) { buffer.add(JSubscriptionAny(*i)); } for (set::const_iterator i = TagList.begin(); i != TagList.end(); ++i) { buffer.add(JSubscriptionAll(*i)); } in.MyId("JGetMessage"); in.Subscribe(buffer); in.SendMeAlways(); } JPrefix prefix; vector buffer; for (const string stop("stop"); buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) { in.WaitHead(prefix); buffer.resize(prefix.getSize()); in.GetFullData(buffer.data(), buffer.size()); if (date) { cout << getDateAndTime() << ' '; } cout << left << setw(8) << prefix.getTag() << ' ' << right << setw(8) << prefix.getSize(); if (TagList.find(prefix) != TagList.end()) { cout << ' ' << string(buffer.data(), buffer.size()); } cout << endl; } } catch(const JControlHostException& error) { FATAL(error << endl); } return 0; }