switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / detail / EventBinding.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief EventBinding public header */
30
31 #ifndef HH_SENF_PPI_detail_EventBinding_
32 #define HH_SENF_PPI_detail_EventBinding_ 1
33
34 // Custom includes
35 #include <senf/Scheduler/ClockService.hh>
36 #include <senf/PPI/predecl.hh>
37 #include "Callback.hh"
38
39 //#include "EventBinding.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43 namespace ppi {
44 namespace detail {
45
46     /** \brief Internal: Association Event - Module - Handler, base-class */
47     class EventBindingBase
48     {
49     public:
50         ~EventBindingBase();
51
52         EventManager & manager() const;
53         module::Module & module() const;
54
55     protected:
56         EventBindingBase(EventManager & manager, module::Module & module,
57                          EventDescriptor & descriptor);
58
59         void eventTime(ClockService::clock_type time);
60
61     private:
62         EventManager * manager_;
63         module::Module * module_;
64         EventDescriptor * descriptor_;
65
66         friend class senf::ppi::EventManager;
67         friend class senf::ppi::EventDescriptor;
68     };
69
70     /** \brief Internal: Callback forwarders
71      */
72     template <class EventType, class Self>
73     class EventBindingHelper
74     {
75     public:
76         typedef typename detail::EventArgType<EventType>::type EventArg;
77
78         void callback(EventArg event, ClockService::clock_type time);
79         void callback(EventArg event);
80
81     private:
82         Self & self();
83     };
84
85 #ifndef DOXYGEN
86
87     template <class Self>
88     class EventBindingHelper<void,Self>
89     {
90     public:
91         void callback(ClockService::clock_type time);
92         void callback();
93
94     private:
95         Self & self();
96     };
97
98 #endif
99
100     /** \brief Internal: Association Event - Module - Handler, event type specific */
101     template <class EventType>
102     class EventBinding
103         : public EventBindingBase,
104           public EventBindingHelper<EventType, EventBinding<EventType> >
105     {
106     public:
107         typedef EventType Event;
108         typedef typename detail::EventArgType<Event>::type EventArg;
109         typedef typename detail::Callback<EventArg>::type Callback;
110
111         EventBinding(EventManager & manager, module::Module & module, Callback callback,
112                      EventDescriptor & descriptor);
113
114     private:
115         Callback callback_;
116
117         friend class EventBindingHelper<EventType, EventBinding<EventType> >;
118     };
119
120 }}}
121
122 //-/////////////////////////////////////////////////////////////////////////////////////////////////
123 #include "EventBinding.cci"
124 //#include "EventBinding.ct"
125 #include "EventBinding.cti"
126 #endif
127
128 \f
129 // Local Variables:
130 // mode: c++
131 // fill-column: 100
132 // comment-column: 40
133 // c-file-style: "senf"
134 // indent-tabs-mode: nil
135 // ispell-local-dictionary: "american"
136 // compile-command: "scons -u ../test"
137 // End: