EventHook.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_EventHook_
18 #define HH_SENF_Scheduler_EventHook_ 1
19 
20 // Custom includes
21 #include <boost/function.hpp>
22 #include <boost/intrusive/list_hook.hpp>
23 #include "FIFORunner.hh"
24 
25 //#include "EventHook.mpp"
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 
28 namespace senf {
29 namespace scheduler {
30 
31  namespace detail {
32  struct EventHookListTag;
33  typedef boost::intrusive::list_base_hook< boost::intrusive::tag<EventHookListTag> > EventHookListBase;
34  class EventHookDispatcher;
35  }
36 
58  class EventHook
61  {
62  public:
63  //-////////////////////////////////////////////////////////////////////////
64  // Types
65 
66  typedef boost::function<void ()> Callback;
67 
68  static Priority const PRE = PRIORITY_HIGH;
69  static Priority const POST = PRIORITY_LOW;
70 
71  //-////////////////////////////////////////////////////////////////////////
73  //\{
74 
75  EventHook(std::string const & name, Callback const & cb,
76  Priority priority, bool initiallyEnabled = true);
78 
89  ~EventHook();
90 
91  //\}
92  //-////////////////////////////////////////////////////////////////////////
93 
94  void disable();
95  void enable();
96 
97  void action(Callback const & cb);
98 
99  protected:
100 
101  private:
102  virtual void v_run();
103  virtual char const * v_type() const;
104  virtual std::string v_info() const;
105 
106  Callback cb_;
107 
108  friend class detail::EventHookDispatcher;
109  };
110 
111 }}
112 
113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
114 #include "EventHook.cci"
115 //#include "EventHook.ct"
116 //#include "EventHook.cti"
117 #endif
118 
119 
120 // Local Variables:
121 // mode: c++
122 // fill-column: 100
123 // comment-column: 40
124 // c-file-style: "senf"
125 // indent-tabs-mode: nil
126 // ispell-local-dictionary: "american"
127 // compile-command: "scons -u test"
128 // End:
boost::intrusive::list_base_hook< boost::intrusive::tag< EventHookListTag > > EventHookListBase
Definition: EventHook.hh:32
FIFORunner public header.
boost::function< void()> Callback
Definition: EventHook.hh:66
Event hook event.
Definition: EventHook.hh:58