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.

216 lines
5.4KB

  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. }
  67. if (va->load_init) {
  68. strncpy (req.x.intclient.init, va->load_init,
  69. sizeof(req.x.intclient.init));
  70. }
  71. jack_client_deliver_request (client, &req);
  72. *status |= req.status;
  73. if (*status & JackFailure) {
  74. return -1;
  75. }
  76. jack_uuid_copy (&uuid, req.x.intclient.uuid);
  77. return 0;
  78. }
  79. char *
  80. jack_get_internal_client_name (jack_client_t *client,
  81. jack_intclient_t intclient)
  82. {
  83. jack_request_t req;
  84. char *name;
  85. memset (&req, 0, sizeof(req));
  86. req.type = IntClientName;
  87. req.x.intclient.options = JackNullOption;
  88. jack_uuid_copy (&req.x.intclient.uuid, intclient);
  89. jack_client_deliver_request (client, &req);
  90. if (req.status & JackFailure) {
  91. return NULL;
  92. }
  93. /* allocate storage for returning the name */
  94. if ((name = strdup (req.x.intclient.name)) == NULL) {
  95. return NULL;
  96. }
  97. return name;
  98. }
  99. int
  100. jack_internal_client_handle (jack_client_t *client,
  101. const char *client_name,
  102. jack_status_t *status,
  103. jack_intclient_t *handle)
  104. {
  105. jack_request_t req;
  106. jack_status_t my_status;
  107. if (status == NULL) { /* no status from caller? */
  108. status = &my_status; /* use local status word */
  109. }
  110. *status = 0;
  111. memset (&req, 0, sizeof(req));
  112. req.type = IntClientHandle;
  113. req.x.intclient.options = JackNullOption;
  114. strncpy (req.x.intclient.name, client_name,
  115. sizeof(req.x.intclient.name));
  116. *status = jack_client_deliver_request (client, &req);
  117. if (!jack_uuid_empty (req.x.intclient.uuid)) {
  118. jack_uuid_copy (handle, req.x.intclient.uuid);
  119. return 0;
  120. }
  121. return -1;
  122. }
  123. int
  124. jack_internal_client_load_aux (jack_client_t *client,
  125. const char *client_name,
  126. jack_options_t options,
  127. jack_status_t *status,
  128. jack_intclient_t handle, va_list ap)
  129. {
  130. jack_varargs_t va;
  131. jack_status_t my_status;
  132. if (status == NULL) { /* no status from caller? */
  133. status = &my_status; /* use local status word */
  134. }
  135. *status = 0;
  136. /* validate parameters */
  137. if ((options & ~JackLoadOptions)) {
  138. *status |= (JackFailure | JackInvalidOption);
  139. return -1;
  140. }
  141. /* parse variable arguments */
  142. jack_varargs_parse (options, ap, &va);
  143. return jack_intclient_request (IntClientLoad, client, client_name,
  144. options, status, handle, &va);
  145. }
  146. int
  147. jack_internal_client_load (jack_client_t *client,
  148. const char *client_name,
  149. jack_options_t options,
  150. jack_status_t *status,
  151. jack_intclient_t handle, ...)
  152. {
  153. va_list ap;
  154. va_start (ap, handle);
  155. int res = jack_internal_client_load_aux (client, client_name, options, status, handle, ap);
  156. va_end (ap);
  157. return res;
  158. }
  159. jack_status_t
  160. jack_internal_client_unload (jack_client_t *client,
  161. jack_intclient_t intclient)
  162. {
  163. jack_request_t req;
  164. jack_status_t status;
  165. if (intclient) {
  166. memset (&req, 0, sizeof(req));
  167. req.type = IntClientUnload;
  168. req.x.intclient.options = JackNullOption;
  169. jack_uuid_copy (&req.x.intclient.uuid, intclient);
  170. jack_client_deliver_request (client, &req);
  171. status = req.status;
  172. } else { /* intclient is null */
  173. status = (JackNoSuchClient | JackFailure);
  174. }
  175. return status;
  176. }