forked from alexfreud/winamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stimer.cpp
175 lines (146 loc) · 4.61 KB
/
stimer.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "api.h"
#include "stimer.h"
#include <api/script/objcontroller.h>
#include <api/script/objects/rootobj.h>
#include "Factory.h"
extern Factory factory;
STimer::STimer() {
getScriptObject()->vcpu_setInterface(timerGuid, (void *)static_cast<STimer *>(this));
getScriptObject()->vcpu_setClassName(L"Timer");
getScriptObject()->vcpu_setController(timerController);
delay = 1000;
started = 0;
}
STimer::~STimer() {
}
void STimer::setDelay(int d) {
delay = d;
if (started)
timerclient_setTimer(STIMER_ID, getDelay());
}
int STimer::getDelay(void) {
return delay;
}
void STimer::start(void) {
if (started) { stop(); }
timerclient_setTimer(STIMER_ID, getDelay());
started = 1;
}
void STimer::stop(void) {
if (!started) return;
timerclient_killTimer(STIMER_ID);
started = 0;
}
void STimer::onTimer(void)
{
if (started)
{
script_onTimer(SCRIPT_CALL, getScriptObject());
}
}
void STimer::timerclient_timerCallback(int id)
{
if (id == STIMER_ID)
onTimer();
}
int STimer::isRunning() {
return started;
}
extern ScriptObjectController *script_root;
TimerScriptController _timerController;
TimerScriptController *timerController=&_timerController;
// -- Functions table -------------------------------------
function_descriptor_struct TimerScriptController::exportedFunction[] = {
{L"setDelay", 1, (void*)STimer::script_setDelay },
{L"getDelay", 0, (void*)STimer::script_getDelay },
{L"start", 0, (void*)STimer::script_start },
{L"stop", 0, (void*)STimer::script_stop },
{L"onTimer", 0, (void*)STimer::script_onTimer },
{L"isRunning",0, (void*)STimer::script_isRunning },
{L"getSkipped",0, (void*)STimer::script_getSkipped },
};
// --------------------------------------------------------
const wchar_t *TimerScriptController::getClassName() {
return L"Timer";
}
const wchar_t *TimerScriptController::getAncestorClassName() {
return L"Object";
}
ScriptObjectController *TimerScriptController::getAncestorController() {
return script_root;
}
ScriptObject *TimerScriptController::instantiate() {
if (!WASABI_API_TIMER)
{
WASABI_API_TIMER = (TimerApi *)factory.GetInterface(0);
}
STimer *s = new STimer;
ASSERT(s != NULL);
return s->getScriptObject();
}
void TimerScriptController::destroy(ScriptObject *o) {
STimer *s = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
ASSERT(s != NULL);
delete s;
}
void *TimerScriptController::encapsulate(ScriptObject *o) {
return NULL; // no encapsulation for timer yet
}
void TimerScriptController::deencapsulate(void *o) {
}
int TimerScriptController::getNumFunctions() {
return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
}
const function_descriptor_struct *TimerScriptController::getExportedFunctions() {
return exportedFunction;
}
GUID TimerScriptController::getClassGuid() {
return timerGuid;
}
scriptVar STimer::script_onTimer(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
SCRIPT_FUNCTION_INIT;
PROCESS_HOOKS0(o, timerController);
SCRIPT_FUNCTION_CHECKABORTEVENT;
SCRIPT_EXEC_EVENT0(o);
}
static bool isNumeric(int t)
{
return (t == SCRIPT_INT || t == SCRIPT_BOOLEAN || t == SCRIPT_FLOAT || t == SCRIPT_DOUBLE);
}
scriptVar STimer::script_setDelay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar d) {
SCRIPT_FUNCTION_INIT;
ASSERT(isNumeric(d.type));
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
if (t) t->setDelay(d.data.idata);
RETURN_SCRIPT_VOID;
}
scriptVar STimer::script_getDelay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
SCRIPT_FUNCTION_INIT;
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
if (t) return MAKE_SCRIPT_INT(t->getDelay());
RETURN_SCRIPT_ZERO;
}
scriptVar STimer::script_start(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
SCRIPT_FUNCTION_INIT;
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
if (t) t->start();
RETURN_SCRIPT_VOID;
}
scriptVar STimer::script_stop(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
SCRIPT_FUNCTION_INIT;
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
if (t) t->stop();
RETURN_SCRIPT_VOID;
}
scriptVar STimer::script_isRunning(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
SCRIPT_FUNCTION_INIT;
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
if (t) return MAKE_SCRIPT_BOOLEAN(t->isRunning());
RETURN_SCRIPT_ZERO;
}
scriptVar STimer::script_getSkipped(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
SCRIPT_FUNCTION_INIT;
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
if (t) return MAKE_SCRIPT_INT(t->timerclient_getSkipped());
RETURN_SCRIPT_ZERO;
}