]> code.delx.au - pulseaudio/blob - src/polyp/subscribe.c
* modify pa_context_exit_daemon() to return a pa_operation object
[pulseaudio] / src / polyp / subscribe.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 <assert.h>
27 #include <stdio.h>
28
29 #include <polypcore/gccmacro.h>
30 #include <polypcore/pstream-util.h>
31
32 #include "internal.h"
33
34 #include "subscribe.h"
35
36 void pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
37 pa_context *c = userdata;
38 pa_subscription_event_type_t e;
39 uint32_t index;
40
41 assert(pd);
42 assert(command == PA_COMMAND_SUBSCRIBE_EVENT);
43 assert(t);
44 assert(c);
45
46 pa_context_ref(c);
47
48 if (pa_tagstruct_getu32(t, &e) < 0 ||
49 pa_tagstruct_getu32(t, &index) < 0 ||
50 !pa_tagstruct_eof(t)) {
51 pa_context_fail(c, PA_ERR_PROTOCOL);
52 goto finish;
53 }
54
55 if (c->subscribe_callback)
56 c->subscribe_callback(c, e, index, c->subscribe_userdata);
57
58 finish:
59 pa_context_unref(c);
60 }
61
62
63 pa_operation* pa_context_subscribe(pa_context *c, pa_subscription_mask_t m, pa_context_success_cb_t cb, void *userdata) {
64 pa_operation *o;
65 pa_tagstruct *t;
66 uint32_t tag;
67
68 assert(c);
69 assert(c->ref >= 1);
70
71 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
72
73 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
74
75 t = pa_tagstruct_new(NULL, 0);
76 pa_tagstruct_putu32(t, PA_COMMAND_SUBSCRIBE);
77 pa_tagstruct_putu32(t, tag = c->ctag++);
78 pa_tagstruct_putu32(t, m);
79 pa_pstream_send_tagstruct(c->pstream, t);
80 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o));
81
82 return o;
83 }
84
85 void pa_context_set_subscribe_callback(pa_context *c, pa_context_subscribe_cb_t cb, void *userdata) {
86 assert(c);
87 assert(c->ref >= 1);
88
89 c->subscribe_callback = cb;
90 c->subscribe_userdata = userdata;
91 }