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.

134 lines
3.7KB

  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 "JackGraphManager.h"
  20. #include "JackLibGlobals.h"
  21. #include "JackGlobals.h"
  22. #include "varargs.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 jack_client_t * jack_client_new (const char *client_name);
  37. EXPORT int jack_client_close (jack_client_t *client);
  38. #ifdef __cplusplus
  39. }
  40. #endif
  41. JackLibGlobals* JackLibGlobals::fGlobals = NULL;
  42. long JackLibGlobals::fClientCount = 0;
  43. static inline bool CheckPort(jack_port_id_t port_index)
  44. {
  45. return (port_index < PORT_NUM);
  46. }
  47. EXPORT jack_client_t* jack_client_new(const char* client_name)
  48. {
  49. int options = JackUseExactName;
  50. if (getenv("JACK_START_SERVER") == NULL)
  51. options |= JackNoStartServer;
  52. return jack_client_open(client_name, (jack_options_t)options, NULL);
  53. }
  54. // TO BE IMPLEMENTED PROPERLY
  55. EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  56. {
  57. va_list ap; /* variable argument pointer */
  58. jack_varargs_t va; /* variable arguments */
  59. jack_status_t my_status;
  60. if (status == NULL) /* no status from caller? */
  61. status = &my_status; /* use local status word */
  62. *status = (jack_status_t)0;
  63. /* validate parameters */
  64. if ((options & ~JackOpenOptions)) {
  65. int my_status1 = *status | (JackFailure | JackInvalidOption);
  66. *status = (jack_status_t)my_status1;
  67. return NULL;
  68. }
  69. /* parse variable arguments */
  70. va_start(ap, status);
  71. jack_varargs_parse(options, ap, &va);
  72. va_end(ap);
  73. JackLog("jack_client_open %s\n", client_name);
  74. if (client_name == NULL) {
  75. jack_error("jack_client_new called with a NULL client_name");
  76. return NULL;
  77. }
  78. JackLibGlobals::Init(); // jack library initialisation
  79. #ifdef __CLIENTDEBUG__
  80. JackClient* client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
  81. #else
  82. JackClient* client = new JackLibClient(GetSynchroTable());
  83. #endif
  84. int res = client->Open(client_name);
  85. if (res < 0) {
  86. delete client;
  87. JackLibGlobals::Destroy(); // jack library destruction
  88. return NULL;
  89. } else {
  90. *status = (jack_status_t)0;
  91. return (jack_client_t*)client;
  92. }
  93. return NULL;
  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. }
  103. int res = client->Close();
  104. delete client;
  105. JackLog("jack_client_close OK\n");
  106. JackLibGlobals::Destroy(); // jack library destruction
  107. return res;
  108. }