Events.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_PPI_Events_
18 #define HH_SENF_PPI_Events_ 1
19 
20 // Custom includes
21 #include <vector>
23 #include "predecl.hh"
24 
25 //#include "Events.mpp"
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 
28 namespace senf {
29 namespace ppi {
30 
31  namespace detail { class EventBindingBase; }
32 
46  // Implementation: The concrete EventDescriptor implementation will need to set things up so
47  // some callback (within the EventDescriptor implementation) will be called when the event
48  // happens. This setup happens in 'v_enable()'. This internal handler sets up an EventType
49  // instance if needed and calls 'callback()'.
50  //
51  // 'callback()' will access the EventBinding wrapper to find the user-callback to signal. It
52  // will do any needed internal processing, call that user callback and clean up afterwards.
53 
61  {
62  public:
63  virtual ~EventDescriptor();
64 
65  bool enabled() const;
66  void enabled(bool v);
67 
68  protected:
70 
71  private:
72  virtual void v_enable() = 0;
73  virtual void v_disable() = 0;
74 
75  virtual bool v_isRegistered() = 0;
76 
77  void notifyThrottle();
78  void notifyUnthrottle();
79 
80  void registerRoute(ForwardingRoute & route);
81  void unregisterRoute(ForwardingRoute & route);
82 
83  bool enabled_;
84  bool throttled_;
85 
86  typedef std::vector<ForwardingRoute*> Routes;
87  Routes routes_;
88 
89  detail::EventBindingBase * binding_;
90 
91  friend class ForwardingRoute;
93  };
94 
97  template <class EventType, class Self>
99  {
100  protected:
101  typedef typename detail::EventArgType<EventType>::type EventArg;
102 
103  void callback(EventArg event, ClockService::clock_type time);
105 
108  void callback(EventArg event);
109 
112  private:
114  };
115 
116 #ifndef DOXYGEN
117 
118  template <class Self>
119  class EventImplementationHelper<void,Self>
120  {
121  protected:
122  void callback(ClockService::clock_type time);
123  void callback();
124 
125  private:
126  detail::EventBinding<void> & binding();
127  };
128 
129 #endif
130 
168  template <class EventType>
170  : public EventDescriptor,
171  public EventImplementationHelper< EventType, EventImplementation<EventType> >
172  {
173  public:
174  typedef EventType Event;
175  typedef typename detail::EventArgType<EventType>::type EventArg;
176 
177  module::Module & module() const;
178  EventManager & manager() const;
179 
180  protected:
182 
183  private:
184  virtual bool v_isRegistered();
185  void setBinding(detail::EventBinding<Event> & binding);
186 
187  detail::EventBinding<Event> * binding_;
188 
189  friend class EventManager;
190  friend class EventImplementationHelper< EventType, EventImplementation<EventType> >;
191  };
192 
193 }}
194 
195 //-/////////////////////////////////////////////////////////////////////////////////////////////////
196 #include "Events.cci"
197 //#include "Events.ct"
198 #include "Events.cti"
199 #endif
200 
201 
202 // Local Variables:
203 // mode: c++
204 // fill-column: 100
205 // c-file-style: "senf"
206 // indent-tabs-mode: nil
207 // ispell-local-dictionary: "american"
208 // compile-command: "scons -u test"
209 // comment-column: 40
210 // End:
Internal: Association Event - Module - Handler, base-class.
Definition: EventBinding.hh:33
config::time_type clock_type
Module base-class.
Definition: Module.hh:169
Internal: Callback forwarders.
Definition: Events.hh:98
Generic event interface base-class.
Definition: Events.hh:60
Event registry and control.
Definition: EventManager.hh:40
predecl public header
detail::EventArgType< EventType >::type EventArg
Definition: Events.hh:101
Event implementation base class.
Definition: Events.hh:169
Forwarding route base class.
Definition: Route.hh:69
detail::EventArgType< EventType >::type EventArg
Definition: Events.hh:175
Internal: Association Event - Module - Handler, event type specific.
Definition: EventBinding.hh:88