switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Scheduler / EventManager.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
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 EventManager public header */
30
31 #ifndef HH_SENF_Scheduler_EventManager_
32 #define HH_SENF_Scheduler_EventManager_ 1
33
34 // Custom includes
35 #include <string>
36 #include <boost/iterator/filter_iterator.hpp>
37 #include <senf/boost_intrusive/ilist.hpp>
38 #include <senf/boost_intrusive/ilist_hook.hpp>
39 #include <senf/Utils/singleton.hh>
40
41 //#include "EventManager.mpp"
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43
44 namespace senf {
45 namespace scheduler {
46 namespace detail {
47
48     class Event;
49     struct EventListTag;
50     typedef boost::intrusive::ilist_base_hook<EventListTag> EventListBase;
51     typedef boost::intrusive::ilist<EventListBase::value_traits<Event>, false> EventList;
52
53     /** \brief
54       */
55     class Event
56         : public EventListBase
57     {
58     public:
59         //-////////////////////////////////////////////////////////////////////////
60         // Types
61
62         //-////////////////////////////////////////////////////////////////////////
63         ///\name Structors and default members
64         //\{
65
66         explicit Event(std::string const & name);
67         virtual ~Event();
68
69         //\}
70         //-////////////////////////////////////////////////////////////////////////
71
72         std::string const & name() const; ///< Get event name
73         bool enabled() const;           ///< \c true, if event is enabled, \c false otherwise
74         unsigned runCount() const;      ///< Number of times, event was fired
75         char const * type() const;      ///< Event type code
76         std::string info() const;       ///< Additional event information
77
78     protected:
79         void countRun();
80
81     private:
82         virtual bool v_enabled() const = 0;
83         virtual char const * v_type() const = 0;
84         virtual std::string v_info() const = 0;
85
86         std::string name_;
87         unsigned runCount_;
88     };
89
90     /** \brief
91       */
92     class EventManager
93         : public singleton<EventManager>
94     {
95     public:
96         using singleton<EventManager>::instance;
97         using singleton<EventManager>::alive;
98
99         struct IteratorFilter {
100             bool operator()(Event const & e);
101         };
102
103         typedef boost::filter_iterator<
104             IteratorFilter, EventList::const_iterator> iterator;
105
106         void add(Event & event);
107         void remove(Event & event);
108
109         iterator begin() const;
110         iterator end() const;
111
112         void listEvents(std::ostream & os);
113
114     protected:
115
116     private:
117         EventManager();
118
119         EventList events_;
120
121         friend class singleton<EventManager>;
122     };
123
124 }}}
125
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
127 #include "EventManager.cci"
128 //#include "EventManager.ct"
129 //#include "EventManager.cti"
130 #endif
131
132 \f
133 // Local Variables:
134 // mode: c++
135 // fill-column: 100
136 // comment-column: 40
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"
141 // End: