blob: 1a512a447d61335277017687dac6cc410de33394 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#pragma once
#include "system_headers.h"
#include <functional>
#include <memory>
#include <map>
#include <optional>
#include "base.h"
#include "application.h"
namespace cru
{
using TimerAction = std::function<void()>;
class TimerManager : public Object
{
friend class cru::Application;
private:
static TimerManager* instance_;
public:
static TimerManager* GetInstance();
public:
TimerManager();
TimerManager(const TimerManager& other) = delete;
TimerManager(TimerManager&& other) = delete;
TimerManager& operator=(const TimerManager& other) = delete;
TimerManager& operator=(TimerManager&& other) = delete;
~TimerManager() override;
UINT_PTR CreateTimer(UINT microseconds, bool loop, const TimerAction& action);
void KillTimer(UINT_PTR id);
std::optional<TimerAction> GetAction(UINT_PTR id);
private:
std::map<UINT_PTR, TimerAction> map_{};
};
struct ITimerTask : virtual Interface
{
virtual void Cancel() = 0;
};
std::shared_ptr<ITimerTask> SetTimeout(double seconds, const TimerAction& action);
std::shared_ptr<ITimerTask> SetInterval(double seconds, const TimerAction& action);
}
|