SPlaylistsEnumerator.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include "SPlaylistsEnumerator.h"
  2. #include "api__playlist.h"
  3. #include <bfc/nsguid.h>
  4. #include "Playlists.h"
  5. extern ScriptObjectController *script_root;
  6. extern PlaylistsEnumeratorScriptController playlistsEnumeratorController;
  7. // {C18F8E50-2C81-4001-9F46-FD942B07ECCD}
  8. static const GUID makiPlaylistsEnumeratorGUID =
  9. { 0xc18f8e50, 0x2c81, 0x4001, { 0x9f, 0x46, 0xfd, 0x94, 0x2b, 0x7, 0xec, 0xcd } };
  10. // -- Functions table -------------------------------------
  11. function_descriptor_struct PlaylistsEnumeratorScriptController::exportedFunction[] = {
  12. {L"GetCount", 0, (void *)SPlaylistsEnumerator::script_vcpu_GetCount },
  13. {L"GetFilename", 1, (void *)SPlaylistsEnumerator::script_vcpu_GetFilename },
  14. {L"GetTitle", 1, (void *)SPlaylistsEnumerator::script_vcpu_GetTitle },
  15. {L"GetLength", 1, (void *)SPlaylistsEnumerator::script_vcpu_GetLength },
  16. {L"GetNumItems", 1, (void *)SPlaylistsEnumerator::script_vcpu_GetNumItems },
  17. {L"GetGUID", 1, (void *)SPlaylistsEnumerator::script_vcpu_GetGUID },
  18. };
  19. // --------------------------------------------------------
  20. const wchar_t *PlaylistsEnumeratorScriptController::getClassName()
  21. {
  22. return L"PlaylistsEnumerator";
  23. }
  24. const wchar_t *PlaylistsEnumeratorScriptController::getAncestorClassName()
  25. {
  26. return L"Object";
  27. }
  28. ScriptObjectController *PlaylistsEnumeratorScriptController::getAncestorController()
  29. {
  30. return script_root;
  31. }
  32. ScriptObject *PlaylistsEnumeratorScriptController::instantiate()
  33. {
  34. SPlaylistsEnumerator *xd = new SPlaylistsEnumerator;
  35. ASSERT(xd != NULL);
  36. return xd->getScriptObject();
  37. }
  38. void PlaylistsEnumeratorScriptController::destroy( ScriptObject *o )
  39. {
  40. SPlaylistsEnumerator *xd = static_cast<SPlaylistsEnumerator *>( o->vcpu_getInterface( makiPlaylistsEnumeratorGUID ) );
  41. ASSERT( xd != NULL );
  42. delete xd;
  43. }
  44. void *PlaylistsEnumeratorScriptController::encapsulate( ScriptObject *o )
  45. {
  46. return NULL;
  47. }
  48. void PlaylistsEnumeratorScriptController::deencapsulate( void *o )
  49. {}
  50. int PlaylistsEnumeratorScriptController::getNumFunctions()
  51. {
  52. return sizeof( exportedFunction ) / sizeof( function_descriptor_struct );
  53. }
  54. const function_descriptor_struct *PlaylistsEnumeratorScriptController::getExportedFunctions()
  55. {
  56. return exportedFunction;
  57. }
  58. GUID PlaylistsEnumeratorScriptController::getClassGuid()
  59. {
  60. return makiPlaylistsEnumeratorGUID;
  61. }
  62. /* --- */
  63. SPlaylistsEnumerator::SPlaylistsEnumerator()
  64. {
  65. getScriptObject()->vcpu_setInterface( makiPlaylistsEnumeratorGUID, static_cast<SPlaylistsEnumerator *>( this ) );
  66. getScriptObject()->vcpu_setClassName( L"PlaylistsEnumerator" );
  67. getScriptObject()->vcpu_setController( &playlistsEnumeratorController );
  68. }
  69. SPlaylistsEnumerator::~SPlaylistsEnumerator()
  70. {
  71. //info.deleteAll();
  72. for (auto obj : info)
  73. {
  74. delete obj;
  75. }
  76. info.clear();
  77. }
  78. scriptVar SPlaylistsEnumerator::script_vcpu_GetCount( SCRIPT_FUNCTION_PARAMS, ScriptObject *o )
  79. {
  80. SCRIPT_FUNCTION_INIT;
  81. SPlaylistsEnumerator *enumerator = static_cast<SPlaylistsEnumerator *>( o->vcpu_getInterface( makiPlaylistsEnumeratorGUID ) );
  82. if ( enumerator )
  83. {
  84. return MAKE_SCRIPT_INT( (int)enumerator->info.size() );
  85. }
  86. return MAKE_SCRIPT_INT( 0 );
  87. }
  88. static const wchar_t *static_splaylistsenumerator_empty_string = L"";
  89. scriptVar SPlaylistsEnumerator::script_vcpu_GetFilename( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar playlistNumber )
  90. {
  91. SCRIPT_FUNCTION_INIT;
  92. SPlaylistsEnumerator *enumerator = static_cast<SPlaylistsEnumerator *>( o->vcpu_getInterface( makiPlaylistsEnumeratorGUID ) );
  93. size_t i = GET_SCRIPT_INT( playlistNumber );
  94. if ( enumerator && i < enumerator->info.size() )
  95. {
  96. return MAKE_SCRIPT_STRING( enumerator->info[ i ]->filename );
  97. }
  98. return MAKE_SCRIPT_STRING( static_splaylistsenumerator_empty_string );
  99. }
  100. scriptVar SPlaylistsEnumerator::script_vcpu_GetTitle( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar playlistNumber )
  101. {
  102. SCRIPT_FUNCTION_INIT;
  103. SPlaylistsEnumerator *enumerator = static_cast<SPlaylistsEnumerator *>( o->vcpu_getInterface( makiPlaylistsEnumeratorGUID ) );
  104. size_t i = GET_SCRIPT_INT( playlistNumber );
  105. if ( enumerator && i < enumerator->info.size() )
  106. {
  107. return MAKE_SCRIPT_STRING( enumerator->info[ i ]->title );
  108. }
  109. return MAKE_SCRIPT_STRING( static_splaylistsenumerator_empty_string );
  110. }
  111. scriptVar SPlaylistsEnumerator::script_vcpu_GetLength( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar playlistNumber )
  112. {
  113. SCRIPT_FUNCTION_INIT;
  114. SPlaylistsEnumerator *enumerator = static_cast<SPlaylistsEnumerator *>( o->vcpu_getInterface( makiPlaylistsEnumeratorGUID ) );
  115. size_t i = GET_SCRIPT_INT( playlistNumber );
  116. if ( enumerator && i < enumerator->info.size() )
  117. {
  118. return MAKE_SCRIPT_INT( enumerator->info[ i ]->length );
  119. }
  120. return MAKE_SCRIPT_INT( -1 );
  121. }
  122. scriptVar SPlaylistsEnumerator::script_vcpu_GetNumItems( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar playlistNumber )
  123. {
  124. SCRIPT_FUNCTION_INIT;
  125. SPlaylistsEnumerator *enumerator = static_cast<SPlaylistsEnumerator *>( o->vcpu_getInterface( makiPlaylistsEnumeratorGUID ) );
  126. size_t i = GET_SCRIPT_INT( playlistNumber );
  127. if ( enumerator && i < enumerator->info.size() )
  128. {
  129. return MAKE_SCRIPT_INT( enumerator->info[ i ]->numItems );
  130. }
  131. return MAKE_SCRIPT_INT( 0 );
  132. }
  133. static wchar_t static_splaylistsenumerator_guid_string[39];
  134. scriptVar SPlaylistsEnumerator::script_vcpu_GetGUID( SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar playlistNumber )
  135. {
  136. SCRIPT_FUNCTION_INIT;
  137. SPlaylistsEnumerator *enumerator = static_cast<SPlaylistsEnumerator *>( o->vcpu_getInterface( makiPlaylistsEnumeratorGUID ) );
  138. size_t i = GET_SCRIPT_INT( playlistNumber );
  139. if ( enumerator && i < enumerator->info.size() )
  140. {
  141. nsGUID::toCharW( enumerator->info[ i ]->guid, static_splaylistsenumerator_guid_string );
  142. return MAKE_SCRIPT_STRING( static_splaylistsenumerator_guid_string );
  143. }
  144. return MAKE_SCRIPT_STRING( static_splaylistsenumerator_empty_string );
  145. }
  146. void SPlaylistsEnumerator::Reserve( size_t count )
  147. {
  148. info.reserve( count );
  149. }
  150. void SPlaylistsEnumerator::AppendPlaylist( const PlaylistInfo &newPlaylist )
  151. {
  152. info.push_back( new PlaylistInfo( newPlaylist ) );
  153. }