TimerEvent.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Scheduler_TimerEvent_
18 #define HH_SENF_Scheduler_TimerEvent_ 1
19 
20 // Custom includes
21 #include <signal.h>
22 #include <boost/intrusive/set_hook.hpp>
23 #include "ClockService.hh"
24 #include "FIFORunner.hh"
27 
28 //#include "TimerEvent.mpp"
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 namespace senf {
32 namespace scheduler {
33 
34  namespace detail {
35  struct TimerSetTag;
36  typedef boost::intrusive::set_base_hook< boost::intrusive::tag<TimerSetTag> > TimerSetBase;
37  struct TimerSetCompare;
38  class TimerDispatcher;
39  }
40 
59  class TimerEvent
62  {
63  public:
64  //-////////////////////////////////////////////////////////////////////////
65  // Types
66 
67  typedef boost::function<void ()> Callback;
68 
69  //-////////////////////////////////////////////////////////////////////////
71  //\{
72 
73  TimerEvent(std::string const & name, Callback const & cb, ClockService::clock_type timeout,
74  bool initiallyEnabled = true);
76 
87  TimerEvent(std::string const & name, Callback const & cb);
89 
95  ~TimerEvent();
96 
97  //\}
98  //-////////////////////////////////////////////////////////////////////////
99 
100  void disable();
101  void enable();
102 
103  void action(Callback const & cb);
104  void timeout(ClockService::clock_type const & timeout, bool initiallyEnabled=true);
106 
109  ClockService::clock_type const & timeout() const;
111 
112  private:
113  virtual void v_run();
114  virtual char const * v_type() const;
115  virtual std::string v_info() const;
116 
117  Callback cb_;
118  ClockService::clock_type timeout_;
119 
120  friend class detail::TimerDispatcher;
121  friend struct detail::TimerSetCompare;
122  };
123 
124 }}
125 
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
127 #include "TimerEvent.cci"
128 //#include "TimerEvent.ct"
129 //#include "TimerEvent.cti"
130 #endif
131 
132 
133 // Local Variables:
134 // mode: c++
135 // fill-column: 100
136 // comment-column: 40
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"
141 // End:
config::time_type clock_type
ClockService timer data type.
Definition: ClockService.hh:78
boost::function< void()> Callback
Definition: TimerEvent.hh:67
FIFORunner public header.
Deadline timer event.
Definition: TimerEvent.hh:59
boost::intrusive::set_base_hook< boost::intrusive::tag< TimerSetTag > > TimerSetBase
Definition: TimerEvent.hh:35
ClockService public header.