Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JGetMessage.cc File Reference

Auxiliary program to receive messages from ControlHost server. More...

#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <set>
#include "JNet/JControlHost.hh"
#include "JSystem/JDateAndTime.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Detailed Description

Auxiliary program to receive messages from ControlHost server.

The option -H <hostname>[:port] correponds to the hostname and the port of the server, respectively.
The options -t and -T correspond to the ControlHost tag(s), with subscriptions any and all, respectively.
Each message tag will be printed and for the latter also the message content.
The program will terminate when it receives message <stop>.

Author
mdejong

Definition in file JGetMessage.cc.

Function Documentation

◆ main()

int main ( int argc,
const char * argv[] )

Definition at line 27 of file JGetMessage.cc.

28{
29 using namespace std;
30 using namespace JPP;
31
32 string hostname;
33 set<JTag> tagList;
34 set<JTag> TagList;
35 bool date;
36 int debug;
37
38 try {
39
40 JParser<> zap("Auxiliary program to receive messages from ControlHost server.");
41
42 zap['H'] = make_field(hostname, "host name of message srver") = "localhost";
43 zap['t'] = make_field(tagList, "list of tags with subscription any") = JPARSER::initialised();
44 zap['T'] = make_field(TagList, "list of tags with subscription all") = JPARSER::initialised();
45 zap['D'] = make_field(date, "print date and time of message receipt");
46 zap['d'] = make_field(debug) = 3;
47
48 zap(argc, argv);
49 }
50 catch(const exception &error) {
51 FATAL(error.what() << endl);
52 }
53
54
55 if (tagList.empty() && TagList.empty()) {
56 FATAL("No tags specified.");
57 }
58
59
60 JControlHost::Throw(true);
61
62 try {
63
64 JControlHost in(hostname);
65
66 {
67 JSubscriptionList buffer;
68
69 for (set<JTag>::const_iterator i = tagList.begin(); i != tagList.end(); ++i) {
70 buffer.add(JSubscriptionAny(*i));
71 }
72
73 for (set<JTag>::const_iterator i = TagList.begin(); i != TagList.end(); ++i) {
74 buffer.add(JSubscriptionAll(*i));
75 }
76
77 in.MyId("JGetMessage");
78 in.Subscribe(buffer);
79 in.SendMeAlways();
80 }
81
82
83 JPrefix prefix;
84 vector<char> buffer;
85
86 for (const string stop("stop"); buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) {
87
88 in.WaitHead(prefix);
89
90 buffer.resize(prefix.getSize());
91
92 in.GetFullData(buffer.data(), buffer.size());
93
94 if (date) {
95 cout << getDateAndTime() << ' ';
96 }
97
98 cout << left << setw(8) << prefix.getTag() << ' ' << right << setw(8) << prefix.getSize();
99
100 if (TagList.find(prefix) != TagList.end()) {
101 cout << ' ' << string(buffer.data(), buffer.size());
102 }
103
104 cout << endl;
105 }
106 }
107 catch(const exception& error) {
108 FATAL(error.what() << endl);
109 }
110
111 return 0;
112}
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
ControlHost class.
ControlHost prefix.
Definition JPrefix.hh:33
int getSize() const
Get size.
Definition JPrefix.hh:62
Subscription list.
JSubscriptionList & add(const JSubscription &subscription)
Add subscription.
const JTag & getTag() const
Get tag.
Definition JTag.hh:86
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for all subscription.
Auxiliary class for any subscription.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68