]> code.delx.au - pulseaudio/blob - polyp/pabrowse.c
634c308a2cef35e7a0f96588046de8626212d0d4
[pulseaudio] / polyp / pabrowse.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <assert.h>
28 #include <signal.h>
29
30 #include <polyp/mainloop.h>
31 #include <polyp/mainloop-signal.h>
32 #include <polyp/polyplib-browser.h>
33 #include <polyp/typeid.h>
34
35 static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
36 fprintf(stderr, "Got signal, exiting\n");
37 m->quit(m, 0);
38 }
39
40 static void dump_server(const pa_browse_info *i) {
41 char t[16];
42
43 if (i->cookie)
44 snprintf(t, sizeof(t), "0x%08x", *i->cookie);
45
46 printf("server: %s\n"
47 "server-version: %s\n"
48 "user-name: %s\n"
49 "fqdn: %s\n"
50 "cookie: %s\n",
51 i->server,
52 i->server_version ? i->server_version : "n/a",
53 i->user_name ? i->user_name : "n/a",
54 i->fqdn ? i->fqdn : "n/a",
55 i->cookie ? t : "n/a");
56 }
57
58 static void dump_device(const pa_browse_info *i) {
59 char t[16], ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
60
61 if (i->sample_spec)
62 pa_sample_spec_snprint(ss, sizeof(ss), i->sample_spec);
63
64 if (i->typeid)
65 pa_typeid_to_string(*i->typeid, t, sizeof(t));
66
67 printf("device: %s\n"
68 "description: %s\n"
69 "type: %s\n"
70 "sample spec: %s\n",
71 i->device,
72 i->description ? i->description : "n/a",
73 i->typeid ? t : "n/a",
74 i->sample_spec ? ss : "n/a");
75
76 }
77
78 static void browser_callback(pa_browser *b, pa_browse_opcode c, const pa_browse_info *i, void *userdata) {
79 assert(b && i);
80
81 switch (c) {
82
83 case PA_BROWSE_NEW_SERVER:
84 printf("\n=> new server <%s>\n", i->name);
85 dump_server(i);
86 break;
87
88 case PA_BROWSE_NEW_SINK:
89 printf("\n=> new sink <%s>\n", i->name);
90 dump_server(i);
91 dump_device(i);
92 break;
93
94 case PA_BROWSE_NEW_SOURCE:
95 printf("\n=> new source <%s>\n", i->name);
96 dump_server(i);
97 dump_device(i);
98 break;
99
100 case PA_BROWSE_REMOVE:
101 printf("\n=> removed service <%s>\n", i->name);
102 break;
103
104 default:
105 ;
106 }
107 }
108
109
110 int main(int argc, char *argv[]) {
111 pa_mainloop *mainloop = NULL;
112 pa_browser *browser = NULL;
113 int ret = 1, r;
114
115 if (!(mainloop = pa_mainloop_new()))
116 goto finish;
117
118 r = pa_signal_init(pa_mainloop_get_api(mainloop));
119 assert(r == 0);
120 pa_signal_new(SIGINT, exit_signal_callback, NULL);
121 pa_signal_new(SIGTERM, exit_signal_callback, NULL);
122 signal(SIGPIPE, SIG_IGN);
123
124 if (!(browser = pa_browser_new(pa_mainloop_get_api(mainloop))))
125 goto finish;
126
127 pa_browser_set_callback(browser, browser_callback, NULL);
128
129 ret = 0;
130 pa_mainloop_run(mainloop, &ret);
131
132 finish:
133 if (mainloop) {
134 pa_signal_done();
135 pa_mainloop_free(mainloop);
136 }
137
138 return ret;
139 }