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 00012 namespace dtn 00013 { 00014 namespace core 00015 { 00016 WallClock::WallClock(size_t frequency) : _frequency(frequency), _next(0), _running(false) 00017 { 00018 } 00019 00020 WallClock::~WallClock() 00021 { 00022 if (isRunning()) 00023 { 00024 componentDown(); 00025 } 00026 } 00027 00028 void WallClock::sync() 00029 { 00030 wait(); 00031 } 00032 00033 void WallClock::componentUp() 00034 { 00035 } 00036 00037 void WallClock::componentDown() 00038 { 00039 _running = false; 00040 join(); 00041 } 00042 00043 void WallClock::componentRun() 00044 { 00045 _running = true; 00046 00047 while (_running) 00048 { 00049 size_t dtntime = dtn::utils::Clock::getTime(); 00050 00051 if (dtntime == 0) 00052 { 00053 TimeEvent::raise(dtntime, TIME_SECOND_TICK); 00054 go(); 00055 this->sleep(500); 00056 } 00057 else if (_next <= dtntime) 00058 { 00059 TimeEvent::raise(dtntime, TIME_SECOND_TICK); 00060 go(); 00061 _next = dtntime + _frequency; 00062 } 00063 00064 this->sleep(500); 00065 yield(); 00066 } 00067 } 00068 } 00069 }
1.6.3