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.

297 lines
9.0KB

  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. #include "JackTools.h"
  20. #include "JackException.h"
  21. namespace Jack
  22. {
  23. #define TRY_CALL \
  24. try { \
  25. #define CATCH_EXCEPTION_RETURN \
  26. } catch(std::bad_alloc& e) { \
  27. jack_error("Memory allocation error..."); \
  28. return -1; \
  29. } catch(JackTemporaryException& e) { \
  30. jack_error("JackTemporaryException : now quits..."); \
  31. JackTools::KillServer(); \
  32. return -1; \
  33. } catch (...) { \
  34. jack_error("Unknown error..."); \
  35. return -1; \
  36. } \
  37. #define CATCH_ENGINE_EXCEPTION \
  38. } catch(std::bad_alloc& e) { \
  39. jack_error("Memory allocation error..."); \
  40. } catch (...) { \
  41. jack_error("Unknown error..."); \
  42. } \
  43. /*!
  44. \brief Locked Engine, access to methods is serialized using a mutex.
  45. */
  46. class SERVER_EXPORT JackLockedEngine : public JackLockAble
  47. {
  48. private:
  49. JackEngine fEngine;
  50. public:
  51. JackLockedEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler):
  52. fEngine(manager, table, controler)
  53. {}
  54. ~JackLockedEngine()
  55. {}
  56. int Open()
  57. {
  58. // No lock needed
  59. TRY_CALL
  60. return fEngine.Open();
  61. CATCH_EXCEPTION_RETURN
  62. }
  63. int Close()
  64. {
  65. // No lock needed
  66. TRY_CALL
  67. return fEngine.Close();
  68. CATCH_EXCEPTION_RETURN
  69. }
  70. // Client management
  71. int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status)
  72. {
  73. TRY_CALL
  74. JackLock lock(this);
  75. return fEngine.ClientCheck(name, name_res, protocol, options, status);
  76. CATCH_EXCEPTION_RETURN
  77. }
  78. int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
  79. {
  80. TRY_CALL
  81. JackLock lock(this);
  82. return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
  83. CATCH_EXCEPTION_RETURN
  84. }
  85. int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
  86. {
  87. TRY_CALL
  88. JackLock lock(this);
  89. return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
  90. CATCH_EXCEPTION_RETURN
  91. }
  92. int ClientExternalClose(int refnum)
  93. {
  94. TRY_CALL
  95. JackLock lock(this);
  96. return fEngine.ClientExternalClose(refnum);
  97. CATCH_EXCEPTION_RETURN
  98. }
  99. int ClientInternalClose(int refnum, bool wait)
  100. {
  101. TRY_CALL
  102. JackLock lock(this);
  103. return fEngine.ClientInternalClose(refnum, wait);
  104. CATCH_EXCEPTION_RETURN
  105. }
  106. int ClientActivate(int refnum, bool is_real_time)
  107. {
  108. TRY_CALL
  109. JackLock lock(this);
  110. return fEngine.ClientActivate(refnum, is_real_time);
  111. CATCH_EXCEPTION_RETURN
  112. }
  113. int ClientDeactivate(int refnum)
  114. {
  115. TRY_CALL
  116. JackLock lock(this);
  117. return fEngine.ClientDeactivate(refnum);
  118. CATCH_EXCEPTION_RETURN
  119. }
  120. // Internal client management
  121. int GetInternalClientName(int int_ref, char* name_res)
  122. {
  123. TRY_CALL
  124. JackLock lock(this);
  125. return fEngine.GetInternalClientName(int_ref, name_res);
  126. CATCH_EXCEPTION_RETURN
  127. }
  128. int InternalClientHandle(const char* client_name, int* status, int* int_ref)
  129. {
  130. TRY_CALL
  131. JackLock lock(this);
  132. return fEngine.InternalClientHandle(client_name, status, int_ref);
  133. CATCH_EXCEPTION_RETURN
  134. }
  135. int InternalClientUnload(int refnum, int* status)
  136. {
  137. TRY_CALL
  138. JackLock lock(this);
  139. return fEngine.InternalClientUnload(refnum, status);
  140. CATCH_EXCEPTION_RETURN
  141. }
  142. // Port management
  143. int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
  144. {
  145. TRY_CALL
  146. JackLock lock(this);
  147. return fEngine.PortRegister(refnum, name, type, flags, buffer_size, port);
  148. CATCH_EXCEPTION_RETURN
  149. }
  150. int PortUnRegister(int refnum, jack_port_id_t port)
  151. {
  152. TRY_CALL
  153. JackLock lock(this);
  154. return fEngine.PortUnRegister(refnum, port);
  155. CATCH_EXCEPTION_RETURN
  156. }
  157. int PortConnect(int refnum, const char* src, const char* dst)
  158. {
  159. TRY_CALL
  160. JackLock lock(this);
  161. return fEngine.PortConnect(refnum, src, dst);
  162. CATCH_EXCEPTION_RETURN
  163. }
  164. int PortDisconnect(int refnum, const char* src, const char* dst)
  165. {
  166. TRY_CALL
  167. JackLock lock(this);
  168. return fEngine.PortDisconnect(refnum, src, dst);
  169. CATCH_EXCEPTION_RETURN
  170. }
  171. int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
  172. {
  173. TRY_CALL
  174. JackLock lock(this);
  175. return fEngine.PortConnect(refnum, src, dst);
  176. CATCH_EXCEPTION_RETURN
  177. }
  178. int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
  179. {
  180. TRY_CALL
  181. JackLock lock(this);
  182. return fEngine.PortDisconnect(refnum, src, dst);
  183. CATCH_EXCEPTION_RETURN
  184. }
  185. int PortRename(int refnum, jack_port_id_t port, const char* name)
  186. {
  187. TRY_CALL
  188. JackLock lock(this);
  189. return fEngine.PortRename(refnum, port, name);
  190. CATCH_EXCEPTION_RETURN
  191. }
  192. // Graph
  193. bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
  194. {
  195. // RT : no lock
  196. return fEngine.Process(cur_cycle_begin, prev_cycle_end);
  197. }
  198. // Notifications
  199. void NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
  200. {
  201. // RT : no lock
  202. fEngine.NotifyXRun(cur_cycle_begin, delayed_usecs);
  203. }
  204. void NotifyXRun(int refnum)
  205. {
  206. TRY_CALL
  207. JackLock lock(this);
  208. fEngine.NotifyXRun(refnum);
  209. CATCH_ENGINE_EXCEPTION
  210. }
  211. void NotifyGraphReorder()
  212. {
  213. TRY_CALL
  214. JackLock lock(this);
  215. fEngine.NotifyGraphReorder();
  216. CATCH_ENGINE_EXCEPTION
  217. }
  218. void NotifyBufferSize(jack_nframes_t buffer_size)
  219. {
  220. TRY_CALL
  221. JackLock lock(this);
  222. fEngine.NotifyBufferSize(buffer_size);
  223. CATCH_ENGINE_EXCEPTION
  224. }
  225. void NotifySampleRate(jack_nframes_t sample_rate)
  226. {
  227. TRY_CALL
  228. JackLock lock(this);
  229. fEngine.NotifySampleRate(sample_rate);
  230. CATCH_ENGINE_EXCEPTION
  231. }
  232. void NotifyFreewheel(bool onoff)
  233. {
  234. TRY_CALL
  235. JackLock lock(this);
  236. fEngine.NotifyFreewheel(onoff);
  237. CATCH_ENGINE_EXCEPTION
  238. }
  239. void NotifyFailure(int code, const char* reason)
  240. {
  241. TRY_CALL
  242. JackLock lock(this);
  243. fEngine.NotifyFailure(code, reason);
  244. CATCH_ENGINE_EXCEPTION
  245. }
  246. int GetClientPID(const char* name)
  247. {
  248. TRY_CALL
  249. JackLock lock(this);
  250. return fEngine.GetClientPID(name);
  251. CATCH_EXCEPTION_RETURN
  252. }
  253. int GetClientRefNum(const char* name)
  254. {
  255. TRY_CALL
  256. JackLock lock(this);
  257. return fEngine.GetClientRefNum(name);
  258. CATCH_EXCEPTION_RETURN
  259. }
  260. };
  261. } // end of namespace
  262. #endif