Scheduler: Remove obsolete 'Scheduler' class
[senf.git] / Scheduler / TimerEvent.cci
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 inline non-template implementation */
25
26 #include "TimerEvent.ih"
27
28 // Custom includes
29 #include <unistd.h>
30
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::scheduler::TimerEvent
36
37 prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb,
38                                                 ClockService::clock_type timeout,
39                                                 bool initiallyEnabled)
40     : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (timeout)
41 {
42     if (initiallyEnabled)
43         enable();
44 }
45
46 prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb)
47     : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (0)
48 {}
49
50 prefix_ senf::scheduler::TimerEvent::~TimerEvent()
51 {
52     if (senf::scheduler::detail::TimerDispatcher::alive())
53         disable();
54 }
55
56 prefix_ void senf::scheduler::TimerEvent::enable()
57 {
58     if (! detail::TimerSetBase::linked())
59         senf::scheduler::detail::TimerDispatcher::instance().add(*this);
60 }
61
62 prefix_ void senf::scheduler::TimerEvent::disable()
63 {
64     if (detail::TimerSetBase::linked())
65         senf::scheduler::detail::TimerDispatcher::instance().remove(*this);
66 }
67
68 prefix_ bool senf::scheduler::TimerEvent::enabled()
69 {
70     return detail::TimerSetBase::linked();
71 }
72
73 prefix_ void senf::scheduler::TimerEvent::action(Callback const & cb)
74 {
75     cb_ = cb;
76 }
77
78 prefix_ void senf::scheduler::TimerEvent::timeout(ClockService::clock_type timeout, 
79                                                   bool initiallyEnabled)
80 {
81     disable();
82     timeout_ = timeout;
83     if (initiallyEnabled)
84         enable();
85 }
86
87 ///////////////////////////////////////////////////////////////////////////
88 // senf::scheduler::detail::TimerDispatcher
89
90 prefix_ bool senf::scheduler::detail::TimerDispatcher::empty()
91     const
92 {
93     return timers_.empty();
94 }
95
96 ///////////////////////////////cci.e///////////////////////////////////////
97 #undef prefix_
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: