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 if (_next <= dtntime) 00051 { 00052 TimeEvent::raise(dtntime, TIME_SECOND_TICK); 00053 go(); 00054 _next = dtntime + _frequency; 00055 } 00056 00057 this->sleep(500); 00058 yield(); 00059 } 00060 } 00061 } 00062 }
1.5.6