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.

181 lines
5.3KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2006 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. #ifdef WIN32
  17. #pragma warning (disable : 4786)
  18. #endif
  19. #include "JackInternalClient.h"
  20. #include "JackGraphManager.h"
  21. #include "JackServer.h"
  22. #include "JackDebugClient.h"
  23. #include "JackServerGlobals.h"
  24. #include "JackError.h"
  25. #include "JackServerLaunch.h"
  26. #ifdef WIN32
  27. #define EXPORT __declspec(dllexport)
  28. #else
  29. #define EXPORT
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name, const char* dll_name, const char* object_data);
  36. EXPORT void my_jack_internal_client_close(jack_client_t* ext_client);
  37. EXPORT jack_client_t * jack_client_open (const char *client_name,
  38. jack_options_t options,
  39. jack_status_t *status, ...);
  40. EXPORT jack_client_t * jack_client_new (const char *client_name);
  41. EXPORT int jack_client_close (jack_client_t *client);
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45. using namespace Jack;
  46. EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name, const char* dll_name, const char* object_data)
  47. {
  48. jack_status_t my_status = (jack_status_t)0;
  49. JackLog("jack_internal_client_new %s", client_name);
  50. if (client_name == NULL) {
  51. jack_error("jack_internal_client_new called with a NULL client_name");
  52. return NULL;
  53. }
  54. JackClient* client;
  55. try {
  56. #ifdef __CLIENTDEBUG__
  57. client = new JackDebugClient(new JackLoadableInternalClient(JackServer::fInstance, GetSynchroTable(), dll_name, object_data)); // Debug mode
  58. #else
  59. client = new JackLoadableInternalClient(JackServer::fInstance, GetSynchroTable(), dll_name, object_data); // To improve...
  60. #endif
  61. } catch (...) { // Allocation or dynamic code loading failure
  62. return NULL;
  63. }
  64. jack_options_t options = JackUseExactName;
  65. int res = client->Open(client_name, options, &my_status);
  66. if (res < 0) {
  67. delete client;
  68. return NULL;
  69. } else {
  70. return (jack_client_t*)client;
  71. }
  72. }
  73. EXPORT void my_jack_internal_client_close(jack_client_t* ext_client)
  74. {
  75. JackLog("jack_internal_client_close");
  76. JackClient* client = (JackClient*)ext_client;
  77. if (client == NULL) {
  78. jack_error("jack_internal_client_close called with a NULL client");
  79. } else {
  80. client->Close();
  81. delete client;
  82. JackLog("jack_internal_client_close OK");
  83. }
  84. }
  85. EXPORT jack_client_t* jack_client_new(const char* client_name)
  86. {
  87. int options = JackUseExactName;
  88. if (getenv("JACK_START_SERVER") == NULL)
  89. options |= JackNoStartServer;
  90. return jack_client_open(client_name, (jack_options_t)options, NULL);
  91. }
  92. EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  93. {
  94. va_list ap; /* variable argument pointer */
  95. jack_varargs_t va; /* variable arguments */
  96. jack_status_t my_status;
  97. if (status == NULL) /* no status from caller? */
  98. status = &my_status; /* use local status word */
  99. *status = (jack_status_t)0;
  100. /* validate parameters */
  101. if ((options & ~JackOpenOptions)) {
  102. int my_status1 = *status | (JackFailure | JackInvalidOption);
  103. *status = (jack_status_t)my_status1;
  104. return NULL;
  105. }
  106. /* parse variable arguments */
  107. va_start(ap, status);
  108. jack_varargs_parse(options, ap, &va);
  109. va_end(ap);
  110. JackLog("jack_client_open %s\n", client_name);
  111. if (client_name == NULL) {
  112. jack_error("jack_client_new called with a NULL client_name");
  113. return NULL;
  114. }
  115. if (!JackServerGlobals::Init()) { // jack server initialisation
  116. int my_status1 = (JackFailure | JackServerError);
  117. *status = (jack_status_t)my_status1;
  118. return NULL;
  119. }
  120. #ifdef __CLIENTDEBUG__
  121. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  122. #else
  123. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  124. #endif
  125. int res = client->Open(client_name, options, status);
  126. if (res < 0) {
  127. delete client;
  128. JackServerGlobals::Destroy(); // jack server destruction
  129. int my_status1 = (JackFailure | JackServerError);
  130. *status = (jack_status_t)my_status1;
  131. return NULL;
  132. } else {
  133. return (jack_client_t*)client;
  134. }
  135. }
  136. EXPORT int jack_client_close(jack_client_t* ext_client)
  137. {
  138. JackLog("jack_client_close\n");
  139. JackClient* client = (JackClient*)ext_client;
  140. if (client == NULL) {
  141. jack_error("jack_client_close called with a NULL client");
  142. return -1;
  143. } else {
  144. int res = client->Close();
  145. delete client;
  146. JackLog("jack_client_close OK\n");
  147. JackServerGlobals::Destroy(); // jack server destruction
  148. return res;
  149. }
  150. }