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.

148 lines
4.2KB

  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 Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "JackDebugClient.h"
  17. #include "JackLibClient.h"
  18. #include "JackChannel.h"
  19. #include "JackLibGlobals.h"
  20. #include "JackGlobals.h"
  21. #include "JackServerLaunch.h"
  22. #include "JackTools.h"
  23. using namespace Jack;
  24. #ifdef WIN32
  25. #define EXPORT __declspec(dllexport)
  26. #else
  27. #define EXPORT
  28. #endif
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #endif
  33. EXPORT jack_client_t * jack_client_open_aux (const char *client_name,
  34. jack_options_t options,
  35. jack_status_t *status, ...);
  36. EXPORT jack_client_t * jack_client_open (const char *client_name,
  37. jack_options_t options,
  38. jack_status_t *status, ...);
  39. EXPORT int jack_client_close (jack_client_t *client);
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. JackLibGlobals* JackLibGlobals::fGlobals = NULL;
  44. int JackLibGlobals::fClientCount = 0;
  45. EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
  46. {
  47. va_list ap; /* variable argument pointer */
  48. jack_varargs_t va; /* variable arguments */
  49. jack_status_t my_status;
  50. JackClient* client;
  51. char client_name[JACK_CLIENT_NAME_SIZE];
  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. va_start(ap, status);
  64. jack_varargs_parse(options, ap, &va);
  65. va_end(ap);
  66. jack_log("jack_client_open %s", client_name);
  67. if (client_name == NULL) {
  68. jack_error("jack_client_open called with a NULL client_name");
  69. return NULL;
  70. }
  71. JackLibGlobals::Init(); // jack library initialisation
  72. #ifndef WIN32
  73. if (try_start_server(&va, options, status)) {
  74. jack_error("jack server is not running or cannot be started");
  75. JackLibGlobals::Destroy(); // jack library destruction
  76. return 0;
  77. }
  78. #endif
  79. #ifndef WIN32
  80. char* jack_debug = getenv("JACK_CLIENT_DEBUG");
  81. if (jack_debug && strcmp(jack_debug, "on") == 0)
  82. client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
  83. else
  84. client = new JackLibClient(GetSynchroTable());
  85. #else
  86. client = new JackLibClient(GetSynchroTable());
  87. #endif
  88. int res = client->Open(va.server_name, client_name, options, status);
  89. if (res < 0) {
  90. delete client;
  91. JackLibGlobals::Destroy(); // jack library destruction
  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. jack_log("jack_client_close OK");
  118. JackLibGlobals::Destroy(); // jack library destruction
  119. return res;
  120. }
  121. }