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

A tool to forward messages with the given tags from one ControlHost server (e.g. More...

#include <chrono>
#include <iostream>
#include <set>
#include <string>
#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

A tool to forward messages with the given tags from one ControlHost server (e.g.

JLigier) to another.

The options -H <source>[:port] and -H <target>[:port] correpond to the hostname and the port of the source and target server, respectively. The options -t and -T correspond to the ControlHost tag(s) with the mode subscription "any" and subscription "all".

Author
tgal

Definition in file JLigierMirror.cc.

Function Documentation

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

Definition at line 23 of file JLigierMirror.cc.

24 {
25  using namespace std;
26 
27  string source;
28  string target;
29  int report_interval; // in seconds
30  set<JNET::JTag> tagList;
31  set<JNET::JTag> TagList;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Program to forward messages from one ControlHost server to another.");
37 
38  zap['H'] = make_field(source) = "localhost";
39  zap['X'] = make_field(target) = "localhost";
40  zap['t'] = make_field(tagList);
41  zap['T'] = make_field(TagList);
42  zap['i'] = make_field(report_interval) = 30;
43  zap['d'] = make_field(debug) = 0;
44 
45  zap['t'] = JPARSER::initialised();
46  zap['T'] = JPARSER::initialised();
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  using namespace JPP;
60 
61  cout << "Forwarding messages from " << endl << " " << source << " -> " << target << endl;
62 
63 
64  JControlHost::Throw(true);
65 
66  try {
67 
68  JControlHost in(source);
69  JControlHost out(target);
70 
71  cout << "with the following tags: ";
72 
73  {
74  JSubscriptionList buffer;
75 
76  for (set<JTag>::const_iterator i = tagList.begin(); i != tagList.end(); ++i) {
77  buffer.add(JSubscriptionAny(*i));
78  cout << *i << "(any) ";
79  }
80 
81  for (set<JTag>::const_iterator i = TagList.begin(); i != TagList.end(); ++i) {
82  buffer.add(JSubscriptionAll(*i));
83  cout << *i << "(all) ";
84  }
85 
86  cout << endl;
87 
88  in.Subscribe(buffer);
89  in.SendMeAlways();
90  }
91 
92 
93  JPrefix prefix;
94  vector<char> buffer;
95  unsigned int message_count = 0;
96  float milliseconds_passed;
97  std::chrono::high_resolution_clock::time_point start_time = std::chrono::high_resolution_clock::now();
98 
99  for (const string stop("stop"); buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) {
100 
101  in.WaitHead(prefix);
102 
103  buffer.resize(prefix.getSize());
104 
105  in.GetFullData(buffer.data(), buffer.size());
106 
107  DEBUG(getDateAndTime() << ' ' << left << setw(8) << prefix.getTag() << ' ' << right << setw(8) << prefix.getSize() << endl);
108 
109  out.PutFullData(prefix.getTag(), buffer.data(), buffer.size());
110 
111  message_count += 1;
112  milliseconds_passed = (std::chrono::high_resolution_clock::now() - start_time) / std::chrono::milliseconds(1);
113 
114  if(milliseconds_passed > report_interval * 1e3) {
115  cout << getDateAndTime() << " : " << "Message rate: " << message_count / milliseconds_passed * 1e3 << " Hz" << endl;
116  start_time = std::chrono::high_resolution_clock::now();
117  message_count = 0;
118  }
119  }
120  }
121  catch(const JControlHostException& error) {
122  ERROR(error << endl);
123  }
124 }
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
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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