waf: configure option for enforcing autostart method
[jack2.git] / example-clients / evmon.c
blob67a75e9912fae75fcd4f9b8df9b5d8079c06687a
1 /*
2 Copyright (C) 2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <stdio.h>
20 #include <errno.h>
21 #ifndef WIN32
22 #include <unistd.h>
23 #endif
24 #include <string.h>
25 #include <signal.h>
26 #include <stdlib.h>
28 #include <jack/jack.h>
30 jack_client_t *client;
32 static void signal_handler(int sig)
34 jack_client_close(client);
35 fprintf(stderr, "signal received, exiting ...\n");
36 exit(0);
39 static void
40 port_callback (jack_port_id_t port, int yn, void* arg)
42 printf ("Port %d %s\n", port, (yn ? "registered" : "unregistered"));
45 static void
46 connect_callback (jack_port_id_t a, jack_port_id_t b, int yn, void* arg)
48 printf ("Ports %d and %d %s\n", a, b, (yn ? "connected" : "disconnected"));
51 static void
52 client_callback (const char* client, int yn, void* arg)
54 printf ("Client %s %s\n", client, (yn ? "registered" : "unregistered"));
57 static int
58 graph_callback (void* arg)
60 printf ("Graph reordered\n");
61 return 0;
64 int
65 main (int argc, char *argv[])
67 jack_options_t options = JackNullOption;
68 jack_status_t status;
70 if ((client = jack_client_open ("event-monitor", options, &status, NULL)) == 0) {
71 fprintf (stderr, "jack_client_open() failed, "
72 "status = 0x%2.0x\n", status);
73 if (status & JackServerFailed) {
74 fprintf (stderr, "Unable to connect to JACK server\n");
76 return 1;
79 if (jack_set_port_registration_callback (client, port_callback, NULL)) {
80 fprintf (stderr, "cannot set port registration callback\n");
81 return 1;
83 if (jack_set_port_connect_callback (client, connect_callback, NULL)) {
84 fprintf (stderr, "cannot set port connect callback\n");
85 return 1;
87 if (jack_set_client_registration_callback (client, client_callback, NULL)) {
88 fprintf (stderr, "cannot set client registration callback\n");
89 return 1;
91 if (jack_set_graph_order_callback (client, graph_callback, NULL)) {
92 fprintf (stderr, "cannot set graph order registration callback\n");
93 return 1;
95 if (jack_activate (client)) {
96 fprintf (stderr, "cannot activate client");
97 return 1;
100 #ifdef WIN32
101 signal(SIGINT, signal_handler);
102 signal(SIGABRT, signal_handler);
103 signal(SIGTERM, signal_handler);
104 #else
105 signal(SIGQUIT, signal_handler);
106 signal(SIGTERM, signal_handler);
107 signal(SIGHUP, signal_handler);
108 signal(SIGINT, signal_handler);
109 #endif
111 sleep (-1);
112 exit (0);