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.

325 lines
7.9KB

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