Add port rename and property change to evmon (sync with jack1)
[jack2.git] / example-clients / evmon.c
blob3f3b8050a4d747c762f91c7ae513bd371cc2ab3a
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>
29 #include <jack/metadata.h>
30 #include <jack/uuid.h>
32 jack_client_t *client;
34 static void signal_handler(int sig)
36 jack_client_close(client);
37 fprintf(stderr, "signal received, exiting ...\n");
38 exit(0);
41 static void
42 port_rename_callback (jack_port_id_t port, const char* old_name, const char* new_name, void* arg)
44 printf ("Port %d renamed from %s to %s\n", port, old_name, new_name);
47 static void
48 port_callback (jack_port_id_t port, int yn, void* arg)
50 printf ("Port %d %s\n", port, (yn ? "registered" : "unregistered"));
53 static void
54 connect_callback (jack_port_id_t a, jack_port_id_t b, int yn, void* arg)
56 printf ("Ports %d and %d %s\n", a, b, (yn ? "connected" : "disconnected"));
59 static void
60 client_callback (const char* client, int yn, void* arg)
62 printf ("Client %s %s\n", client, (yn ? "registered" : "unregistered"));
65 static int
66 graph_callback (void* arg)
68 printf ("Graph reordered\n");
69 return 0;
72 void
73 propchange (jack_uuid_t subject, const char* key, jack_property_change_t change)
75 char buf[JACK_UUID_STRING_SIZE];
76 const char* action = "";
78 switch (change) {
79 case PropertyCreated:
80 action = "created";
81 break;
83 case PropertyChanged:
84 action = "changed";
85 break;
87 case PropertyDeleted:
88 action = "deleted";
89 break;
92 if (jack_uuid_empty (subject)) {
93 printf ("All properties changed!\n");
94 } else {
95 jack_uuid_unparse (subject, buf);
97 if (key) {
98 printf ("key [%s] for %s %s\n", key, buf, action);
99 } else {
100 printf ("all keys for %s %s\n", buf, action);
106 main (int argc, char *argv[])
108 jack_options_t options = JackNullOption;
109 jack_status_t status;
111 if ((client = jack_client_open ("event-monitor", options, &status, NULL)) == 0) {
112 fprintf (stderr, "jack_client_open() failed, "
113 "status = 0x%2.0x\n", status);
114 if (status & JackServerFailed) {
115 fprintf (stderr, "Unable to connect to JACK server\n");
117 return 1;
120 if (jack_set_port_registration_callback (client, port_callback, NULL)) {
121 fprintf (stderr, "cannot set port registration callback\n");
122 return 1;
124 if (jack_set_port_rename_callback (client, port_rename_callback, NULL)) {
125 fprintf (stderr, "cannot set port registration callback\n");
126 return 1;
128 if (jack_set_port_connect_callback (client, connect_callback, NULL)) {
129 fprintf (stderr, "cannot set port connect callback\n");
130 return 1;
132 if (jack_set_client_registration_callback (client, client_callback, NULL)) {
133 fprintf (stderr, "cannot set client registration callback\n");
134 return 1;
136 if (jack_set_graph_order_callback (client, graph_callback, NULL)) {
137 fprintf (stderr, "cannot set graph order registration callback\n");
138 return 1;
140 if (jack_set_property_change_callback (client, (JackPropertyChangeCallback) propchange, 0)) {
141 fprintf (stderr, "cannot set property change callback\n");
142 return 1;
144 if (jack_activate (client)) {
145 fprintf (stderr, "cannot activate client");
146 return 1;
149 #ifndef WIN32
150 signal(SIGINT, signal_handler);
151 signal(SIGQUIT, signal_handler);
152 signal(SIGHUP, signal_handler);
153 #endif
154 signal(SIGABRT, signal_handler);
155 signal(SIGTERM, signal_handler);
157 #ifdef WIN32
158 Sleep(INFINITE);
159 #else
160 sleep (-1);
161 #endif
162 exit (0);