NEW FILE HEADER / COPYRIGHT FORMAT
[senf.git] / Scheduler / ClockService.cc
index a614462..44b5404 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
 // Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Fraunhofer Institute for Open Communication Systems (FOKUS) 
+// Competence Center NETwork research (NET), St. Augustin, GERMANY 
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 #include <signal.h>
 #include <sys/time.h>
 #include <pthread.h>
-#include "Utils/Exception.hh"
+#include "../Utils/Exception.hh"
 
 //#include "ClockService.mpp"
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-#define CheckError(op,args) if (op args < 0) throw SystemException(# op, errno)
+#define CheckError(op,args) if (op args < 0) throwErrno(# op, errno)
 
 ///////////////////////////////////////////////////////////////////////////
 // senf::ClockService::Impl
@@ -49,6 +49,7 @@ struct senf::ClockService::Impl
     void block();
     void unblock();
 
+    /// Internal: temporarily block signals (RAII idiom)
     struct Blocker {
         Blocker(Impl * i) : impl(i) { impl->block(); }
         ~Blocker() { impl->unblock(); }
@@ -125,14 +126,19 @@ prefix_ void senf::ClockService::restart_m(bool restart)
     action.sa_flags = SA_RESTART;
     CheckError( sigaction, (SIGALRM, &action, restart ? 0 : &impl_->oldaction) );
 
+    restartTimer(restart);
+    
+    impl_->unblock();
+}
+
+prefix_ void senf::ClockService::restartTimer(bool restart)
+{
     struct itimerval itimer;
     itimer.it_interval.tv_sec = CheckInterval;
     itimer.it_interval.tv_usec = 0;
     itimer.it_value.tv_sec = CheckInterval;
     itimer.it_value.tv_usec = 0;
     CheckError( setitimer, (ITIMER_REAL, &itimer, restart ? 0 : &impl_->olditimer) );
-    
-    impl_->unblock();
 }
 
 prefix_ void senf::ClockService::updateSkew(boost::posix_time::ptime time)
@@ -149,6 +155,8 @@ prefix_ void senf::ClockService::updateSkew(boost::posix_time::ptime time)
                          + boost::posix_time::seconds(CheckInterval) 
                          - boost::posix_time::seconds(itimer.it_value.tv_sec)
                          - boost::posix_time::microseconds(itimer.it_value.tv_usec)));
+        heartbeat_ = time;
+        restartTimer();
     }
 }