jack1 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.

200 lines
5.1KB

  1. /* -*- mode: c; c-file-style: "bsd"; -*- */
  2. /*
  3. * Copyright (C) 2004 Jack O'Quin
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. *
  19. */
  20. #include <config.h>
  21. #include <errno.h>
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <jack/intclient.h>
  26. #include "internal.h"
  27. #include "varargs.h"
  28. #include "local.h"
  29. static jack_intclient_t
  30. jack_intclient_request(RequestType type, jack_client_t *client,
  31. const char* client_name, jack_options_t options,
  32. jack_status_t *status, jack_varargs_t *va)
  33. {
  34. jack_request_t req;
  35. memset (&req, 0, sizeof (req));
  36. if (strlen (client_name) >= sizeof (req.x.intclient.name)) {
  37. jack_error ("\"%s\" is too long for a JACK client name.\n"
  38. "Please use %lu characters or less.",
  39. client_name, sizeof (req.x.intclient.name));
  40. return 0;
  41. }
  42. if (va->load_name
  43. && (strlen (va->load_name) > sizeof (req.x.intclient.path) - 1)) {
  44. jack_error ("\"%s\" is too long for a shared object name.\n"
  45. "Please use %lu characters or less.",
  46. va->load_name, sizeof (req.x.intclient.path) - 1);
  47. *status |= (JackFailure|JackInvalidOption);
  48. return 0;
  49. }
  50. if (va->load_init
  51. && (strlen (va->load_init) > sizeof (req.x.intclient.init) - 1)) {
  52. jack_error ("\"%s\" is too long for internal client init "
  53. "string.\nPlease use %lu characters or less.",
  54. va->load_init, sizeof (req.x.intclient.init) - 1);
  55. *status |= (JackFailure|JackInvalidOption);
  56. return 0;
  57. }
  58. req.type = type;
  59. req.x.intclient.options = options;
  60. strncpy (req.x.intclient.name, client_name,
  61. sizeof (req.x.intclient.name));
  62. if (va->load_name)
  63. strncpy (req.x.intclient.path, va->load_name,
  64. sizeof (req.x.intclient.path));
  65. if (va->load_init)
  66. strncpy (req.x.intclient.init, va->load_init,
  67. sizeof (req.x.intclient.init));
  68. jack_client_deliver_request (client, &req);
  69. *status |= req.status;
  70. if (*status & JackFailure)
  71. return 0;
  72. return req.x.intclient.id;
  73. }
  74. char *
  75. jack_get_internal_client_name (jack_client_t *client,
  76. jack_intclient_t intclient)
  77. {
  78. jack_request_t req;
  79. char *name;
  80. memset (&req, 0, sizeof (req));
  81. req.type = IntClientName;
  82. req.x.intclient.options = JackNullOption;
  83. req.x.intclient.id = intclient;
  84. jack_client_deliver_request (client, &req);
  85. if (req.status & JackFailure) {
  86. return NULL;
  87. }
  88. /* allocate storage for returning the name */
  89. if ((name = strdup (req.x.intclient.name)) == NULL) {
  90. return NULL;
  91. }
  92. return name;
  93. }
  94. jack_intclient_t
  95. jack_internal_client_handle (jack_client_t *client,
  96. const char *client_name,
  97. jack_status_t *status)
  98. {
  99. jack_request_t req;
  100. jack_status_t my_status;
  101. if (status == NULL) /* no status from caller? */
  102. status = &my_status; /* use local status word */
  103. *status = 0;
  104. memset (&req, 0, sizeof (req));
  105. req.type = IntClientHandle;
  106. req.x.intclient.options = JackNullOption;
  107. strncpy (req.x.intclient.name, client_name,
  108. sizeof (req.x.intclient.name));
  109. *status = jack_client_deliver_request (client, &req);
  110. return req.x.intclient.id;
  111. }
  112. jack_intclient_t
  113. jack_internal_client_load_aux (jack_client_t *client,
  114. const char *client_name,
  115. jack_options_t options,
  116. jack_status_t *status, va_list ap)
  117. {
  118. jack_varargs_t va;
  119. jack_status_t my_status;
  120. if (status == NULL) /* no status from caller? */
  121. status = &my_status; /* use local status word */
  122. *status = 0;
  123. /* validate parameters */
  124. if ((options & ~JackLoadOptions)) {
  125. *status |= (JackFailure|JackInvalidOption);
  126. return 0;
  127. }
  128. /* parse variable arguments */
  129. jack_varargs_parse (options, ap, &va);
  130. return jack_intclient_request (IntClientLoad, client, client_name,
  131. options, status, &va);
  132. }
  133. jack_intclient_t
  134. jack_internal_client_load (jack_client_t *client,
  135. const char *client_name,
  136. jack_options_t options,
  137. jack_status_t *status, ...)
  138. {
  139. va_list ap;
  140. va_start(ap, status);
  141. jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
  142. va_end(ap);
  143. return res;
  144. }
  145. jack_status_t
  146. jack_internal_client_unload (jack_client_t *client,
  147. jack_intclient_t intclient)
  148. {
  149. jack_request_t req;
  150. jack_status_t status;
  151. if (intclient) {
  152. memset (&req, 0, sizeof (req));
  153. req.type = IntClientUnload;
  154. req.x.intclient.options = JackNullOption;
  155. req.x.intclient.id = intclient;
  156. jack_client_deliver_request (client, &req);
  157. status = req.status;
  158. } else { /* intclient is null */
  159. status = (JackNoSuchClient|JackFailure);
  160. }
  161. return status;
  162. }