From: tho Date: Wed, 28 Jul 2010 11:20:04 +0000 (+0000) Subject: Scheduler: Fix for TimerEventProxy X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=adc12e8819cd179bf717132e9eb5a5849f281e52;p=senf.git Scheduler: Fix for TimerEventProxy git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1651 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/PPI/SocketSource.ct b/senf/PPI/SocketSource.ct index bc60d29..58131fa 100644 --- a/senf/PPI/SocketSource.ct +++ b/senf/PPI/SocketSource.ct @@ -76,15 +76,6 @@ prefix_ senf::ppi::module::ActiveSocketSource::ActiveSocketSource(Handle route(event_, output); } -//////////////////////////////////////// -// private members - -template -prefix_ void senf::ppi::module::ActiveSocketSource::read() -{ - output(reader_(handle_)); -} - ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_ diff --git a/senf/PPI/SocketSource.cti b/senf/PPI/SocketSource.cti index 8bb2e7c..ffffdd5 100644 --- a/senf/PPI/SocketSource.cti +++ b/senf/PPI/SocketSource.cti @@ -53,6 +53,15 @@ prefix_ void senf::ppi::module::ActiveSocketSource::handle(Handle handle event_.set(handle_, IOEvent::Read); } +//////////////////////////////////////// +// private members + +template +prefix_ void senf::ppi::module::ActiveSocketSource::read() +{ + output(reader_(handle_)); +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/senf/Scheduler/TimerEventProxy.ct b/senf/Scheduler/TimerEventProxy.ct index 3bbdcd4..a5548d9 100644 --- a/senf/Scheduler/TimerEventProxy.ct +++ b/senf/Scheduler/TimerEventProxy.ct @@ -30,33 +30,24 @@ ///////////////////////////////ct.p//////////////////////////////////////// template -prefix_ senf::scheduler::TimerEventProxy::TimerEventProxy() +prefix_ senf::scheduler::TimerEventProxy::TimerEventProxy(std::string const & description) : entrySetById( entrySet.template get()), entrySetByTimeout( entrySet.template get ()), - timer( "TimerEventProxy", membind(&TimerEventProxy::timerEvent, this), 0, false) + timer( "TimerEventProxy " + description, + membind(&TimerEventProxy::timerEvent, this), 0, false) { } template -prefix_ senf::scheduler::TimerEventProxy::TimerEventProxy(std::string const & name, console::DirectoryNode & node) - : entrySetById( entrySet.template get()), - entrySetByTimeout( entrySet.template get ()), - timer( "TimerEventProxy", membind(&TimerEventProxy::timerEvent, this), 0, false) -{ - node.add(name, console::factory::Command( - &TimerEventProxy::list, this) .doc("List active Timers")); -} - -template prefix_ void senf::scheduler::TimerEventProxy::timerEvent() { - ClockService::clock_type actual = ClockService::now(); + ClockService::clock_type now = ClockService::now(); typename EntrySetByTimeout_t::iterator it = entrySetByTimeout.begin(); - while (it != entrySetByTimeout.end() && it->timeout <= actual) { + while (it != entrySetByTimeout.end() && it->timeout <= now) { Entry item (*it); // remove due entry from set entrySetByTimeout.erase(it); // call callback - item.cb(actual, item.id); + item.cb(now, item.id); it = entrySetByTimeout.begin(); } if (entrySet.size() > 0) @@ -76,7 +67,12 @@ prefix_ void senf::scheduler::TimerEventProxy::add( template prefix_ bool senf::scheduler::TimerEventProxy::remove(IdType const & id) { - return entrySetById.erase( id) > 0; + bool removed (entrySetById.erase( id) > 0); + if (entrySet.size() > 0) + timer.timeout(entrySetByTimeout.begin()->timeout); + else + timer.disable(); + return removed; } template diff --git a/senf/Scheduler/TimerEventProxy.hh b/senf/Scheduler/TimerEventProxy.hh index 3517db6..75c4f8c 100644 --- a/senf/Scheduler/TimerEventProxy.hh +++ b/senf/Scheduler/TimerEventProxy.hh @@ -55,10 +55,9 @@ namespace scheduler { public: typedef boost::function Callback; - TimerEventProxy(); ///< Instantiate a TimerEventProxy - TimerEventProxy(std::string const & name, console::DirectoryNode & node); - /**< \brief Instantiate a TimerEventProxy and add the list - command to the give DirectoryNode */ + TimerEventProxy(std::string const & description = ""); + ///< Instantiate a TimerEventProxy + /**< \param[in] description Descriptive name (purely informational) */ void add(ClockService::clock_type timeout, IdType const & id, Callback cb); ///< Add new deadline timer diff --git a/senf/Scheduler/TimerEventProxy.test.cc b/senf/Scheduler/TimerEventProxy.test.cc index 992af10..dfab9cc 100644 --- a/senf/Scheduler/TimerEventProxy.test.cc +++ b/senf/Scheduler/TimerEventProxy.test.cc @@ -61,7 +61,7 @@ SENF_AUTO_UNIT_TEST(timerEventProxy) senf::ClockService::clock_type t (senf::ClockService::now()); { - senf::scheduler::TimerEventProxy timers; + senf::scheduler::TimerEventProxy timers ("unit-test"); // timers.add( t + senf::ClockService::milliseconds(10000), 0 , &handler); timers.add( t + senf::ClockService::milliseconds(800), 4, &handler); @@ -78,8 +78,6 @@ SENF_AUTO_UNIT_TEST(timerEventProxy) BOOST_CHECK( mask == 3); } - - senf::scheduler::TimerEventProxy timers ("test", senf::console::ScopedDirectory<>()); }