diff --git a/f8/timer.cc b/f8/timer.cc new file mode 100644 index 0000000..6fca259 --- /dev/null +++ b/f8/timer.cc @@ -0,0 +1,106 @@ +#include + +#include + +#include + +namespace f8 +{ + + Attacher::Attacher() + { + + } + + void Timer::Init() + { + + } + + void Timer::UnInit() + { + + } + + bool Timer::Initialized() + { + + } + + void Timer::Update() + { + + } + + void Timer::SetTimeout(int expire_time, a8::TimerCb cb) + { + + } + + void Timer::SetTimeoutEx(int expire_time, a8::TimerCb cb, Attacher* attacher) + { + + } + + TimerWp Timer::SetTimeoutWp(int expire_time, a8::TimerCb cb) + { + + } + + TimerWp Timer::SetTimeoutWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher) + { + + } + + void Timer::SetInterval(int expire_time, a8::TimerCb cb) + { + + } + + void Timer::SetIntervalEx(int expire_time, a8::TimerCb cb, Attacher* attacher) + { + + } + + TimerWp Timer::SetIntervalWp(int expire_time, a8::TimerCb cb) + { + + } + + TimerWp Timer::SetIntervalWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher) + { + + } + + void Timer::FireEvent(TimerWp& timer_wp, int event, a8::Args* args) + { + + } + + void Timer::ModifyTime(TimerWp& timer_wp, int expire_time) + { + + } + + void Timer::Delete(TimerWp& timer_wp) + { + + } + + long long Timer::GetRemainTime(TimerWp& timer_wp) + { + + + } + + void Timer::DeleteCurrentTimer() + { + + } + + bool Timer::IsRunning() + { + + } + +} diff --git a/f8/timer.h b/f8/timer.h new file mode 100644 index 0000000..be215f5 --- /dev/null +++ b/f8/timer.h @@ -0,0 +1,66 @@ +#pragma once + +#include +#include + +namespace f8 +{ + class TimerWp + { + public: + TimerWp(a8::XTimerWp wp): p_(wp) {}; + bool expired() { return p_.expired();}; + auto&& lock() { return p_.lock(); }; + + private: + a8::XTimerWp p_; + friend class Timer; + }; + + class Attacher + { + public: + Attacher(); + void ClearTimerList() { p_.ClearTimerList(); }; + + private: + a8::Attacher p_; + friend class Timer; + }; + + class Timer : public a8::Singleton + { + + private: + Timer() {}; + friend class a8::Singleton; + + public: + void Init(); + void UnInit(); + bool Initialized(); + void Update(); + + void SetTimeout(int expire_time, a8::TimerCb cb); + void SetTimeoutEx(int expire_time, a8::TimerCb cb, Attacher* attacher); + TimerWp SetTimeoutWp(int expire_time, a8::TimerCb cb); + TimerWp SetTimeoutWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher); + + void SetInterval(int expire_time, a8::TimerCb cb); + void SetIntervalEx(int expire_time, a8::TimerCb cb, Attacher* attacher); + TimerWp SetIntervalWp(int expire_time, a8::TimerCb cb); + TimerWp SetIntervalWpEx(int expire_time, a8::TimerCb cb, Attacher* attacher); + + void FireEvent(TimerWp& timer_wp, int event, a8::Args* args); + void ModifyTime(TimerWp& timer_wp, int expire_time); + void Delete(TimerWp& timer_wp); + long long GetRemainTime(TimerWp& timer_wp); + void DeleteCurrentTimer(); + bool IsRunning(); + + private: + bool initialized_ = false; + a8::XTimer xtimer_; + }; + +}