1
0

sapplication.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #include "sapplication.h"
  2. #include <api/application/api_application.h>
  3. #include <api.h>
  4. // {B8E867B0-2715-4da7-A5BA-53DBA1FCFEAC}
  5. static const GUID application_script_object_guid =
  6. { 0xb8e867b0, 0x2715, 0x4da7, { 0xa5, 0xba, 0x53, 0xdb, 0xa1, 0xfc, 0xfe, 0xac } };
  7. static ApplicationScriptObjectController _applicationController;
  8. ScriptObjectController *applicationController=&_applicationController;
  9. // -- Functions table -------------------------------------
  10. function_descriptor_struct ApplicationScriptObjectController::exportedFunction[] =
  11. {
  12. {L"GetApplicationName", 0, (void*)SApplication::GetApplicationName },
  13. {L"GetVersionString", 0, (void*)SApplication::GetVersionString },
  14. {L"GetVersionNumberString", 0, (void*)SApplication::GetVersionNumberString },
  15. {L"GetBuildNumber",0, (void*)SApplication::GetBuildNumber },
  16. {L"GetGUID",0, (void*)SApplication::GetGUID },
  17. {L"GetCommandLine",0, (void*)SApplication::GetCommandLine },
  18. {L"Shutdown",0, (void*)SApplication::Shutdown },
  19. {L"CancelShutdown",0, (void*)SApplication::CancelShutdown },
  20. {L"IsShuttingDown",0, (void*)SApplication::IsShuttingDown },
  21. {L"GetApplicationPath",0, (void*)SApplication::GetApplicationPath },
  22. {L"GetSettingsPath",0, (void*)SApplication::GetSettingsPath },
  23. {L"GetWorkingPath",0, (void*)SApplication::GetWorkingPath },
  24. {L"SetWorkingPath",1, (void*)SApplication::SetWorkingPath },
  25. {L"GetMachineGUID",0, (void*)SApplication::GetMachineGUID },
  26. {L"GetUserGUID",0, (void*)SApplication::GetUserGUID },
  27. {L"GetSessionGUID",0, (void*)SApplication::GetSessionGUID },
  28. };
  29. // --------------------------------------------------------
  30. const wchar_t *ApplicationScriptObjectController::getClassName()
  31. {
  32. return L"Application";
  33. }
  34. const wchar_t *ApplicationScriptObjectController::getAncestorClassName()
  35. {
  36. return L"Object";
  37. }
  38. ScriptObjectController *ApplicationScriptObjectController::getAncestorController()
  39. {
  40. return NULL;
  41. }
  42. ScriptObject *ApplicationScriptObjectController::instantiate()
  43. {
  44. SApplication *c = new SApplication;
  45. if (!c) return NULL;
  46. return c->getScriptObject();
  47. }
  48. int ApplicationScriptObjectController::getInstantiable()
  49. {
  50. return 0;
  51. }
  52. void ApplicationScriptObjectController::destroy(ScriptObject *o)
  53. {
  54. SApplication *obj = static_cast<SApplication *>(o->vcpu_getInterface(application_script_object_guid));
  55. ASSERT(obj != NULL);
  56. delete obj;
  57. }
  58. void *ApplicationScriptObjectController::encapsulate(ScriptObject *o)
  59. {
  60. return NULL;
  61. }
  62. void ApplicationScriptObjectController::deencapsulate(void *o)
  63. {
  64. }
  65. int ApplicationScriptObjectController::getNumFunctions()
  66. {
  67. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  68. }
  69. const function_descriptor_struct *ApplicationScriptObjectController::getExportedFunctions()
  70. {
  71. return exportedFunction;
  72. }
  73. GUID ApplicationScriptObjectController::getClassGuid()
  74. {
  75. return application_script_object_guid;
  76. }
  77. SApplication::SApplication()
  78. {
  79. getScriptObject()->vcpu_setInterface(application_script_object_guid, static_cast<SApplication *>(this));
  80. getScriptObject()->vcpu_setClassName(L"Application");
  81. getScriptObject()->vcpu_setController(applicationController);
  82. }
  83. SApplication::~SApplication()
  84. {
  85. }
  86. static wchar_t guid_scratchpad[40];
  87. scriptVar SApplication::GetApplicationName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  88. {
  89. SCRIPT_FUNCTION_INIT;
  90. return MAKE_SCRIPT_STRING(WASABI_API_APP->main_getAppName());
  91. }
  92. scriptVar SApplication::GetVersionString(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  93. {
  94. SCRIPT_FUNCTION_INIT;
  95. return MAKE_SCRIPT_STRING(WASABI_API_APP->main_getVersionString());
  96. }
  97. scriptVar SApplication::GetVersionNumberString(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  98. {
  99. SCRIPT_FUNCTION_INIT;
  100. return MAKE_SCRIPT_STRING(WASABI_API_APP->main_getVersionNumString());
  101. }
  102. scriptVar SApplication::GetBuildNumber(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  103. {
  104. SCRIPT_FUNCTION_INIT;
  105. return MAKE_SCRIPT_INT(WASABI_API_APP->main_getBuildNumber());
  106. }
  107. scriptVar SApplication::GetGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  108. {
  109. SCRIPT_FUNCTION_INIT;
  110. GUID g = WASABI_API_APP->main_getGUID();
  111. nsGUID::toCharW(g, guid_scratchpad);
  112. return MAKE_SCRIPT_STRING(guid_scratchpad);
  113. }
  114. scriptVar SApplication::GetCommandLine(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  115. {
  116. SCRIPT_FUNCTION_INIT;
  117. return MAKE_SCRIPT_STRING(WASABI_API_APP->main_getCommandLine());
  118. }
  119. scriptVar SApplication::Shutdown(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  120. {
  121. SCRIPT_FUNCTION_INIT;
  122. WASABI_API_APP->main_shutdown();
  123. return MAKE_SCRIPT_VOID();
  124. }
  125. scriptVar SApplication::CancelShutdown(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  126. {
  127. SCRIPT_FUNCTION_INIT;
  128. WASABI_API_APP->main_cancelShutdown();
  129. return MAKE_SCRIPT_VOID();
  130. }
  131. scriptVar SApplication::IsShuttingDown(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  132. {
  133. SCRIPT_FUNCTION_INIT;
  134. return MAKE_SCRIPT_BOOLEAN(WASABI_API_APP->main_isShuttingDown());
  135. }
  136. scriptVar SApplication::GetApplicationPath(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  137. {
  138. SCRIPT_FUNCTION_INIT;
  139. return MAKE_SCRIPT_STRING(WASABI_API_APP->path_getAppPath());
  140. }
  141. scriptVar SApplication::GetSettingsPath(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  142. {
  143. SCRIPT_FUNCTION_INIT;
  144. return MAKE_SCRIPT_STRING(WASABI_API_APP->path_getUserSettingsPath());
  145. }
  146. scriptVar SApplication::GetWorkingPath(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  147. {
  148. SCRIPT_FUNCTION_INIT;
  149. return MAKE_SCRIPT_STRING(WASABI_API_APP->path_getWorkingPath());
  150. }
  151. scriptVar SApplication::SetWorkingPath(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar string_path)
  152. {
  153. SCRIPT_FUNCTION_INIT;
  154. WASABI_API_APP->path_setWorkingPath(GET_SCRIPT_STRING(string_path));
  155. return MAKE_SCRIPT_VOID();
  156. }
  157. scriptVar SApplication::GetMachineGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  158. {
  159. SCRIPT_FUNCTION_INIT;
  160. GUID g;
  161. WASABI_API_APP->GetMachineID(&g);
  162. nsGUID::toCharW(g, guid_scratchpad);
  163. return MAKE_SCRIPT_STRING(guid_scratchpad);
  164. }
  165. scriptVar SApplication::GetUserGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  166. {
  167. SCRIPT_FUNCTION_INIT;
  168. GUID g;
  169. WASABI_API_APP->GetUserID(&g);
  170. nsGUID::toCharW(g, guid_scratchpad);
  171. return MAKE_SCRIPT_STRING(guid_scratchpad);
  172. }
  173. scriptVar SApplication::GetSessionGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  174. {
  175. SCRIPT_FUNCTION_INIT;
  176. GUID g;
  177. WASABI_API_APP->GetSessionID(&g);
  178. nsGUID::toCharW(g, guid_scratchpad);
  179. return MAKE_SCRIPT_STRING(guid_scratchpad);
  180. }