-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventProcessor.cpp
95 lines (86 loc) · 2.22 KB
/
EventProcessor.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
85
86
87
88
89
90
91
92
93
94
95
/*
* 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 "EventProcessor.h"
#include "SEGSTimer.h"
#include "TimeEvent.h"
#include <cassert>
#ifdef _MSC_VER
#include <iso646.h> // visual studio needs this
#endif
using namespace SEGSEvents;
int EventProcessor::open( void *args /* = 0 */ )
{
return super::open(args);
}
int EventProcessor::handle_timeout( const ACE_Time_Value ¤t_time, const void *act /* = 0 */ )
{
const SEGSTimer *timer_object = static_cast<const SEGSTimer *>(act);
assert(timer_object!=nullptr);
// if target is known
if(timer_object->target())
{
Event *mb=new Timeout(current_time,timer_object->user_id(),this);
// post a new event to it
return timer_object->target()->putq(mb);
}
return 0;
}
int EventProcessor::svc( )
{
if(not this->per_thread_startup())
return -1;
Event *mb;
while(getq(mb,nullptr)!=-1)
{
if(mb->type()==evFinish)
{
if(thr_count() > 1)
putq(mb); // put this back on our message queue, our siblings will receive it and shut down as well
else
{
mb->release();
this->flush();
}
return 0;
}
dispatch(mb);
mb->release();
}
this->per_thread_shutdown();
return 0;
}
/**
* @brief This is mostly used by unit testing and debugging functions.
* @return 0 if no more events on queue, -1 if finish event was encountered., 1 if everything went ok.
*/
int EventProcessor::process_single_event()
{
// this event processor cannot have any threads running to allow single-stepping
assert(thr_count() < 1);
Event *mb;
ACE_Time_Value tv = ACE_OS::gettimeofday();
if(getq(mb,&tv)==-1)
return 0;
if(mb->type()==SEGSEvents::evFinish)
{
return -1;
}
dispatch(mb);
mb->release();
return 1;
}
int EventProcessor::putq(Event *ev,ACE_Time_Value *timeout)
{
#ifdef EVENT_RECORDING
#endif
return super::putq(ev,timeout);
}
//! @}