6c71d7e27e598463b41d58aba5e17367fe9cd16d
[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 #include <senf/Utils/Console/LazyDirectory.hh>
36
37 //#include "EventManager.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40 namespace senf {
41 namespace scheduler {
42 namespace detail {
43
44     class Event;
45     struct EventListTag;
46     typedef boost::intrusive::ilist_base_hook<EventListTag> EventListBase;
47     typedef boost::intrusive::ilist<EventListBase::value_traits<Event>, false> EventList;
48
49     /** \brief
50       */
51     class Event
52         : public EventListBase
53     {
54     public:
55         ///////////////////////////////////////////////////////////////////////////
56         // Types
57
58         ///////////////////////////////////////////////////////////////////////////
59         ///\name Structors and default members
60         ///@{
61
62         explicit Event(std::string const & name);
63         virtual ~Event();
64
65         ///@}
66         ///////////////////////////////////////////////////////////////////////////
67
68         std::string const & name() const; ///< Get event name
69         bool enabled() const;           ///< \c true, if event is enabled, \c false otherwise
70         unsigned runCount() const;      ///< Number of times, event was fired
71         char const * type() const;      ///< Event type code
72         std::string info() const;       ///< Additional event information
73
74     protected:
75         void countRun();
76
77     private:
78         virtual bool v_enabled() const = 0;
79         virtual char const * v_type() const = 0;
80         virtual std::string v_info() const = 0;
81
82         std::string name_;
83         unsigned runCount_;
84     };
85
86     /** \brief
87       */
88     class EventManager
89         : public singleton<EventManager>
90     {
91     public:
92         using singleton<EventManager>::instance;
93         using singleton<EventManager>::alive;
94
95         struct IteratorFilter {
96             bool operator()(Event const & e);
97         };
98
99         typedef boost::filter_iterator<
100             IteratorFilter, EventList::const_iterator> iterator;
101
102         void add(Event & event);
103         void remove(Event & event);
104
105         iterator begin() const;
106         iterator end() const;
107
108         void listEvents(std::ostream & os);
109
110     protected:
111
112     private:
113         EventManager();
114
115         EventList events_;
116
117         friend class singleton<EventManager>;
118
119 #ifndef SENF_DISABLE_CONSOLE
120         console::LazyDirectory consoleDir_;
121 #endif
122     };
123
124 }}}
125
126 ///////////////////////////////hh.e////////////////////////////////////////
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: