X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FScheduler%2FTimerEventProxy.ct;h=a1c744a6344804af01ae2ad2e613241a829cc30d;hb=78a6e233083efa63a9cd0684a92abc64202a9ee7;hp=cb665b69c2c05f997330d79dbcdd10523c94fec6;hpb=acce6d54436fa760c0f4770ea3a6c76ae40e0bb8;p=senf.git diff --git a/senf/Scheduler/TimerEventProxy.ct b/senf/Scheduler/TimerEventProxy.ct index cb665b6..a1c744a 100644 --- a/senf/Scheduler/TimerEventProxy.ct +++ b/senf/Scheduler/TimerEventProxy.ct @@ -4,6 +4,7 @@ // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Mathias Kretschmer +// Jens Moedeker // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,94 +22,93 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief TimerEventProxy public header */ + \brief TimerEventProxy non-inline template implementation */ -#define prefix_ +// Custom includes -template -prefix_ senf::scheduler::TimerEventProxy::TimerEventProxy() : - timer("timer", senf::membind(&TimerEventProxy::timerEvent, this), 0, - false), entrySetById(entrySet.template get ()), - entrySetByTimeout(entrySet.template get ()) -{ +#define prefix_ +///////////////////////////////ct.p//////////////////////////////////////// -} +template +prefix_ senf::scheduler::TimerEventProxy::TimerEventProxy(std::string const & description) + : entrySetById( entrySet.template get()), + entrySetByTimeout( entrySet.template get ()), + timer( "TimerEventProxy " + description, + membind(&TimerEventProxy::timerEvent, this), 0, false) +{ } -template -prefix_ senf::scheduler::TimerEventProxy::TimerEventProxy( std::string const & name, - senf::console::DirectoryNode & node) : - timer("timer", senf::membind(&TimerEventProxy::timerEvent, this), 0, - false), entrySetById(entrySet.template get ()), - entrySetByTimeout(entrySet.template get ()) +template +prefix_ void senf::scheduler::TimerEventProxy::timerEvent() { - node.add(name, senf::console::factory::Command( - &TimerEventProxy::listTimers, this) .doc("List active Timers")); -} - -template -prefix_ void senf::scheduler::TimerEventProxy::timerEvent() { - - senf::ClockService::clock_type actual = senf::ClockService::now(); - typename EntrySetByTimeout_t::iterator it; - - // execute the timer callbacks first - - it = entrySetByTimeout.begin(); - while (it != entrySetByTimeout.end() && it->timeout <= actual) { - Entry item(*it); + ClockService::clock_type now = senf::scheduler::now(); + typename EntrySetByTimeout_t::iterator it = entrySetByTimeout.begin(); + while (it != entrySetByTimeout.end() && it->timeout <= now) { + Entry item (*it); // remove due entry from set entrySetByTimeout.erase(it); // call callback - item.fkt(actual, item.id); - + item.cb(now, item.id); it = entrySetByTimeout.begin(); } - - if (entrySet.size() > 0) { + if (entrySet.size() > 0) timer.timeout(entrySetByTimeout.begin()->timeout); - } } -template -prefix_ void senf::scheduler::TimerEventProxy::add( - senf::ClockService::clock_type timeout, T const & id, Callback fkt) +template +prefix_ void senf::scheduler::TimerEventProxy::add( + ClockService::clock_type timeout, IdType const & id, Callback cb) { // insert new entry - entrySetByTimeout.insert(Entry (timeout, id, fkt)); - + entrySetByTimeout.insert( Entry(timeout, id, cb)); // the scheduler time to the first earliest timeout (ordered index) - timer.timeout(entrySetByTimeout.begin()->timeout); - - // // if map was empty before, hence we need to activate the time event object - // if( entrySetByTimeout.size() >= 1){ - // timer.enable(); - // } + timer.timeout( entrySetByTimeout.begin()->timeout); } -template -prefix_ bool senf::scheduler::TimerEventProxy::del(T const & id) +template +prefix_ bool senf::scheduler::TimerEventProxy::remove(IdType const & id) { - typename EntrySetById_t::iterator it(entrySetById.find(Entry (0, id, NULL))); + bool removed (entrySetById.erase( id) > 0); + if (entrySet.size() > 0) + timer.timeout(entrySetByTimeout.begin()->timeout); + else + timer.disable(); + return removed; +} - if (it != entrySetById.end()) { - entrySetById.erase(it); - return true; - } - return false; +template +prefix_ senf::ClockService::clock_type senf::scheduler::TimerEventProxy::timeout(IdType const & id) + const +{ + typename EntrySetById_t::const_iterator i ( entrySetById.find( id)); + return i == entrySetById.end() ? 0 : i->timeout; } -template -prefix_ std::vector > senf::scheduler::TimerEventProxy::list() + +template +prefix_ std::vector > senf::scheduler::TimerEventProxy::list() + const { - std::vector > tmp; + std::vector > tmp; - typename EntrySetByTimeout_t::iterator it; + typename EntrySetByTimeout_t::const_iterator it; for (it = entrySetByTimeout.begin(); it != entrySetByTimeout.end(); ++it) { - tmp.push_back(std::make_pair( it->timeout, it->id)); + tmp.push_back(std::make_pair( it->timeout, it->id)); } - return tmp; } +///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_ + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: + +