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.

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