8 #include <jack/intclient.h>
10 jack_client_t
*client
;
11 jack_intclient_t intclient
;
15 char *load_init
= NULL
;
16 char *server_name
= NULL
;
20 signal_handler (int sig
)
24 fprintf (stderr
, "signal received, unloading...");
25 status
= jack_internal_client_unload (client
, intclient
);
26 if (status
& JackFailure
)
27 fprintf (stderr
, "(failed), status = 0x%2.0x\n", status
);
29 fprintf (stderr
, "(succeeded)\n");
30 jack_client_close (client
);
37 fprintf (stderr
, "usage: %s [ options ] client-name [ load-name "
38 "[ init-string]]\n\noptions:\n", client_name
);
40 "\t-h, --help \t\t print help message\n"
41 "\t-i, --init string\t initialize string\n"
42 "\t-s, --server name\t select JACK server\n"
43 "\t-w, --wait \t\t wait for signal, then unload\n"
49 parse_args (int argc
, char *argv
[])
53 char *short_options
= "hi:s:w";
54 struct option long_options
[] = {
55 { "help", 0, 0, 'h' },
56 { "init", required_argument
, 0, 'i' },
57 { "server", required_argument
, 0, 's' },
58 { "wait", 0, 0, 'w' },
62 client_name
= strrchr(argv
[0], '/');
63 if (client_name
== NULL
) {
64 client_name
= argv
[0];
69 while ((c
= getopt_long (argc
, argv
, short_options
, long_options
,
70 &option_index
)) >= 0) {
88 if (optind
== argc
) { /* no positional args? */
93 load_name
= intclient_name
= argv
[optind
++];
96 load_name
= argv
[optind
++];
99 load_init
= argv
[optind
++];
101 //fprintf (stderr, "client-name = `%s', load-name = `%s', "
102 // "load-init = `%s', wait = %d\n",
103 // intclient_name, load_name, load_init, wait_opt);
105 return 0; /* args OK */
109 main (int argc
, char *argv
[])
111 jack_status_t status
;
113 /* parse and validate command arguments */
114 if (parse_args (argc
, argv
))
115 exit (1); /* invalid command line */
117 /* first, become a JACK client */
118 client
= jack_client_open (client_name
, JackServerName
,
119 &status
, server_name
);
120 if (client
== NULL
) {
121 fprintf (stderr
, "jack_client_open() failed, "
122 "status = 0x%2.0x\n", status
);
123 if (status
& JackServerFailed
) {
124 fprintf (stderr
, "Unable to connect to JACK server\n");
128 if (status
& JackServerStarted
) {
129 fprintf (stderr
, "JACK server started\n");
131 if (status
& JackNameNotUnique
) {
132 client_name
= jack_get_client_name(client
);
133 fprintf (stderr
, "unique name `%s' assigned\n", client_name
);
136 /* then, load the internal client */
137 intclient
= jack_internal_client_load (client
, intclient_name
,
138 (JackLoadName
|JackLoadInit
),
139 &status
, load_name
, load_init
);
140 if (status
& JackFailure
) {
141 fprintf (stderr
, "could not load %s, status = 0x%2.0x\n",
145 if (status
& JackNameNotUnique
) {
147 jack_get_internal_client_name (client
, intclient
);
148 fprintf (stderr
, "unique internal client name `%s' assigned\n",
152 fprintf (stdout
, "%s is running.\n", load_name
);
155 /* define a signal handler to unload the client, then
156 * wait for it to exit */
157 signal (SIGQUIT
, signal_handler
);
158 signal (SIGTERM
, signal_handler
);
159 signal (SIGHUP
, signal_handler
);
160 signal (SIGINT
, signal_handler
);