1
0

SPlaylistManager.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "SPlaylistManager.h"
  2. #include "SPlaylist.h"
  3. #include "api__playlist.h"
  4. #include "PlaylistManager.h"
  5. extern ScriptObjectController *script_root;
  6. extern PlaylistManagerScriptController playlistManagerController;
  7. // {C6207729-2600-4bb8-B562-2E0BC04E4416}
  8. static const GUID makePlaylistManagerGUID =
  9. { 0xc6207729, 0x2600, 0x4bb8, { 0xb5, 0x62, 0x2e, 0xb, 0xc0, 0x4e, 0x44, 0x16 } };
  10. // -- Functions table -------------------------------------
  11. function_descriptor_struct PlaylistManagerScriptController::exportedFunction[] = {
  12. {L"OpenPlaylist", 1, (void*)SPlaylistManager::script_vcpu_OpenPlaylist },
  13. {L"SavePlaylist", 2, (void*)SPlaylistManager::script_vcpu_SavePlaylist },
  14. };
  15. // --------------------------------------------------------
  16. const wchar_t *PlaylistManagerScriptController::getClassName() {
  17. return L"PlaylistManager";
  18. }
  19. const wchar_t *PlaylistManagerScriptController::getAncestorClassName() {
  20. return L"Object";
  21. }
  22. ScriptObjectController *PlaylistManagerScriptController::getAncestorController()
  23. {
  24. return script_root;
  25. }
  26. int PlaylistManagerScriptController::getInstantiable()
  27. {
  28. return 0;
  29. }
  30. int PlaylistManagerScriptController::getReferenceable()
  31. {
  32. return 0;
  33. }
  34. ScriptObject *PlaylistManagerScriptController::instantiate() {
  35. SPlaylistManager *xd = new SPlaylistManager;
  36. ASSERT(xd != NULL);
  37. return xd->getScriptObject();
  38. }
  39. void PlaylistManagerScriptController::destroy(ScriptObject *o) {
  40. SPlaylistManager *xd = static_cast<SPlaylistManager *>(o->vcpu_getInterface(makePlaylistManagerGUID));
  41. ASSERT(xd != NULL);
  42. delete xd;
  43. }
  44. void *PlaylistManagerScriptController::encapsulate(ScriptObject *o) {
  45. return NULL;
  46. }
  47. void PlaylistManagerScriptController::deencapsulate(void *o) {
  48. }
  49. int PlaylistManagerScriptController::getNumFunctions() {
  50. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  51. }
  52. const function_descriptor_struct *PlaylistManagerScriptController::getExportedFunctions() {
  53. return exportedFunction;
  54. }
  55. GUID PlaylistManagerScriptController::getClassGuid() {
  56. return makePlaylistManagerGUID;
  57. }
  58. /* --- */
  59. SPlaylistManager::SPlaylistManager()
  60. {
  61. getScriptObject()->vcpu_setInterface(makePlaylistManagerGUID, static_cast<SPlaylistManager *>(this));
  62. getScriptObject()->vcpu_setClassName(L"PlaylistManager");
  63. getScriptObject()->vcpu_setController(&playlistManagerController);
  64. }
  65. scriptVar SPlaylistManager::script_vcpu_OpenPlaylist(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar scriptFilename)
  66. {
  67. SCRIPT_FUNCTION_INIT;
  68. const wchar_t *filename = GET_SCRIPT_STRING(scriptFilename);
  69. if (filename && *filename)
  70. {
  71. SPlaylist *playlist = new SPlaylist;
  72. if (playlistManager.Load(filename, &playlist->playlist) == PLAYLISTMANAGER_SUCCESS)
  73. {
  74. return MAKE_SCRIPT_OBJECT(playlist->getScriptObject());
  75. }
  76. else
  77. {
  78. delete playlist;
  79. return MAKE_SCRIPT_OBJECT(0);
  80. }
  81. }
  82. return MAKE_SCRIPT_OBJECT(0);
  83. }
  84. scriptVar SPlaylistManager::script_vcpu_SavePlaylist(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar scriptFilename, scriptVar scriptPlaylist)
  85. {
  86. SCRIPT_FUNCTION_INIT;
  87. const wchar_t *filename = GET_SCRIPT_STRING(scriptFilename);
  88. SPlaylist *playlist = static_cast<SPlaylist *>(GET_SCRIPT_OBJECT_AS(scriptPlaylist, makiPlaylistGUID));
  89. if (filename && *filename && playlist)
  90. {
  91. playlistManager.Save(filename, &playlist->playlist);
  92. }
  93. RETURN_SCRIPT_VOID;
  94. }