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 "../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);
91 typedef std::vector<ForwardingRoute*> Routes;
94 friend class ForwardingRoute;
97 /** \brief Internal: Callback forwarders
99 template <class EventType, class Self>
100 class EventImplementationHelper
103 typedef typename detail::EventArgType<EventType>::type EventArg;
105 void callback(EventArg event, ClockService::clock_type time);
106 ///< Forward event to user callback
107 /**< \param[in] event Event argument to pass to the user
109 \param[in] time Expected time of the event */
110 void callback(EventArg event); ///< Forward event to user callback
111 /**< \param[in] event Event argument to pass to the user
115 detail::EventBinding<EventType> & binding();
120 template <class Self>
121 class EventImplementationHelper<void,Self>
124 void callback(ClockService::clock_type time);
128 detail::EventBinding<void> & binding();
133 /** \brief Event implementation base class
135 EventImplementation provides the base-class for all Event implementations.
137 class SomeEvent : public EventImplementation<SomeEventArg>
143 virtual void v_enable() {
144 // register cb() to be called when the event occurs
147 virtual void v_disable() {
152 // Build event argument
153 SomeEventArg arg (...);
154 // Call the event callback
160 Every event needs to implement v_enable() and v_disable(). v_enable() should register some
161 member (in the example \c cb() ) to be called whenever the event occurs, while v_disable()
162 should unregister it.
164 The \a EventType argument to EventImplementation defines the type of argument passed to the
165 user callback. It defaults to \c void. . This user callback is called from within the
166 registered member (e.g. \c cb() ) by calling the inherited callback() member. This member
167 takes an \a EventType reference as argument which will be forwarded to the user callback. If
168 available, you should also provide the \e expected event time as a second argument.
170 template <class EventType>
171 class EventImplementation
172 : public EventDescriptor,
173 public EventImplementationHelper< EventType, EventImplementation<EventType> >
176 typedef EventType Event;
177 typedef typename detail::EventArgType<EventType>::type EventArg;
179 module::Module & module() const; ///< Module in which the event is registered
180 EventManager & manager() const; ///< EventManager of the event
183 EventImplementation();
186 virtual bool v_isRegistered();
187 void setBinding(detail::EventBinding<Event> & binding);
189 detail::EventBinding<Event> * binding_;
191 friend class EventManager;
192 friend class EventImplementationHelper< EventType, EventImplementation<EventType> >;
197 ///////////////////////////////hh.e////////////////////////////////////////
198 #include "Events.cci"
199 //#include "Events.ct"
200 #include "Events.cti"
207 // c-file-style: "senf"
208 // indent-tabs-mode: nil
209 // ispell-local-dictionary: "american"
210 // compile-command: "scons -u test"
211 // comment-column: 40