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.

150 lines
4.2KB

  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. static jack_client_t* jack_client_open_aux(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. if (status == NULL) /* no status from caller? */
  52. status = &my_status; /* use local status word */
  53. *status = (jack_status_t)0;
  54. /* validate parameters */
  55. if ((options & ~JackOpenOptions)) {
  56. int my_status1 = *status | (JackFailure | JackInvalidOption);
  57. *status = (jack_status_t)my_status1;
  58. return NULL;
  59. }
  60. /* parse variable arguments */
  61. va_start(ap, status);
  62. jack_varargs_parse(options, ap, &va);
  63. va_end(ap);
  64. JackLog("jack_client_open %s\n", client_name);
  65. if (client_name == NULL) {
  66. jack_error("jack_client_new called with a NULL client_name");
  67. return NULL;
  68. }
  69. JackLibGlobals::Init(); // jack library initialisation
  70. #ifndef WIN32
  71. if (try_start_server(&va, options, status)) {
  72. jack_error("jack server is not running or cannot be started");
  73. JackLibGlobals::Destroy(); // jack library destruction
  74. return 0;
  75. }
  76. #endif
  77. #ifdef __CLIENTDEBUG__
  78. JackClient* client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
  79. #else
  80. JackClient* client = new JackLibClient(GetSynchroTable());
  81. #endif
  82. int res = client->Open(client_name, options, status);
  83. if (res < 0) {
  84. delete client;
  85. JackLibGlobals::Destroy(); // jack library destruction
  86. int my_status1 = (JackFailure|JackServerError);
  87. *status = (jack_status_t)my_status1;
  88. return NULL;
  89. } else {
  90. return (jack_client_t*)client;
  91. }
  92. }
  93. EXPORT jack_client_t* jack_client_new(const char* client_name)
  94. {
  95. int options = JackUseExactName;
  96. if (getenv("JACK_START_SERVER") == NULL)
  97. options |= JackNoStartServer;
  98. return jack_client_open_aux(client_name, (jack_options_t)options, NULL);
  99. }
  100. EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  101. {
  102. va_list ap;
  103. va_start(ap, status);
  104. jack_client_t* res = jack_client_open_aux(client_name, options, status, ap);
  105. va_end(ap);
  106. return res;
  107. }
  108. EXPORT int jack_client_close(jack_client_t* ext_client)
  109. {
  110. JackLog("jack_client_close\n");
  111. JackClient* client = (JackClient*)ext_client;
  112. if (client == NULL) {
  113. jack_error("jack_client_close called with a NULL client");
  114. return -1;
  115. } else {
  116. int res = client->Close();
  117. delete client;
  118. JackLog("jack_client_close OK\n");
  119. JackLibGlobals::Destroy(); // jack library destruction
  120. return res;
  121. }
  122. }