Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
7 #include "Jeep/JParser.hh"
8 #include "Jeep/JMessage.hh"
9 #include "JNet/JControlHost.hh"
10 #include "JSystem/JDate.hh"
11 
12 
13 /**
14  * \file
15  *
16  * Auxiliary program to receive messages from ControlHost server.
17  *
18  * The option <tt>-H <hostname>[:port]</tt> correponds to the hostname and the port of the server, respectively.
19  * The options <tt>-t</tt> and <tt>-T</tt> correspond to the ControlHost tag(s).
20  * Each message tag will be printed and for the latter also the message content.
21  * The program will terminate when it receives message <stop>.
22  * \author mdejong
23  */
24 int main(int argc, const char *argv[])
25 {
26  using namespace std;
27 
28  string hostname;
29  set<JNET::JTag> tagList;
30  set<JNET::JTag> TagList;
31  bool date;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Auxiliary program to receive messages from ControlHost server.");
37 
38  zap['H'] = make_field(hostname) = "localhost";
39  zap['t'] = make_field(tagList);
40  zap['T'] = make_field(TagList);
41  zap['D'] = make_field(date);
42  zap['d'] = make_field(debug) = 3;
43 
44  zap['t'] = JPARSER::initialised();
45  zap['T'] = JPARSER::initialised();
46 
47  zap(argc, argv);
48  }
49  catch(const exception &error) {
50  FATAL(error.what() << endl);
51  }
52 
53 
54  if (tagList.empty() && TagList.empty()) {
55  FATAL("No tags specified.");
56  }
57 
58  using namespace JPP;
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.Subscribe(buffer);
78  in.SendMeAlways();
79  }
80 
81 
82  JPrefix prefix;
83  vector<char> buffer;
84 
85  for (const string stop("stop"); buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) {
86 
87  in.WaitHead(prefix);
88 
89  buffer.resize(prefix.getSize());
90 
91  in.GetFullData(buffer.data(), buffer.size());
92 
93  if (date) {
94  cout << getDateAndTime() << ' ';
95  }
96 
97  cout << left << setw(8) << prefix.getTag() << ' ' << right << setw(8) << prefix.getSize();
98 
99  if (TagList.find(prefix) != TagList.end()) {
100  cout << ' ' << string(buffer.data(), buffer.size());
101  }
102 
103  cout << endl;
104  }
105  }
106  catch(const JControlHostException& error) {
107  ERROR(error << endl);
108  }
109 }
110 
111 
Utility class to parse command line options.
Definition: JParser.hh:1493
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
Date and time functions.
static JDateAndTime getDateAndTime
Function object to get ASCII formatted date and time.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:61
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then print u2 $script< option > print u2 Possible stop
int main(int argc, char *argv[])
Definition: Main.cpp:15