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.

172 lines
5.0KB

  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);
  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)
  47. {
  48. JackLog("jack_internal_client_new %s", client_name);
  49. if (client_name == NULL) {
  50. jack_error("jack_internal_client_new called with a NULL client_name");
  51. return NULL;
  52. }
  53. #ifdef __CLIENTDEBUG__
  54. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  55. #else
  56. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  57. #endif
  58. jack_options_t options = JackUseExactName;
  59. int res = client->Open(client_name, options, NULL);
  60. if (res < 0) {
  61. delete client;
  62. return NULL;
  63. } else {
  64. return (jack_client_t*)client;
  65. }
  66. }
  67. EXPORT void my_jack_internal_client_close(jack_client_t* ext_client)
  68. {
  69. JackLog("jack_internal_client_close");
  70. JackClient* client = (JackClient*)ext_client;
  71. if (client == NULL) {
  72. jack_error("jack_internal_client_close called with a NULL client");
  73. } else {
  74. client->Close();
  75. delete client;
  76. JackLog("jack_internal_client_close OK");
  77. }
  78. }
  79. EXPORT jack_client_t* jack_client_new(const char* client_name)
  80. {
  81. int options = JackUseExactName;
  82. if (getenv("JACK_START_SERVER") == NULL)
  83. options |= JackNoStartServer;
  84. return jack_client_open(client_name, (jack_options_t)options, NULL);
  85. }
  86. EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  87. {
  88. va_list ap; /* variable argument pointer */
  89. jack_varargs_t va; /* variable arguments */
  90. jack_status_t my_status;
  91. if (status == NULL) /* no status from caller? */
  92. status = &my_status; /* use local status word */
  93. *status = (jack_status_t)0;
  94. /* validate parameters */
  95. if ((options & ~JackOpenOptions)) {
  96. int my_status1 = *status | (JackFailure | JackInvalidOption);
  97. *status = (jack_status_t)my_status1;
  98. return NULL;
  99. }
  100. /* parse variable arguments */
  101. va_start(ap, status);
  102. jack_varargs_parse(options, ap, &va);
  103. va_end(ap);
  104. JackLog("jack_client_open %s\n", client_name);
  105. if (client_name == NULL) {
  106. jack_error("jack_client_new called with a NULL client_name");
  107. return NULL;
  108. }
  109. if (!JackServerGlobals::Init()) { // jack server initialisation
  110. int my_status1 = (JackFailure | JackServerError);
  111. *status = (jack_status_t)my_status1;
  112. return NULL;
  113. }
  114. #ifdef __CLIENTDEBUG__
  115. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  116. #else
  117. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  118. #endif
  119. int res = client->Open(client_name, options, status);
  120. if (res < 0) {
  121. delete client;
  122. JackServerGlobals::Destroy(); // jack server destruction
  123. int my_status1 = (JackFailure | JackServerError);
  124. *status = (jack_status_t)my_status1;
  125. return NULL;
  126. } else {
  127. return (jack_client_t*)client;
  128. }
  129. }
  130. EXPORT int jack_client_close(jack_client_t* ext_client)
  131. {
  132. JackLog("jack_client_close\n");
  133. JackClient* client = (JackClient*)ext_client;
  134. if (client == NULL) {
  135. jack_error("jack_client_close called with a NULL client");
  136. return -1;
  137. } else {
  138. int res = client->Close();
  139. delete client;
  140. JackLog("jack_client_close OK\n");
  141. JackServerGlobals::Destroy(); // jack server destruction
  142. return res;
  143. }
  144. }