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
29 #include "polyplib-subscribe.h"
30 #include "polyplib-internal.h"
31 #include "pstream-util.h"
33 void pa_command_subscribe_event(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
34 struct pa_context
*c
= userdata
;
35 enum pa_subscription_event_type e
;
37 assert(pd
&& command
== PA_COMMAND_SUBSCRIBE_EVENT
&& t
&& c
);
41 if (pa_tagstruct_getu32(t
, &e
) < 0 ||
42 pa_tagstruct_getu32(t
, &index
) < 0 ||
43 !pa_tagstruct_eof(t
)) {
44 pa_context_fail(c
, PA_ERROR_PROTOCOL
);
48 if (c
->subscribe_callback
)
49 c
->subscribe_callback(c
, e
, index
, c
->subscribe_userdata
);
56 struct pa_operation
* pa_context_subscribe(struct pa_context
*c
, enum pa_subscription_mask m
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
57 struct pa_operation
*o
;
58 struct pa_tagstruct
*t
;
62 o
= pa_operation_new(c
, NULL
);
64 o
->userdata
= userdata
;
66 t
= pa_tagstruct_new(NULL
, 0);
67 pa_tagstruct_putu32(t
, PA_COMMAND_SUBSCRIBE
);
68 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
69 pa_tagstruct_putu32(t
, m
);
70 pa_pstream_send_tagstruct(c
->pstream
, t
);
71 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
73 return pa_operation_ref(o
);
76 void pa_context_set_subscribe_callback(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, enum pa_subscription_event_type t
, uint32_t index
, void *userdata
), void *userdata
) {
78 c
->subscribe_callback
= cb
;
79 c
->subscribe_userdata
= userdata
;