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.0KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2006 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. using namespace Jack;
  23. #ifdef WIN32
  24. #define EXPORT __declspec(dllexport)
  25. #else
  26. #define EXPORT
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #endif
  32. EXPORT jack_client_t * jack_client_open (const char *client_name,
  33. jack_options_t options,
  34. jack_status_t *status, ...);
  35. EXPORT jack_client_t * jack_client_new (const char *client_name);
  36. EXPORT int jack_client_close (jack_client_t *client);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. JackLibGlobals* JackLibGlobals::fGlobals = NULL;
  41. long JackLibGlobals::fClientCount = 0;
  42. static inline bool CheckPort(jack_port_id_t port_index)
  43. {
  44. return (port_index < PORT_NUM);
  45. }
  46. EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  47. {
  48. va_list ap; /* variable argument pointer */
  49. jack_varargs_t va; /* variable arguments */
  50. jack_status_t my_status;
  51. JackClient* client;
  52. if (status == NULL) /* no status from caller? */
  53. status = &my_status; /* use local status word */
  54. *status = (jack_status_t)0;
  55. /* validate parameters */
  56. if ((options & ~JackOpenOptions)) {
  57. int my_status1 = *status | (JackFailure | JackInvalidOption);
  58. *status = (jack_status_t)my_status1;
  59. return NULL;
  60. }
  61. /* parse variable arguments */
  62. va_start(ap, status);
  63. jack_varargs_parse(options, ap, &va);
  64. va_end(ap);
  65. JackLog("jack_client_open %s\n", client_name);
  66. if (client_name == NULL) {
  67. jack_error("jack_client_new called with a NULL client_name");
  68. return NULL;
  69. }
  70. JackLibGlobals::Init(); // jack library initialisation
  71. #ifndef WIN32
  72. if (try_start_server(&va, options, status)) {
  73. jack_error("jack server is not running or cannot be started");
  74. JackLibGlobals::Destroy(); // jack library destruction
  75. return 0;
  76. }
  77. #endif
  78. #ifndef WIN32
  79. char* jack_debug = getenv("JACK_CLIENT_DEBUG");
  80. if (jack_debug && strcmp(jack_debug, "on") == 0)
  81. client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
  82. else
  83. client = new JackLibClient(GetSynchroTable());
  84. #else
  85. client = new JackLibClient(GetSynchroTable());
  86. #endif
  87. int res = client->Open(va.server_name, client_name, options, status);
  88. if (res < 0) {
  89. delete client;
  90. JackLibGlobals::Destroy(); // jack library destruction
  91. int my_status1 = (JackFailure|JackServerError);
  92. *status = (jack_status_t)my_status1;
  93. return NULL;
  94. } else {
  95. return (jack_client_t*)client;
  96. }
  97. }
  98. EXPORT jack_client_t* jack_client_new(const char* client_name)
  99. {
  100. int options = JackUseExactName;
  101. if (getenv("JACK_START_SERVER") == NULL)
  102. options |= JackNoStartServer;
  103. return jack_client_open(client_name, (jack_options_t)options, NULL);
  104. }
  105. EXPORT int jack_client_close(jack_client_t* ext_client)
  106. {
  107. JackLog("jack_client_close\n");
  108. JackClient* client = (JackClient*)ext_client;
  109. if (client == NULL) {
  110. jack_error("jack_client_close called with a NULL client");
  111. return -1;
  112. } else {
  113. int res = client->Close();
  114. delete client;
  115. JackLog("jack_client_close OK\n");
  116. JackLibGlobals::Destroy(); // jack library destruction
  117. return res;
  118. }
  119. }