IBR-DTNSuite 0.6

daemon/src/core/WallClock.cpp

Go to the documentation of this file.
00001 /*
00002  * Clock.cpp
00003  *
00004  *  Created on: 17.07.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #include "core/WallClock.h"
00009 #include "core/TimeEvent.h"
00010 #include <ibrdtn/utils/Clock.h>
00011 #include <ibrcommon/thread/MutexLock.h>
00012 
00013 namespace dtn
00014 {
00015         namespace core
00016         {
00017                 WallClock::WallClock(size_t frequency) : _frequency(frequency), _next(0), _timer(*this, 0)
00018                 {
00019                         _timer.set(frequency);
00020                 }
00021 
00022                 WallClock::~WallClock()
00023                 {
00024                 }
00025 
00026                 void WallClock::sync()
00027                 {
00028                         try {
00029                                 ibrcommon::MutexLock l(*this);
00030                                 wait();
00031                         } catch (const ibrcommon::Conditional::ConditionalAbortException &ex) {
00032 
00033                         }
00034                 }
00035 
00036                 void WallClock::componentUp()
00037                 {
00038                         _timer.start();
00039                 }
00040 
00041                 void WallClock::componentDown()
00042                 {
00043                         _timer.remove();
00044                 }
00045 
00046                 size_t WallClock::timeout(size_t)
00047                 {
00048                         size_t dtntime = dtn::utils::Clock::getTime();
00049 
00050                         if (dtntime == 0)
00051                         {
00052                                 TimeEvent::raise(dtntime, TIME_SECOND_TICK);
00053 
00054                                 ibrcommon::MutexLock l(*this);
00055                                 signal(true);
00056                         }
00057                         else if (_next <= dtntime)
00058                         {
00059                                 TimeEvent::raise(dtntime, TIME_SECOND_TICK);
00060                                 _next = dtntime + _frequency;
00061 
00062                                 ibrcommon::MutexLock l(*this);
00063                                 signal(true);
00064                         }
00065 
00066                         return _frequency;
00067                 }
00068 
00069                 const std::string WallClock::getName() const
00070                 {
00071                         return "WallClock";
00072                 }
00073         }
00074 }