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
, " -w, --wait Wait for server to become available\n");
21 fprintf (stderr
, " -q, --quit Wait until server is quit\n");
22 fprintf (stderr
, " -c, --check Check wether server is running\n");
23 fprintf (stderr
, " -t, --timeout Wait timeout in seconds\n");
24 fprintf (stderr
, " -h, --help Display this help message\n");
25 fprintf (stderr
, "For more information see http://jackaudio.org/\n");
29 main (int argc
, char *argv
[])
31 jack_client_t
*client
;
33 jack_options_t options
= JackNoStartServer
;
36 char *server_name
= NULL
;
37 int wait_for_start
= 0;
38 int wait_for_quit
= 0;
41 time_t start_timestamp
;
44 struct option long_options
[] = {
45 { "server", 1, 0, 's' },
46 { "wait", 0, 0, 'w' },
47 { "quit", 0, 0, 'q' },
48 { "check", 0, 0, 'c' },
49 { "timeout", 1, 0, 't' },
50 { "help", 0, 0, 'h' },
54 my_name
= strrchr(argv
[0], '/');
61 while ((c
= getopt_long (argc
, argv
, "s:wqct:hv", long_options
, &option_index
)) >= 0) {
64 server_name
= (char *) malloc (sizeof (char) * strlen(optarg
));
65 strcpy (server_name
, optarg
);
66 options
|= JackServerName
;
78 wait_timeout
= atoi(optarg
);
91 /* try to open server in a loop. breaking under certein conditions */
93 start_timestamp
= time( NULL
);
96 client
= jack_client_open ("wait", options
, &status
, server_name
);
97 /* check for some real error and bail out */
98 if( (client
== NULL
) && !(status
& JackServerFailed
) ) {
99 fprintf (stderr
, "jack_client_open() failed, "
100 "status = 0x%2.0x\n", status
);
104 if( client
== NULL
) {
105 if( wait_for_quit
) {
106 fprintf( stdout
, "server is gone\n" );
110 fprintf( stdout
, "not running\n" );
114 jack_client_close( client
);
115 if( wait_for_start
) {
116 fprintf( stdout
, "server is available\n" );
120 fprintf( stdout
, "running\n" );
125 if( (time( NULL
) - start_timestamp
) > wait_timeout
) {
126 fprintf( stdout
, "timeout\n" );
131 // Wait a second, and repeat