TimerEvent.ih
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 
14 /** \file
15  \brief TimerDispatcher internal header */
16 
17 #ifndef IH_SENF_Scheduler_TimerEvent_
18 #define IH_SENF_Scheduler_TimerEvent_ 1
19 
20 // Custom includes
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/intrusive/set.hpp>
23 #include "TimerSource.hh"
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 namespace senf {
28 namespace scheduler {
29 
30  void restart();
31 
32 namespace detail {
33 
34  struct TimerSetCompare {
35  bool operator()(TimerEvent const & a, TimerEvent const & b) const
36  { return a.timeout_ < b.timeout_; }
37  };
38 
39  class TimerDispatcher
40  : public singleton<TimerDispatcher>
41  {
42  SENF_LOG_CLASS_AREA();
43 
44  public:
45  using singleton<TimerDispatcher>::instance;
46  using singleton<TimerDispatcher>::alive;
47 
48  void add(TimerEvent & event);
49  void remove(TimerEvent & event);
50 
51  void enable();
52  void disable();
53 
54  void prepareRun();
55  void reschedule();
56 
57  bool empty() const;
58 
59  void timerSource(std::unique_ptr<TimerSource> timerSource);
60  TimerSource * timerSource();
61 
62  protected:
63 
64  private:
65  TimerDispatcher();
66  ~TimerDispatcher();
67 
68  typedef boost::intrusive::multiset< TimerEvent,
69  boost::intrusive::constant_time_size<false>,
70  boost::intrusive::compare<TimerSetCompare>,
71  boost::intrusive::base_hook<TimerSetBase> > TimerSet;
72 
73  TimerSet timers_;
74 
75  boost::scoped_ptr<TimerSource> source_;
76 
77  friend void senf::scheduler::restart();
78  friend class singleton<TimerDispatcher>;
79  };
80 
81 }}}
82 
83 //-/////////////////////////////////////////////////////////////////////////////////////////////////
84 #endif
85 
86 
87 // Local Variables:
88 // mode: c++
89 // fill-column: 100
90 // comment-column: 40
91 // c-file-style: "senf"
92 // indent-tabs-mode: nil
93 // ispell-local-dictionary: "american"
94 // compile-command: "scons -u test"
95 // End: