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.

154 lines
4.5KB

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