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.

176 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. #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 "varargs.h"
  26. /*
  27. TODO:
  28. - implement the "jack_client_new", "jack_client_open", "jack_client_close" API so that we can provide a libjackdmp shared library
  29. to be used by clients for direct access.
  30. - 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.
  31. */
  32. #ifdef WIN32
  33. #define EXPORT __declspec(dllexport)
  34. #else
  35. #define EXPORT
  36. #endif
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name);
  42. EXPORT void my_jack_internal_client_close(jack_client_t* ext_client);
  43. EXPORT jack_client_t * jack_client_open (const char *client_name,
  44. jack_options_t options,
  45. jack_status_t *status, ...);
  46. EXPORT jack_client_t * jack_client_new (const char *client_name);
  47. EXPORT int jack_client_close (jack_client_t *client);
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. using namespace Jack;
  52. EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name, jack_options_t options, jack_status_t* status)
  53. {
  54. JackLog("jack_internal_client_new %s", client_name);
  55. if (client_name == NULL) {
  56. jack_error("jack_internal_client_new called with a NULL client_name");
  57. return NULL;
  58. }
  59. #ifdef __CLIENTDEBUG__
  60. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  61. #else
  62. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  63. #endif
  64. int res = client->Open(client_name, options, status);
  65. if (res < 0) {
  66. delete client;
  67. return NULL;
  68. } else {
  69. return (jack_client_t*)client;
  70. }
  71. }
  72. EXPORT void my_jack_internal_client_close(jack_client_t* ext_client)
  73. {
  74. JackLog("jack_internal_client_close");
  75. JackClient* client = (JackClient*)ext_client;
  76. if (client == NULL) {
  77. jack_error("jack_internal_client_close called with a NULL client");
  78. } else {
  79. client->Close();
  80. delete client;
  81. JackLog("jack_internal_client_close OK");
  82. }
  83. }
  84. EXPORT jack_client_t* jack_client_new(const char* client_name)
  85. {
  86. int options = JackUseExactName;
  87. if (getenv("JACK_START_SERVER") == NULL)
  88. options |= JackNoStartServer;
  89. return jack_client_open(client_name, (jack_options_t)options, NULL);
  90. }
  91. // TO BE IMPLEMENTED PROPERLY
  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. JackServerGlobals::Init(); // jack server initialisation
  116. #ifdef __CLIENTDEBUG__
  117. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  118. #else
  119. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  120. #endif
  121. int res = client->Open(client_name, options, status);
  122. if (res < 0) {
  123. delete client;
  124. JackServerGlobals::Destroy(); // jack server destruction
  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 library destruction
  142. return res;
  143. }
  144. }