b2f6fe61e70d3c0918953e2599962ee282effa54
[senf.git] / Scheduler / FIFORunner.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 FIFORunner inline non-template implementation */
25
26 //#include "FIFORunner.ih"
27
28 // Custom includes
29 #ifdef SENF_DEBUG
30 #include <sstream>
31 #include "../Utils/Backtrace.hh"
32 #endif
33
34 #define prefix_ inline
35 ///////////////////////////////cci.p///////////////////////////////////////
36
37 ///////////////////////////////////////////////////////////////////////////
38 //  senf::scheduler::detail::FIFORunner::TaskInfo
39
40 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::TaskInfo(std::string const & name,
41                                                                 Priority priority)
42     : Event(name), runnable_ (false), priority_ (priority)
43 {}
44
45 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::~TaskInfo()
46 {}
47
48 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::setRunnable()
49 {
50     runnable_ = true;
51 }
52
53 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::run()
54 {
55     countRun();
56     // Be sure to run v_run last since the callback may destroy this instance
57     v_run();
58 }
59
60 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::runnable()
61     const
62 {
63     return runnable_;
64 }
65
66 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::v_enabled()
67     const
68 {
69     return TaskListBase::linked();
70 }
71
72 ///////////////////////////////////////////////////////////////////////////
73 // senf::scheduler::detail::FIFORunner::NullTask
74
75 prefix_ senf::scheduler::detail::FIFORunner::NullTask::NullTask()
76     : senf::scheduler::detail::FIFORunner::TaskInfo ("<null>") 
77 {}
78
79 prefix_ senf::scheduler::detail::FIFORunner::NullTask::~NullTask()
80 {
81     if (TaskListBase::linked())
82         FIFORunner::instance().dequeue(this);
83 }
84
85 prefix_ void senf::scheduler::detail::FIFORunner::NullTask::v_run()
86 {}
87
88 prefix_ char const * senf::scheduler::detail::FIFORunner::NullTask::v_type()
89     const
90 {
91     return 0;
92 }
93
94 prefix_ std::string senf::scheduler::detail::FIFORunner::NullTask::v_info()
95     const
96 {
97     return "";
98 }
99
100 ///////////////////////////////////////////////////////////////////////////
101 // senf::scheduler::detail::FIFORunner
102
103 prefix_ void senf::scheduler::detail::FIFORunner::enqueue(TaskInfo * task)
104 {
105     tasks_.insert(priorityEnd(task->priority_), *task);
106 #ifdef SENF_DEBUG
107     std::stringstream ss;
108     backtrace(ss, 32);
109     task->backtrace_ = ss.str();
110 #endif
111 }
112
113 prefix_ void senf::scheduler::detail::FIFORunner::taskTimeout(unsigned ms)
114 {
115     watchdogMs_ = ms;
116 }
117
118 prefix_ unsigned senf::scheduler::detail::FIFORunner::taskTimeout()
119     const
120 {
121     return watchdogMs_;
122 }
123
124 prefix_ unsigned senf::scheduler::detail::FIFORunner::hangCount()
125     const
126 {
127     return hangCount_;
128 }
129
130 prefix_ senf::scheduler::detail::FIFORunner::iterator
131 senf::scheduler::detail::FIFORunner::begin()
132     const
133 {
134     // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added is such
135     // an element and must be skipped.
136     return boost::make_filter_iterator(
137         EventManager::IteratorFilter(), tasks_.begin(), tasks_.end());
138 }
139
140 prefix_ senf::scheduler::detail::FIFORunner::iterator senf::scheduler::detail::FIFORunner::end()
141     const
142 {
143     return boost::make_filter_iterator(
144         EventManager::IteratorFilter(), tasks_.end(), tasks_.end());
145 }
146
147 ///////////////////////////////cci.e///////////////////////////////////////
148 #undef prefix_
149
150 \f
151 // Local Variables:
152 // mode: c++
153 // fill-column: 100
154 // comment-column: 40
155 // c-file-style: "senf"
156 // indent-tabs-mode: nil
157 // ispell-local-dictionary: "american"
158 // compile-command: "scons -u test"
159 // End: