Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
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

◆ main()

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
50 JLogger* out = NULL;
51
52 if (use_cout)
53 out = new JStreamLogger(cout);
54 else
55 out = new JControlHostLogger(message_logger);
56
57 JMessageLogger logger(out, argv[0], debug);
58 JMessageScheduler scheduler(logger, JTimekeeper(log_s * 1000000));
59
60 scheduler.setCredit(3);
61
62 for (int i = 0; i != numberOfMessages; ++i) {
63
64 cout << "sleep [s] " << i * log_s << endl;
65
66 usleep(i * log_s * 1000000);
67
68 for (int i = 0; i != numberOfMessages; ++i) {
69 JErrorStream(scheduler) << i;
70 }
71 }
72}
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Time keeper.
Message logging based on ControlHost.
Interface for logging messages.
Definition JLogger.hh:22
Message logger with time scheduler.
Message logging based on std::ostream.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).