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.

179 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 "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)
  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);
  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. int res = client->Deactivate();
  80. JackLog("jack_internal_client_close Deactivate %ld", res);
  81. res = client->Close();
  82. delete client;
  83. JackLog("jack_internal_client_close OK");
  84. }
  85. }
  86. EXPORT jack_client_t* jack_client_new(const char* client_name)
  87. {
  88. int options = JackUseExactName;
  89. if (getenv("JACK_START_SERVER") == NULL)
  90. options |= JackNoStartServer;
  91. return jack_client_open(client_name, (jack_options_t)options, NULL);
  92. }
  93. // TO BE IMPLEMENTED PROPERLY
  94. EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  95. {
  96. va_list ap; /* variable argument pointer */
  97. jack_varargs_t va; /* variable arguments */
  98. jack_status_t my_status;
  99. if (status == NULL) /* no status from caller? */
  100. status = &my_status; /* use local status word */
  101. *status = (jack_status_t)0;
  102. /* validate parameters */
  103. if ((options & ~JackOpenOptions)) {
  104. int my_status1 = *status | (JackFailure | JackInvalidOption);
  105. *status = (jack_status_t)my_status1;
  106. return NULL;
  107. }
  108. /* parse variable arguments */
  109. va_start(ap, status);
  110. jack_varargs_parse(options, ap, &va);
  111. va_end(ap);
  112. JackLog("jack_client_open %s\n", client_name);
  113. if (client_name == NULL) {
  114. jack_error("jack_client_new called with a NULL client_name");
  115. return NULL;
  116. }
  117. JackServerGlobals::Init(); // jack server initialisation
  118. #ifdef __CLIENTDEBUG__
  119. JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  120. #else
  121. JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
  122. #endif
  123. int res = client->Open(client_name);
  124. if (res < 0) {
  125. delete client;
  126. JackServerGlobals::Destroy(); // jack server destruction
  127. return NULL;
  128. } else {
  129. *status = (jack_status_t)0;
  130. return (jack_client_t*)client;
  131. }
  132. return NULL;
  133. }
  134. EXPORT int jack_client_close(jack_client_t* ext_client)
  135. {
  136. JackLog("jack_client_close\n");
  137. JackClient* client = (JackClient*)ext_client;
  138. if (client == NULL) {
  139. jack_error("jack_client_close called with a NULL client");
  140. return -1;
  141. }
  142. int res = client->Close();
  143. delete client;
  144. JackLog("jack_client_close OK\n");
  145. JackServerGlobals::Destroy(); // jack library destruction
  146. return res;
  147. }