added a method() to query the number of active timer events
[senf.git] / senf / Scheduler / TimerEventProxy.ct
index a1c744a..c9a58f6 100644 (file)
     \brief TimerEventProxy non-inline template implementation */
 
 // Custom includes
+#include <senf/Utils/membind.hh>
 
 #define prefix_
-///////////////////////////////ct.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
 template<typename IdType>
 prefix_ senf::scheduler::TimerEventProxy<IdType>::TimerEventProxy(std::string const & description)
@@ -58,8 +59,15 @@ template<typename IdType>
 prefix_ void senf::scheduler::TimerEventProxy<IdType>::add(
         ClockService::clock_type timeout, IdType const & id, Callback cb)
 {
-    // insert new entry
-    entrySetByTimeout.insert( Entry(timeout, id, cb));
+    // insert new entry or replace the timeout of an entry already indexed
+    typename EntrySetById_t::iterator i = entrySetById.find(id);
+    if(i == entrySetById.end())
+       entrySetByTimeout.insert( Entry(timeout, id, cb));
+       else{
+               Entry tmp = *i;
+               tmp.timeout = timeout;
+               entrySetById.replace(i,tmp);
+       }
     // the scheduler time to the first earliest timeout (ordered index)
     timer.timeout( entrySetByTimeout.begin()->timeout);
 }
@@ -97,7 +105,14 @@ prefix_ std::vector<std::pair<senf::ClockService::clock_type, IdType> > senf::sc
     return tmp;
 }
 
-///////////////////////////////ct.e////////////////////////////////////////
+template<typename IdType>
+prefix_ unsigned senf::scheduler::TimerEventProxy<IdType>::numEvents()
+  const
+{
+  return entrySetByTimeout.size();
+}
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #undef prefix_
 
 \f