Merge branch 'master' into server_no_deadlock
[jack2.git] / example-clients / alias.c
blob87a19b883229281c5dce98ac5440134308ba4537
1 /*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <string.h>
21 #include <getopt.h>
22 #include <jack/jack.h>
24 char * my_name;
26 void
27 show_version (void)
29 //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
32 void
33 show_usage (void)
35 show_version ();
36 fprintf (stderr, "\nUsage: %s [options] portname alias\n", my_name);
37 fprintf (stderr, "List active Jack ports, and optionally display extra information.\n\n");
38 fprintf (stderr, "Display options:\n");
39 fprintf (stderr, " -u, --unalias remove `alias' as an alias for `port'\n");
40 fprintf (stderr, " -h, --help Display this help message\n");
41 fprintf (stderr, " --version Output version information and exit\n\n");
42 fprintf (stderr, "For more information see http://jackaudio.org/\n");
45 int
46 main (int argc, char *argv[])
48 jack_client_t *client;
49 jack_status_t status;
50 char* portname;
51 char* alias;
52 int unset = 0;
53 int ret;
54 int c;
55 int option_index;
56 extern int optind;
57 jack_port_t* port;
59 struct option long_options[] = {
60 { "unalias", 0, 0, 'u' },
61 { "help", 0, 0, 'h' },
62 { "version", 0, 0, 'v' },
63 { 0, 0, 0, 0 }
66 if (argc < 3) {
67 show_usage ();
68 return 1;
71 my_name = strrchr(argv[0], '/');
72 if (my_name == 0) {
73 my_name = argv[0];
74 } else {
75 my_name ++;
78 while ((c = getopt_long (argc, argv, "uhv", long_options, &option_index)) >= 0) {
79 switch (c) {
80 case 'u':
81 unset = 1;
82 break;
83 case 'h':
84 show_usage ();
85 return 1;
86 break;
87 case 'v':
88 show_version ();
89 return 1;
90 break;
91 default:
92 show_usage ();
93 return 1;
94 break;
98 portname = argv[optind++];
99 alias = argv[optind];
101 /* Open a client connection to the JACK server. Starting a
102 * new server only to list its ports seems pointless, so we
103 * specify JackNoStartServer. */
104 //JOQ: need a new server name option
106 client = jack_client_open ("lsp", JackNoStartServer, &status);
108 if (client == NULL) {
109 if (status & JackServerFailed) {
110 fprintf (stderr, "JACK server not running\n");
111 } else {
112 fprintf (stderr, "jack_client_open() failed, "
113 "status = 0x%2.0x\n", status);
115 return 1;
118 if ((port = jack_port_by_name (client, portname)) == 0) {
119 fprintf (stderr, "No port named \"%s\"\n", portname);
120 return 1;
123 if (!unset) {
124 ret = jack_port_set_alias (port, alias);
125 } else {
126 ret = jack_port_unset_alias (port, alias);
129 jack_client_close (client);
131 return ret;