Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JGetMessage.cc File Reference

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

#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <set>
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JNet/JControlHost.hh"
#include "JSystem/JDate.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). 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

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

Definition at line 24 of file JGetMessage.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
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:1961
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
then print u2 $script< option > print u2 Possible stop