00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _PROPHET_TIMER_H_
00018 #define _PROPHET_TIMER_H_
00019
00020 #include <oasys/thread/Timer.h>
00021 #include <oasys/thread/Lock.h>
00022 #include "prophet/Alarm.h"
00023 #include "prophet/Encounter.h"
00024
00025 namespace dtn
00026 {
00027
00028 class ProphetTimer : public oasys::Timer,
00029 public prophet::Alarm
00030 {
00031 public:
00032 ProphetTimer(prophet::ExpirationHandler* eh,
00033 oasys::SpinLock* lock)
00034 : oasys::Timer(),
00035 prophet::Alarm(eh),
00036 lock_(lock)
00037 {
00038 ASSERT( eh != NULL );
00039 ASSERT( lock != NULL );
00040 }
00041
00042 virtual ~ProphetTimer() {}
00043
00047 void timeout(const struct timeval& now)
00048 {
00049 (void)now;
00050 oasys::ScopeLock l(lock_,"ProphetTimer::timeout");
00051 prophet::Alarm::timeout();
00052 }
00053
00055 void schedule(u_int milliseconds)
00056 {
00057 oasys::Timer::schedule_in(milliseconds);
00058 }
00059 u_int time_remaining() const
00060 {
00061 struct timeval now;
00062 ::gettimeofday(&now,0);
00063 struct timeval when = const_cast<ProphetTimer*>(this)->when();
00064 int diff = TIMEVAL_DIFF_MSEC(when, now);
00065 return (diff < 0) ? 0 : diff;
00066 }
00067 void cancel() { oasys::Timer::cancel(); }
00068 bool pending() const { return oasys::Timer::pending_; }
00069 bool cancelled() const { return oasys::Timer::cancelled_; }
00071
00072 protected:
00073 oasys::SpinLock* lock_;
00074
00075 };
00076
00077 };
00078
00079 #endif // _PROPHET_TIMER_H_