Remove compiler warning
[jack2.git] / example-clients / lsp.c
blobb949db71fcac8007b8047af77ff3ad473470830a
1 #include <stdio.h>
2 #include <stdlib.h>
3 #ifndef WIN32
4 #include <unistd.h>
5 #endif
6 #include <string.h>
7 #include <getopt.h>
9 #include "jack.h"
11 char * my_name;
13 void
14 show_version (void)
16 //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n",
17 //my_name);
20 void
21 show_usage (void)
23 show_version ();
24 fprintf (stderr, "\nUsage: %s [options]\n", my_name);
25 fprintf (stderr, "List active Jack ports, and optionally display extra information.\n\n");
26 fprintf (stderr, "Display options:\n");
27 fprintf (stderr, " -c, --connections List connections to/from each port\n");
28 fprintf (stderr, " -l, --latency Display per-port latency in frames at each port\n");
29 fprintf (stderr, " -L, --latency Display total latency in frames at each port\n");
30 fprintf (stderr, " -p, --properties Display port properties. Output may include:\n"
31 " input|output, can-monitor, physical, terminal\n\n");
32 fprintf (stderr, " -t, --type Display port type\n");
33 fprintf (stderr, " -h, --help Display this help message\n");
34 fprintf (stderr, " --version Output version information and exit\n\n");
35 fprintf (stderr, "For more information see http://jackit.sourceforge.net/\n");
38 int
39 main (int argc, char *argv[])
41 jack_client_t *client;
42 jack_status_t status;
43 const char **ports, **connections;
44 unsigned int i, j;
45 int show_con = 0;
46 int show_port_latency = 0;
47 int show_total_latency = 0;
48 int show_properties = 0;
49 int show_type = 0;
50 int c;
51 int option_index;
52 jack_port_t *port;
54 struct option long_options[] = {
55 { "connections", 0, 0, 'c' },
56 { "port-latency", 0, 0, 'l' },
57 { "total-latency", 0, 0, 'L' },
58 { "properties", 0, 0, 'p' },
59 { "type", 0, 0, 't' },
60 { "help", 0, 0, 'h' },
61 { "version", 0, 0, 'v' },
62 { 0, 0, 0, 0 }
65 my_name = strrchr(argv[0], '/');
66 if (my_name == 0) {
67 my_name = argv[0];
68 } else {
69 my_name ++;
72 while ((c = getopt_long (argc, argv, "clLphvt", long_options, &option_index)) >= 0) {
73 switch (c) {
74 case 'c':
75 show_con = 1;
76 break;
77 case 'l':
78 show_port_latency = 1;
79 break;
80 case 'L':
81 show_total_latency = 1;
82 break;
83 case 'p':
84 show_properties = 1;
85 break;
86 case 't':
87 show_type = 1;
88 break;
89 case 'h':
90 show_usage ();
91 return 1;
92 break;
93 case 'v':
94 show_version ();
95 return 1;
96 break;
97 default:
98 show_usage ();
99 return 1;
100 break;
104 /* Open a client connection to the JACK server. Starting a
105 * new server only to list its ports seems pointless, so we
106 * specify JackNoStartServer. */
107 //JOQ: need a new server name option
109 client = jack_client_open ("lsp", JackNoStartServer, &status);
110 if (client == NULL) {
111 if (status & JackServerFailed) {
112 fprintf (stderr, "JACK server not running\n");
113 } else {
114 fprintf (stderr, "jack_client_open() failed, "
115 "status = 0x%2.0x\n", status);
117 return 1;
120 ports = jack_get_ports (client, NULL, NULL, 0);
122 for (i = 0; ports[i]; ++i) {
123 printf ("%s\n", ports[i]);
125 port = jack_port_by_name (client, ports[i]);
127 if (show_con) {
128 if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
129 for (j = 0; connections[j]; j++) {
130 printf (" %s\n", connections[j]);
132 free (connections);
135 if (show_port_latency) {
136 if (port) {
137 printf (" port latency = %ld frames\n",
138 jack_port_get_latency (port));
141 if (show_total_latency) {
142 if (port) {
143 printf (" total latency = %ld frames\n",
144 jack_port_get_total_latency (client, port));
147 if (show_properties) {
148 if (port) {
149 int flags = jack_port_flags (port);
150 printf (" properties: ");
151 if (flags & JackPortIsInput) {
152 fputs ("input,", stdout);
154 if (flags & JackPortIsOutput) {
155 fputs ("output,", stdout);
157 if (flags & JackPortCanMonitor) {
158 fputs ("can-monitor,", stdout);
160 if (flags & JackPortIsPhysical) {
161 fputs ("physical,", stdout);
163 if (flags & JackPortIsTerminal) {
164 fputs ("terminal,", stdout);
166 putc ('\n', stdout);
169 if (show_type) {
170 if (port) {
171 putc ('\t', stdout);
172 fputs (jack_port_type (port), stdout);
173 putc ('\n', stdout);
177 jack_client_close (client);
178 exit (0);