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.

283 lines
7.3KB

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