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.

133 lines
3.8KB

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