00001 // $Id: TimerEvent.cci 1772 2011-03-10 12:45: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 "TimerEvent.ih" 00027 00028 // Custom includes 00029 #include <unistd.h> 00030 00031 #define prefix_ inline 00032 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00033 00034 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00035 // senf::scheduler::TimerEvent 00036 00037 prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb, 00038 ClockService::clock_type timeout, 00039 bool initiallyEnabled) 00040 : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (timeout) 00041 { 00042 if (initiallyEnabled) 00043 enable(); 00044 } 00045 00046 prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb) 00047 : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (0) 00048 {} 00049 00050 prefix_ senf::scheduler::TimerEvent::~TimerEvent() 00051 { 00052 if (detail::TimerDispatcher::alive()) 00053 disable(); 00054 } 00055 00056 prefix_ void senf::scheduler::TimerEvent::enable() 00057 { 00058 if (! detail::TimerSetBase::linked()) 00059 detail::TimerDispatcher::instance().add(*this); 00060 } 00061 00062 prefix_ void senf::scheduler::TimerEvent::disable() 00063 { 00064 if (detail::TimerSetBase::linked()) 00065 detail::TimerDispatcher::instance().remove(*this); 00066 } 00067 00068 prefix_ void senf::scheduler::TimerEvent::action(Callback const & cb) 00069 { 00070 cb_ = cb; 00071 } 00072 00073 prefix_ void senf::scheduler::TimerEvent::timeout(ClockService::clock_type timeout, 00074 bool initiallyEnabled) 00075 { 00076 disable(); 00077 timeout_ = timeout; 00078 if (initiallyEnabled) 00079 enable(); 00080 } 00081 00082 prefix_ senf::ClockService::clock_type senf::scheduler::TimerEvent::timeout() 00083 const 00084 { 00085 return timeout_; 00086 } 00087 00088 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00089 // senf::scheduler::detail::TimerDispatcher 00090 00091 prefix_ void senf::scheduler::detail::TimerDispatcher::enable() 00092 { 00093 source_->enable(); 00094 } 00095 00096 prefix_ void senf::scheduler::detail::TimerDispatcher::disable() 00097 { 00098 source_->disable(); 00099 } 00100 00101 prefix_ bool senf::scheduler::detail::TimerDispatcher::empty() 00102 const 00103 { 00104 return timers_.empty(); 00105 } 00106 00107 prefix_ void senf::scheduler::detail::TimerDispatcher:: 00108 timerSource(std::auto_ptr<TimerSource> timerSource) 00109 { 00110 source_.reset(timerSource.release()); 00111 } 00112 00113 prefix_ senf::scheduler::detail::TimerSource * 00114 senf::scheduler::detail::TimerDispatcher::timerSource() 00115 { 00116 return source_.get(); 00117 } 00118 00119 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00120 #undef prefix_ 00121 00122 00123 // Local Variables: 00124 // mode: c++ 00125 // fill-column: 100 00126 // comment-column: 40 00127 // c-file-style: "senf" 00128 // indent-tabs-mode: nil 00129 // ispell-local-dictionary: "american" 00130 // compile-command: "scons -u test" 00131 // End: