Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Scheduler / TimerEvent.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 TimerDispatcher public header */
25
26 #ifndef HH_SENF_Scheduler_TimerEvent_
27 #define HH_SENF_Scheduler_TimerEvent_ 1
28
29 // Custom includes
30 #include <signal.h>
31 #include <senf/boost_intrusive/iset_hook.hpp>
32 #include "ClockService.hh"
33 #include "FIFORunner.hh"
34 #include <senf/Utils/Logger/SenfLog.hh>
35
36 //#include "TimerEvent.mpp"
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace senf {
40 namespace scheduler {
41
42     namespace detail {
43         struct TimerSetTag;
44         typedef boost::intrusive::iset_base_hook<TimerSetTag> TimerSetBase;
45         struct TimerSetCompare;
46         class TimerDispatcher;
47     }
48
49     /** \brief Deadline timer event
50
51         The TimerEvent class registers a deadline timer callback which will be called when the
52         timer expires.
53
54         Timer events are implemented using POSIX timers. Depending on kernel features, the timer
55         resolution will be far more precise than the linux clock tick resolution. The nominal timer
56         resolution is 1 nanosecond.
57
58         The timeout time is set as \e absolute time as returned by the senf::ClockService. After
59         expiration, the timer will be disabled. It may be re-enabled by setting a new timeout time.
60         It is also possible to change a running timer resetting the timeout time.
61
62         The TimerEvent class is an implementation of the RAII idiom: The event will be automatically
63         unregistered in the TimerEvent destructor. The TimerEvent instance should be created
64         within the same scope or on a scope below where the callback is defined (e.g. if the
65         callback is a member function it should be defined as a class member).
66      */
67     class TimerEvent
68         : public detail::FIFORunner::TaskInfo,
69           public detail::TimerSetBase
70     {
71     public:
72         //-////////////////////////////////////////////////////////////////////////
73         // Types
74
75         typedef boost::function<void ()> Callback;
76
77         //-////////////////////////////////////////////////////////////////////////
78         ///\name Structors and default members
79         //\{
80
81         TimerEvent(std::string const & name, Callback const & cb, ClockService::clock_type timeout,
82                    bool initiallyEnabled = true);
83                                         ///< Register a timer event
84                                         /**< Registers \a cb to be called as soon as possible after
85                                              the time \a timeout is reached. If \a initiallyEnabled
86                                              is set \c false, the callback will not be enabled
87                                              automatically. Use enable() to do so.
88                                              \param[in] name Descriptive timer name (purely
89                                                  informational)
90                                              \param[in] cb Callback to call
91                                              \param[in] timeout timeout time after the timer
92                                                  will be disabled
93                                              \param[in] initiallyEnabled if set \c false, do not
94                                                  enable callback automatically. */
95         TimerEvent(std::string const & name, Callback const & cb);
96                                         ///< Create a timer event
97                                         /**< Creates a timer event for callback \a cb. The timer is
98                                              initially disabled. Use the timeout() member to set the
99                                              timeout time.
100                                              \param[in] name Descriptive timer name (purely
101                                                  informational)
102                                              \param[in] cb Callback to call. */
103         ~TimerEvent();
104
105         //\}
106         //-////////////////////////////////////////////////////////////////////////
107
108         void disable();                 ///< Disable timer
109         void enable();                  ///< Enable timer
110
111         void action(Callback const & cb); ///< Change timer event callback
112         void timeout(ClockService::clock_type timeout, bool initiallyEnabled=true);
113                                         ///< Re-arm or move timeout
114                                         /**< \param[in] timeout new timeout time
115                                              \param[in] initiallyEnabled if set \c false, do not
116                                                  enable callback automatically. */
117         ClockService::clock_type timeout() const;
118                                         ///< Get current/last timeout value
119
120     private:
121         virtual void v_run();
122         virtual char const * v_type() const;
123         virtual std::string v_info() const;
124
125         Callback cb_;
126         ClockService::clock_type timeout_;
127
128         friend class detail::TimerDispatcher;
129         friend class detail::TimerSetCompare;
130     };
131
132 }}
133
134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 #include "TimerEvent.cci"
136 //#include "TimerEvent.ct"
137 //#include "TimerEvent.cti"
138 #endif
139
140 \f
141 // Local Variables:
142 // mode: c++
143 // fill-column: 100
144 // comment-column: 40
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"
149 // End: