2 This file is part of PulseAudio.
4 Copyright 2008 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 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
26 #include <pulse/context.h>
27 #include <pulse/gccmacro.h>
29 #include <pulsecore/macro.h>
30 #include <pulsecore/pstream-util.h>
34 #include "ext-stream-restore.h"
45 static void ext_stream_restore_test_cb(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
46 pa_operation
*o
= userdata
;
47 uint32_t version
= PA_INVALID_INDEX
;
51 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
56 if (command
!= PA_COMMAND_REPLY
) {
57 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
60 } else if (pa_tagstruct_getu32(t
, &version
) < 0 ||
61 !pa_tagstruct_eof(t
)) {
63 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
68 pa_ext_stream_restore_test_cb_t cb
= (pa_ext_stream_restore_test_cb_t
) o
->callback
;
69 cb(o
->context
, version
, o
->userdata
);
74 pa_operation_unref(o
);
77 pa_operation
*pa_ext_stream_restore_test(
79 pa_ext_stream_restore_test_cb_t cb
,
87 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
90 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
91 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
93 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
95 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
96 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
97 pa_tagstruct_puts(t
, "module-stream-restore");
98 pa_tagstruct_putu32(t
, SUBCOMMAND_TEST
);
99 pa_pstream_send_tagstruct(c
->pstream
, t
);
100 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, ext_stream_restore_test_cb
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
105 static void ext_stream_restore_read_cb(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
106 pa_operation
*o
= userdata
;
111 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
116 if (command
!= PA_COMMAND_REPLY
) {
117 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
123 while (!pa_tagstruct_eof(t
)) {
124 pa_ext_stream_restore_info i
;
125 pa_bool_t mute
= FALSE
;
127 memset(&i
, 0, sizeof(i
));
129 if (pa_tagstruct_gets(t
, &i
.name
) < 0 ||
130 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
131 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
132 pa_tagstruct_gets(t
, &i
.device
) < 0 ||
133 pa_tagstruct_get_boolean(t
, &mute
) < 0) {
135 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
142 pa_ext_stream_restore_read_cb_t cb
= (pa_ext_stream_restore_read_cb_t
) o
->callback
;
143 cb(o
->context
, &i
, 0, o
->userdata
);
149 pa_ext_stream_restore_read_cb_t cb
= (pa_ext_stream_restore_read_cb_t
) o
->callback
;
150 cb(o
->context
, NULL
, eol
, o
->userdata
);
154 pa_operation_done(o
);
155 pa_operation_unref(o
);
158 pa_operation
*pa_ext_stream_restore_read(
160 pa_ext_stream_restore_read_cb_t cb
,
168 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
171 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
172 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
174 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
176 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
177 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
178 pa_tagstruct_puts(t
, "module-stream-restore");
179 pa_tagstruct_putu32(t
, SUBCOMMAND_READ
);
180 pa_pstream_send_tagstruct(c
->pstream
, t
);
181 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, ext_stream_restore_read_cb
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
186 pa_operation
*pa_ext_stream_restore_write(
188 pa_update_mode_t mode
,
189 const pa_ext_stream_restore_info data
[],
191 pa_bool_t apply_immediately
,
192 pa_context_success_cb_t cb
,
200 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
201 pa_assert(mode
== PA_UPDATE_MERGE
|| mode
== PA_UPDATE_REPLACE
|| mode
== PA_UPDATE_SET
);
205 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
206 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
208 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
210 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
211 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
212 pa_tagstruct_puts(t
, "module-stream-restore");
213 pa_tagstruct_putu32(t
, SUBCOMMAND_WRITE
);
215 pa_tagstruct_putu32(t
, mode
);
216 pa_tagstruct_put_boolean(t
, apply_immediately
);
218 for (; n
> 0; n
--, data
++) {
219 pa_tagstruct_puts(t
, data
->name
);
220 pa_tagstruct_put_channel_map(t
, &data
->channel_map
);
221 pa_tagstruct_put_cvolume(t
, &data
->volume
);
222 pa_tagstruct_puts(t
, data
->device
);
223 pa_tagstruct_put_boolean(t
, data
->mute
);
226 pa_pstream_send_tagstruct(c
->pstream
, t
);
227 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
232 pa_operation
*pa_ext_stream_restore_delete(
234 const char *const s
[],
235 pa_context_success_cb_t cb
,
241 const char *const *k
;
244 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
248 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
249 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
251 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
253 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
254 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
255 pa_tagstruct_puts(t
, "module-stream-restore");
256 pa_tagstruct_putu32(t
, SUBCOMMAND_DELETE
);
259 pa_tagstruct_puts(t
, *k
);
261 pa_pstream_send_tagstruct(c
->pstream
, t
);
262 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
267 pa_operation
*pa_ext_stream_restore_subscribe(
270 pa_context_success_cb_t cb
,
278 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
281 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
282 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
284 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
286 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
287 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
288 pa_tagstruct_puts(t
, "module-stream-restore");
289 pa_tagstruct_putu32(t
, SUBCOMMAND_SUBSCRIBE
);
290 pa_tagstruct_put_boolean(t
, enable
);
291 pa_pstream_send_tagstruct(c
->pstream
, t
);
292 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, pa_operation_ref(o
), (pa_free_cb_t
) pa_operation_unref
);
297 void pa_ext_stream_restore_set_subscribe_cb(
299 pa_ext_stream_restore_subscribe_cb_t cb
,
303 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
305 c
->ext_stream_restore
.callback
= cb
;
306 c
->ext_stream_restore
.userdata
= userdata
;
309 void pa_ext_stream_restore_command(pa_context
*c
, uint32_t tag
, pa_tagstruct
*t
) {
313 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
316 if (pa_tagstruct_getu32(t
, &subcommand
) < 0 ||
317 !pa_tagstruct_eof(t
)) {
319 pa_context_fail(c
, PA_ERR_PROTOCOL
);
323 if (subcommand
!= SUBCOMMAND_EVENT
) {
324 pa_context_fail(c
, PA_ERR_PROTOCOL
);
328 if (c
->ext_stream_restore
.callback
)
329 c
->ext_stream_restore
.callback(c
, c
->ext_stream_restore
.userdata
);