Jpp  16.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
12 namespace JLOGGER {}
13 namespace JPP { using namespace JLOGGER; }
14 
15 namespace JLOGGER {
16 
17  using JEEP::JTimekeeper;
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) :
49  JMessageLogger(logger),
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:
102  int credit;
103  };
104 }
105 
106 #endif
Message logger with time scheduler.
Time keeper.
Definition: JTimekeeper.hh:34
virtual void typeout(const std::string &tag, const std::string &message) override
Report message.
Scheduling of actions via fixed latency intervals.
void reset()
Reset time.
Definition: JTimekeeper.hh:111
virtual void typeout(const std::string &tag, const std::string &message) override
Report message.
JSharedPointer< JLogger > logger
void setCredit(const int credit)
Set credit.
General purpose message reporting.
JMessageScheduler()
Default constructor.
JMessageScheduler(const JMessageLogger &logger, const JTimekeeper &timer)
Constructor.