PPI: Remove specializations from documentation
[senf.git] / PPI / Events.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief Events public header */
23
24 #ifndef HH_Events_
25 #define HH_Events_ 1
26
27 // Custom includes
28 #include <vector>
29 #include "Scheduler/ClockService.hh"
30 #include "predecl.hh"
31
32 //#include "Events.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36 namespace ppi {
37
38     // Implementation: The concrete EventDescriptor implementation will need to set things up so
39     // some callback (within the EventDescriptor implementation) will be called when the event
40     // happens. This setup happens in 'v_enable()'. This internal handler sets up an EventType
41     // instance if needed and calls 'callback()'. 
42     //
43     // 'callback()' will access the EventBinding wrapper to find the user-callback to signal. It
44     // will do any needed internal processing, call that user callback and clean up afterwards.
45
46     /** \brief Generic event interface baseclass
47
48         The EventDescriptor baseclass provides an interface to manipulate events in a generic
49         way. This allows to register events or to temporarily disable event processing.
50      */ 
51     class EventDescriptor
52     {
53     public:
54         virtual ~EventDescriptor();
55
56         bool enabled(); ///< Check, whether the event is currently enabled
57         void enabled(bool v); ///< Enable or disable the event
58
59     protected:
60         EventDescriptor();
61
62     private:
63         virtual void v_enable() = 0;    ///< Called to enable the event delivery
64         virtual void v_disable() = 0;   ///< Called to disable the event delivery
65
66         virtual bool v_isRegistered() = 0;
67
68         void notifyThrottle();
69         void notifyUnthrottle();
70
71         void registerRoute(ForwardingRoute & route);
72
73         bool enabled_;
74
75         typedef std::vector<ForwardingRoute*> Routes;
76         Routes routes_;
77
78         friend class ForwardingRoute;
79     };
80     
81     template <class EventType, class Self>
82     class EventImplementationHelper
83     {
84     protected:
85         typedef typename detail::EventArgType<EventType>::type EventArg;
86
87         void callback(EventArg event, ClockService::clock_type time);
88         void callback(EventArg event);
89
90     private:
91         detail::EventBinding<EventType> & binding();
92     };
93     
94 #ifndef DOXYGEN
95
96     template <class Self>
97     class EventImplementationHelper<void,Self>
98     {
99     protected:
100         void callback(ClockService::clock_type time);
101         void callback();
102
103     private:
104         detail::EventBinding<void> & binding();
105     };
106
107 #endif
108
109     template <class EventType>
110     class EventImplementation
111         : public EventDescriptor, 
112           public EventImplementationHelper< EventType, EventImplementation<EventType> >
113     {
114     public:
115         typedef EventType Event;
116         typedef typename detail::EventArgType<EventType>::type EventArg;
117
118         module::Module & module() const;
119         EventManager & manager() const;
120         
121     protected:
122         EventImplementation();
123
124     private:
125         virtual bool v_isRegistered();
126         void setBinding(detail::EventBinding<Event> & binding);
127
128         detail::EventBinding<Event> * binding_;
129
130         friend class EventManager;
131         friend class EventImplementationHelper< EventType, EventImplementation<EventType> >;
132     };
133
134 }}
135
136 ///////////////////////////////hh.e////////////////////////////////////////
137 #include "Events.cci"
138 //#include "Events.ct"
139 #include "Events.cti"
140 #endif
141
142 \f
143 // Local Variables:
144 // mode: c++
145 // fill-column: 100
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // comment-column: 40
151 // End: