///////////////////////////////ct.p////////////////////////////////////////
template<typename IdType>
-prefix_ senf::scheduler::TimerEventProxy<IdType>::TimerEventProxy()
+prefix_ senf::scheduler::TimerEventProxy<IdType>::TimerEventProxy(std::string const & description)
: entrySetById( entrySet.template get<Id>()),
entrySetByTimeout( entrySet.template get<Timeout> ()),
- timer( "TimerEventProxy", membind(&TimerEventProxy<IdType>::timerEvent, this), 0, false)
+ timer( "TimerEventProxy " + description,
+ membind(&TimerEventProxy<IdType>::timerEvent, this), 0, false)
{ }
template<typename IdType>
-prefix_ senf::scheduler::TimerEventProxy<IdType>::TimerEventProxy(std::string const & name, console::DirectoryNode & node)
- : entrySetById( entrySet.template get<Id>()),
- entrySetByTimeout( entrySet.template get<Timeout> ()),
- timer( "TimerEventProxy", membind(&TimerEventProxy<IdType>::timerEvent, this), 0, false)
-{
- node.add(name, console::factory::Command(
- &TimerEventProxy<IdType>::list, this) .doc("List active Timers"));
-}
-
-template<typename IdType>
prefix_ void senf::scheduler::TimerEventProxy<IdType>::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)
template<typename IdType>
prefix_ bool senf::scheduler::TimerEventProxy<IdType>::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<typename IdType>
public:
typedef boost::function<void(ClockService::clock_type, IdType const &)> 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
senf::ClockService::clock_type t (senf::ClockService::now());
{
- senf::scheduler::TimerEventProxy<int> timers;
+ senf::scheduler::TimerEventProxy<int> timers ("unit-test");
// timers.add( t + senf::ClockService::milliseconds(10000), 0 , &handler);
timers.add( t + senf::ClockService::milliseconds(800), 4, &handler);
BOOST_CHECK( mask == 3);
}
-
- senf::scheduler::TimerEventProxy<int> timers ("test", senf::console::ScopedDirectory<>());
}