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.

246 lines
6.8KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "JackSystemDeps.h"
  17. #include "JackServerGlobals.h"
  18. #include "JackGraphManager.h"
  19. #include "JackConstants.h"
  20. #include "JackInternalClient.h"
  21. #include "JackLockedEngine.h"
  22. #include "JackServer.h"
  23. #include "JackEngineControl.h"
  24. #include "JackClientControl.h"
  25. #include "JackInternalClientChannel.h"
  26. #include "JackGenericClientChannel.h"
  27. #include "JackTools.h"
  28. #include <assert.h>
  29. namespace Jack
  30. {
  31. JackGraphManager* JackInternalClient::fGraphManager = NULL;
  32. JackEngineControl* JackInternalClient::fEngineControl = NULL;
  33. // Used for external C API (JackAPI.cpp)
  34. SERVER_EXPORT JackGraphManager* GetGraphManager()
  35. {
  36. return JackServerGlobals::fInstance->GetGraphManager();
  37. }
  38. SERVER_EXPORT JackEngineControl* GetEngineControl()
  39. {
  40. return JackServerGlobals::fInstance->GetEngineControl();
  41. }
  42. SERVER_EXPORT JackSynchro* GetSynchroTable()
  43. {
  44. return JackServerGlobals::fInstance->GetSynchroTable();
  45. }
  46. JackInternalClient::JackInternalClient(JackServer* server, JackSynchro* table): JackClient(table)
  47. {
  48. fChannel = new JackInternalClientChannel(server);
  49. }
  50. JackInternalClient::~JackInternalClient()
  51. {
  52. delete fChannel;
  53. }
  54. int JackInternalClient::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
  55. {
  56. int result;
  57. char name_res[JACK_CLIENT_NAME_SIZE + 1];
  58. jack_log("JackInternalClient::Open name = %s", name);
  59. strncpy(fServerName, server_name, sizeof(fServerName));
  60. fChannel->ClientCheck(name, uuid, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result, false);
  61. if (result < 0) {
  62. int status1 = *status;
  63. if (status1 & JackVersionError) {
  64. jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION);
  65. } else {
  66. jack_error("Client name = %s conflits with another running client", name);
  67. }
  68. goto error;
  69. }
  70. strcpy(fClientControl.fName, name_res);
  71. // Require new client
  72. fChannel->ClientOpen(name_res, &fClientControl.fRefNum, &fEngineControl, &fGraphManager, this, &result);
  73. if (result < 0) {
  74. jack_error("Cannot open client name = %s", name_res);
  75. goto error;
  76. }
  77. SetupDriverSync(false);
  78. JackGlobals::fClientTable[fClientControl.fRefNum] = this;
  79. JackGlobals::fServerRunning = true;
  80. jack_log("JackInternalClient::Open name = %s refnum = %ld", name_res, fClientControl.fRefNum);
  81. return 0;
  82. error:
  83. fChannel->Close();
  84. return -1;
  85. }
  86. void JackInternalClient::ShutDown()
  87. {
  88. jack_log("JackInternalClient::ShutDown");
  89. JackClient::ShutDown();
  90. }
  91. JackGraphManager* JackInternalClient::GetGraphManager() const
  92. {
  93. assert(fGraphManager);
  94. return fGraphManager;
  95. }
  96. JackEngineControl* JackInternalClient::GetEngineControl() const
  97. {
  98. assert(fEngineControl);
  99. return fEngineControl;
  100. }
  101. JackClientControl* JackInternalClient::GetClientControl() const
  102. {
  103. return const_cast<JackClientControl*>(&fClientControl);
  104. }
  105. int JackLoadableInternalClient::Init(const char* so_name)
  106. {
  107. char path_to_so[JACK_PATH_MAX + 1];
  108. BuildClientPath(path_to_so, sizeof(path_to_so), so_name);
  109. fHandle = LoadJackModule(path_to_so);
  110. jack_log("JackLoadableInternalClient::JackLoadableInternalClient path_to_so = %s", path_to_so);
  111. if (fHandle == NULL) {
  112. PrintLoadError(so_name);
  113. return -1;
  114. }
  115. fFinish = (FinishCallback)GetJackProc(fHandle, "jack_finish");
  116. if (fFinish == NULL) {
  117. UnloadJackModule(fHandle);
  118. jack_error("symbol jack_finish cannot be found in %s", so_name);
  119. return -1;
  120. }
  121. fDescriptor = (JackDriverDescFunction)GetJackProc(fHandle, "jack_get_descriptor");
  122. if (fDescriptor == NULL) {
  123. jack_info("No jack_get_descriptor entry-point for %s", so_name);
  124. }
  125. return 0;
  126. }
  127. int JackLoadableInternalClient1::Init(const char* so_name)
  128. {
  129. if (JackLoadableInternalClient::Init(so_name) < 0) {
  130. return -1;
  131. }
  132. fInitialize = (InitializeCallback)GetJackProc(fHandle, "jack_initialize");
  133. if (fInitialize == NULL) {
  134. UnloadJackModule(fHandle);
  135. jack_error("symbol jack_initialize cannot be found in %s", so_name);
  136. return -1;
  137. }
  138. return 0;
  139. }
  140. int JackLoadableInternalClient2::Init(const char* so_name)
  141. {
  142. if (JackLoadableInternalClient::Init(so_name) < 0) {
  143. return -1;
  144. }
  145. fInitialize = (InternalInitializeCallback)GetJackProc(fHandle, "jack_internal_initialize");
  146. if (fInitialize == NULL) {
  147. UnloadJackModule(fHandle);
  148. jack_error("symbol jack_internal_initialize cannot be found in %s", so_name);
  149. return -1;
  150. }
  151. return 0;
  152. }
  153. JackLoadableInternalClient1::JackLoadableInternalClient1(JackServer* server, JackSynchro* table, const char* object_data)
  154. : JackLoadableInternalClient(server, table)
  155. {
  156. strncpy(fObjectData, object_data, JACK_LOAD_INIT_LIMIT);
  157. }
  158. JackLoadableInternalClient2::JackLoadableInternalClient2(JackServer* server, JackSynchro* table, const JSList* parameters)
  159. : JackLoadableInternalClient(server, table)
  160. {
  161. fParameters = parameters;
  162. }
  163. JackLoadableInternalClient::~JackLoadableInternalClient()
  164. {
  165. if (fFinish != NULL) {
  166. fFinish(fProcessArg);
  167. }
  168. if (fHandle != NULL) {
  169. UnloadJackModule(fHandle);
  170. }
  171. }
  172. int JackLoadableInternalClient1::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
  173. {
  174. int res = -1;
  175. if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) {
  176. if (fInitialize((jack_client_t*)this, fObjectData) == 0) {
  177. res = 0;
  178. } else {
  179. JackInternalClient::Close();
  180. fFinish = NULL;
  181. }
  182. }
  183. return res;
  184. }
  185. int JackLoadableInternalClient2::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
  186. {
  187. int res = -1;
  188. if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) {
  189. if (fInitialize((jack_client_t*)this, fParameters) == 0) {
  190. res = 0;
  191. } else {
  192. JackInternalClient::Close();
  193. fFinish = NULL;
  194. }
  195. }
  196. return res;
  197. }
  198. } // end of namespace