Jpp  15.0.0
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), 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

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

Definition at line 25 of file JGetMessage.cc.

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string hostname;
31  set<JTag> tagList;
32  set<JTag> TagList;
33  bool date;
34  int debug;
35 
36  try {
37 
38  JParser<> zap("Auxiliary program to receive messages from ControlHost server.");
39 
40  zap['H'] = make_field(hostname, "host name of message srver") = "localhost";
41  zap['t'] = make_field(tagList, "list of tags with subscription any") = JPARSER::initialised();
42  zap['T'] = make_field(TagList, "list of tags with subscription all") = JPARSER::initialised();
43  zap['D'] = make_field(date, "print date and time of message receipt");
44  zap['d'] = make_field(debug) = 3;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52 
53  if (tagList.empty() && TagList.empty()) {
54  FATAL("No tags specified.");
55  }
56 
57 
58  JControlHost::Throw(true);
59 
60  try {
61 
62  JControlHost in(hostname);
63 
64  {
65  JSubscriptionList buffer;
66 
67  for (set<JTag>::const_iterator i = tagList.begin(); i != tagList.end(); ++i) {
68  buffer.add(JSubscriptionAny(*i));
69  }
70 
71  for (set<JTag>::const_iterator i = TagList.begin(); i != TagList.end(); ++i) {
72  buffer.add(JSubscriptionAll(*i));
73  }
74 
75  in.MyId("JGetMessage");
76  in.Subscribe(buffer);
77  in.SendMeAlways();
78  }
79 
80 
81  JPrefix prefix;
82  vector<char> buffer;
83 
84  for (const string stop("stop"); buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) {
85 
86  in.WaitHead(prefix);
87 
88  buffer.resize(prefix.getSize());
89 
90  in.GetFullData(buffer.data(), buffer.size());
91 
92  if (date) {
93  cout << getDateAndTime() << ' ';
94  }
95 
96  cout << left << setw(8) << prefix.getTag() << ' ' << right << setw(8) << prefix.getSize();
97 
98  if (TagList.find(prefix) != TagList.end()) {
99  cout << ' ' << string(buffer.data(), buffer.size());
100  }
101 
102  cout << endl;
103  }
104  }
105  catch(const JControlHostException& error) {
106  FATAL(error << endl);
107  }
108 
109  return 0;
110 }
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
then usage $script[port]< option > nPossible stop
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
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:41