1
0

WinampConfigScriptObject.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #include <precomp.h>
  2. #include "WinampConfigScriptObject.h"
  3. // {B2AD3F2B-31ED-4e31-BC6D-E9951CD555BB}
  4. static const GUID winampConfigScriptGuid =
  5. { 0xb2ad3f2b, 0x31ed, 0x4e31, { 0xbc, 0x6d, 0xe9, 0x95, 0x1c, 0xd5, 0x55, 0xbb } };
  6. // {FC17844E-C72B-4518-A068-A8F930A5BA80}
  7. static const GUID winampConfigGroupScriptGuid =
  8. { 0xfc17844e, 0xc72b, 0x4518, { 0xa0, 0x68, 0xa8, 0xf9, 0x30, 0xa5, 0xba, 0x80 } };
  9. static WinampConfigScriptController _winampConfigController;
  10. ScriptObjectController *winampConfigController = &_winampConfigController;
  11. static WinampConfigGroupScriptController _winampConfigGroupController;
  12. ScriptObjectController *winampConfigGroupController = &_winampConfigGroupController;
  13. BEGIN_SERVICES(WinampConfig_svcs);
  14. DECLARE_SERVICETSINGLE(svc_scriptObject, WinampConfigScriptObjectSvc);
  15. END_SERVICES(WinampConfig_svcs, _WinampConfig_svcs);
  16. #ifdef _X86_
  17. extern "C"
  18. {
  19. int _link_WinampConfig_svcs;
  20. }
  21. #else
  22. extern "C"
  23. {
  24. int __link_WinampConfig_svcs;
  25. }
  26. #endif
  27. // -----------------------------------------------------------------------------------------------------
  28. // Service
  29. ScriptObjectController *WinampConfigScriptObjectSvc::getController(int n)
  30. {
  31. switch (n)
  32. {
  33. case 0:
  34. return winampConfigController;
  35. case 1:
  36. return winampConfigGroupController;
  37. }
  38. return NULL;
  39. }
  40. // -- Functions table -------------------------------------
  41. function_descriptor_struct WinampConfigScriptController::exportedFunction[] =
  42. {
  43. {L"getGroup", 1, (void*)WinampConfig::script_vcpu_getGroup },
  44. };
  45. // --------------------------------------------------------
  46. const wchar_t *WinampConfigScriptController::getClassName()
  47. {
  48. return L"WinampConfig";
  49. }
  50. const wchar_t *WinampConfigScriptController::getAncestorClassName()
  51. {
  52. return L"Object";
  53. }
  54. ScriptObject *WinampConfigScriptController::instantiate()
  55. {
  56. WinampConfig *wc = new WinampConfig;
  57. ASSERT(wc != NULL);
  58. return wc->getScriptObject();
  59. }
  60. void WinampConfigScriptController::destroy(ScriptObject *o)
  61. {
  62. WinampConfig *wc = static_cast<WinampConfig *>(o->vcpu_getInterface(winampConfigScriptGuid));
  63. if (wc)
  64. delete wc;
  65. }
  66. void *WinampConfigScriptController::encapsulate(ScriptObject *o)
  67. {
  68. return NULL; // no encapsulation yet
  69. }
  70. void WinampConfigScriptController::deencapsulate(void *o)
  71. {
  72. }
  73. int WinampConfigScriptController::getNumFunctions()
  74. {
  75. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  76. }
  77. const function_descriptor_struct *WinampConfigScriptController::getExportedFunctions()
  78. {
  79. return exportedFunction;
  80. }
  81. GUID WinampConfigScriptController::getClassGuid()
  82. {
  83. return winampConfigScriptGuid;
  84. }
  85. /* ------------- */
  86. WinampConfig::WinampConfig()
  87. {
  88. getScriptObject()->vcpu_setInterface(winampConfigScriptGuid, (void *)static_cast<WinampConfig *>(this));
  89. getScriptObject()->vcpu_setClassName(L"WinampConfig");
  90. getScriptObject()->vcpu_setController(winampConfigController);
  91. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(Agave::AgaveConfigGUID);
  92. if (sf)
  93. config = (Agave::api_config *)sf->getInterface();
  94. }
  95. WinampConfig::~WinampConfig()
  96. {
  97. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(Agave::AgaveConfigGUID);
  98. if (sf)
  99. sf->releaseInterface(config);
  100. }
  101. scriptVar WinampConfig::script_vcpu_getGroup(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar groupguid)
  102. {
  103. SCRIPT_FUNCTION_INIT
  104. const wchar_t *g = GET_SCRIPT_STRING(groupguid);
  105. GUID _g = nsGUID::fromCharW(g);
  106. WinampConfig *wc = static_cast<WinampConfig *>(o->vcpu_getInterface(winampConfigScriptGuid));
  107. if (wc)
  108. {
  109. Agave::ifc_configgroup *group = wc->config->GetGroup(_g);
  110. if (group)
  111. {
  112. WinampConfigGroup *winampConfigGroup = new WinampConfigGroup(group);
  113. return MAKE_SCRIPT_OBJECT(winampConfigGroup->getScriptObject());
  114. }
  115. }
  116. RETURN_SCRIPT_NULL;
  117. }
  118. /* ------------- */
  119. // -- Functions table -------------------------------------
  120. function_descriptor_struct WinampConfigGroupScriptController::exportedFunction[] =
  121. {
  122. {L"getBool", 1, (void*)WinampConfigGroup::script_vcpu_getBool },
  123. {L"getString", 1, (void*)WinampConfigGroup::script_vcpu_getString },
  124. {L"getInt", 1, (void*)WinampConfigGroup::script_vcpu_getInt },
  125. {L"setBool", 2, (void*)WinampConfigGroup::script_vcpu_setBool },
  126. };
  127. // --------------------------------------------------------
  128. const wchar_t *WinampConfigGroupScriptController::getClassName()
  129. {
  130. return L"WinampConfigGroup";
  131. }
  132. const wchar_t *WinampConfigGroupScriptController::getAncestorClassName()
  133. {
  134. return L"Object";
  135. }
  136. ScriptObject *WinampConfigGroupScriptController::instantiate()
  137. {
  138. WinampConfigGroup *wc = new WinampConfigGroup;
  139. ASSERT(wc != NULL);
  140. return wc->getScriptObject();
  141. }
  142. void WinampConfigGroupScriptController::destroy(ScriptObject *o)
  143. {
  144. WinampConfigGroup *wc = static_cast<WinampConfigGroup *>(o->vcpu_getInterface(winampConfigGroupScriptGuid));
  145. if (wc)
  146. delete wc;
  147. }
  148. void *WinampConfigGroupScriptController::encapsulate(ScriptObject *o)
  149. {
  150. return NULL; // no encapsulation yet
  151. }
  152. void WinampConfigGroupScriptController::deencapsulate(void *o)
  153. {
  154. }
  155. int WinampConfigGroupScriptController::getNumFunctions()
  156. {
  157. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  158. }
  159. const function_descriptor_struct *WinampConfigGroupScriptController::getExportedFunctions()
  160. {
  161. return exportedFunction;
  162. }
  163. GUID WinampConfigGroupScriptController::getClassGuid()
  164. {
  165. return winampConfigGroupScriptGuid;
  166. }
  167. /* ------------- */
  168. WinampConfigGroup::WinampConfigGroup()
  169. {
  170. getScriptObject()->vcpu_setInterface(winampConfigGroupScriptGuid, (void *)static_cast<WinampConfigGroup *>(this));
  171. getScriptObject()->vcpu_setClassName(L"WinampConfigGroup");
  172. getScriptObject()->vcpu_setController(winampConfigGroupController);
  173. configGroup = 0;
  174. }
  175. WinampConfigGroup::WinampConfigGroup(Agave::ifc_configgroup *_configGroup)
  176. {
  177. getScriptObject()->vcpu_setInterface(winampConfigGroupScriptGuid, (void *)static_cast<WinampConfigGroup *>(this));
  178. getScriptObject()->vcpu_setClassName(L"WinampConfigGroup");
  179. getScriptObject()->vcpu_setController(winampConfigGroupController);
  180. configGroup = _configGroup;
  181. }
  182. Agave::ifc_configitem *WinampConfigGroup::GetItem(ScriptObject *o, scriptVar itemname)
  183. {
  184. const wchar_t *item = GET_SCRIPT_STRING(itemname);
  185. WinampConfigGroup *group = static_cast<WinampConfigGroup *>(o->vcpu_getInterface(winampConfigGroupScriptGuid));
  186. if (group)
  187. {
  188. Agave::ifc_configitem *configitem = group->configGroup->GetItem(item);
  189. return configitem;
  190. }
  191. return 0;
  192. }
  193. scriptVar WinampConfigGroup::script_vcpu_getBool(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemname)
  194. {
  195. SCRIPT_FUNCTION_INIT
  196. Agave::ifc_configitem *configitem = GetItem(o, itemname);
  197. if (configitem)
  198. return MAKE_SCRIPT_BOOLEAN(configitem->GetBool());
  199. RETURN_SCRIPT_ZERO;
  200. }
  201. scriptVar WinampConfigGroup::script_vcpu_getString(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemname)
  202. {
  203. SCRIPT_FUNCTION_INIT
  204. Agave::ifc_configitem *configitem = GetItem(o, itemname);
  205. if (configitem)
  206. return MAKE_SCRIPT_STRING(configitem->GetString());
  207. RETURN_SCRIPT_ZERO;
  208. }
  209. scriptVar WinampConfigGroup::script_vcpu_getInt(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemname)
  210. {
  211. SCRIPT_FUNCTION_INIT
  212. Agave::ifc_configitem *configitem = GetItem(o, itemname);
  213. if (configitem)
  214. return MAKE_SCRIPT_INT(configitem->GetInt());
  215. RETURN_SCRIPT_ZERO;
  216. }
  217. scriptVar WinampConfigGroup::script_vcpu_setBool(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar itemname, scriptVar value)
  218. {
  219. SCRIPT_FUNCTION_INIT
  220. const wchar_t *item = GET_SCRIPT_STRING(itemname);
  221. WinampConfigGroup *group = static_cast<WinampConfigGroup *>(o->vcpu_getInterface(winampConfigGroupScriptGuid));
  222. if (group)
  223. {
  224. Agave::ifc_configitem *configitem = group->configGroup->GetItem(item);
  225. if (configitem)
  226. configitem->SetBool(!!GET_SCRIPT_BOOLEAN(value));
  227. }
  228. RETURN_SCRIPT_VOID;
  229. }