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 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 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
35 #include "polyplib-error.h"
37 #include "mainloop-signal.h"
39 static struct pa_context
*context
= NULL
;
40 static struct pa_mainloop_api
*mainloop_api
= NULL
;
48 static void quit(int ret
) {
50 mainloop_api
->quit(mainloop_api
, ret
);
53 static void context_die_callback(struct pa_context
*c
, void *userdata
) {
55 fprintf(stderr
, "Connection to server shut down, exiting.\n");
59 static void context_drain_complete(struct pa_context
*c
, void *userdata
) {
61 fprintf(stderr
, "Connection to server shut down, exiting.\n");
65 static void drain(void) {
66 if (pa_context_drain(context
, context_drain_complete
, NULL
) < 0)
70 static void stat_callback(struct pa_context
*c
, uint32_t blocks
, uint32_t total
, void *userdata
) {
71 if (blocks
== (uint32_t) -1) {
72 fprintf(stderr
, "Failed to get statistics: %s\n", pa_strerror(pa_context_errno(c
)));
77 fprintf(stderr
, "Currently in use: %u blocks containing %u bytes total.\n", blocks
, total
);
81 static void context_complete_callback(struct pa_context
*c
, int success
, void *userdata
) {
85 fprintf(stderr
, "Connection failed: %s\n", pa_strerror(pa_context_errno(c
)));
89 fprintf(stderr
, "Connection established.\n");
92 pa_context_stat(c
, stat_callback
, NULL
);
94 assert(action
== EXIT
);
105 static void exit_signal_callback(void *id
, int sig
, void *userdata
) {
106 fprintf(stderr
, "Got SIGINT, exiting.\n");
111 int main(int argc
, char *argv
[]) {
112 struct pa_mainloop
* m
= NULL
;
116 if (!strcmp(argv
[1], "stat"))
118 else if (!strcmp(argv
[1], "exit"))
122 if (action
== NONE
) {
123 fprintf(stderr
, "No valid action specified. Use one of: stat, exit\n");
127 if (!(m
= pa_mainloop_new())) {
128 fprintf(stderr
, "pa_mainloop_new() failed.\n");
132 mainloop_api
= pa_mainloop_get_api(m
);
134 r
= pa_signal_init(mainloop_api
);
136 pa_signal_register(SIGINT
, exit_signal_callback
, NULL
);
137 signal(SIGPIPE
, SIG_IGN
);
139 if (!(context
= pa_context_new(mainloop_api
, argv
[0]))) {
140 fprintf(stderr
, "pa_context_new() failed.\n");
144 if (pa_context_connect(context
, NULL
, context_complete_callback
, NULL
) < 0) {
145 fprintf(stderr
, "pa_context_connext() failed.\n");
149 pa_context_set_die_callback(context
, context_die_callback
, NULL
);
151 if (pa_mainloop_run(m
, &ret
) < 0) {
152 fprintf(stderr
, "pa_mainloop_run() failed.\n");
158 pa_context_free(context
);