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.

197 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/internal.h>
  26. #include <jack/intclient.h>
  27. #include <jack/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. /* allocate storage for returning the name */
  88. name = malloc (strlen (req.x.intclient.name));
  89. strcpy (name, req.x.intclient.name);
  90. return name;
  91. }
  92. jack_intclient_t
  93. jack_internal_client_handle (jack_client_t *client,
  94. const char *client_name,
  95. jack_status_t *status)
  96. {
  97. jack_request_t req;
  98. jack_status_t my_status;
  99. if (status == NULL) /* no status from caller? */
  100. status = &my_status; /* use local status word */
  101. *status = 0;
  102. memset (&req, 0, sizeof (req));
  103. req.type = IntClientHandle;
  104. req.x.intclient.options = JackNullOption;
  105. strncpy (req.x.intclient.name, client_name,
  106. sizeof (req.x.intclient.name));
  107. *status = jack_client_deliver_request (client, &req);
  108. return req.x.intclient.id;
  109. }
  110. jack_intclient_t
  111. jack_internal_client_load_aux (jack_client_t *client,
  112. const char *client_name,
  113. jack_options_t options,
  114. jack_status_t *status, va_list ap)
  115. {
  116. jack_varargs_t va;
  117. jack_status_t my_status;
  118. if (status == NULL) /* no status from caller? */
  119. status = &my_status; /* use local status word */
  120. *status = 0;
  121. /* validate parameters */
  122. if ((options & ~JackLoadOptions)) {
  123. *status |= (JackFailure|JackInvalidOption);
  124. return 0;
  125. }
  126. /* parse variable arguments */
  127. jack_varargs_parse (options, ap, &va);
  128. return jack_intclient_request (IntClientLoad, client, client_name,
  129. options, status, &va);
  130. }
  131. jack_intclient_t
  132. jack_internal_client_load (jack_client_t *client,
  133. const char *client_name,
  134. jack_options_t options,
  135. jack_status_t *status, ...)
  136. {
  137. va_list ap;
  138. va_start(ap, status);
  139. jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
  140. va_end(ap);
  141. return res;
  142. }
  143. jack_status_t
  144. jack_internal_client_unload (jack_client_t *client,
  145. jack_intclient_t intclient)
  146. {
  147. jack_request_t req;
  148. jack_status_t status;
  149. if (intclient) {
  150. memset (&req, 0, sizeof (req));
  151. req.type = IntClientUnload;
  152. req.x.intclient.options = JackNullOption;
  153. req.x.intclient.id = intclient;
  154. jack_client_deliver_request (client, &req);
  155. status = req.status;
  156. } else { /* intclient is null */
  157. status = (JackNoSuchClient|JackFailure);
  158. }
  159. return status;
  160. }