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.

243 lines
6.7KB

  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 "JackTools.h"
  27. #include <assert.h>
  28. namespace Jack
  29. {
  30. JackGraphManager* JackInternalClient::fGraphManager = NULL;
  31. JackEngineControl* JackInternalClient::fEngineControl = NULL;
  32. // Used for external C API (JackAPI.cpp)
  33. SERVER_EXPORT JackGraphManager* GetGraphManager()
  34. {
  35. return JackServerGlobals::fInstance->GetGraphManager();
  36. }
  37. SERVER_EXPORT JackEngineControl* GetEngineControl()
  38. {
  39. return JackServerGlobals::fInstance->GetEngineControl();
  40. }
  41. SERVER_EXPORT JackSynchro* GetSynchroTable()
  42. {
  43. return JackServerGlobals::fInstance->GetSynchroTable();
  44. }
  45. JackInternalClient::JackInternalClient(JackServer* server, JackSynchro* table): JackClient(table)
  46. {
  47. fChannel = new JackInternalClientChannel(server);
  48. }
  49. JackInternalClient::~JackInternalClient()
  50. {
  51. delete fChannel;
  52. }
  53. int JackInternalClient::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
  54. {
  55. int result;
  56. char name_res[JACK_CLIENT_NAME_SIZE + 1];
  57. jack_log("JackInternalClient::Open name = %s", name);
  58. strncpy(fServerName, server_name, sizeof(fServerName));
  59. fChannel->ClientCheck(name, uuid, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result, false);
  60. if (result < 0) {
  61. int status1 = *status;
  62. if (status1 & JackVersionError) {
  63. jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION);
  64. } else {
  65. jack_error("Client name = %s conflits with another running client", name);
  66. }
  67. goto error;
  68. }
  69. strcpy(fClientControl.fName, name_res);
  70. // Require new client
  71. fChannel->ClientOpen(name_res, &fClientControl.fRefNum, &fEngineControl, &fGraphManager, this, &result);
  72. if (result < 0) {
  73. jack_error("Cannot open client name = %s", name_res);
  74. goto error;
  75. }
  76. SetupDriverSync(false);
  77. JackGlobals::fClientTable[fClientControl.fRefNum] = this;
  78. JackGlobals::fServerRunning = true;
  79. jack_log("JackInternalClient::Open name = %s refnum = %ld", name_res, fClientControl.fRefNum);
  80. return 0;
  81. error:
  82. fChannel->Close();
  83. return -1;
  84. }
  85. void JackInternalClient::ShutDown()
  86. {
  87. jack_log("JackInternalClient::ShutDown");
  88. JackClient::ShutDown();
  89. }
  90. JackGraphManager* JackInternalClient::GetGraphManager() const
  91. {
  92. assert(fGraphManager);
  93. return fGraphManager;
  94. }
  95. JackEngineControl* JackInternalClient::GetEngineControl() const
  96. {
  97. assert(fEngineControl);
  98. return fEngineControl;
  99. }
  100. JackClientControl* JackInternalClient::GetClientControl() const
  101. {
  102. return const_cast<JackClientControl*>(&fClientControl);
  103. }
  104. int JackLoadableInternalClient::Init(const char* so_name)
  105. {
  106. char path_to_so[JACK_PATH_MAX + 1];
  107. BuildClientPath(path_to_so, sizeof(path_to_so), so_name);
  108. fHandle = LoadJackModule(path_to_so);
  109. jack_log("JackLoadableInternalClient::JackLoadableInternalClient path_to_so = %s", path_to_so);
  110. if (fHandle == NULL) {
  111. PrintLoadError(so_name);
  112. return -1;
  113. }
  114. fFinish = (FinishCallback)GetJackProc(fHandle, "jack_finish");
  115. if (fFinish == NULL) {
  116. UnloadJackModule(fHandle);
  117. jack_error("symbol jack_finish cannot be found in %s", so_name);
  118. return -1;
  119. }
  120. fDescriptor = (JackDriverDescFunction)GetJackProc(fHandle, "jack_get_descriptor");
  121. if (fDescriptor == NULL) {
  122. jack_info("No jack_get_descriptor entry-point for %s", so_name);
  123. }
  124. return 0;
  125. }
  126. int JackLoadableInternalClient1::Init(const char* so_name)
  127. {
  128. if (JackLoadableInternalClient::Init(so_name) < 0) {
  129. return -1;
  130. }
  131. fInitialize = (InitializeCallback)GetJackProc(fHandle, "jack_initialize");
  132. if (fInitialize == NULL) {
  133. UnloadJackModule(fHandle);
  134. jack_error("symbol jack_initialize cannot be found in %s", so_name);
  135. return -1;
  136. }
  137. return 0;
  138. }
  139. int JackLoadableInternalClient2::Init(const char* so_name)
  140. {
  141. if (JackLoadableInternalClient::Init(so_name) < 0) {
  142. return -1;
  143. }
  144. fInitialize = (InternalInitializeCallback)GetJackProc(fHandle, "jack_internal_initialize");
  145. if (fInitialize == NULL) {
  146. UnloadJackModule(fHandle);
  147. jack_error("symbol jack_internal_initialize cannot be found in %s", so_name);
  148. return -1;
  149. }
  150. return 0;
  151. }
  152. JackLoadableInternalClient1::JackLoadableInternalClient1(JackServer* server, JackSynchro* table, const char* object_data)
  153. : JackLoadableInternalClient(server, table)
  154. {
  155. strncpy(fObjectData, object_data, JACK_LOAD_INIT_LIMIT);
  156. }
  157. JackLoadableInternalClient2::JackLoadableInternalClient2(JackServer* server, JackSynchro* table, const JSList* parameters)
  158. : JackLoadableInternalClient(server, table)
  159. {
  160. fParameters = parameters;
  161. }
  162. JackLoadableInternalClient::~JackLoadableInternalClient()
  163. {
  164. if (fFinish != NULL) {
  165. fFinish(fProcessArg);
  166. }
  167. if (fHandle != NULL) {
  168. UnloadJackModule(fHandle);
  169. }
  170. }
  171. int JackLoadableInternalClient1::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
  172. {
  173. int res = -1;
  174. if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) {
  175. if (fInitialize((jack_client_t*)this, fObjectData) == 0) {
  176. res = 0;
  177. } else {
  178. JackInternalClient::Close();
  179. fFinish = NULL;
  180. }
  181. }
  182. return res;
  183. }
  184. int JackLoadableInternalClient2::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
  185. {
  186. int res = -1;
  187. if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) {
  188. if (fInitialize((jack_client_t*)this, fParameters) == 0) {
  189. res = 0;
  190. } else {
  191. JackInternalClient::Close();
  192. fFinish = NULL;
  193. }
  194. }
  195. return res;
  196. }
  197. } // end of namespace