123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #include <precomp.h>
- #include "timer.h"
- #include <api/script/scriptmgr.h>
- #include <api/script/objects/rootobject.h>
- //#include <api/wac/main.h>//CUT!!
- //#include <api/timer/genwnd.h> //CUT!!
- 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;
- }
- 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 rootScriptObjectController;
- }
- ScriptObject *TimerScriptController::instantiate() {
- 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);
- }
- scriptVar STimer::script_setDelay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar d) {
- SCRIPT_FUNCTION_INIT;
- ASSERT(SOM::isNumeric(&d));
- STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
- if (t) t->setDelay(SOM::makeInt(&d));
- 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;
- }
|