wacobj.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include <precomp.h>
  2. #include <bfc/wasabi_std.h>
  3. #include <bfc/nsguid.h>
  4. #include <api/script/script.h>
  5. #include <api/script/scriptobj.h>
  6. #include <api/script/scriptmgr.h>
  7. #include <api/script/objects/wacobj.h>
  8. #ifdef _WASABIRUNTIME
  9. #include <api/api.h>
  10. #include <api/wac/compon.h>
  11. #endif
  12. WacScriptController _wacController;
  13. WacScriptController *wacController = &_wacController;
  14. // -- Functions table -------------------------------------
  15. function_descriptor_struct WacScriptController::exportedFunction[] = {
  16. {L"getGUID", 1, (void*)WACObject::script_getGUID },
  17. {L"getName", 1, (void*)WACObject::script_getName },
  18. {L"onNotify", 3, (void*)WACObject::script_vcpu_onNotify },
  19. // DEPRECATED! DO NOTHING
  20. {L"sendCommand", 4, (void*)WACObject::script_vcpu_dummy4},
  21. {L"show", 0, (void*)WACObject::script_vcpu_dummy0},
  22. {L"hide", 0, (void*)WACObject::script_vcpu_dummy0},
  23. {L"isVisible", 0, (void*)WACObject::script_vcpu_dummy0},
  24. {L"onShow", 0, (void*)WACObject::script_vcpu_dummy0},
  25. {L"onHide", 0, (void*)WACObject::script_vcpu_dummy0},
  26. {L"setStatusBar", 1, (void*)WACObject::script_vcpu_dummy1},
  27. {L"getStatusBar", 0, (void*)WACObject::script_vcpu_dummy0},
  28. };
  29. // --------------------------------------------------------
  30. const wchar_t *WacScriptController::getClassName() {
  31. return L"Wac";
  32. }
  33. const wchar_t *WacScriptController::getAncestorClassName() {
  34. return L"Object";
  35. }
  36. ScriptObjectController *WacScriptController::getAncestorController() { return rootScriptObjectController; }
  37. int WacScriptController::getInstantiable() {
  38. return 0;
  39. }
  40. int WacScriptController::getNumFunctions() {
  41. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  42. }
  43. const function_descriptor_struct *WacScriptController::getExportedFunctions() {
  44. return exportedFunction;
  45. }
  46. GUID WacScriptController::getClassGuid() {
  47. return wacGuid;
  48. }
  49. ScriptObject *WacScriptController::instantiate() {
  50. return NULL;
  51. }
  52. void WacScriptController::destroy(ScriptObject *o) {
  53. }
  54. void *WacScriptController::encapsulate(ScriptObject *o) {
  55. return NULL; // no encapsulation for wacobject yet
  56. }
  57. void WacScriptController::deencapsulate(void *o ) {
  58. }
  59. WACObject::WACObject() {
  60. getScriptObject()->vcpu_setInterface(wacGuid, (void *)static_cast<WACObject *>(this));
  61. getScriptObject()->vcpu_setClassName(L"Wac");
  62. getScriptObject()->vcpu_setController(wacController);
  63. wacobjs.addItem(this);
  64. }
  65. WACObject::~WACObject() {
  66. wacobjs.delItem(this);
  67. }
  68. void WACObject::setGUID(GUID g) {
  69. myGUID = g;
  70. }
  71. GUID WACObject::getGUID(void) {
  72. return myGUID;
  73. }
  74. int WACObject::onScriptNotify(const wchar_t *s, int i1, int i2)
  75. {
  76. scriptVar _i1 = SOM::makeVar(SCRIPT_INT);
  77. SOM::assign(&_i1, i1);
  78. scriptVar _i2 = SOM::makeVar(SCRIPT_INT);
  79. SOM::assign(&_i2, i2);
  80. scriptVar _str = SOM::makeVar(SCRIPT_STRING);
  81. SOM::assign(&_str, (wchar_t *)s);
  82. script_vcpu_onNotify(SCRIPT_CALL, getScriptObject(), _str, _i1, _i2);
  83. return 1;
  84. }
  85. int WACObject::notifyScripts(WaComponent *comp, const wchar_t *s, int i1, int i2)
  86. {
  87. for (int i=0;i<wacobjs.getNumItems();i++)
  88. {
  89. GUID g = comp->getGUID();
  90. if (!MEMCMP(&g, &wacobjs.enumItem(i)->myGUID, sizeof(GUID)))
  91. return wacobjs.enumItem(i)->onScriptNotify(s, i1, i2);
  92. }
  93. return 0;
  94. }
  95. scriptVar WACObject::script_getGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  96. {
  97. SCRIPT_FUNCTION_INIT;
  98. static wchar_t guid[nsGUID::GUID_STRLEN+1];
  99. WACObject *wo = static_cast<WACObject *>(o->vcpu_getInterface(wacGuid));
  100. *guid=0;
  101. if (wo)
  102. nsGUID::toCharW(wo->myGUID, guid);
  103. return MAKE_SCRIPT_STRING(guid);
  104. }
  105. scriptVar WACObject::script_getName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  106. SCRIPT_FUNCTION_INIT;
  107. #ifdef WASABI_COMPILE_COMPONENTS
  108. WACObject *wo = static_cast<WACObject *>(o->vcpu_getInterface(wacGuid));
  109. if (wo) return MAKE_SCRIPT_STRING(WASABI_API_COMPONENT->getComponentName(wo->myGUID));
  110. #endif
  111. return MAKE_SCRIPT_STRING(L"");
  112. }
  113. scriptVar WACObject::script_vcpu_onNotify(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar str, scriptVar i1, scriptVar i2) {
  114. SCRIPT_FUNCTION_INIT;
  115. PROCESS_HOOKS3(o, wacController, str, i1, i2);
  116. SCRIPT_FUNCTION_CHECKABORTEVENT;
  117. SCRIPT_EXEC_EVENT3(o, str, i1, i2);
  118. }
  119. scriptVar WACObject::script_vcpu_dummy4(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar a, scriptVar b, scriptVar c, scriptVar d) {
  120. SCRIPT_FUNCTION_INIT;
  121. RETURN_SCRIPT_ZERO;
  122. }
  123. scriptVar WACObject::script_vcpu_dummy1(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar a) {
  124. SCRIPT_FUNCTION_INIT;
  125. RETURN_SCRIPT_ZERO;
  126. }
  127. scriptVar WACObject::script_vcpu_dummy0(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  128. SCRIPT_FUNCTION_INIT;
  129. RETURN_SCRIPT_ZERO;
  130. }
  131. PtrList<WACObject> WACObject::wacobjs;