EventManager.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_EventManager_
18 #define HH_SENF_Scheduler_EventManager_ 1
19 
20 // Custom includes
21 #include <string>
22 #include <boost/iterator/filter_iterator.hpp>
23 #include <boost/intrusive/list.hpp>
24 #include <boost/intrusive/list_hook.hpp>
25 #include <senf/Utils/singleton.hh>
26 
27 //#include "EventManager.mpp"
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 namespace senf {
31 namespace scheduler {
32 namespace detail {
33 
34  class Event;
35  struct EventListTag;
36 
37  typedef boost::intrusive::list_base_hook< boost::intrusive::tag<EventListTag> > EventListBase;
38  typedef boost::intrusive::list< Event,
39  boost::intrusive::constant_time_size<false>,
40  boost::intrusive::base_hook<EventListBase> > EventList;
41 
44  class Event
45  : public EventListBase
46  {
47  public:
48  //-////////////////////////////////////////////////////////////////////////
49  // Types
50 
51  //-////////////////////////////////////////////////////////////////////////
53  //\{
54 
55  explicit Event(std::string const & name);
56  virtual ~Event();
57 
58  //\}
59  //-////////////////////////////////////////////////////////////////////////
60 
61  std::string const & name() const;
62  bool enabled() const;
63  unsigned runCount() const;
64  char const * type() const;
65  std::string info() const;
66 
67  protected:
68  void countRun();
69 
70  private:
71  virtual bool v_enabled() const = 0;
72  virtual char const * v_type() const = 0;
73  virtual std::string v_info() const = 0;
74 
75  std::string name_;
76  unsigned runCount_;
77  };
78 
82  : public singleton<EventManager>
83  {
84  public:
87 
88  struct IteratorFilter {
89  bool operator()(Event const & e);
90  };
91 
92  typedef boost::filter_iterator<
93  IteratorFilter, EventList::const_iterator> iterator;
94 
95  void add(Event & event);
96  void remove(Event & event);
97 
98  iterator begin() const;
99  iterator end() const;
100 
101  void listEvents(std::ostream & os);
102 
103  protected:
104 
105  private:
106  EventManager();
107 
108  EventList events_;
109 
110  friend class singleton<EventManager>;
111  };
112 
113 }}}
114 
115 //-/////////////////////////////////////////////////////////////////////////////////////////////////
116 #include "EventManager.cci"
117 //#include "EventManager.ct"
118 //#include "EventManager.cti"
119 #endif
120 
121 
122 // Local Variables:
123 // mode: c++
124 // fill-column: 100
125 // comment-column: 40
126 // c-file-style: "senf"
127 // indent-tabs-mode: nil
128 // ispell-local-dictionary: "american"
129 // compile-command: "scons -u test"
130 // End:
std::string info() const
Additional event information.
boost::intrusive::list_base_hook< boost::intrusive::tag< EventListTag > > EventListBase
Definition: EventManager.hh:35
Event(std::string const &name)
char const * type() const
Event type code.
unsigned runCount() const
Number of times, event was fired.
boost::intrusive::list< Event, boost::intrusive::constant_time_size< false >, boost::intrusive::base_hook< EventListBase > > EventList
Definition: EventManager.hh:40
bool enabled() const
true, if event is enabled, false otherwise
std::string const & name() const
Get event name.
boost::filter_iterator< IteratorFilter, EventList::const_iterator > iterator
Definition: EventManager.hh:93