Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JMessageScheduler.hh
Go to the documentation of this file.
1#ifndef __JLOGGER__JMESSAGESCHEDULER__
2#define __JLOGGER__JMESSAGESCHEDULER__
3
5#include "Jeep/JTimekeeper.hh"
6
7
8/**
9 * \author mdejong
10 */
11
12namespace JLOGGER {}
13namespace JPP { using namespace JLOGGER; }
14
15namespace JLOGGER {
16
18
19
20 /**
21 * Message logger with time scheduler.
22 * Messages will only be reported when the elapsed time since last message exceeds the specified time interval.
23 * The first message is always reported.
24 */
26 public JMessageLogger,
27 public JTimekeeper
28 {
29 public:
30 /**
31 * Default constructor.
32 */
35 JTimekeeper (),
36 credit (0)
37 {}
38
39
40 /**
41 * Constructor.
42 * The time is reset so that the first message is sent any way.
43 *
44 * \param logger logger
45 * \param timer timer
46 */
48 const JTimekeeper& timer) :
50 JTimekeeper (timer),
51 credit (1)
52 {
54 }
55
56
57 /**
58 * Set credit.
59 * Note that the maximal number of messages reported per interval time
60 * is equal to the credit which is set once at a time.
61 *
62 * \param credit credit
63 */
64 void setCredit(const int credit)
65 {
66 this->credit = credit;
67 }
68
69 /**
70 * Report message.
71 *
72 * \param tag tag
73 * \param message message
74 */
75 virtual void typeout(const std::string& tag,
76 const std::string& message) override
77 {
78 if (JTimekeeper::operator()()) {
79 reset();
80 }
81
82 if (credit != 0) {
83
84 JMessageLogger::typeout(tag, message);
85
86 --credit;
87 }
88 }
89
90
91 /**
92 * Reset.
93 */
94 void reset()
95 {
97
98 credit = 1;
99 }
100
101 protected:
103 };
104}
105
106#endif
General purpose message reporting.
Scheduling of actions via fixed latency intervals.
Time keeper.
void reset()
Reset time.
JSharedPointer< JLogger > logger
virtual void typeout(const std::string &tag, const std::string &message) override
Report message.
Message logger with time scheduler.
void setCredit(const int credit)
Set credit.
virtual void typeout(const std::string &tag, const std::string &message) override
Report message.
JMessageScheduler(const JMessageLogger &logger, const JTimekeeper &timer)
Constructor.
JMessageScheduler()
Default constructor.
Message logging.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).