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.

146 lines
4.4KB

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