4 This file is part of polypaudio.
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.
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.
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
30 #include <polyp/polypaudio.h>
31 #include <polyp/browser.h>
33 static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
34 fprintf(stderr, "Got signal, exiting\n");
38 static void dump_server(const pa_browse_info *i) {
42 snprintf(t, sizeof(t), "0x%08x", *i->cookie);
45 "server-version: %s\n"
50 i->server_version ? i->server_version : "n/a",
51 i->user_name ? i->user_name : "n/a",
52 i->fqdn ? i->fqdn : "n/a",
53 i->cookie ? t : "n/a");
56 static void dump_device(const pa_browse_info *i) {
57 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
60 pa_sample_spec_snprint(ss, sizeof(ss), i->sample_spec);
66 i->description ? i->description : "n/a",
67 i->sample_spec ? ss : "n/a");
71 static void browser_callback(pa_browser *b, pa_browse_opcode_t c, const pa_browse_info *i, void *userdata) {
76 case PA_BROWSE_NEW_SERVER:
77 printf("\n=> new server <%s>\n", i->name);
81 case PA_BROWSE_NEW_SINK:
82 printf("\n=> new sink <%s>\n", i->name);
87 case PA_BROWSE_NEW_SOURCE:
88 printf("\n=> new source <%s>\n", i->name);
93 case PA_BROWSE_REMOVE_SERVER:
94 printf("\n=> removed server <%s>\n", i->name);
97 case PA_BROWSE_REMOVE_SINK:
98 printf("\n=> removed sink <%s>\n", i->name);
101 case PA_BROWSE_REMOVE_SOURCE:
102 printf("\n=> removed source <%s>\n", i->name);
110 int main(int argc, char *argv[]) {
111 pa_mainloop *mainloop = NULL;
112 pa_browser *browser = NULL;
115 if (!(mainloop = pa_mainloop_new()))
118 r = pa_signal_init(pa_mainloop_get_api(mainloop));
120 pa_signal_new(SIGINT, exit_signal_callback, NULL);
121 pa_signal_new(SIGTERM, exit_signal_callback, NULL);
122 signal(SIGPIPE, SIG_IGN);
124 if (!(browser = pa_browser_new(pa_mainloop_get_api(mainloop))))
127 pa_browser_set_callback(browser, browser_callback, NULL);
130 pa_mainloop_run(mainloop, &ret);
135 pa_mainloop_free(mainloop);