Console: Move into Scheduler as subdirectory
[senf.git] / 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_SchedulerEventManager_
27 #define HH_SchedulerEventManager_ 1
28
29 // Custom includes
30 #include <string>
31 #include <boost/iterator/filter_iterator.hpp>
32 #include "../boost/intrusive/ilist.hpp"
33 #include "../boost/intrusive/ilist_hook.hpp"
34 #include "../Utils/singleton.hh"
35 #include "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;
69         bool enabled() const;
70         unsigned runCount() const;
71         char const * type() const;
72         std::string info() const;
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         struct IteratorFilter {
92             bool operator()(Event const & e);
93         };
94
95     public:
96         using singleton<EventManager>::instance;
97         using singleton<EventManager>::alive;
98         
99         typedef boost::filter_iterator<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     protected:
108
109     private:
110         EventManager();
111
112         EventList events_;
113
114         friend class singleton<EventManager>;
115
116 #ifndef SENF_DISABLE_CONSOLE
117         void consoleEvents(std::ostream & os);
118         
119         console::LazyDirectory consoleDir_;
120 #endif
121     };
122
123 }}}
124
125 ///////////////////////////////hh.e////////////////////////////////////////
126 #include "EventManager.cci"
127 //#include "EventManager.ct"
128 //#include "EventManager.cti"
129 #endif
130
131 \f
132 // Local Variables:
133 // mode: c++
134 // fill-column: 100
135 // comment-column: 40
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"
140 // End: