-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSEGSTimer.cpp
70 lines (60 loc) · 1.58 KB
/
SEGSTimer.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
/*
* SEGS - Super Entity Game Server
* http://www.segs.io/
* Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
* This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
*/
/*!
* @addtogroup Components
* @{
*/
#include <cassert>
#include "SEGSTimer.h"
#include "EventProcessor.h"
SEGSTimer::SEGSTimer(EventProcessor *m_processor, uint64_t data, const ACE_Time_Value &fire_delta_time, bool one_shot)
:
m_id(-1),m_user_id(data),m_target(m_processor),m_fire_delta_time(fire_delta_time),m_one_shot(one_shot)
{
if(m_one_shot)
schedule();
else
schedule_repeatable();
}
// TODO: Make sure there are no timeouts scheduled by this timer, maybe ACE takes care of that when timer is canceled ?
SEGSTimer::~SEGSTimer()
{
cancel();
m_target = nullptr;
m_user_id = 0;
}
void SEGSTimer::schedule()
{
assert(m_id==-1);
m_id = GlobalTimerQueue::instance()->schedule(m_target,this,ACE_OS::gettimeofday()+m_fire_delta_time);
}
void SEGSTimer::cancel()
{
if(m_id!=-1)
GlobalTimerQueue::instance()->cancel(m_id,nullptr);
m_id=-1;
}
void SEGSTimer::reset()
{
cancel();
if(m_one_shot)
schedule();
else
schedule_repeatable();
}
void SEGSTimer::reschedule( const ACE_Time_Value &new_time )
{
cancel();
m_fire_delta_time = new_time;
schedule();
}
void SEGSTimer::schedule_repeatable()
{
assert(m_id==-1);
m_id = GlobalTimerQueue::instance()->schedule(m_target,this,ACE_OS::gettimeofday()+m_fire_delta_time,m_fire_delta_time);
}
//! @}