waf: configure option for enforcing autostart method
[jack2.git] / example-clients / cpu_load.c
blob2c7deaa888e57056a290b0cc8d1aa1105f583c4e
1 /** @file cpu_load.c
3 */
5 #include <stdio.h>
6 #include <errno.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <math.h>
10 #include <signal.h>
11 #ifndef WIN32
12 #include <unistd.h>
13 #endif
14 #include <jack/jack.h>
17 jack_client_t *client;
19 static void signal_handler(int sig)
21 jack_client_close(client);
22 fprintf(stderr, "signal received, exiting ...\n");
23 exit(0);
27 /**
28 * JACK calls this shutdown_callback if the server ever shuts down or
29 * decides to disconnect the client.
31 void
32 jack_shutdown(void *arg)
34 exit(1);
37 int
38 main(int argc, char *argv[])
40 jack_options_t options = JackNullOption;
41 jack_status_t status;
43 /* open a client connection to the JACK server */
45 client = jack_client_open ("jack_cpu_load", options, &status);
46 if (client == NULL) {
47 fprintf(stderr, "jack_client_open() failed, "
48 "status = 0x%2.0x\n", status);
49 if (status & JackServerFailed) {
50 fprintf(stderr, "Unable to connect to JACK server\n");
52 exit(1);
55 jack_on_shutdown(client, jack_shutdown, 0);
57 /* Tell the JACK server that we are ready to roll. Our
58 * process() callback will start running now. */
60 if (jack_activate(client)) {
61 fprintf(stderr, "cannot activate client");
62 exit(1);
65 /* install a signal handler to properly quits jack client */
66 #ifdef WIN32
67 signal(SIGINT, signal_handler);
68 signal(SIGABRT, signal_handler);
69 signal(SIGTERM, signal_handler);
70 #else
71 signal(SIGQUIT, signal_handler);
72 signal(SIGTERM, signal_handler);
73 signal(SIGHUP, signal_handler);
74 signal(SIGINT, signal_handler);
75 #endif
77 while (1) {
78 printf("jack DSP load %f\n", jack_cpu_load(client));
79 #ifdef WIN32
80 Sleep(1000);
81 #else
82 sleep(1);
83 #endif
86 jack_client_close(client);
87 exit(0 );