Jpp  17.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPutData.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <limits>
5 
6 #include "Jeep/JParser.hh"
7 #include "Jeep/JMessage.hh"
8 #include "Jeep/JTimekeeper.hh"
9 #include "JSystem/JTime.hh"
10 #include "JNet/JControlHost.hh"
11 
12 
13 /**
14  * \file
15  *
16  * Auxiliary program to send messages to 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) for free and all subscription, respectively.
20  * The option <tt>-R</tt> corresponds to the rate at which messages will be sent.
21  * \author mdejong
22  */
23 int main(int argc, const char *argv[])
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  string hostname;
29  JTag tag;
30  JTag Tag;
31  double rate_Hz;
32  int numberOfEvents;
33  int size;
34  int debug;
35 
36  try {
37 
38  JParser<> zap("Auxiliary program to send messages to ControlHost server.");
39 
40  zap['H'] = make_field(hostname) = "localhost";
41  zap['t'] = make_field(tag) = DISPTAG_UNDEFINED;
42  zap['T'] = make_field(Tag) = DISPTAG_UNDEFINED;
43  zap['R'] = make_field(rate_Hz);
44  zap['n'] = make_field(numberOfEvents) = numeric_limits<int>::max();
45  zap['s'] = make_field(size) = 1024;
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 
56  if (tag == DISPTAG_UNDEFINED && Tag == DISPTAG_UNDEFINED) {
57  FATAL("No tags specified.");
58  }
59 
60  JControlHost::Throw(true);
61 
62  try {
63 
64  JControlHost out(hostname);
65 
66  JTimekeeper timer((long long int) (1.0e6 / rate_Hz));
67 
68  vector<char> buffer(size);
69 
70  for (int i = 0; i != size; ++i) {
71  buffer[i] = 'a' + (i%26);
72  }
73 
74  int all = 0;
75  int few = 0;
76 
77  timer.reset();
78 
79  const long long int t0 = getLocalTime();
80 
81  for (int i = 1; i <= numberOfEvents; ++i) {
82 
83  if (Tag != DISPTAG_UNDEFINED) { out.PutFullData(Tag, buffer.data(), buffer.size()); ++all; }
84  if (tag != DISPTAG_UNDEFINED) { out.PutFullData(tag, buffer.data(), buffer.size()); ++few; }
85 
86  if (i%100 == 0) {
87 
88  const long long int t1 = getLocalTime();
89 
90  DEBUG("Time [us] " << setw(10) << t1 - t0 << endl);
91  DEBUG("<delay> [us] " << setw(10) << timer.getDelay() / i << endl);
92  DEBUG("Count all " << setw(10) << all << endl);
93  DEBUG("Count few " << setw(10) << few << endl);
94  }
95 
96  timer.wait();
97  }
98  }
99  catch(const JControlHostException& error) {
100  ERROR(error << endl);
101  }
102 }
103 
104 
Utility class to parse command line options.
Definition: JParser.hh:1517
int main(int argc, char *argv[])
Definition: Main.cc:15
Scheduling of actions via fixed latency intervals.
static const JLocalTime getLocalTime
Function object to get local time in micro seconds.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define ERROR(A)
Definition: JMessage.hh:66
static const JTag DISPTAG_UNDEFINED(0)
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
System time information.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62