jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
8.8KB

  1. /*
  2. Copyright (C) 2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef __JackLockedEngine__
  16. #define __JackLockedEngine__
  17. #include "JackEngine.h"
  18. #include "JackMutex.h"
  19. namespace Jack
  20. {
  21. #define TRY_CALL \
  22. try { \
  23. #define CATCH_EXCEPTION_RETURN \
  24. } catch(std::bad_alloc& e) { \
  25. jack_error("Memory allocation error..."); \
  26. return -1; \
  27. } catch (...) { \
  28. jack_error("Unknown error..."); \
  29. return -1; \
  30. } \
  31. #define CATCH_ENGINE_EXCEPTION \
  32. } catch(std::bad_alloc& e) { \
  33. jack_error("Memory allocation error..."); \
  34. } catch (...) { \
  35. jack_error("Unknown error..."); \
  36. } \
  37. /*!
  38. \brief Locked Engine, access to methods is serialized using a mutex.
  39. */
  40. class SERVER_EXPORT JackLockedEngine : public JackLockAble
  41. {
  42. private:
  43. JackEngine fEngine;
  44. public:
  45. JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler):
  46. fEngine(manager, table, controler)
  47. {}
  48. ~JackLockedEngine()
  49. {}
  50. int Open()
  51. {
  52. // No lock needed
  53. TRY_CALL
  54. return fEngine.Open();
  55. CATCH_EXCEPTION_RETURN
  56. }
  57. int Close()
  58. {
  59. // No lock needed
  60. TRY_CALL
  61. return fEngine.Close();
  62. CATCH_EXCEPTION_RETURN
  63. }
  64. // Client management
  65. int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status)
  66. {
  67. TRY_CALL
  68. JackLock lock(this);
  69. return fEngine.ClientCheck(name, name_res, protocol, options, status);
  70. CATCH_EXCEPTION_RETURN
  71. }
  72. int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
  73. {
  74. TRY_CALL
  75. JackLock lock(this);
  76. return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
  77. CATCH_EXCEPTION_RETURN
  78. }
  79. int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
  80. {
  81. TRY_CALL
  82. JackLock lock(this);
  83. return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
  84. CATCH_EXCEPTION_RETURN
  85. }
  86. int ClientExternalClose(int refnum)
  87. {
  88. TRY_CALL
  89. JackLock lock(this);
  90. return fEngine.ClientExternalClose(refnum);
  91. CATCH_EXCEPTION_RETURN
  92. }
  93. int ClientInternalClose(int refnum, bool wait)
  94. {
  95. TRY_CALL
  96. JackLock lock(this);
  97. return fEngine.ClientInternalClose(refnum, wait);
  98. CATCH_EXCEPTION_RETURN
  99. }
  100. int ClientActivate(int refnum, bool is_real_time)
  101. {
  102. TRY_CALL
  103. JackLock lock(this);
  104. return fEngine.ClientActivate(refnum, is_real_time);
  105. CATCH_EXCEPTION_RETURN
  106. }
  107. int ClientDeactivate(int refnum)
  108. {
  109. TRY_CALL
  110. JackLock lock(this);
  111. return fEngine.ClientDeactivate(refnum);
  112. CATCH_EXCEPTION_RETURN
  113. }
  114. // Internal client management
  115. int GetInternalClientName(int int_ref, char* name_res)
  116. {
  117. TRY_CALL
  118. JackLock lock(this);
  119. return fEngine.GetInternalClientName(int_ref, name_res);
  120. CATCH_EXCEPTION_RETURN
  121. }
  122. int InternalClientHandle(const char* client_name, int* status, int* int_ref)
  123. {
  124. TRY_CALL
  125. JackLock lock(this);
  126. return fEngine.InternalClientHandle(client_name, status, int_ref);
  127. CATCH_EXCEPTION_RETURN
  128. }
  129. int InternalClientUnload(int refnum, int* status)
  130. {
  131. TRY_CALL
  132. JackLock lock(this);
  133. return fEngine.InternalClientUnload(refnum, status);
  134. CATCH_EXCEPTION_RETURN
  135. }
  136. // Port management
  137. int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
  138. {
  139. TRY_CALL
  140. JackLock lock(this);
  141. return fEngine.PortRegister(refnum, name, type, flags, buffer_size, port);
  142. CATCH_EXCEPTION_RETURN
  143. }
  144. int PortUnRegister(int refnum, jack_port_id_t port)
  145. {
  146. TRY_CALL
  147. JackLock lock(this);
  148. return fEngine.PortUnRegister(refnum, port);
  149. CATCH_EXCEPTION_RETURN
  150. }
  151. int PortConnect(int refnum, const char* src, const char* dst)
  152. {
  153. TRY_CALL
  154. JackLock lock(this);
  155. return fEngine.PortConnect(refnum, src, dst);
  156. CATCH_EXCEPTION_RETURN
  157. }
  158. int PortDisconnect(int refnum, const char* src, const char* dst)
  159. {
  160. TRY_CALL
  161. JackLock lock(this);
  162. return fEngine.PortDisconnect(refnum, src, dst);
  163. CATCH_EXCEPTION_RETURN
  164. }
  165. int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
  166. {
  167. TRY_CALL
  168. JackLock lock(this);
  169. return fEngine.PortConnect(refnum, src, dst);
  170. CATCH_EXCEPTION_RETURN
  171. }
  172. int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
  173. {
  174. TRY_CALL
  175. JackLock lock(this);
  176. return fEngine.PortDisconnect(refnum, src, dst);
  177. CATCH_EXCEPTION_RETURN
  178. }
  179. int PortRename(int refnum, jack_port_id_t port, const char* name)
  180. {
  181. TRY_CALL
  182. JackLock lock(this);
  183. return fEngine.PortRename(refnum, port, name);
  184. CATCH_EXCEPTION_RETURN
  185. }
  186. // Graph
  187. bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
  188. {
  189. // RT : no lock
  190. return fEngine.Process(cur_cycle_begin, prev_cycle_end);
  191. }
  192. // Notifications
  193. void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
  194. {
  195. // RT : no lock
  196. fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
  197. }
  198. void NotifyXRun(int refnum)
  199. {
  200. TRY_CALL
  201. JackLock lock(this);
  202. fEngine.NotifyXRun(refnum);
  203. CATCH_ENGINE_EXCEPTION
  204. }
  205. void NotifyGraphReorder()
  206. {
  207. TRY_CALL
  208. JackLock lock(this);
  209. fEngine.NotifyGraphReorder();
  210. CATCH_ENGINE_EXCEPTION
  211. }
  212. void NotifyBufferSize(jack_nframes_t buffer_size)
  213. {
  214. TRY_CALL
  215. JackLock lock(this);
  216. fEngine.NotifyBufferSize(buffer_size);
  217. CATCH_ENGINE_EXCEPTION
  218. }
  219. void NotifySampleRate(jack_nframes_t sample_rate)
  220. {
  221. TRY_CALL
  222. JackLock lock(this);
  223. fEngine.NotifySampleRate(sample_rate);
  224. CATCH_ENGINE_EXCEPTION
  225. }
  226. void NotifyFreewheel(bool onoff)
  227. {
  228. TRY_CALL
  229. JackLock lock(this);
  230. fEngine.NotifyFreewheel(onoff);
  231. CATCH_ENGINE_EXCEPTION
  232. }
  233. void NotifyFailure(int code, const char* reason)
  234. {
  235. TRY_CALL
  236. JackLock lock(this);
  237. fEngine.NotifyFailure(code, reason);
  238. CATCH_ENGINE_EXCEPTION
  239. }
  240. int GetClientPID(const char* name)
  241. {
  242. TRY_CALL
  243. JackLock lock(this);
  244. return fEngine.GetClientPID(name);
  245. CATCH_EXCEPTION_RETURN
  246. }
  247. int GetClientRefNum(const char* name)
  248. {
  249. TRY_CALL
  250. JackLock lock(this);
  251. return fEngine.GetClientRefNum(name);
  252. CATCH_EXCEPTION_RETURN
  253. }
  254. };
  255. } // end of namespace
  256. #endif