-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.cpp
84 lines (69 loc) · 1.39 KB
/
sample.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include "timer.h"
#include <iostream>
#include <random>
#if defined(WIN32)
#include <windows.h>
#else
#include <unistd.h>
#endif
static int count_ = 0;
class TimerTest
{
public:
void pt(int count)
{
std::cout << count << std::endl;
}
};
class RecommendTest
{
public:
RecommendTest()
{
using namespace gsf::utils;
timer_event_ptr_ = Timer::instance().add_timer(delay_milliseconds(3000)
, makeTimerHandler(&RecommendTest::pt, this, std::string("hello!")));
}
~RecommendTest()
{
if (timer_event_ptr_){
if (gsf::utils::Timer::instance().rmv_timer(timer_event_ptr_) == 0){ //! succ
delete timer_event_ptr_;
timer_event_ptr_ = nullptr;
}
}
}
void pt(std::string str)
{
std::cout << str.c_str() << std::endl;
delete timer_event_ptr_;
timer_event_ptr_ = nullptr;
}
private:
gsf::utils::TimerEvent *timer_event_ptr_;
};
void test_timer_delay_1000ms(const char *str)
{
std::cout << str << std::endl;
}
int main()
{
using namespace gsf::utils;
Timer::instance().add_timer(delay_milliseconds(1000), makeTimerHandler(test_timer_delay_1000ms, "hello,timer!"));
TimerTest *tt = new TimerTest();
for (int i = 0; i < 100; ++i)
{
Timer::instance().add_timer(delay_milliseconds(i * 100), makeTimerHandler(&TimerTest::pt, tt, i));
}
while (1)
{
Timer::instance().update();
#if defined(WIN32)
Sleep(1);
#else
usleep(1000);
#endif
}
return 0;
}