svc_playlist.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #ifndef _SVC_PLAYLIST_H
  2. #define _SVC_PLAYLIST_H
  3. #include <bfc/dispatch.h>
  4. #include <api/service/services.h>
  5. class Playlist;
  6. class NOVTABLE svc_playlistReader : public Dispatchable {
  7. public:
  8. static FOURCC getServiceType() { return WaSvc::PLAYLISTREADER; }
  9. const char *getExtension();
  10. int testFilename(const char *filename);
  11. const char *getDescription();
  12. void setAllowedMetadataColumns(const char *columnslist); // "a;b;c" ""=all
  13. void setBannedMetadataColumns(const char *columnslist); // "a;b;c" ""==all
  14. void enableDatabaseAdd(int enabled); // defaults to TRUE
  15. // void enableMetadata(int enabled); // defaults to TRUE
  16. int readPlaylist(const char *filename);
  17. const char *getLabel();
  18. int getNumEntries();
  19. const char *enumEntry(int n);
  20. protected:
  21. enum {
  22. GETEXTENSION=0, READPLAYLIST=1, GETLABEL=2, GETNUMENTRIES=3, ENUMENTRY=4,
  23. TESTFILENAME=100,
  24. GETDESCRIPTION=110,
  25. ENABLEDATABASEADD=200,
  26. };
  27. };
  28. inline
  29. const char *svc_playlistReader::getExtension() {
  30. return _call(GETEXTENSION, "");
  31. }
  32. inline
  33. int svc_playlistReader::testFilename(const char *filename) {
  34. return _call(TESTFILENAME, -1, filename);
  35. }
  36. inline
  37. const char *svc_playlistReader::getDescription() {
  38. return _call(GETDESCRIPTION, (const char *)NULL);
  39. }
  40. inline
  41. void svc_playlistReader::enableDatabaseAdd(int enabled) {
  42. _voidcall(ENABLEDATABASEADD, enabled);
  43. }
  44. inline
  45. int svc_playlistReader::readPlaylist(const char *filename) {
  46. return _call(READPLAYLIST, 0, filename);
  47. }
  48. inline
  49. const char *svc_playlistReader::getLabel() {
  50. return _call(GETLABEL, (const char *)0);
  51. }
  52. inline
  53. int svc_playlistReader::getNumEntries() {
  54. return _call(GETNUMENTRIES, 0);
  55. }
  56. inline
  57. const char *svc_playlistReader::enumEntry(int n) {
  58. return _call(ENUMENTRY, (const char *)NULL, n);
  59. }
  60. class NOVTABLE svc_playlistReaderI : public svc_playlistReader {
  61. public:
  62. virtual const char *getExtension()=0;
  63. virtual int testFilename(const char *filename) { return -1; }
  64. virtual const char *getDescription() { return NULL; }
  65. virtual void enableDatabaseAdd(int enabled)=0;
  66. virtual int readPlaylist(const char *filename)=0;
  67. virtual const char *getLabel()=0;
  68. virtual int getNumEntries()=0;
  69. virtual const char *enumEntry(int n)=0;
  70. private:
  71. RECVS_DISPATCH;
  72. };
  73. class NOVTABLE svc_playlistWriter : public Dispatchable {
  74. public:
  75. static FOURCC getServiceType() { return WaSvc::PLAYLISTWRITER; }
  76. const char *getExtension();
  77. const char *getDescription();
  78. void enableMetadata(int enabled);
  79. int writePlaylist(const char *filename, Playlist *pl, int full_data, int first, int last);
  80. // old-style, DEPRECATED
  81. int beginWrite(const char *filename, int n, const char *label);
  82. void writeEntry(const char *playstring);
  83. void endWrite();
  84. protected:
  85. enum {
  86. GETEXTENSION=0,
  87. GETDESCRIPTION=1,
  88. BEGINWRITE=2,
  89. WRITEENTRY=3,
  90. ENDWRITE=4,
  91. WRITEPLAYLIST=100,
  92. ENABLEMETADATA=200,
  93. };
  94. };
  95. inline
  96. const char *svc_playlistWriter::getExtension() {
  97. return _call(GETEXTENSION, (const char *)0);
  98. }
  99. inline
  100. const char *svc_playlistWriter::getDescription() {
  101. return _call(GETDESCRIPTION, (const char *)0);
  102. }
  103. inline
  104. void svc_playlistWriter::enableMetadata(int enabled) {
  105. _voidcall(ENABLEMETADATA, enabled);
  106. }
  107. inline
  108. int svc_playlistWriter::writePlaylist(const char *filename, Playlist *pl, int full_data, int first, int last) {
  109. return _call(WRITEPLAYLIST, -1, filename, pl, full_data, first, last);
  110. }
  111. inline
  112. int svc_playlistWriter::beginWrite(const char *filename, int n, const char *label) {
  113. return _call(BEGINWRITE, 0, filename, n, label);
  114. }
  115. inline
  116. void svc_playlistWriter::writeEntry(const char *playstring) {
  117. _voidcall(WRITEENTRY, playstring);
  118. }
  119. inline
  120. void svc_playlistWriter::endWrite() {
  121. _voidcall(ENDWRITE);
  122. }
  123. class NOVTABLE svc_playlistWriterI : public svc_playlistWriter {
  124. public:
  125. virtual const char *getExtension()=0;
  126. virtual const char *getDescription() { return NULL; }
  127. virtual void enableMetadata(int enabled) { }
  128. virtual int writePlaylist(const char *filename, Playlist *pl, int full_data, int first, int last) { return -1; }
  129. // old-style, DEPRECATED
  130. virtual int beginWrite(const char *filename, int n, const char *label) { return 0; }
  131. virtual void writeEntry(const char *playstring) { }
  132. virtual void endWrite() { }
  133. protected:
  134. RECVS_DISPATCH;
  135. };
  136. #include <api/service/servicei.h>
  137. template <class T>
  138. class PlaylistReaderCreator : public waServiceFactoryT<svc_playlistReader, T> {};
  139. template <class T>
  140. class PlaylistWriterCreator : public waServiceFactoryT<svc_playlistWriter, T> {};
  141. #include <api/service/svc_enum.h>
  142. #include <bfc/string/string.h>
  143. class PlaylistReaderEnum : public SvcEnumT<svc_playlistReader> {
  144. public:
  145. PlaylistReaderEnum(const char *filename) : fn(filename) {}
  146. protected:
  147. virtual int testService(svc_playlistReader *svc) {
  148. int r = svc->testFilename(fn);
  149. if (r == -1) return STRCASEEQL(svc->getExtension(), Std::extension(fn));
  150. return r;
  151. }
  152. private:
  153. String fn;
  154. };
  155. class PlaylistWriterEnum : public SvcEnumT<svc_playlistWriter> {
  156. public:
  157. PlaylistWriterEnum(const char *filename) :
  158. ext(Std::extension(filename)) {}
  159. protected:
  160. virtual int testService(svc_playlistWriter *svc) {
  161. return STRCASEEQL(svc->getExtension(), ext);
  162. }
  163. private:
  164. String ext;
  165. };
  166. #endif