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