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.

175 lines
5.2KB

  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. #include "JackInternalClient.h"
  17. #include "JackGraphManager.h"
  18. #include "JackServer.h"
  19. #include "JackDebugClient.h"
  20. #include "JackServerGlobals.h"
  21. #include "JackError.h"
  22. #include "varargs.h"
  23. /*
  24. TODO:
  25. - implement the "jack_client_new", "jack_client_open", "jack_client_close" API so that we can provide a libjackdmp shared library
  26. to be used by clients for direct access.
  27. - automatic launch of the jack server with the first client open, automatic close when the last client exit. Use of a jackd.rsc configuration file.
  28. */
  29. #ifdef WIN32
  30. #define EXPORT __declspec(dllexport)
  31. #else
  32. #define EXPORT
  33. #endif
  34. #ifdef __cplusplus
  35. extern "C"
  36. {
  37. #endif
  38. EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name);
  39. EXPORT void my_jack_internal_client_close(jack_client_t* ext_client);
  40. EXPORT jack_client_t * jack_client_open (const char *client_name,
  41. jack_options_t options,
  42. jack_status_t *status, ...);
  43. EXPORT jack_client_t * jack_client_new (const char *client_name);
  44. EXPORT int jack_client_close (jack_client_t *client);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. using namespace Jack;
  49. EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name)
  50. {
  51. JackLog("jack_internal_client_new %s", client_name);
  52. if (client_name == NULL) {
  53. jack_error("jack_internal_client_new called with a NULL client_name");
  54. return NULL;
  55. }
  56. #ifdef __CLIENTDEBUG__
  57. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  58. #else
  59. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  60. #endif
  61. int res = client->Open(client_name);
  62. if (res < 0) {
  63. delete client;
  64. return NULL;
  65. } else {
  66. return (jack_client_t*)client;
  67. }
  68. }
  69. EXPORT void my_jack_internal_client_close(jack_client_t* ext_client)
  70. {
  71. JackLog("jack_internal_client_close");
  72. JackClient* client = (JackClient*)ext_client;
  73. if (client == NULL) {
  74. jack_error("jack_internal_client_close called with a NULL client");
  75. } else {
  76. int res = client->Deactivate();
  77. JackLog("jack_internal_client_close Deactivate %ld", res);
  78. res = client->Close();
  79. delete client;
  80. JackLog("jack_internal_client_close OK");
  81. }
  82. }
  83. EXPORT jack_client_t* jack_client_new(const char* client_name)
  84. {
  85. int options = JackUseExactName;
  86. if (getenv("JACK_START_SERVER") == NULL)
  87. options |= JackNoStartServer;
  88. return jack_client_open(client_name, (jack_options_t)options, NULL);
  89. }
  90. // TO BE IMPLEMENTED PROPERLY
  91. EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  92. {
  93. va_list ap; /* variable argument pointer */
  94. jack_varargs_t va; /* variable arguments */
  95. jack_status_t my_status;
  96. if (status == NULL) /* no status from caller? */
  97. status = &my_status; /* use local status word */
  98. *status = (jack_status_t)0;
  99. /* validate parameters */
  100. if ((options & ~JackOpenOptions)) {
  101. int my_status1 = *status | (JackFailure | JackInvalidOption);
  102. *status = (jack_status_t)my_status1;
  103. return NULL;
  104. }
  105. /* parse variable arguments */
  106. va_start(ap, status);
  107. jack_varargs_parse(options, ap, &va);
  108. va_end(ap);
  109. JackLog("jack_client_open %s\n", client_name);
  110. if (client_name == NULL) {
  111. jack_error("jack_client_new called with a NULL client_name");
  112. return NULL;
  113. }
  114. JackServerGlobals::Init(); // jack server initialisation
  115. #ifdef __CLIENTDEBUG__
  116. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  117. #else
  118. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  119. #endif
  120. int res = client->Open(client_name);
  121. if (res < 0) {
  122. delete client;
  123. JackServerGlobals::Destroy(); // jack server destruction
  124. return NULL;
  125. } else {
  126. *status = (jack_status_t)0;
  127. return (jack_client_t*)client;
  128. }
  129. return NULL;
  130. }
  131. EXPORT int jack_client_close(jack_client_t* ext_client)
  132. {
  133. JackLog("jack_client_close\n");
  134. JackClient* client = (JackClient*)ext_client;
  135. if (client == NULL) {
  136. jack_error("jack_client_close called with a NULL client");
  137. return -1;
  138. }
  139. int res = client->Close();
  140. delete client;
  141. JackLog("jack_client_close OK\n");
  142. JackServerGlobals::Destroy(); // jack library destruction
  143. return res;
  144. }