Jpp  18.0.1-rc.2
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 "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

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 JControlHostException& error) {
108  FATAL(error << endl);
109  }
110 
111  return 0;
112 }
Utility class to parse command line options.
Definition: JParser.hh:1514
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
then usage $script[port]< option > nPossible stop
static JDateAndTime getDateAndTime
Function object to get current date and time.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
then awk string
#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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level