Console: Implement BSDSocketAddress and BSDAddressingPolicy
[senf.git] / Scheduler / Timer.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 Timer public header */
25
26 #ifndef HH_Timer_
27 #define HH_Timer_ 1
28
29 // Custom includes
30 #include "Scheduler.hh"
31
32 //#include "Timer.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37     /** \brief Manage scheduler timer
38
39         This class will manage a single timer: The timer can be enabled, disabled and updated and
40         will automatically be removed, when this instance is destroyed.
41
42         \code
43         class Foo
44         {
45         public:
46             Foo() : timer_ ( ClockServer::now() + ClockService::milliseconds(500),
47                              senf::membind(&Foo::timer, this) ) {}
48
49             void blarf() { timer_.disable(); }
50         
51         private:
52             void timer(); 
53         
54             senf::SchedulerTimer timer_;
55         };
56         \endcode
57       */
58     class SchedulerTimer
59         : boost::noncopyable
60     {
61     public:
62         ///////////////////////////////////////////////////////////////////////////
63         ///\name Structors and default members
64         ///@{
65
66         SchedulerTimer(ClockService::clock_type timeout, Scheduler::SimpleCallback const & cb,
67                        bool enabled=true);
68         ~SchedulerTimer();
69
70         ///@}
71         ///////////////////////////////////////////////////////////////////////////
72
73         void enable();                  ///< Enable timer
74         void disable();                 ///< Disable timer
75         bool enabled();                 ///< \c true, if timer is currently enabled
76                                         /**< An expired timer can still be in enabled state. */
77
78         void update(ClockService::clock_type timeout); ///< Change timeout time and enable timer
79                                         /**< If the timer is not enabled, you need to call enable()
80                                              for the timer to become effective. */
81
82     protected:
83
84     private:
85         ClockService::clock_type timeout_;
86         Scheduler::SimpleCallback cb_;
87         unsigned id_;
88         bool enabled_;
89     };
90
91 }
92
93 ///////////////////////////////hh.e////////////////////////////////////////
94 #include "Timer.cci"
95 //#include "Timer.ct"
96 //#include "Timer.cti"
97 #endif
98
99 \f
100 // Local Variables:
101 // mode: c++
102 // fill-column: 100
103 // comment-column: 40
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -u test"
108 // End: