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.

161 lines
4.7KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2008 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. #if defined(HAVE_CONFIG_H)
  17. #include "config.h"
  18. #endif
  19. #ifdef WIN32
  20. #pragma warning (disable : 4786)
  21. #endif
  22. #include "JackGraphManager.h"
  23. #include "JackInternalClient.h"
  24. #include "JackServer.h"
  25. #include "JackDebugClient.h"
  26. #include "JackServerGlobals.h"
  27. #include "JackServerLaunch.h"
  28. #include "JackTools.h"
  29. #include "JackExports.h"
  30. #include "JackEngine.h"
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. EXPORT jack_client_t * jack_client_open_aux (const char *client_name,
  36. jack_options_t options,
  37. jack_status_t *status, va_list ap);
  38. EXPORT jack_client_t * jack_client_open (const char *client_name,
  39. jack_options_t options,
  40. jack_status_t *status, ...);
  41. EXPORT int jack_client_close (jack_client_t *client);
  42. EXPORT int jack_get_client_pid (const char *name);
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. using namespace Jack;
  47. // beware!!! things can go nasty if one client is started with JackNoStartServer and another without it
  48. bool g_nostart;
  49. EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_options_t options, jack_status_t* status, va_list ap)
  50. {
  51. jack_varargs_t va; /* variable arguments */
  52. jack_status_t my_status;
  53. JackClient* client;
  54. char client_name[JACK_CLIENT_NAME_SIZE + 1];
  55. if (ext_client_name == NULL) {
  56. jack_error("jack_client_open called with a NULL client_name");
  57. return NULL;
  58. }
  59. jack_log("jack_client_open %s", ext_client_name);
  60. JackTools::RewriteName(ext_client_name, client_name);
  61. if (status == NULL) /* no status from caller? */
  62. status = &my_status; /* use local status word */
  63. *status = (jack_status_t)0;
  64. /* validate parameters */
  65. if ((options & ~JackOpenOptions)) {
  66. int my_status1 = *status | (JackFailure | JackInvalidOption);
  67. *status = (jack_status_t)my_status1;
  68. return NULL;
  69. }
  70. /* parse variable arguments */
  71. if (ap)
  72. jack_varargs_parse(options, ap, &va);
  73. else
  74. jack_varargs_init(&va);
  75. g_nostart = (options & JackNoStartServer) != 0;
  76. if (!g_nostart) {
  77. if (!JackServerGlobals::Init()) { // jack server initialisation
  78. int my_status1 = (JackFailure | JackServerError);
  79. *status = (jack_status_t)my_status1;
  80. return NULL;
  81. }
  82. }
  83. #ifndef WIN32
  84. char* jack_debug = getenv("JACK_CLIENT_DEBUG");
  85. if (jack_debug && strcmp(jack_debug, "on") == 0)
  86. client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
  87. else
  88. client = new JackInternalClient(JackServer::fInstance, GetSynchroTable());
  89. #else
  90. client = new JackInternalClient(JackServer::fInstance, GetSynchroTable());
  91. #endif
  92. int res = client->Open(va.server_name, client_name, options, status);
  93. if (res < 0) {
  94. delete client;
  95. if (!g_nostart) {
  96. JackServerGlobals::Destroy(); // jack server destruction
  97. }
  98. int my_status1 = (JackFailure | JackServerError);
  99. *status = (jack_status_t)my_status1;
  100. return NULL;
  101. } else {
  102. return (jack_client_t*)client;
  103. }
  104. }
  105. EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
  106. {
  107. va_list ap;
  108. va_start(ap, status);
  109. jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
  110. va_end(ap);
  111. return res;
  112. }
  113. EXPORT int jack_client_close(jack_client_t* ext_client)
  114. {
  115. jack_log("jack_client_close");
  116. JackClient* client = (JackClient*)ext_client;
  117. if (client == NULL) {
  118. jack_error("jack_client_close called with a NULL client");
  119. return -1;
  120. } else {
  121. int res = client->Close();
  122. delete client;
  123. jack_log("jack_client_close OK");
  124. if (!g_nostart) {
  125. JackServerGlobals::Destroy(); // jack server destruction
  126. }
  127. return res;
  128. }
  129. }
  130. EXPORT int jack_get_client_pid(const char *name)
  131. {
  132. return (JackServer::fInstance != NULL)
  133. ? JackServer::fInstance->GetEngine()->GetClientPID(name)
  134. : 0;
  135. }