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);
89 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
90 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
92 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
94 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
95 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
96 pa_tagstruct_puts(t
, "module-stream-restore");
97 pa_tagstruct_putu32(t
, SUBCOMMAND_TEST
);
98 pa_pstream_send_tagstruct(c
->pstream
, t
);
99 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
);
104 static void ext_stream_restore_read_cb(pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, pa_tagstruct
*t
, void *userdata
) {
105 pa_operation
*o
= userdata
;
110 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
115 if (command
!= PA_COMMAND_REPLY
) {
116 if (pa_context_handle_error(o
->context
, command
, t
, FALSE
) < 0)
122 while (!pa_tagstruct_eof(t
)) {
123 pa_ext_stream_restore_info i
;
124 pa_bool_t mute
= FALSE
;
126 memset(&i
, 0, sizeof(i
));
128 if (pa_tagstruct_gets(t
, &i
.name
) < 0 ||
129 pa_tagstruct_get_channel_map(t
, &i
.channel_map
) < 0 ||
130 pa_tagstruct_get_cvolume(t
, &i
.volume
) < 0 ||
131 pa_tagstruct_gets(t
, &i
.device
) < 0 ||
132 pa_tagstruct_get_boolean(t
, &mute
) < 0) {
134 pa_context_fail(o
->context
, PA_ERR_PROTOCOL
);
141 pa_ext_stream_restore_read_cb_t cb
= (pa_ext_stream_restore_read_cb_t
) o
->callback
;
142 cb(o
->context
, &i
, 0, o
->userdata
);
148 pa_ext_stream_restore_read_cb_t cb
= (pa_ext_stream_restore_read_cb_t
) o
->callback
;
149 cb(o
->context
, NULL
, eol
, o
->userdata
);
153 pa_operation_done(o
);
154 pa_operation_unref(o
);
157 pa_operation
*pa_ext_stream_restore_read(
159 pa_ext_stream_restore_read_cb_t cb
,
167 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
169 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
170 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
172 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
174 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
175 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
176 pa_tagstruct_puts(t
, "module-stream-restore");
177 pa_tagstruct_putu32(t
, SUBCOMMAND_READ
);
178 pa_pstream_send_tagstruct(c
->pstream
, t
);
179 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
);
184 pa_operation
*pa_ext_stream_restore_write(
186 pa_update_mode_t mode
,
187 const pa_ext_stream_restore_info data
[],
189 int apply_immediately
,
190 pa_context_success_cb_t cb
,
198 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
199 pa_assert(mode
== PA_UPDATE_MERGE
|| mode
== PA_UPDATE_REPLACE
|| mode
== PA_UPDATE_SET
);
202 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
203 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
205 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
207 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
208 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
209 pa_tagstruct_puts(t
, "module-stream-restore");
210 pa_tagstruct_putu32(t
, SUBCOMMAND_WRITE
);
212 pa_tagstruct_putu32(t
, mode
);
213 pa_tagstruct_put_boolean(t
, apply_immediately
);
215 for (; n
> 0; n
--, data
++) {
216 pa_tagstruct_puts(t
, data
->name
);
217 pa_tagstruct_put_channel_map(t
, &data
->channel_map
);
218 pa_tagstruct_put_cvolume(t
, &data
->volume
);
219 pa_tagstruct_puts(t
, data
->device
);
220 pa_tagstruct_put_boolean(t
, data
->mute
);
223 pa_pstream_send_tagstruct(c
->pstream
, t
);
224 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
);
229 pa_operation
*pa_ext_stream_restore_delete(
231 const char *const s
[],
232 pa_context_success_cb_t cb
,
238 const char *const *k
;
241 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
244 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
245 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
247 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
249 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
250 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
251 pa_tagstruct_puts(t
, "module-stream-restore");
252 pa_tagstruct_putu32(t
, SUBCOMMAND_DELETE
);
255 pa_tagstruct_puts(t
, *k
);
257 pa_pstream_send_tagstruct(c
->pstream
, t
);
258 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
);
263 pa_operation
*pa_ext_stream_restore_subscribe(
266 pa_context_success_cb_t cb
,
274 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
276 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->state
== PA_CONTEXT_READY
, PA_ERR_BADSTATE
);
277 PA_CHECK_VALIDITY_RETURN_NULL(c
, c
->version
>= 14, PA_ERR_NOTSUPPORTED
);
279 o
= pa_operation_new(c
, NULL
, (pa_operation_cb_t
) cb
, userdata
);
281 t
= pa_tagstruct_command(c
, PA_COMMAND_EXTENSION
, &tag
);
282 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
283 pa_tagstruct_puts(t
, "module-stream-restore");
284 pa_tagstruct_putu32(t
, SUBCOMMAND_SUBSCRIBE
);
285 pa_tagstruct_put_boolean(t
, enable
);
286 pa_pstream_send_tagstruct(c
->pstream
, t
);
287 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
);
292 void pa_ext_stream_restore_set_subscribe_cb(
294 pa_ext_stream_restore_subscribe_cb_t cb
,
298 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
300 c
->ext_stream_restore
.callback
= cb
;
301 c
->ext_stream_restore
.userdata
= userdata
;
304 void pa_ext_stream_restore_command(pa_context
*c
, uint32_t tag
, pa_tagstruct
*t
) {
308 pa_assert(PA_REFCNT_VALUE(c
) >= 1);
311 if (pa_tagstruct_getu32(t
, &subcommand
) < 0 ||
312 !pa_tagstruct_eof(t
)) {
314 pa_context_fail(c
, PA_ERR_PROTOCOL
);
318 if (subcommand
!= SUBCOMMAND_EVENT
) {
319 pa_context_fail(c
, PA_ERR_PROTOCOL
);
323 if (c
->ext_stream_restore
.callback
)
324 c
->ext_stream_restore
.callback(c
, c
->ext_stream_restore
.userdata
);