Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMessageScheduler.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
10 
11 #include "Jeep/JParser.hh"
12 #include "Jeep/JMessage.hh"
13 
14 
15 /**
16  * \file
17  *
18  * Example program to test message scheduling.
19  * \author mdejong
20  */
21 int main(int argc, char* argv[])
22 {
23  using namespace std;
24 
25  string message_logger;
26  bool use_cout;
27  int log_s;
28  int numberOfMessages;
29  int debug;
30 
31  try {
32 
33  JParser<> zap("Example program to test message scheduling.");
34 
35  zap['M'] = make_field(message_logger) = "localhost";
36  zap['c'] = make_field(use_cout);
37  zap['T'] = make_field(log_s);
38  zap['n'] = make_field(numberOfMessages);
39  zap['d'] = make_field(debug) = 3;
40 
41  zap(argc, argv);
42  }
43  catch(const exception &error) {
44  FATAL(error.what() << endl);
45  }
46 
47  using namespace JPP;
48 
49  cout.tie(&cerr);
50 
51  JLogger* out = NULL;
52 
53  if (use_cout)
54  out = new JStreamLogger(cout);
55  else
56  out = new JControlHostLogger(message_logger);
57 
58  JMessageLogger logger(out, argv[0], debug);
59  JMessageScheduler scheduler(logger, JTimekeeper(log_s * 1000000));
60 
61  scheduler.setCredit(3);
62 
63  for (int i = 0; i != numberOfMessages; ++i) {
64 
65  cout << "sleep [s] " << i * log_s << endl;
66 
67  usleep(i * log_s * 1000000);
68 
69  for (int i = 0; i != numberOfMessages; ++i) {
70  JErrorStream(scheduler) << i;
71  }
72  }
73 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Message reporting compatible with STL output stream operations.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
General purpose message reporting.
Utility class to parse command line options.