no more dither when converting from float to 24 bit values - i am not sure how this...
[jack.git] / libjack / intclient.c
blob4607dd54640735277ef17ccb56c173307151d3df
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.
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.
21 #include <config.h>
23 #include <errno.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
28 #include <jack/internal.h>
29 #include <jack/intclient.h>
30 #include <jack/varargs.h>
32 #include "local.h"
34 static jack_intclient_t
35 jack_intclient_request(RequestType type, jack_client_t *client,
36 const char* client_name, jack_options_t options,
37 jack_status_t *status, jack_varargs_t *va)
39 jack_request_t req;
41 memset (&req, 0, sizeof (req));
43 if (strlen (client_name) >= sizeof (req.x.intclient.name)) {
44 jack_error ("\"%s\" is too long for a JACK client name.\n"
45 "Please use %lu characters or less.",
46 client_name, sizeof (req.x.intclient.name));
47 return 0;
50 if (va->load_name
51 && (strlen (va->load_name) > sizeof (req.x.intclient.path) - 1)) {
52 jack_error ("\"%s\" is too long for a shared object name.\n"
53 "Please use %lu characters or less.",
54 va->load_name, sizeof (req.x.intclient.path) - 1);
55 *status |= (JackFailure|JackInvalidOption);
56 return 0;
59 if (va->load_init
60 && (strlen (va->load_init) > sizeof (req.x.intclient.init) - 1)) {
61 jack_error ("\"%s\" is too long for internal client init "
62 "string.\nPlease use %lu characters or less.",
63 va->load_init, sizeof (req.x.intclient.init) - 1);
64 *status |= (JackFailure|JackInvalidOption);
65 return 0;
68 req.type = type;
69 req.x.intclient.options = options;
70 strncpy (req.x.intclient.name, client_name,
71 sizeof (req.x.intclient.name));
72 if (va->load_name)
73 strncpy (req.x.intclient.path, va->load_name,
74 sizeof (req.x.intclient.path));
75 if (va->load_init)
76 strncpy (req.x.intclient.init, va->load_init,
77 sizeof (req.x.intclient.init));
79 jack_client_deliver_request (client, &req);
81 *status |= req.status;
83 if (*status & JackFailure)
84 return 0;
86 return req.x.intclient.id;
89 char *
90 jack_get_internal_client_name (jack_client_t *client,
91 jack_intclient_t intclient)
93 jack_request_t req;
94 char *name;
96 memset (&req, 0, sizeof (req));
97 req.type = IntClientName;
98 req.x.intclient.options = JackNullOption;
99 req.x.intclient.id = intclient;
101 jack_client_deliver_request (client, &req);
103 if (req.status & JackFailure)
104 return NULL;
106 /* allocate storage for returning the name */
107 name = malloc (strlen (req.x.intclient.name));
108 strcpy (name, req.x.intclient.name);
110 return name;
113 jack_intclient_t
114 jack_internal_client_handle (jack_client_t *client,
115 const char *client_name,
116 jack_status_t *status)
118 jack_request_t req;
119 jack_status_t my_status;
121 if (status == NULL) /* no status from caller? */
122 status = &my_status; /* use local status word */
123 *status = 0;
125 memset (&req, 0, sizeof (req));
126 req.type = IntClientHandle;
127 req.x.intclient.options = JackNullOption;
128 strncpy (req.x.intclient.name, client_name,
129 sizeof (req.x.intclient.name));
131 *status = jack_client_deliver_request (client, &req);
133 return req.x.intclient.id;
136 jack_intclient_t
137 jack_internal_client_load_aux (jack_client_t *client,
138 const char *client_name,
139 jack_options_t options,
140 jack_status_t *status, va_list ap)
142 jack_varargs_t va;
143 jack_status_t my_status;
145 if (status == NULL) /* no status from caller? */
146 status = &my_status; /* use local status word */
147 *status = 0;
149 /* validate parameters */
150 if ((options & ~JackLoadOptions)) {
151 *status |= (JackFailure|JackInvalidOption);
152 return 0;
155 /* parse variable arguments */
156 jack_varargs_parse (options, ap, &va);
158 return jack_intclient_request (IntClientLoad, client, client_name,
159 options, status, &va);
162 jack_intclient_t
163 jack_internal_client_load (jack_client_t *client,
164 const char *client_name,
165 jack_options_t options,
166 jack_status_t *status, ...)
168 va_list ap;
169 va_start(ap, status);
170 jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
171 va_end(ap);
172 return res;
175 jack_status_t
176 jack_internal_client_unload (jack_client_t *client,
177 jack_intclient_t intclient)
179 jack_request_t req;
180 jack_status_t status;
182 if (intclient) {
184 memset (&req, 0, sizeof (req));
185 req.type = IntClientUnload;
186 req.x.intclient.options = JackNullOption;
187 req.x.intclient.id = intclient;
188 jack_client_deliver_request (client, &req);
189 status = req.status;
191 } else { /* intclient is null */
192 status = (JackNoSuchClient|JackFailure);
195 return status;