Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

FIFORunner.cci

Go to the documentation of this file.
00001 // $Id: FIFORunner.cci 1790 2011-06-06 16:32:21Z tho $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 //#include "FIFORunner.ih"
00027 
00028 // Custom includes
00029 #ifdef SENF_DEBUG
00030 #include <sstream>
00031 #include <senf/Utils/Backtrace.hh>
00032 #endif
00033 
00034 #define prefix_ inline
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 //  senf::scheduler::detail::FIFORunner::TaskInfo
00039 
00040 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::TaskInfo(std::string const & name,
00041                                                                 Priority priority)
00042     : Event(name), runnable_ (false), priority_ (priority)
00043 {
00044 #ifdef SENF_BACKTRACE
00045     std::stringstream ss;
00046     senf::backtrace(ss, 32);
00047     backtrace_ = ss.str();
00048 #endif
00049 }
00050 
00051 prefix_ senf::scheduler::detail::FIFORunner::TaskInfo::~TaskInfo()
00052 {}
00053 
00054 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::setRunnable()
00055 {
00056     runnable_ = true;
00057 }
00058 
00059 prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::run()
00060 {
00061     countRun();
00062     // Be sure to run v_run last since the callback may destroy this instance
00063     v_run();
00064 }
00065 
00066 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::runnable()
00067     const
00068 {
00069     return runnable_;
00070 }
00071 
00072 prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::v_enabled()
00073     const
00074 {
00075     return TaskListBase::linked();
00076 }
00077 
00078 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00079 // senf::scheduler::detail::FIFORunner::NullTask
00080 
00081 prefix_ senf::scheduler::detail::FIFORunner::NullTask::NullTask()
00082     : senf::scheduler::detail::FIFORunner::TaskInfo ("<null>")
00083 {}
00084 
00085 prefix_ senf::scheduler::detail::FIFORunner::NullTask::~NullTask()
00086 {
00087     if (TaskListBase::linked())
00088         FIFORunner::instance().dequeue(this);
00089 }
00090 
00091 prefix_ void senf::scheduler::detail::FIFORunner::NullTask::v_run()
00092 {}
00093 
00094 prefix_ char const * senf::scheduler::detail::FIFORunner::NullTask::v_type()
00095     const
00096 {
00097     return 0;
00098 }
00099 
00100 prefix_ std::string senf::scheduler::detail::FIFORunner::NullTask::v_info()
00101     const
00102 {
00103     return "";
00104 }
00105 
00106 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00107 // senf::scheduler::detail::FIFORunner
00108 
00109 prefix_ void senf::scheduler::detail::FIFORunner::enqueue(TaskInfo * task)
00110 {
00111     tasks_.insert(priorityEnd(task->priority_), *task);
00112 }
00113 
00114 prefix_ void senf::scheduler::detail::FIFORunner::taskTimeout(unsigned ms)
00115 {
00116     watchdogMs_ = ms;
00117     if (watchdogRunning_)
00118         startWatchdog();
00119 }
00120 
00121 prefix_ unsigned senf::scheduler::detail::FIFORunner::taskTimeout()
00122     const
00123 {
00124     return watchdogMs_;
00125 }
00126 
00127 prefix_ void senf::scheduler::detail::FIFORunner::abortOnTimeout(bool flag)
00128 {
00129     watchdogAbort_ = flag;
00130 }
00131 
00132 prefix_ bool senf::scheduler::detail::FIFORunner::abortOnTimeout()
00133     const
00134 {
00135     return watchdogAbort_;
00136 }
00137 
00138 prefix_ unsigned senf::scheduler::detail::FIFORunner::hangCount()
00139 {
00140     unsigned hc (hangCount_);
00141     hangCount_ = 0;
00142     return hc;
00143 }
00144 
00145 prefix_ senf::scheduler::detail::FIFORunner::iterator
00146 senf::scheduler::detail::FIFORunner::begin()
00147     const
00148 {
00149     // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added is such
00150     // an element and must be skipped.
00151     return boost::make_filter_iterator(
00152         EventManager::IteratorFilter(), tasks_.begin(), tasks_.end());
00153 }
00154 
00155 prefix_ senf::scheduler::detail::FIFORunner::iterator senf::scheduler::detail::FIFORunner::end()
00156     const
00157 {
00158     return boost::make_filter_iterator(
00159         EventManager::IteratorFilter(), tasks_.end(), tasks_.end());
00160 }
00161 
00162 prefix_ void senf::scheduler::detail::FIFORunner::yield()
00163 {
00164     yield_ = true;
00165 }
00166 
00167 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00168 #undef prefix_
00169 
00170 
00171 // Local Variables:
00172 // mode: c++
00173 // fill-column: 100
00174 // comment-column: 40
00175 // c-file-style: "senf"
00176 // indent-tabs-mode: nil
00177 // ispell-local-dictionary: "american"
00178 // compile-command: "scons -u test"
00179 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research