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.

188 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. * $Id$
  20. */
  21. #include <config.h>
  22. #include <errno.h>
  23. #include <stdarg.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <jack/internal.h>
  27. #include <jack/intclient.h>
  28. #include <jack/varargs.h>
  29. #include "local.h"
  30. static jack_intclient_t
  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_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 0;
  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 0;
  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 0;
  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 0;
  73. return req.x.intclient.id;
  74. }
  75. char *
  76. jack_get_internal_client_name (jack_client_t *client,
  77. jack_intclient_t intclient)
  78. {
  79. jack_request_t req;
  80. char *name;
  81. memset (&req, 0, sizeof (req));
  82. req.type = IntClientName;
  83. req.x.intclient.options = JackNullOption;
  84. req.x.intclient.id = intclient;
  85. jack_client_deliver_request (client, &req);
  86. if (req.status & JackFailure)
  87. return NULL;
  88. /* allocate storage for returning the name */
  89. name = malloc (strlen (req.x.intclient.name));
  90. strcpy (name, req.x.intclient.name);
  91. return name;
  92. }
  93. jack_intclient_t
  94. jack_internal_client_handle (jack_client_t *client,
  95. const char *client_name,
  96. jack_status_t *status)
  97. {
  98. jack_request_t req;
  99. jack_status_t my_status;
  100. if (status == NULL) /* no status from caller? */
  101. status = &my_status; /* use local status word */
  102. *status = 0;
  103. memset (&req, 0, sizeof (req));
  104. req.type = IntClientHandle;
  105. req.x.intclient.options = JackNullOption;
  106. strncpy (req.x.intclient.name, client_name,
  107. sizeof (req.x.intclient.name));
  108. *status = jack_client_deliver_request (client, &req);
  109. return req.x.intclient.id;
  110. }
  111. jack_intclient_t
  112. jack_internal_client_load (jack_client_t *client,
  113. const char *client_name,
  114. jack_options_t options,
  115. jack_status_t *status, ...)
  116. {
  117. va_list ap;
  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. va_start (ap, status);
  130. jack_varargs_parse (options, ap, &va);
  131. va_end (ap);
  132. return jack_intclient_request (IntClientLoad, client, client_name,
  133. options, status, &va);
  134. }
  135. jack_status_t
  136. jack_internal_client_unload (jack_client_t *client,
  137. jack_intclient_t intclient)
  138. {
  139. jack_request_t req;
  140. jack_status_t status;
  141. if (intclient) {
  142. memset (&req, 0, sizeof (req));
  143. req.type = IntClientUnload;
  144. req.x.intclient.options = JackNullOption;
  145. req.x.intclient.id = intclient;
  146. jack_client_deliver_request (client, &req);
  147. status = req.status;
  148. } else { /* intclient is null */
  149. status = (JackNoSuchClient|JackFailure);
  150. }
  151. return status;
  152. }