PPI: Checkin of first compiling (yet not working) version
[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 <boost/date_time/posix_time/posix_time_types.hpp>
29 #include "predecl.hh"
30
31 //#include "Events.mpp"
32 ///////////////////////////////hh.p////////////////////////////////////////
33
34 namespace senf {
35 namespace ppi {
36
37     // Implementation: The concrete EventDescriptor implementation will need to set things up so
38     // some callback (within the EventDescriptor implementation) will be called when the event
39     // happens. This setup happens in 'v_enable()'. This internal handler sets up an EventType
40     // instance if needed and calls 'callback()'. 
41     //
42     // 'callback()' will access the EventBinding wrapper to find the user-callback to signal. It
43     // will do any needed internal processing, call that user callback and clean up afterwards.
44
45     /** \brief Generic event interface baseclass
46
47         The EventDescriptor baseclass provides an interface to manipulate events in a generic
48         way. This allows to register events or to temporarily disable event processing.
49      */ 
50     class EventDescriptor
51     {
52     public:
53         virtual ~EventDescriptor();
54
55         bool enabled(); ///< Check, whether the event is currently enabled
56         void enabled(bool v); ///< Enable or disable the event
57
58     protected:
59         EventDescriptor();
60
61     private:
62         virtual void v_enable() = 0;    ///< Called to enable the event delivery
63         virtual void v_disable() = 0;   ///< Called to disable the event delivery
64
65         virtual bool v_isRegistered() = 0;
66
67         bool enabled_;
68     };
69
70     template <class EventType>
71     class EventImplementation
72         : public EventDescriptor
73     {
74     public:
75         typedef EventType Event;
76         typedef typename detail::EventArgType<EventType>::type EventArg;
77
78     protected:
79         EventImplementation();
80
81         void callback(EventArg event, boost::posix_time::ptime time);
82         void callback(EventArg event);
83
84     private:
85         virtual bool v_isRegistered();
86         void setBinding(detail::EventBinding<Event> & binding);
87
88         detail::EventBinding<Event> * binding_;
89
90         friend class EventManager;
91     };
92
93 }}
94
95 ///////////////////////////////hh.e////////////////////////////////////////
96 #include "Events.cci"
97 //#include "Events.ct"
98 #include "Events.cti"
99 #endif
100
101 \f
102 // Local Variables:
103 // mode: c++
104 // fill-column: 100
105 // c-file-style: "senf"
106 // indent-tabs-mode: nil
107 // ispell-local-dictionary: "american"
108 // compile-command: "scons -u test"
109 // comment-column: 40
110 // End: