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
;
38 signal_handler (int sig
)
42 fprintf (stderr
, "signal received, unloading...");
43 status
= jack_internal_client_unload (client
, intclient
);
44 if (status
& JackFailure
)
45 fprintf (stderr
, "(failed), status = 0x%2.0x\n", status
);
47 fprintf (stderr
, "(succeeded)\n");
48 jack_client_close (client
);
55 fprintf (stderr
, "usage: %s [ options ] client-name [ load-name "
56 "[ init-string]]\n\noptions:\n", client_name
);
58 "\t-h, --help \t\t print help message\n"
59 "\t-i, --init string\t initialize string\n"
60 "\t-s, --server name\t select JACK server\n"
61 "\t-w, --wait \t\t wait for signal, then unload\n"
67 parse_args (int argc
, char *argv
[])
71 char *short_options
= "hi:s:w";
72 struct option long_options
[] = {
73 { "help", 0, 0, 'h' },
74 { "init", required_argument
, 0, 'i' },
75 { "server", required_argument
, 0, 's' },
76 { "wait", 0, 0, 'w' },
80 client_name
= strrchr(argv
[0], '/');
81 if (client_name
== NULL
) {
82 client_name
= argv
[0];
87 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
,
88 &option_index
)) >= 0) {
106 if (optind
== argc
) { /* no positional args? */
111 load_name
= intclient_name
= argv
[optind
++];
114 load_name
= argv
[optind
++];
117 load_init
= argv
[optind
++];
119 //fprintf (stderr, "client-name = `%s', load-name = `%s', "
120 // "load-init = `%s', wait = %d\n",
121 // intclient_name, load_name, load_init, wait_opt);
123 return 0; /* args OK */
127 main (int argc
, char *argv
[])
129 jack_status_t status
;
132 /* parse and validate command arguments */
133 if (parse_args (argc
, argv
))
134 exit (1); /* invalid command line */
136 /* first, become a JACK client */
137 client
= jack_client_open (client_name
, JackServerName
,
138 &status
, server_name
);
139 if (client
== NULL
) {
140 fprintf (stderr
, "jack_client_open() failed, "
141 "status = 0x%2.0x\n", status
);
142 if (status
& JackServerFailed
) {
143 fprintf (stderr
, "Unable to connect to JACK server\n");
147 if (status
& JackServerStarted
) {
148 fprintf (stderr
, "JACK server started\n");
150 if (status
& JackNameNotUnique
) {
151 client_name
= jack_get_client_name(client
);
152 fprintf (stderr
, "unique name `%s' assigned\n", client_name
);
155 /* then, load the internal client */
156 intclient
= jack_internal_client_load (client
, intclient_name
,
157 (JackLoadName
|JackLoadInit
),
158 &status
, load_name
, load_init
);
159 if (status
& JackFailure
) {
160 fprintf (stderr
, "could not load %s, intclient = %d status = 0x%2.0x\n",
161 load_name
, (int)intclient
, status
);
164 if (status
& JackNameNotUnique
) {
166 jack_get_internal_client_name (client
, intclient
);
167 fprintf (stderr
, "unique internal client name `%s' assigned\n",
171 fprintf (stdout
, "%s is running.\n", load_name
);
173 name
= jack_get_internal_client_name(client
, intclient
);
175 printf("client name = %s\n", name
);
180 /* define a signal handler to unload the client, then
181 * wait for it to exit */
183 signal(SIGINT
, signal_handler
);
184 signal(SIGABRT
, signal_handler
);
185 signal(SIGTERM
, signal_handler
);
187 signal(SIGQUIT
, signal_handler
);
188 signal(SIGTERM
, signal_handler
);
189 signal(SIGHUP
, signal_handler
);
190 signal(SIGINT
, signal_handler
);
202 jack_client_close(client
);