4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Events public header */
26 #ifndef HH_SENF_PPI_Events_
27 #define HH_SENF_PPI_Events_ 1
31 #include <senf/Scheduler/ClockService.hh>
34 //#include "Events.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
40 /** \defgroup event_group Events
42 Events provide notification of events outside the PPI framework: I/O activity, Timers
43 etc. Events are very important since they drive the PPI: Without events, nothing will
46 \section event_impl Implementing Events
48 All events are derived from EventImplementation which is based on EventDescriptor.
49 \see EventImplementation \n
53 // Implementation: The concrete EventDescriptor implementation will need to set things up so
54 // some callback (within the EventDescriptor implementation) will be called when the event
55 // happens. This setup happens in 'v_enable()'. This internal handler sets up an EventType
56 // instance if needed and calls 'callback()'.
58 // 'callback()' will access the EventBinding wrapper to find the user-callback to signal. It
59 // will do any needed internal processing, call that user callback and clean up afterwards.
61 /** \brief Generic event interface base-class
63 The EventDescriptor base-class provides an interface to control events.
70 virtual ~EventDescriptor();
72 bool enabled(); ///< Check, whether the event is currently enabled
73 void enabled(bool v); ///< Enable or disable the event
79 virtual void v_enable() = 0; ///< Called to enable the event delivery
80 virtual void v_disable() = 0; ///< Called to disable the event delivery
82 virtual bool v_isRegistered() = 0;
84 void notifyThrottle();
85 void notifyUnthrottle();
87 void registerRoute(ForwardingRoute & route);
92 typedef std::vector<ForwardingRoute*> Routes;
95 friend class ForwardingRoute;
98 /** \brief Internal: Callback forwarders
100 template <class EventType, class Self>
101 class EventImplementationHelper
104 typedef typename detail::EventArgType<EventType>::type EventArg;
106 void callback(EventArg event, ClockService::clock_type time);
107 ///< Forward event to user callback
108 /**< \param[in] event Event argument to pass to the user
110 \param[in] time Expected time of the event */
111 void callback(EventArg event); ///< Forward event to user callback
112 /**< \param[in] event Event argument to pass to the user
116 detail::EventBinding<EventType> & binding();
121 template <class Self>
122 class EventImplementationHelper<void,Self>
125 void callback(ClockService::clock_type time);
129 detail::EventBinding<void> & binding();
134 /** \brief Event implementation base class
136 EventImplementation provides the base-class for all Event implementations.
138 class SomeEvent : public EventImplementation<SomeEventArg>
144 virtual void v_enable() {
145 // register cb() to be called when the event occurs
148 virtual void v_disable() {
153 // Build event argument
154 SomeEventArg arg (...);
155 // Call the event callback
161 Every event needs to implement v_enable() and v_disable(). v_enable() should register some
162 member (in the example \c cb() ) to be called whenever the event occurs, while v_disable()
163 should unregister it.
165 The \a EventType argument to EventImplementation defines the type of argument passed to the
166 user callback. It defaults to \c void. . This user callback is called from within the
167 registered member (e.g. \c cb() ) by calling the inherited callback() member. This member
168 takes an \a EventType reference as argument which will be forwarded to the user callback. If
169 available, you should also provide the \e expected event time as a second argument.
171 template <class EventType>
172 class EventImplementation
173 : public EventDescriptor,
174 public EventImplementationHelper< EventType, EventImplementation<EventType> >
177 typedef EventType Event;
178 typedef typename detail::EventArgType<EventType>::type EventArg;
180 module::Module & module() const; ///< Module in which the event is registered
181 EventManager & manager() const; ///< EventManager of the event
184 EventImplementation();
187 virtual bool v_isRegistered();
188 void setBinding(detail::EventBinding<Event> & binding);
190 detail::EventBinding<Event> * binding_;
192 friend class EventManager;
193 friend class EventImplementationHelper< EventType, EventImplementation<EventType> >;
198 ///////////////////////////////hh.e////////////////////////////////////////
199 #include "Events.cci"
200 //#include "Events.ct"
201 #include "Events.cti"
208 // c-file-style: "senf"
209 // indent-tabs-mode: nil
210 // ispell-local-dictionary: "american"
211 // compile-command: "scons -u test"
212 // comment-column: 40