2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <jack/jack.h>
26 #include <jack/intclient.h>
28 jack_client_t
*client
;
29 jack_intclient_t intclient
;
34 char *server_name
= NULL
;
35 int autoclose_opt
= 0;
37 volatile int idling
= 1;
40 signal_handler (int sig
)
42 /* do nothing if internal client closed itself */
48 fprintf (stderr
, "signal received, unloading...");
49 status
= jack_internal_client_unload (client
, intclient
);
50 if (status
& JackFailure
)
51 fprintf (stderr
, "(failed), status = 0x%2.0x\n", status
);
53 fprintf (stderr
, "(succeeded)\n");
55 jack_deactivate(client
);
56 jack_client_close (client
);
61 registration_callback (const char *name
, int reg
, void *arg
)
63 if (reg
|| strcmp(intclient_name
, name
))
66 /* this will stop the wait loop and thus close this application. */
77 fprintf (stderr
, "usage: %s [ options ] client-name [ load-name "
78 "[ init-string]]\n\noptions:\n", client_name
);
80 "\t-h, --help \t\t print help message\n"
81 "\t-a, --autoclose\t automatically close when intclient is unloaded\n"
82 "\t-i, --init string\t initialize string\n"
83 "\t-s, --server name\t select JACK server\n"
84 "\t-w, --wait \t\t wait for signal, then unload\n"
90 parse_args (int argc
, char *argv
[])
94 char *short_options
= "hai:s:w";
95 struct option long_options
[] = {
96 { "help", 0, 0, 'h' },
97 { "autoclose", 0, 0, 'a' },
98 { "init", required_argument
, 0, 'i' },
99 { "server", required_argument
, 0, 's' },
100 { "wait", 0, 0, 'w' },
104 client_name
= strrchr(argv
[0], '/');
105 if (client_name
== NULL
) {
106 client_name
= argv
[0];
111 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
,
112 &option_index
)) >= 0) {
121 server_name
= optarg
;
133 /* autoclose makes no sense without wait */
134 if (autoclose_opt
&& ! wait_opt
)
137 if (optind
== argc
) { /* no positional args? */
142 load_name
= intclient_name
= argv
[optind
++];
145 load_name
= argv
[optind
++];
148 load_init
= argv
[optind
++];
150 //fprintf (stderr, "client-name = `%s', load-name = `%s', "
151 // "load-init = `%s', wait = %d\n",
152 // intclient_name, load_name, load_init, wait_opt);
154 return 0; /* args OK */
158 main (int argc
, char *argv
[])
160 jack_status_t status
;
163 /* parse and validate command arguments */
164 if (parse_args (argc
, argv
))
165 exit (1); /* invalid command line */
167 /* first, become a JACK client */
168 client
= jack_client_open (client_name
, JackServerName
,
169 &status
, server_name
);
170 if (client
== NULL
) {
171 fprintf (stderr
, "jack_client_open() failed, "
172 "status = 0x%2.0x\n", status
);
173 if (status
& JackServerFailed
) {
174 fprintf (stderr
, "Unable to connect to JACK server\n");
178 if (status
& JackServerStarted
) {
179 fprintf (stderr
, "JACK server started\n");
181 if (status
& JackNameNotUnique
) {
182 client_name
= jack_get_client_name(client
);
183 fprintf (stderr
, "unique name `%s' assigned\n", client_name
);
186 /* then, load the internal client */
187 intclient
= jack_internal_client_load (client
, intclient_name
,
188 (JackLoadName
|JackLoadInit
),
189 &status
, load_name
, load_init
);
190 if (status
& JackFailure
) {
191 fprintf (stderr
, "could not load %s, intclient = %d status = 0x%2.0x\n",
192 load_name
, (int)intclient
, status
);
195 if (status
& JackNameNotUnique
) {
197 jack_get_internal_client_name (client
, intclient
);
198 fprintf (stderr
, "unique internal client name `%s' assigned\n",
202 fprintf (stdout
, "%s is running.\n", load_name
);
204 name
= jack_get_internal_client_name(client
, intclient
);
206 printf("client name = %s\n", name
);
212 jack_set_client_registration_callback(client
, registration_callback
, NULL
);
213 jack_activate(client
);
217 /* define a signal handler to unload the client, then
218 * wait for it to exit */
220 signal(SIGINT
, signal_handler
);
221 signal(SIGABRT
, signal_handler
);
222 signal(SIGTERM
, signal_handler
);
224 signal(SIGQUIT
, signal_handler
);
225 signal(SIGTERM
, signal_handler
);
226 signal(SIGHUP
, signal_handler
);
227 signal(SIGINT
, signal_handler
);
240 jack_deactivate(client
);
243 jack_client_close(client
);