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.

298 lines
7.5KB

  1. /*
  2. Copyright (C) 2004-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 __JackGlobals__
  16. #define __JackGlobals__
  17. #include "JackError.h"
  18. #include "JackThread.h"
  19. namespace Jack
  20. {
  21. class JackSynchro;
  22. class JackServerNotifyChannelInterface;
  23. class JackClientChannelInterface;
  24. class JackNotifyChannelInterface;
  25. class JackServerChannelInterface;
  26. class JackSyncInterface;
  27. class JackThread;
  28. class JackDriverClientInterface;
  29. class JackRunnableInterface;
  30. class JackEngine;
  31. /*!
  32. \brief Factory description
  33. \todo possibly use in a dynamic way to test different communication/synchro implementations.
  34. */
  35. class JackFactoryImpl
  36. {
  37. public:
  38. JackFactoryImpl()
  39. {}
  40. virtual ~JackFactoryImpl()
  41. {}
  42. virtual JackSynchro* MakeSynchro() = 0;
  43. virtual JackServerNotifyChannelInterface* MakeServerNotifyChannel() = 0;
  44. virtual JackClientChannelInterface* MakeClientChannel() = 0;
  45. virtual JackNotifyChannelInterface* MakeNotifyChannel() = 0;
  46. virtual JackServerChannelInterface* MakeServerChannel() = 0;
  47. virtual JackSyncInterface* MakeInterProcessSync() = 0;
  48. virtual JackThread* MakeThread(JackRunnableInterface* runnable) = 0;
  49. };
  50. #ifdef __linux__
  51. class JackFactoryLinuxServer : public JackFactoryImpl
  52. {
  53. public:
  54. JackFactoryLinuxServer()
  55. {}
  56. virtual ~JackFactoryLinuxServer()
  57. {}
  58. JackSynchro* MakeSynchro();
  59. JackServerNotifyChannelInterface* MakeServerNotifyChannel();
  60. JackClientChannelInterface* MakeClientChannel();
  61. JackNotifyChannelInterface* MakeNotifyChannel();
  62. JackServerChannelInterface* MakeServerChannel();
  63. JackSyncInterface* MakeInterProcessSync();
  64. JackThread* MakeThread(JackRunnableInterface* runnable);
  65. };
  66. class JackFactoryLinuxClient : public JackFactoryImpl
  67. {
  68. public:
  69. JackFactoryLinuxClient()
  70. {}
  71. virtual ~JackFactoryLinuxClient()
  72. {}
  73. JackSynchro* MakeSynchro();
  74. JackServerNotifyChannelInterface* MakeServerNotifyChannel();
  75. JackClientChannelInterface* MakeClientChannel();
  76. JackNotifyChannelInterface* MakeNotifyChannel();
  77. JackServerChannelInterface* MakeServerChannel();
  78. JackSyncInterface* MakeInterProcessSync();
  79. JackThread* MakeThread(JackRunnableInterface* runnable);
  80. };
  81. #endif
  82. #ifdef WIN32
  83. class JackFactoryWindowsServer : public JackFactoryImpl
  84. {
  85. public:
  86. JackFactoryWindowsServer()
  87. {}
  88. virtual ~JackFactoryWindowsServer()
  89. {}
  90. JackSynchro* MakeSynchro();
  91. JackServerNotifyChannelInterface* MakeServerNotifyChannel();
  92. JackClientChannelInterface* MakeClientChannel();
  93. JackNotifyChannelInterface* MakeNotifyChannel();
  94. JackServerChannelInterface* MakeServerChannel();
  95. JackSyncInterface* MakeInterProcessSync();
  96. JackThread* MakeThread(JackRunnableInterface* runnable);
  97. };
  98. class JackFactoryWindowsClient : public JackFactoryImpl
  99. {
  100. public:
  101. JackFactoryWindowsClient()
  102. {}
  103. virtual ~JackFactoryWindowsClient()
  104. {}
  105. JackSynchro* MakeSynchro();
  106. JackServerNotifyChannelInterface* MakeServerNotifyChannel();
  107. JackClientChannelInterface* MakeClientChannel();
  108. JackNotifyChannelInterface* MakeNotifyChannel();
  109. JackServerChannelInterface* MakeServerChannel();
  110. JackSyncInterface* MakeInterProcessSync();
  111. JackThread* MakeThread(JackRunnableInterface* runnable);
  112. };
  113. #endif
  114. #if defined(__APPLE__)
  115. class JackFactoryOSXServer : public JackFactoryImpl
  116. {
  117. public:
  118. JackFactoryOSXServer()
  119. {}
  120. virtual ~JackFactoryOSXServer()
  121. {}
  122. JackSynchro* MakeSynchro();
  123. JackServerNotifyChannelInterface* MakeServerNotifyChannel();
  124. JackClientChannelInterface* MakeClientChannel();
  125. JackNotifyChannelInterface* MakeNotifyChannel();
  126. JackServerChannelInterface* MakeServerChannel();
  127. JackSyncInterface* MakeInterProcessSync();
  128. JackThread* MakeThread(JackRunnableInterface* runnable);
  129. };
  130. class JackFactoryOSXClient : public JackFactoryImpl
  131. {
  132. public:
  133. JackFactoryOSXClient()
  134. {}
  135. virtual ~JackFactoryOSXClient()
  136. {}
  137. JackSynchro* MakeSynchro();
  138. JackServerNotifyChannelInterface* MakeServerNotifyChannel();
  139. JackClientChannelInterface* MakeClientChannel();
  140. JackNotifyChannelInterface* MakeNotifyChannel();
  141. JackServerChannelInterface* MakeServerChannel();
  142. JackSyncInterface* MakeInterProcessSync();
  143. JackThread* MakeThread(JackRunnableInterface* runnable);
  144. };
  145. #endif
  146. /*!
  147. \brief Factory for OS specific ressources.
  148. */
  149. class JackGlobals
  150. {
  151. private:
  152. static JackFactoryImpl* fInstance;
  153. public:
  154. JackGlobals()
  155. {}
  156. virtual ~JackGlobals()
  157. {}
  158. static JackSynchro* MakeSynchro()
  159. {
  160. return fInstance->MakeSynchro();
  161. }
  162. static JackServerNotifyChannelInterface* MakeServerNotifyChannel()
  163. {
  164. return fInstance->MakeServerNotifyChannel();
  165. }
  166. static JackClientChannelInterface* MakeClientChannel()
  167. {
  168. return fInstance->MakeClientChannel();
  169. }
  170. static JackNotifyChannelInterface* MakeNotifyChannel()
  171. {
  172. return fInstance->MakeNotifyChannel();
  173. }
  174. static JackServerChannelInterface* MakeServerChannel()
  175. {
  176. return fInstance->MakeServerChannel();
  177. }
  178. static JackSyncInterface* MakeInterProcessSync()
  179. {
  180. return fInstance->MakeInterProcessSync();
  181. }
  182. static JackThread* MakeThread(JackRunnableInterface* runnable)
  183. {
  184. return fInstance->MakeThread(runnable);
  185. }
  186. static void InitServer()
  187. {
  188. jack_log("JackGlobals InitServer");
  189. if (!fInstance) {
  190. #ifdef __APPLE__
  191. fInstance = new JackFactoryOSXServer();
  192. #endif
  193. #ifdef WIN32
  194. fInstance = new JackFactoryWindowsServer();
  195. #endif
  196. #ifdef __linux__
  197. fInstance = new JackFactoryLinuxServer();
  198. #endif
  199. }
  200. }
  201. static void InitClient()
  202. {
  203. jack_log("JackGlobals InitClient");
  204. if (!fInstance) {
  205. #ifdef __APPLE__
  206. fInstance = new JackFactoryOSXClient();
  207. #endif
  208. #ifdef WIN32
  209. fInstance = new JackFactoryWindowsClient();
  210. #endif
  211. #ifdef __linux__
  212. fInstance = new JackFactoryLinuxClient();
  213. #endif
  214. }
  215. }
  216. static void Destroy()
  217. {
  218. jack_log("JackGlobals Destroy");
  219. if (fInstance) {
  220. delete fInstance;
  221. fInstance = NULL;
  222. }
  223. }
  224. };
  225. } // end of namespace
  226. #ifdef __cplusplus
  227. extern "C"
  228. {
  229. #endif
  230. extern jack_tls_key gRealTime;
  231. void __attribute__ ((constructor)) jack_realtime_init();
  232. void __attribute__ ((destructor)) jack_realtime_uninit();
  233. #ifdef __cplusplus
  234. }
  235. #endif
  236. #endif