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

Example program to test message scheduling. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JLogger/JStreamLogger.hh"
#include "JLogger/JControlHostLogger.hh"
#include "JLogger/JMessageLogger.hh"
#include "JLogger/JMessageStream.hh"
#include "JLogger/JMessageScheduler.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

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

Detailed Description

Example program to test message scheduling.

Author
mdejong

Definition in file JMessageScheduler.cc.

Function Documentation

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

Definition at line 21 of file JMessageScheduler.cc.

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
#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