00001 // $Id: IdleEvent.cci 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2009 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 "IdleEvent.ih" 00027 00028 // Custom includes 00029 #include "FdEvent.hh" 00030 00031 #define prefix_ inline 00032 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00033 00034 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00035 // senf::scheduler::IdleEvent 00036 00037 prefix_ senf::scheduler::IdleEvent::IdleEvent(std::string const & name, Callback const & cb, 00038 bool initiallyEnabled) 00039 : detail::FIFORunner::TaskInfo(name), cb_ (cb) 00040 { 00041 if (initiallyEnabled) 00042 enable(); 00043 } 00044 00045 prefix_ senf::scheduler::IdleEvent::~IdleEvent() 00046 { 00047 if (detail::IdleEventDispatcher::alive()) 00048 disable(); 00049 } 00050 00051 prefix_ void senf::scheduler::IdleEvent::disable() 00052 { 00053 if (enabled()) 00054 detail::IdleEventDispatcher::instance().remove(*this); 00055 } 00056 00057 prefix_ void senf::scheduler::IdleEvent::enable() 00058 { 00059 if (! enabled()) { 00060 detail::IdleEventDispatcher::instance().add(*this); 00061 setRunnable(); 00062 } 00063 } 00064 00065 prefix_ void senf::scheduler::IdleEvent::action(Callback const & cb) 00066 { 00067 cb_ = cb; 00068 } 00069 00070 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00071 // senf::scheduler::detail::IdleEventDispatcher 00072 00073 prefix_ void senf::scheduler::detail::IdleEventDispatcher::add(IdleEvent & event) 00074 { 00075 events_.push_back(event); 00076 FIFORunner::instance().enqueue(&event); 00077 detail::FileDispatcher::instance().timeout(0); 00078 } 00079 00080 prefix_ void senf::scheduler::detail::IdleEventDispatcher::timeout(int t) 00081 { 00082 managerTimeout_ = t; 00083 if (events_.empty()) 00084 detail::FileDispatcher::instance().timeout(managerTimeout_); 00085 } 00086 00087 prefix_ int senf::scheduler::detail::IdleEventDispatcher::timeout() 00088 const 00089 { 00090 return managerTimeout_; 00091 } 00092 00093 prefix_ bool senf::scheduler::detail::IdleEventDispatcher::empty() 00094 const 00095 { 00096 return events_.empty(); 00097 } 00098 00099 prefix_ senf::scheduler::detail::IdleEventDispatcher::IdleEventDispatcher() 00100 : managerTimeout_ (scheduler::detail::FileDispatcher::instance().timeout()) 00101 {} 00102 00103 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00104 #undef prefix_ 00105 00106 00107 // Local Variables: 00108 // mode: c++ 00109 // fill-column: 100 00110 // comment-column: 40 00111 // c-file-style: "senf" 00112 // indent-tabs-mode: nil 00113 // ispell-local-dictionary: "american" 00114 // compile-command: "scons -u test" 00115 // End: