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.

187 lines
4.8KB

  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 (jack_client_t *client,
  112. const char *client_name,
  113. jack_options_t options,
  114. jack_status_t *status, ...)
  115. {
  116. va_list ap;
  117. jack_varargs_t va;
  118. jack_status_t my_status;
  119. if (status == NULL) /* no status from caller? */
  120. status = &my_status; /* use local status word */
  121. *status = 0;
  122. /* validate parameters */
  123. if ((options & ~JackLoadOptions)) {
  124. *status |= (JackFailure|JackInvalidOption);
  125. return 0;
  126. }
  127. /* parse variable arguments */
  128. va_start (ap, status);
  129. jack_varargs_parse (options, ap, &va);
  130. va_end (ap);
  131. return jack_intclient_request (IntClientLoad, client, client_name,
  132. options, status, &va);
  133. }
  134. jack_status_t
  135. jack_internal_client_unload (jack_client_t *client,
  136. jack_intclient_t intclient)
  137. {
  138. jack_request_t req;
  139. jack_status_t status;
  140. if (intclient) {
  141. memset (&req, 0, sizeof (req));
  142. req.type = IntClientUnload;
  143. req.x.intclient.options = JackNullOption;
  144. req.x.intclient.id = intclient;
  145. jack_client_deliver_request (client, &req);
  146. status = req.status;
  147. } else { /* intclient is null */
  148. status = (JackNoSuchClient|JackFailure);
  149. }
  150. return status;
  151. }