Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JGetMessage.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <sstream>
4#include <iomanip>
5#include <set>
6
8
10
11#include "Jeep/JParser.hh"
12#include "Jeep/JMessage.hh"
13
14
15/**
16 * \file
17 *
18 * Auxiliary program to receive messages from ControlHost server.
19 *
20 * The option <tt>-H <hostname>[:port]</tt> correponds to the hostname and the port of the server, respectively.\n
21 * The options <tt>-t</tt> and <tt>-T</tt> correspond to the ControlHost tag(s),
22 * with subscriptions any and all, respectively.\n
23 * Each message tag will be printed and for the latter also the message content.\n
24 * The program will terminate when it receives message <stop>.
25 * \author mdejong
26 */
27int main(int argc, const char *argv[])
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}
113
114
Date and time functions.
int main(int argc, const char *argv[])
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
ControlHost class.
int MyId(const std::string &nick_name)
Identify.
int WaitHead(JPrefix &prefix)
Wait for header.
int GetFullData(void *buffer, long long int length)
Receive data.
int SendMeAlways()
Tell server to send messages forever.
int Subscribe(const JSubscription &subscription)
Subscribe to single tag.
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