1 /* -*- mode: c; c-file-style: "bsd"; -*- */
3 * Copyright (C) 2004 Jack O'Quin
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.
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.
28 #include <jack/internal.h>
29 #include <jack/intclient.h>
30 #include <jack/varargs.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
)
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
));
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
);
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
);
69 req
.x
.intclient
.options
= options
;
70 strncpy (req
.x
.intclient
.name
, client_name
,
71 sizeof (req
.x
.intclient
.name
));
73 strncpy (req
.x
.intclient
.path
, va
->load_name
,
74 sizeof (req
.x
.intclient
.path
));
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
)
86 return req
.x
.intclient
.id
;
90 jack_get_internal_client_name (jack_client_t
*client
,
91 jack_intclient_t intclient
)
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
)
106 /* allocate storage for returning the name */
107 name
= malloc (strlen (req
.x
.intclient
.name
));
108 strcpy (name
, req
.x
.intclient
.name
);
114 jack_internal_client_handle (jack_client_t
*client
,
115 const char *client_name
,
116 jack_status_t
*status
)
119 jack_status_t my_status
;
121 if (status
== NULL
) /* no status from caller? */
122 status
= &my_status
; /* use local status word */
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
;
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
)
143 jack_status_t my_status
;
145 if (status
== NULL
) /* no status from caller? */
146 status
= &my_status
; /* use local status word */
149 /* validate parameters */
150 if ((options
& ~JackLoadOptions
)) {
151 *status
|= (JackFailure
|JackInvalidOption
);
155 /* parse variable arguments */
156 jack_varargs_parse (options
, ap
, &va
);
158 return jack_intclient_request (IntClientLoad
, client
, client_name
,
159 options
, status
, &va
);
163 jack_internal_client_load (jack_client_t
*client
,
164 const char *client_name
,
165 jack_options_t options
,
166 jack_status_t
*status
, ...)
169 va_start(ap
, status
);
170 jack_intclient_t res
= jack_internal_client_load_aux(client
, client_name
, options
, status
, ap
);
176 jack_internal_client_unload (jack_client_t
*client
,
177 jack_intclient_t intclient
)
180 jack_status_t status
;
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
);
191 } else { /* intclient is null */
192 status
= (JackNoSuchClient
|JackFailure
);