16 fprintf(stderr
, "\nUsage: %s [options]\n", my_name
);
17 fprintf(stderr
, "Check for jack existence, or wait, until it either quits, or gets started\n");
18 fprintf(stderr
, "options:\n");
19 fprintf(stderr
, " -s, --server <name> Connect to the jack server named <name>\n");
20 fprintf(stderr
, " -n, --name <name> Set client name to <name>\n");
21 fprintf(stderr
, " -w, --wait Wait for server to become available\n");
22 fprintf(stderr
, " -q, --quit Wait until server is quit\n");
23 fprintf(stderr
, " -c, --check Check whether server is running\n");
24 fprintf(stderr
, " -t, --timeout Wait timeout in seconds\n");
25 fprintf(stderr
, " -h, --help Display this help message\n");
26 fprintf(stderr
, "For more information see http://jackaudio.org/\n");
30 main(int argc
, char *argv
[])
32 jack_client_t
*client
;
34 jack_options_t options
= JackNoStartServer
;
37 char *server_name
= NULL
;
38 char *client_name
= NULL
;
39 int wait_for_start
= 0;
40 int wait_for_quit
= 0;
43 time_t start_timestamp
;
46 struct option long_options
[] = {
47 { "server", 1, 0, 's' },
48 { "wait", 0, 0, 'w' },
50 { "quit", 0, 0, 'q' },
51 { "check", 0, 0, 'c' },
52 { "timeout", 1, 0, 't' },
53 { "help", 0, 0, 'h' },
57 my_name
= strrchr(argv
[0], '/');
64 while ((c
= getopt_long (argc
, argv
, "s:n:wqct:hv", long_options
, &option_index
)) >= 0) {
67 server_name
= (char *) malloc (sizeof (char) * (strlen(optarg
) + 1));
68 strcpy (server_name
, optarg
);
69 options
|= JackServerName
;
72 client_name
= (char *) malloc (sizeof (char) * (strlen(optarg
) + 1));
73 strcpy (client_name
, optarg
);
85 wait_timeout
= atoi(optarg
);
98 /* try to open server in a loop. breaking under certein conditions */
100 start_timestamp
= time(NULL
);
104 client
= jack_client_open (client_name
, options
, &status
, server_name
);
107 client
= jack_client_open ("wait", options
, &status
, server_name
);
109 /* check for some real error and bail out */
110 if ((client
== NULL
) && !(status
& JackServerFailed
)) {
111 fprintf (stderr
, "jack_client_open() failed, "
112 "status = 0x%2.0x\n", status
);
116 if (client
== NULL
) {
118 fprintf(stdout
, "server is gone\n");
122 fprintf(stdout
, "not running\n");
126 jack_client_close(client
);
127 if (wait_for_start
) {
128 fprintf(stdout
, "server is available\n");
132 fprintf(stdout
, "running\n");
137 if ((time(NULL
) - start_timestamp
) > wait_timeout
) {
138 fprintf(stdout
, "timeout\n");
143 // Wait a second, and repeat