16f671b8b1a7627c96d147fcd6f8a5ff475198ab
[senf.git] / senf / PPI / EventManager.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief EventManager public header */
25
26 #ifndef HH_SENF_PPI_EventManager_
27 #define HH_SENF_PPI_EventManager_ 1
28
29 // Custom includes
30 #include <boost/ptr_container/ptr_vector.hpp>
31 #include <senf/Scheduler/ClockService.hh>
32 #include "predecl.hh"
33 #include "detail/Callback.hh"
34 #include "detail/EventBinding.hh"
35
36 //#include "EventManager.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40 namespace ppi {
41
42     /** \brief Event registry and control
43
44         The EventManager control event registration and manages global event parameters. The
45         EventManager controls event dispatch but does \e not control event generation. This is the
46         responsibility of an external component (the Scheduler)
47       */
48     class EventManager
49     {
50     public:
51         ///////////////////////////////////////////////////////////////////////////
52         // Types
53
54 #ifndef DOXYGEN
55         // Somehow doxygen barfs on this definition
56         template <class Descriptor>
57         struct Callback
58             : public detail::Callback<typename Descriptor::EventArg>
59         {};
60 #endif
61
62         ///////////////////////////////////////////////////////////////////////////
63         ///\name Structors and default members
64         ///@{
65
66         static EventManager & instance();
67
68         // default default constructor
69         // default copy constructor
70         // default copy assignment
71         // default destructor
72
73         // no conversion constructors
74
75         ///@}
76         ///////////////////////////////////////////////////////////////////////////
77
78         ClockService::clock_type now(); ///< Current time at last event dispatch
79         ClockService::clock_type time(); ///< Expected time of the last event
80
81     protected:
82
83     private:
84         template <class Descriptor>
85         void registerEvent(module::Module & module,
86                            typename Callback<Descriptor>::type callback,
87                            Descriptor & descriptor);
88
89         void destroyModule(module::Module & module);
90         void destroyEvent(EventDescriptor & event);
91
92         typedef boost::ptr_vector<detail::EventBindingBase> EventRegistrations;
93         EventRegistrations registrations_;
94
95         void eventTime(ClockService::clock_type time);
96
97         ClockService::clock_type eventTime_;
98
99         friend class detail::EventBindingBase;
100         friend class module::Module;
101         friend class EventDescriptor;
102     };
103
104 }}
105
106 ///////////////////////////////hh.e////////////////////////////////////////
107 #include "EventManager.cci"
108 #include "EventManager.ct"
109 //#include "EventManager.cti"
110 #endif
111
112 \f
113 // Local Variables:
114 // mode: c++
115 // fill-column: 100
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // End: