diff options
author | crupest <crupest@outlook.com> | 2018-09-25 13:08:40 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-25 13:08:40 +0800 |
commit | 4b86554a0354d78efeb40e551eaccaac0fecd1d1 (patch) | |
tree | c8a73d848401f523ff91fe8ed1b0887aa88bbfb8 /src/timer.h | |
parent | cea138417c54d6cf8043b6334c22e3af957d26f8 (diff) | |
download | cru-4b86554a0354d78efeb40e551eaccaac0fecd1d1.tar.gz cru-4b86554a0354d78efeb40e551eaccaac0fecd1d1.tar.bz2 cru-4b86554a0354d78efeb40e551eaccaac0fecd1d1.zip |
Change the structure of project.
Diffstat (limited to 'src/timer.h')
-rw-r--r-- | src/timer.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/timer.h b/src/timer.h new file mode 100644 index 00000000..9884e46a --- /dev/null +++ b/src/timer.h @@ -0,0 +1,43 @@ +#pragma once + + +#include "system_headers.h" +#include <memory> +#include <map> +#include <chrono> + +#include "base.h" +#include "application.h" + +namespace cru +{ + class TimerManager : public Object + { + public: + static TimerManager* GetInstance() + { + return Application::GetInstance()->GetTimerManager(); + } + + public: + TimerManager() = default; + TimerManager(const TimerManager& other) = delete; + TimerManager(TimerManager&& other) = delete; + TimerManager& operator=(const TimerManager& other) = delete; + TimerManager& operator=(TimerManager&& other) = delete; + ~TimerManager() override = default; + + UINT_PTR CreateTimer(UINT milliseconds, bool loop, ActionPtr action); + void KillTimer(UINT_PTR id); + ActionPtr GetAction(UINT_PTR id); + + private: + std::map<UINT_PTR, ActionPtr> map_{}; + UINT_PTR current_count_ = 0; + }; + + using TimerTask = CancelablePtr; + + TimerTask SetTimeout(std::chrono::milliseconds milliseconds, ActionPtr action); + TimerTask SetInterval(std::chrono::milliseconds milliseconds, ActionPtr action); +} |