PPI: Add methods to IntervalTimer to change the timer interval
g0dil [Tue, 13 Jan 2009 08:34:29 +0000 (08:34 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1060 270642c3-0616-0410-b53a-bc976706d245

PPI/IntervalTimer.cc
PPI/IntervalTimer.cci
PPI/IntervalTimer.hh

index f0dafd1..e4dff93 100644 (file)
@@ -42,6 +42,8 @@
 
 prefix_ void senf::ppi::IntervalTimer::v_enable()
 {
+    if (eventsPerInterval_ <= 0)
+        return;
     info_.intervalStart = manager().now();
     info_.number = 0;
     schedule();
index afa7ba3..674ff7e 100644 (file)
 prefix_ senf::ppi::IntervalTimer::IntervalTimer(ClockService::clock_type interval,
                                                 unsigned eventsPerInterval)
     : interval_ (interval), eventsPerInterval_ (eventsPerInterval),
-      timer_("senf::ppi::IntervalTimer",  boost::bind(&IntervalTimer::cb,this))
+      timer_ ("senf::ppi::IntervalTimer",  boost::bind(&IntervalTimer::cb,this))
 {}
 
+prefix_ senf::ppi::IntervalTimer::IntervalTimer()
+    : interval_ (0), eventsPerInterval_ (0),
+      timer_ ("senf::ppi::IntervalTimer",  boost::bind(&IntervalTimer::cb,this))
+{}
+
+prefix_ void senf::ppi::IntervalTimer::interval(ClockService::clock_type interval,
+                                                unsigned eventsPerInterval)
+{
+    enabled(false);
+    interval_ = interval;
+    eventsPerInterval_ = eventsPerInterval;
+    enabled(true);
+}
+
+prefix_ std::pair<senf::ClockService::clock_type, unsigned> senf::ppi::IntervalTimer::interval()
+    const
+{
+    return std::make_pair(interval_, eventsPerInterval_);
+}
+
 ///////////////////////////////cci.e///////////////////////////////////////
 #undef prefix_
 
index 98228e4..959c48c 100644 (file)
@@ -66,10 +66,14 @@ namespace ppi {
 
         explicit IntervalTimer(ClockService::clock_type interval,
                                unsigned eventsPerInterval=1);
-
+        IntervalTimer();
+        
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
+        void interval(ClockService::clock_type interval, unsigned eventsPerInterval=1);
+        std::pair<ClockService::clock_type, unsigned> interval() const;
+
     protected:
 
     private: