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.

136 lines
3.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 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 (const char *client_name,
  34. jack_options_t options,
  35. jack_status_t *status, ...);
  36. EXPORT int jack_client_close (jack_client_t *client);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. JackLibGlobals* JackLibGlobals::fGlobals = NULL;
  41. int JackLibGlobals::fClientCount = 0;
  42. EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
  43. {
  44. va_list ap; /* variable argument pointer */
  45. jack_varargs_t va; /* variable arguments */
  46. jack_status_t my_status;
  47. JackClient* client;
  48. char client_name[JACK_CLIENT_NAME_SIZE];
  49. JackTools::RewriteName(ext_client_name, client_name);
  50. if (status == NULL) /* no status from caller? */
  51. status = &my_status; /* use local status word */
  52. *status = (jack_status_t)0;
  53. /* validate parameters */
  54. if ((options & ~JackOpenOptions)) {
  55. int my_status1 = *status | (JackFailure | JackInvalidOption);
  56. *status = (jack_status_t)my_status1;
  57. return NULL;
  58. }
  59. /* parse variable arguments */
  60. va_start(ap, status);
  61. jack_varargs_parse(options, ap, &va);
  62. va_end(ap);
  63. JackLog("jack_client_open %s\n", client_name);
  64. if (client_name == NULL) {
  65. jack_error("jack_client_new called with a NULL client_name");
  66. return NULL;
  67. }
  68. JackLibGlobals::Init(); // jack library initialisation
  69. #ifndef WIN32
  70. if (try_start_server(&va, options, status)) {
  71. jack_error("jack server is not running or cannot be started");
  72. JackLibGlobals::Destroy(); // jack library destruction
  73. return 0;
  74. }
  75. #endif
  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 JackLibClient(GetSynchroTable())); // Debug mode
  80. else
  81. client = new JackLibClient(GetSynchroTable());
  82. #else
  83. client = new JackLibClient(GetSynchroTable());
  84. #endif
  85. int res = client->Open(va.server_name, client_name, options, status);
  86. if (res < 0) {
  87. delete client;
  88. JackLibGlobals::Destroy(); // jack library 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 int jack_client_close(jack_client_t* ext_client)
  97. {
  98. JackLog("jack_client_close\n");
  99. JackClient* client = (JackClient*)ext_client;
  100. if (client == NULL) {
  101. jack_error("jack_client_close called with a NULL client");
  102. return -1;
  103. } else {
  104. int res = client->Close();
  105. delete client;
  106. JackLog("jack_client_close OK\n");
  107. JackLibGlobals::Destroy(); // jack library destruction
  108. return res;
  109. }
  110. }