2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio 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.1 of the License,
9 or (at your option) any later version.
11 PulseAudio 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.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/browser.h>
31 #include <pulse/pulseaudio.h>
33 #include <pulsecore/core-util.h>
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");
40 static void dump_server(const pa_browse_info
*i
) {
44 snprintf(t
, sizeof(t
), "0x%08x", *i
->cookie
);
47 "server-version: %s\n"
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");
58 static void dump_device(const pa_browse_info
*i
) {
59 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
];
62 pa_sample_spec_snprint(ss
, sizeof(ss
), i
->sample_spec
);
68 i
->description
? i
->description
: "n/a",
69 i
->sample_spec
? ss
: "n/a");
73 static void browser_callback(pa_browser
*b
, pa_browse_opcode_t c
, const pa_browse_info
*i
, void *userdata
) {
78 case PA_BROWSE_NEW_SERVER
:
79 printf("\n=> new server <%s>\n", i
->name
);
83 case PA_BROWSE_NEW_SINK
:
84 printf("\n=> new sink <%s>\n", i
->name
);
89 case PA_BROWSE_NEW_SOURCE
:
90 printf("\n=> new source <%s>\n", i
->name
);
95 case PA_BROWSE_REMOVE_SERVER
:
96 printf("\n=> removed server <%s>\n", i
->name
);
99 case PA_BROWSE_REMOVE_SINK
:
100 printf("\n=> removed sink <%s>\n", i
->name
);
103 case PA_BROWSE_REMOVE_SOURCE
:
104 printf("\n=> removed source <%s>\n", i
->name
);
112 static void error_callback(pa_browser
*b
, const char *s
, void *userdata
) {
113 pa_mainloop_api
*m
= userdata
;
115 fprintf(stderr
, "Failure: %s\n", s
);
119 int main(int argc
, char *argv
[]) {
120 pa_mainloop
*mainloop
= NULL
;
121 pa_browser
*browser
= NULL
;
125 if (!(mainloop
= pa_mainloop_new()))
128 r
= pa_signal_init(pa_mainloop_get_api(mainloop
));
130 pa_signal_new(SIGINT
, exit_signal_callback
, NULL
);
131 pa_signal_new(SIGTERM
, exit_signal_callback
, NULL
);
132 pa_disable_sigpipe();
134 if (!(browser
= pa_browser_new_full(pa_mainloop_get_api(mainloop
), PA_BROWSE_FOR_SERVERS
|PA_BROWSE_FOR_SINKS
|PA_BROWSE_FOR_SOURCES
, &s
))) {
135 fprintf(stderr
, "pa_browse_new_full(): %s\n", s
);
139 pa_browser_set_callback(browser
, browser_callback
, NULL
);
140 pa_browser_set_error_callback(browser
, error_callback
, pa_mainloop_get_api(mainloop
));
143 pa_mainloop_run(mainloop
, &ret
);
148 pa_browser_unref(browser
);
152 pa_mainloop_free(mainloop
);