f9eb158e619d35a66ba5f5d047c3b2be136b35f5
[senf.git] / senf / Scheduler / IdleEvent.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
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 IdleEvent public header */
25
26 #ifndef HH_SENF_Scheduler_IdleEvent_
27 #define HH_SENF_Scheduler_IdleEvent_ 1
28
29 // Custom includes
30 #include <boost/function.hpp>
31 #include <senf/boost_intrusive/ilist_hook.hpp>
32 #include "FIFORunner.hh"
33
34 //#include "IdleEvent.mpp"
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36
37 namespace senf {
38 namespace scheduler {
39
40 namespace detail {
41     struct IdleEventListTag;
42     typedef boost::intrusive::ilist_base_hook<IdleEventListTag> IdleEventListBase;
43     class IdleEventDispatcher;
44 }
45
46     class IdleEvent
47         : public detail::FIFORunner::TaskInfo,
48           public detail::IdleEventListBase
49     {
50     public:
51         //-////////////////////////////////////////////////////////////////////////
52         // Types
53
54         typedef boost::function<void ()> Callback;
55
56         //-////////////////////////////////////////////////////////////////////////
57         ///\name Structors and default members
58         //\{
59
60         IdleEvent(std::string const & name, Callback const & cb,
61                   bool initiallyEnabled = true);
62         ~IdleEvent();
63
64         //\}
65         //-////////////////////////////////////////////////////////////////////////
66
67         void disable();                 ///< Disable event
68         void enable();                  ///< Enable event
69
70         void action(Callback const & cb); ///< Change event callback
71
72     protected:
73
74     private:
75         virtual void v_run();
76         virtual char const * v_type() const;
77         virtual std::string v_info() const;
78
79         Callback cb_;
80
81         friend class detail::IdleEventDispatcher;
82     };
83
84 }}
85
86 //-/////////////////////////////////////////////////////////////////////////////////////////////////
87 #include "IdleEvent.cci"
88 //#include "IdleEvent.ct"
89 //#include "IdleEvent.cti"
90 #endif
91
92 \f
93 // Local Variables:
94 // mode: c++
95 // fill-column: 100
96 // comment-column: 40
97 // c-file-style: "senf"
98 // indent-tabs-mode: nil
99 // ispell-local-dictionary: "american"
100 // compile-command: "scons -u test"
101 // End: