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.

210 lines
5.6KB

  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 <jack/uuid.h>
  27. #include "internal.h"
  28. #include "varargs.h"
  29. #include "local.h"
  30. static int
  31. jack_intclient_request(RequestType type, jack_client_t *client,
  32. const char* client_name, jack_options_t options,
  33. jack_status_t *status, jack_intclient_t uuid, jack_varargs_t *va)
  34. {
  35. jack_request_t req;
  36. memset (&req, 0, sizeof (req));
  37. if (strlen (client_name) >= sizeof (req.x.intclient.name)) {
  38. jack_error ("\"%s\" is too long for a JACK client name.\n"
  39. "Please use %lu characters or less.",
  40. client_name, sizeof (req.x.intclient.name));
  41. return -1;
  42. }
  43. if (va->load_name
  44. && (strlen (va->load_name) > sizeof (req.x.intclient.path) - 1)) {
  45. jack_error ("\"%s\" is too long for a shared object name.\n"
  46. "Please use %lu characters or less.",
  47. va->load_name, sizeof (req.x.intclient.path) - 1);
  48. *status |= (JackFailure|JackInvalidOption);
  49. return -1;
  50. }
  51. if (va->load_init
  52. && (strlen (va->load_init) > sizeof (req.x.intclient.init) - 1)) {
  53. jack_error ("\"%s\" is too long for internal client init "
  54. "string.\nPlease use %lu characters or less.",
  55. va->load_init, sizeof (req.x.intclient.init) - 1);
  56. *status |= (JackFailure|JackInvalidOption);
  57. return -1;
  58. }
  59. req.type = type;
  60. req.x.intclient.options = options;
  61. strncpy (req.x.intclient.name, client_name,
  62. sizeof (req.x.intclient.name));
  63. if (va->load_name)
  64. strncpy (req.x.intclient.path, va->load_name,
  65. sizeof (req.x.intclient.path));
  66. if (va->load_init)
  67. strncpy (req.x.intclient.init, va->load_init,
  68. sizeof (req.x.intclient.init));
  69. jack_client_deliver_request (client, &req);
  70. *status |= req.status;
  71. if (*status & JackFailure)
  72. return -1;
  73. jack_uuid_copy (&uuid, req.x.intclient.uuid);
  74. return 0;
  75. }
  76. char *
  77. jack_get_internal_client_name (jack_client_t *client,
  78. jack_intclient_t intclient)
  79. {
  80. jack_request_t req;
  81. char *name;
  82. memset (&req, 0, sizeof (req));
  83. req.type = IntClientName;
  84. req.x.intclient.options = JackNullOption;
  85. jack_uuid_copy (&req.x.intclient.uuid, intclient);
  86. jack_client_deliver_request (client, &req);
  87. if (req.status & JackFailure) {
  88. return NULL;
  89. }
  90. /* allocate storage for returning the name */
  91. if ((name = strdup (req.x.intclient.name)) == NULL) {
  92. return NULL;
  93. }
  94. return name;
  95. }
  96. int
  97. jack_internal_client_handle (jack_client_t *client,
  98. const char *client_name,
  99. jack_status_t *status,
  100. jack_intclient_t *handle)
  101. {
  102. jack_request_t req;
  103. jack_status_t my_status;
  104. if (status == NULL) /* no status from caller? */
  105. status = &my_status; /* use local status word */
  106. *status = 0;
  107. memset (&req, 0, sizeof (req));
  108. req.type = IntClientHandle;
  109. req.x.intclient.options = JackNullOption;
  110. strncpy (req.x.intclient.name, client_name,
  111. sizeof (req.x.intclient.name));
  112. *status = jack_client_deliver_request (client, &req);
  113. if (!jack_uuid_empty (req.x.intclient.uuid)) {
  114. jack_uuid_copy (handle, req.x.intclient.uuid);
  115. return 0;
  116. }
  117. return -1;
  118. }
  119. int
  120. jack_internal_client_load_aux (jack_client_t *client,
  121. const char *client_name,
  122. jack_options_t options,
  123. jack_status_t *status,
  124. jack_intclient_t handle, va_list ap)
  125. {
  126. jack_varargs_t va;
  127. jack_status_t my_status;
  128. if (status == NULL) /* no status from caller? */
  129. status = &my_status; /* use local status word */
  130. *status = 0;
  131. /* validate parameters */
  132. if ((options & ~JackLoadOptions)) {
  133. *status |= (JackFailure|JackInvalidOption);
  134. return -1;
  135. }
  136. /* parse variable arguments */
  137. jack_varargs_parse (options, ap, &va);
  138. return jack_intclient_request (IntClientLoad, client, client_name,
  139. options, status, handle, &va);
  140. }
  141. int
  142. jack_internal_client_load (jack_client_t *client,
  143. const char *client_name,
  144. jack_options_t options,
  145. jack_status_t *status,
  146. jack_intclient_t handle, ...)
  147. {
  148. va_list ap;
  149. va_start(ap, handle);
  150. int res = jack_internal_client_load_aux(client, client_name, options, status, handle, ap);
  151. va_end(ap);
  152. return res;
  153. }
  154. jack_status_t
  155. jack_internal_client_unload (jack_client_t *client,
  156. jack_intclient_t intclient)
  157. {
  158. jack_request_t req;
  159. jack_status_t status;
  160. if (intclient) {
  161. memset (&req, 0, sizeof (req));
  162. req.type = IntClientUnload;
  163. req.x.intclient.options = JackNullOption;
  164. jack_uuid_copy (&req.x.intclient.uuid, intclient);
  165. jack_client_deliver_request (client, &req);
  166. status = req.status;
  167. } else { /* intclient is null */
  168. status = (JackNoSuchClient|JackFailure);
  169. }
  170. return status;
  171. }