fixes for ClockService::clock_type -> RestrictedInt change introduced by last commit
[senf.git] / senf / Scheduler / TimerEvent.cci
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief TimerDispatcher inline non-template implementation */
30
31 #include "TimerEvent.ih"
32
33 // Custom includes
34 #include <unistd.h>
35
36 #define prefix_ inline
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 // senf::scheduler::TimerEvent
41
42 prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb,
43                                                 ClockService::clock_type timeout,
44                                                 bool initiallyEnabled)
45     : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (timeout)
46 {
47     if (initiallyEnabled)
48         enable();
49 }
50
51 prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb)
52     : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_(ClockService::clock_type(0))
53 {}
54
55 prefix_ senf::scheduler::TimerEvent::~TimerEvent()
56 {
57     if (detail::TimerDispatcher::alive())
58         disable();
59 }
60
61 prefix_ void senf::scheduler::TimerEvent::enable()
62 {
63     if (! detail::TimerSetBase::linked())
64         detail::TimerDispatcher::instance().add(*this);
65 }
66
67 prefix_ void senf::scheduler::TimerEvent::disable()
68 {
69     if (detail::TimerSetBase::linked())
70         detail::TimerDispatcher::instance().remove(*this);
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 prefix_ senf::ClockService::clock_type senf::scheduler::TimerEvent::timeout()
88     const
89 {
90     return timeout_;
91 }
92
93 //-/////////////////////////////////////////////////////////////////////////////////////////////////
94 // senf::scheduler::detail::TimerDispatcher
95
96 prefix_ void senf::scheduler::detail::TimerDispatcher::enable()
97 {
98     source_->enable();
99 }
100
101 prefix_ void senf::scheduler::detail::TimerDispatcher::disable()
102 {
103     source_->disable();
104 }
105
106 prefix_ bool senf::scheduler::detail::TimerDispatcher::empty()
107     const
108 {
109     return timers_.empty();
110 }
111
112 prefix_ void senf::scheduler::detail::TimerDispatcher::
113 timerSource(std::auto_ptr<TimerSource> timerSource)
114 {
115     source_.reset(timerSource.release());
116 }
117
118 prefix_ senf::scheduler::detail::TimerSource *
119 senf::scheduler::detail::TimerDispatcher::timerSource()
120 {
121     return source_.get();
122 }
123
124 //-/////////////////////////////////////////////////////////////////////////////////////////////////
125 #undef prefix_
126
127 \f
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // comment-column: 40
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // End: