corehandle.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #include <precomp.h>
  2. #include "corehandle.h"
  3. #include <api/api.h>
  4. #include <api/core/buttons.h>
  5. #include <api/service/svcs/svc_coreadmin.h>
  6. #include <api/service/svc_enum.h> // for castService
  7. using namespace UserButton;
  8. static svc_coreAdmin *da_coreadmin=NULL;
  9. static int instancecount=0;
  10. static void initDaCoreAdmin() {
  11. if(!da_coreadmin) {
  12. if (WASABI_API_SVC != NULL) {
  13. waServiceFactory *s=WASABI_API_SVC->service_enumService(WaSvc::COREADMIN,0);
  14. if (s != NULL) {
  15. //CUT ASSERTPR(s,"Core Admin non present!");
  16. da_coreadmin=castService<svc_coreAdmin>(s);
  17. }
  18. }
  19. }
  20. }
  21. CoreHandle::CoreHandle(CoreToken tok) {
  22. initDaCoreAdmin();
  23. instancecount++;
  24. createdcore=0;
  25. token = NO_CORE_TOKEN;
  26. if (da_coreadmin) {
  27. if(da_coreadmin->verifyToken(tok)) token=tok;
  28. else {
  29. token=da_coreadmin->createCore();
  30. createdcore=1;
  31. }
  32. }
  33. }
  34. CoreHandle::CoreHandle(const char *name) {
  35. initDaCoreAdmin();
  36. instancecount++;
  37. createdcore=0;
  38. token = NO_CORE_TOKEN;
  39. if (da_coreadmin) {
  40. token=da_coreadmin->nameToToken(name);
  41. if(token==-1) {
  42. token=da_coreadmin->createCore(name);
  43. createdcore=1;
  44. }
  45. }
  46. }
  47. CoreHandle::~CoreHandle() {
  48. instancecount--;
  49. if (da_coreadmin) {
  50. if(createdcore) da_coreadmin->freeCoreByToken(token);
  51. if(!instancecount) {
  52. WASABI_API_SVC->service_release(da_coreadmin);
  53. da_coreadmin=NULL;
  54. }
  55. }
  56. }
  57. int CoreHandle::isCoreLoaded() {
  58. if (!da_coreadmin) return FALSE;
  59. return TRUE;
  60. }
  61. int CoreHandle::setNextFile(const char *playstring, const char *destination) {
  62. if (da_coreadmin == NULL) return 0;
  63. return da_coreadmin->setNextFile(token, playstring, destination);
  64. }
  65. void CoreHandle::prev() {
  66. userButton(PREV);
  67. }
  68. void CoreHandle::play() {
  69. userButton(PLAY);
  70. }
  71. void CoreHandle::pause() {
  72. userButton(PAUSE);
  73. }
  74. void CoreHandle::stop() {
  75. userButton(STOP);
  76. }
  77. void CoreHandle::next() {
  78. userButton(NEXT);
  79. }
  80. void CoreHandle::userButton(int button) {
  81. if (da_coreadmin == NULL) return;
  82. da_coreadmin->userButton(token, button);
  83. }
  84. const char *CoreHandle::getSupportedExtensions() {
  85. if (da_coreadmin == NULL) return "";
  86. return da_coreadmin->getSupportedExtensions();
  87. }
  88. const char *CoreHandle::getExtSupportedExtensions() {
  89. if (da_coreadmin == NULL) return "";
  90. return da_coreadmin->getExtSupportedExtensions();
  91. }
  92. const char *CoreHandle::getExtensionFamily(const char *extension) {
  93. if (da_coreadmin == NULL) return "";
  94. return da_coreadmin->getExtensionFamily(extension);
  95. }
  96. void CoreHandle::registerExtension(const char *extensions, const char *extension_name) {
  97. if (da_coreadmin == NULL) return;
  98. da_coreadmin->registerExtension(extensions, extension_name);
  99. }
  100. void CoreHandle::unregisterExtension(const char *extensions) {
  101. if (da_coreadmin == NULL) return;
  102. da_coreadmin->unregisterExtension(extensions);
  103. }
  104. String CoreHandle::getTitle() {
  105. if (da_coreadmin == NULL) return String("");
  106. return String(da_coreadmin->getTitle(token));
  107. }
  108. int CoreHandle::getStatus() {
  109. if (da_coreadmin == NULL) return 0;
  110. return da_coreadmin->getStatus(token);
  111. }
  112. const char *CoreHandle::getCurrent() {
  113. if (da_coreadmin == NULL) return "";
  114. return da_coreadmin->getCurrent(token);
  115. }
  116. int CoreHandle::getNumTracks() {
  117. if (da_coreadmin == NULL) return 0;
  118. return da_coreadmin->getNumTracks(token);
  119. }
  120. int CoreHandle::getCurPlaybackNumber() {
  121. if (da_coreadmin == NULL) return 0;
  122. return da_coreadmin->getCurPlaybackNumber(token);
  123. }
  124. int CoreHandle::getPosition() {
  125. if (da_coreadmin == NULL) return 0;
  126. return da_coreadmin->getPosition(token);
  127. }
  128. int CoreHandle::getWritePosition() {
  129. if (da_coreadmin == NULL) return 0;
  130. return da_coreadmin->getWritePosition(token);
  131. }
  132. int CoreHandle::setPosition(int ms) {
  133. if (da_coreadmin == NULL) return 0;
  134. return da_coreadmin->setPosition(token,ms);
  135. }
  136. int CoreHandle::getLength() {
  137. if (da_coreadmin == NULL) return 0;
  138. return da_coreadmin->getLength(token);
  139. }
  140. int CoreHandle::getPluginData(const char *playstring, const char *name, char *data, int data_len, int data_type) {
  141. if (da_coreadmin == NULL) return 0;
  142. return da_coreadmin->getPluginData(playstring, name, data, data_len, data_type);
  143. }
  144. unsigned int CoreHandle::getVolume() {
  145. if (da_coreadmin == NULL) return 0;
  146. return da_coreadmin->getVolume(token);
  147. }
  148. void CoreHandle::setVolume(unsigned int vol) {
  149. if (da_coreadmin == NULL) return;
  150. da_coreadmin->setVolume(token, vol);
  151. }
  152. int CoreHandle::getPan() {
  153. if (da_coreadmin == NULL) return 0;
  154. return da_coreadmin->getPan(token);
  155. }
  156. void CoreHandle::setPan(int bal) {
  157. if (da_coreadmin == NULL) return;
  158. da_coreadmin->setPan(token, bal);
  159. }
  160. void CoreHandle::setMute(int mute) {
  161. if (da_coreadmin == NULL) return;
  162. da_coreadmin->setMute(token, mute);
  163. }
  164. int CoreHandle::getMute() {
  165. if (da_coreadmin == NULL) return 0;
  166. return da_coreadmin->getMute(token);
  167. }
  168. void CoreHandle::addCallback(CoreCallback *cb) {
  169. if (da_coreadmin == NULL) return;
  170. da_coreadmin->addCallback(token, cb);
  171. }
  172. void CoreHandle::delCallback(CoreCallback *cb) {
  173. if (da_coreadmin == NULL) return;
  174. da_coreadmin->delCallback(token, cb);
  175. }
  176. int CoreHandle::getVisData(void *dataptr, int sizedataptr) {
  177. if (da_coreadmin == NULL) return 0;
  178. return da_coreadmin->getVisData(token, dataptr, sizedataptr);
  179. }
  180. int CoreHandle::getLeftVuMeter() {
  181. if (da_coreadmin == NULL) return 0;
  182. return da_coreadmin->getLeftVuMeter(token);
  183. }
  184. int CoreHandle::getRightVuMeter() {
  185. if (da_coreadmin == NULL) return 0;
  186. return da_coreadmin->getRightVuMeter(token);
  187. }
  188. int CoreHandle::registerSequencer(ItemSequencer *seq) {
  189. if (da_coreadmin == NULL) return 0;
  190. return da_coreadmin->registerSequencer(token, seq);
  191. }
  192. int CoreHandle::deregisterSequencer(ItemSequencer *seq) {
  193. if (da_coreadmin == NULL) return 0;
  194. return da_coreadmin->deregisterSequencer(token, seq);
  195. }
  196. ItemSequencer *CoreHandle::getSequencer() {
  197. if (da_coreadmin == NULL) return NULL;
  198. return da_coreadmin->getSequencer(token);
  199. }
  200. int CoreHandle::getEqStatus() {
  201. if (da_coreadmin == NULL) return 0;
  202. return da_coreadmin->getEqStatus(token);
  203. }
  204. void CoreHandle::setEqStatus(int enable) {
  205. if (da_coreadmin == NULL) return;
  206. da_coreadmin->setEqStatus(token, enable);
  207. }
  208. int CoreHandle::getEqPreamp() {
  209. if (da_coreadmin == NULL) return 0;
  210. return da_coreadmin->getEqPreamp(token);
  211. }
  212. void CoreHandle::setEqPreamp(int pre) {
  213. if (da_coreadmin == NULL) return;
  214. da_coreadmin->setEqPreamp(token, pre);
  215. }
  216. int CoreHandle::getEqBand(int band) {
  217. if (da_coreadmin == NULL) return 0;
  218. return da_coreadmin->getEqBand(token, band);
  219. }
  220. void CoreHandle::setEqBand(int band, int val) {
  221. if (da_coreadmin == NULL) return;
  222. da_coreadmin->setEqBand(token, band, val);
  223. }
  224. int CoreHandle::getEqAuto() {
  225. if (da_coreadmin == NULL) return 0;
  226. return da_coreadmin->getEqAuto(token);
  227. }
  228. void CoreHandle::setEqAuto(int enable) {
  229. if (da_coreadmin == NULL) return;
  230. da_coreadmin->setEqAuto(token, enable);
  231. }
  232. void CoreHandle::setPriority(int priority) {
  233. if (da_coreadmin == NULL) return;
  234. da_coreadmin->setPriority(token, priority);
  235. }
  236. int CoreHandle::getPriority() {
  237. if (da_coreadmin == NULL) return 0;
  238. return da_coreadmin->getPriority(token);
  239. }
  240. void CoreHandle::rebuildConvertersChain() {
  241. if (da_coreadmin == NULL) return;
  242. da_coreadmin->rebuildConvertersChain(token);
  243. }
  244. int CoreHandle::sendConvertersMsg(const char *msg, const char *value) {
  245. if (da_coreadmin == NULL) return 0;
  246. return da_coreadmin->sendConvertersMsg(token, msg, value);
  247. }