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
28 #include "polyplib-introspect.h"
29 #include "polyplib-context.h"
30 #include "polyplib-internal.h"
31 #include "pstream-util.h"
35 static void context_stat_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
36 struct pa_operation
*o
= userdata
;
37 struct pa_stat_info i
, *p
= &i
;
38 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
40 if (command
!= PA_COMMAND_REPLY
) {
41 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
45 } else if (pa_tagstruct_getu32(t
, &i
.memblock_total
) < 0 ||
46 pa_tagstruct_getu32(t
, &i
.memblock_total_size
) < 0 ||
47 pa_tagstruct_getu32(t
, &i
.memblock_allocated
) < 0 ||
48 pa_tagstruct_getu32(t
, &i
.memblock_allocated_size
) < 0 ||
49 pa_tagstruct_getu32(t
, &i
.scache_size
) < 0 ||
50 !pa_tagstruct_eof(t
)) {
51 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
56 void (*cb
)(struct pa_context
*s
, const struct pa_stat_info
*i
, void *userdata
) = o
->callback
;
57 cb(o
->context
, p
, o
->userdata
);
62 pa_operation_unref(o
);
65 struct pa_operation
* pa_context_stat(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_stat_info
*i
, void *userdata
), void *userdata
) {
66 return pa_context_send_simple_command(c
, PA_COMMAND_STAT
, context_stat_callback
, cb
, userdata
);
71 static void context_get_server_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
72 struct pa_operation
*o
= userdata
;
73 struct pa_server_info i
, *p
= &i
;
74 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
76 if (command
!= PA_COMMAND_REPLY
) {
77 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
81 } else if (pa_tagstruct_gets(t
, &i
.server_name
) < 0 ||
82 pa_tagstruct_gets(t
, &i
.server_version
) < 0 ||
83 pa_tagstruct_gets(t
, &i
.user_name
) < 0 ||
84 pa_tagstruct_gets(t
, &i
.host_name
) < 0 ||
85 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
86 pa_tagstruct_gets(t
, &i
.default_sink_name
) < 0 ||
87 pa_tagstruct_gets(t
, &i
.default_source_name
) < 0 ||
88 !pa_tagstruct_eof(t
)) {
90 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
95 void (*cb
)(struct pa_context
*s
, const struct pa_server_info
*i
, void *userdata
) = o
->callback
;
96 cb(o
->context
, p
, o
->userdata
);
100 pa_operation_done(o
);
101 pa_operation_unref(o
);
104 struct pa_operation
* pa_context_get_server_info(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_server_info
*i
, void *userdata
), void *userdata
) {
105 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SERVER_INFO
, context_get_server_info_callback
, cb
, userdata
);
110 static void context_get_sink_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
111 struct pa_operation
*o
= userdata
;
113 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
115 if (command
!= PA_COMMAND_REPLY
) {
116 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
122 while (!pa_tagstruct_eof(t
)) {
123 struct pa_sink_info i
;
125 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
126 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
127 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
128 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
129 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
130 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
131 pa_tagstruct_getu32(t
, &i
.monitor_source
) < 0 ||
132 pa_tagstruct_gets(t
, &i
.monitor_source_name
) < 0 ||
133 pa_tagstruct_get_usec(t
, &i
.latency
) < 0) {
134 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
139 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
140 cb(o
->context
, &i
, 0, o
->userdata
);
146 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
147 cb(o
->context
, NULL
, eof
, o
->userdata
);
151 pa_operation_done(o
);
152 pa_operation_unref(o
);
155 struct pa_operation
* pa_context_get_sink_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_info
*i
, int is_last
, void *userdata
), void *userdata
) {
156 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INFO_LIST
, context_get_sink_info_callback
, cb
, userdata
);
159 struct pa_operation
* pa_context_get_sink_info_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_info
*i
, int is_last
, void *userdata
), void *userdata
) {
160 struct pa_tagstruct
*t
;
161 struct pa_operation
*o
;
165 o
= pa_operation_new(c
, NULL
);
167 o
->userdata
= userdata
;
169 t
= pa_tagstruct_new(NULL
, 0);
170 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INFO
);
171 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
172 pa_tagstruct_putu32(t
, index
);
173 pa_tagstruct_puts(t
, "");
174 pa_pstream_send_tagstruct(c
->pstream
, t
);
175 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, o
);
177 return pa_operation_ref(o
);
180 struct pa_operation
* pa_context_get_sink_info_by_name(struct pa_context
*c
, const char *name
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_info
*i
, int is_last
, void *userdata
), void *userdata
) {
181 struct pa_tagstruct
*t
;
182 struct pa_operation
*o
;
186 o
= pa_operation_new(c
, NULL
);
188 o
->userdata
= userdata
;
190 t
= pa_tagstruct_new(NULL
, 0);
191 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INFO
);
192 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
193 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
194 pa_tagstruct_puts(t
, name
);
195 pa_pstream_send_tagstruct(c
->pstream
, t
);
196 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, o
);
198 return pa_operation_ref(o
);
201 /*** Source info ***/
203 static void context_get_source_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
204 struct pa_operation
*o
= userdata
;
206 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
208 if (command
!= PA_COMMAND_REPLY
) {
209 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
215 while (!pa_tagstruct_eof(t
)) {
216 struct pa_source_info i
;
218 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
219 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
220 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
221 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
222 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
223 pa_tagstruct_getu32(t
, &i
.monitor_of_sink
) < 0 ||
224 pa_tagstruct_gets(t
, &i
.monitor_of_sink_name
) < 0 ||
225 pa_tagstruct_get_usec(t
, &i
.latency
) < 0) {
227 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
232 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
233 cb(o
->context
, &i
, 0, o
->userdata
);
239 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
240 cb(o
->context
, NULL
, eof
, o
->userdata
);
244 pa_operation_done(o
);
245 pa_operation_unref(o
);
248 struct pa_operation
* pa_context_get_source_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_source_info
*i
, int is_last
, void *userdata
), void *userdata
) {
249 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_INFO_LIST
, context_get_source_info_callback
, cb
, userdata
);
252 struct pa_operation
* pa_context_get_source_info_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_source_info
*i
, int is_last
, void *userdata
), void *userdata
) {
253 struct pa_tagstruct
*t
;
254 struct pa_operation
*o
;
258 o
= pa_operation_new(c
, NULL
);
260 o
->userdata
= userdata
;
262 t
= pa_tagstruct_new(NULL
, 0);
263 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_INFO
);
264 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
265 pa_tagstruct_putu32(t
, index
);
266 pa_tagstruct_puts(t
, "");
267 pa_pstream_send_tagstruct(c
->pstream
, t
);
268 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, o
);
270 return pa_operation_ref(o
);
273 struct pa_operation
* pa_context_get_source_info_by_name(struct pa_context
*c
, const char *name
, void (*cb
)(struct pa_context
*c
, const struct pa_source_info
*i
, int is_last
, void *userdata
), void *userdata
) {
274 struct pa_tagstruct
*t
;
275 struct pa_operation
*o
;
279 o
= pa_operation_new(c
, NULL
);
281 o
->userdata
= userdata
;
283 t
= pa_tagstruct_new(NULL
, 0);
284 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_INFO
);
285 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
286 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
287 pa_tagstruct_puts(t
, name
);
288 pa_pstream_send_tagstruct(c
->pstream
, t
);
289 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, o
);
291 return pa_operation_ref(o
);
294 /*** Client info ***/
296 static void context_get_client_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
297 struct pa_operation
*o
= userdata
;
299 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
301 if (command
!= PA_COMMAND_REPLY
) {
302 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
308 while (!pa_tagstruct_eof(t
)) {
309 struct pa_client_info i
;
311 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
312 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
313 pa_tagstruct_gets(t
, &i
.protocol_name
) < 0 ||
314 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0) {
315 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
320 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
321 cb(o
->context
, &i
, 0, o
->userdata
);
327 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
328 cb(o
->context
, NULL
, eof
, o
->userdata
);
332 pa_operation_done(o
);
333 pa_operation_unref(o
);
336 struct pa_operation
* pa_context_get_client_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_client_info
*i
, int is_last
, void *userdata
), void *userdata
) {
337 struct pa_tagstruct
*t
;
338 struct pa_operation
*o
;
342 o
= pa_operation_new(c
, NULL
);
344 o
->userdata
= userdata
;
346 t
= pa_tagstruct_new(NULL
, 0);
347 pa_tagstruct_putu32(t
, PA_COMMAND_GET_CLIENT_INFO
);
348 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
349 pa_tagstruct_putu32(t
, index
);
350 pa_pstream_send_tagstruct(c
->pstream
, t
);
351 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_client_info_callback
, o
);
353 return pa_operation_ref(o
);
356 struct pa_operation
* pa_context_get_client_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_client_info
*i
, int is_last
, void *userdata
), void *userdata
) {
357 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CLIENT_INFO_LIST
, context_get_client_info_callback
, cb
, userdata
);
360 /*** Module info ***/
362 static void context_get_module_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
363 struct pa_operation
*o
= userdata
;
365 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
367 if (command
!= PA_COMMAND_REPLY
) {
368 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
374 while (!pa_tagstruct_eof(t
)) {
375 struct pa_module_info i
;
377 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
378 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
379 pa_tagstruct_gets(t
, &i
.argument
) < 0 ||
380 pa_tagstruct_getu32(t
, &i
.n_used
) < 0 ||
381 pa_tagstruct_get_boolean(t
, &i
.auto_unload
) < 0) {
382 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
387 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
388 cb(o
->context
, &i
, 0, o
->userdata
);
394 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
395 cb(o
->context
, NULL
, eof
, o
->userdata
);
399 pa_operation_done(o
);
400 pa_operation_unref(o
);
403 struct pa_operation
* pa_context_get_module_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_module_info
*i
, int is_last
, void *userdata
), void *userdata
) {
404 struct pa_tagstruct
*t
;
405 struct pa_operation
*o
;
409 o
= pa_operation_new(c
, NULL
);
411 o
->userdata
= userdata
;
413 t
= pa_tagstruct_new(NULL
, 0);
414 pa_tagstruct_putu32(t
, PA_COMMAND_GET_MODULE_INFO
);
415 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
416 pa_tagstruct_putu32(t
, index
);
417 pa_pstream_send_tagstruct(c
->pstream
, t
);
418 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_module_info_callback
, o
);
420 return pa_operation_ref(o
);
423 struct pa_operation
* pa_context_get_module_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_module_info
*i
, int is_last
, void *userdata
), void *userdata
) {
424 return pa_context_send_simple_command(c
, PA_COMMAND_GET_MODULE_INFO_LIST
, context_get_module_info_callback
, cb
, userdata
);
427 /*** Sink input info ***/
429 static void context_get_sink_input_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
430 struct pa_operation
*o
= userdata
;
432 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
434 if (command
!= PA_COMMAND_REPLY
) {
435 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
441 while (!pa_tagstruct_eof(t
)) {
442 struct pa_sink_input_info i
;
444 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
445 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
446 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
447 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
448 pa_tagstruct_getu32(t
, &i
.sink
) < 0 ||
449 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
450 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
451 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
452 pa_tagstruct_get_usec(t
, &i
.sink_usec
) < 0) {
453 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
458 void (*cb
)(struct pa_context
*s
, const struct pa_sink_input_info
*i
, int eof
, void *userdata
) = o
->callback
;
459 cb(o
->context
, &i
, 0, o
->userdata
);
465 void (*cb
)(struct pa_context
*s
, const struct pa_sink_input_info
*i
, int eof
, void *userdata
) = o
->callback
;
466 cb(o
->context
, NULL
, eof
, o
->userdata
);
470 pa_operation_done(o
);
471 pa_operation_unref(o
);
474 struct pa_operation
* pa_context_get_sink_input_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_input_info
*i
, int is_last
, void *userdata
), void *userdata
) {
475 struct pa_tagstruct
*t
;
476 struct pa_operation
*o
;
480 o
= pa_operation_new(c
, NULL
);
482 o
->userdata
= userdata
;
484 t
= pa_tagstruct_new(NULL
, 0);
485 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INPUT_INFO
);
486 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
487 pa_tagstruct_putu32(t
, index
);
488 pa_pstream_send_tagstruct(c
->pstream
, t
);
489 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_input_info_callback
, o
);
491 return pa_operation_ref(o
);
494 struct pa_operation
* pa_context_get_sink_input_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_sink_input_info
*i
, int is_last
, void *userdata
), void *userdata
) {
495 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INPUT_INFO_LIST
, context_get_sink_input_info_callback
, cb
, userdata
);
498 /*** Source output info ***/
500 static void context_get_source_output_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
501 struct pa_operation
*o
= userdata
;
503 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
505 if (command
!= PA_COMMAND_REPLY
) {
506 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
512 while (!pa_tagstruct_eof(t
)) {
513 struct pa_source_output_info i
;
515 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
516 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
517 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
518 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
519 pa_tagstruct_getu32(t
, &i
.source
) < 0 ||
520 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
521 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
522 pa_tagstruct_get_usec(t
, &i
.source_usec
) < 0) {
523 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
528 void (*cb
)(struct pa_context
*s
, const struct pa_source_output_info
*i
, int eof
, void *userdata
) = o
->callback
;
529 cb(o
->context
, &i
, 0, o
->userdata
);
535 void (*cb
)(struct pa_context
*s
, const struct pa_source_output_info
*i
, int eof
, void *userdata
) = o
->callback
;
536 cb(o
->context
, NULL
, eof
, o
->userdata
);
540 pa_operation_done(o
);
541 pa_operation_unref(o
);
544 struct pa_operation
* pa_context_get_source_output_info(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_source_output_info
*i
, int is_last
, void *userdata
), void *userdata
) {
545 struct pa_tagstruct
*t
;
546 struct pa_operation
*o
;
550 o
= pa_operation_new(c
, NULL
);
552 o
->userdata
= userdata
;
554 t
= pa_tagstruct_new(NULL
, 0);
555 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO
);
556 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
557 pa_tagstruct_putu32(t
, index
);
558 pa_pstream_send_tagstruct(c
->pstream
, t
);
559 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_output_info_callback
, o
);
561 return pa_operation_ref(o
);
564 struct pa_operation
* pa_context_get_source_output_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_source_output_info
*i
, int is_last
, void *userdata
), void *userdata
) {
565 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
, context_get_source_output_info_callback
, cb
, userdata
);
568 /*** Volume manipulation ***/
570 struct pa_operation
* pa_context_set_sink_volume_by_index(struct pa_context
*c
, uint32_t index
, pa_volume_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
571 struct pa_operation
*o
;
572 struct pa_tagstruct
*t
;
574 assert(c
&& index
!= PA_INVALID_INDEX
);
576 o
= pa_operation_new(c
, NULL
);
578 o
->userdata
= userdata
;
580 t
= pa_tagstruct_new(NULL
, 0);
581 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
582 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
583 pa_tagstruct_putu32(t
, index
);
584 pa_tagstruct_puts(t
, "");
585 pa_tagstruct_putu32(t
, volume
);
586 pa_pstream_send_tagstruct(c
->pstream
, t
);
587 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
589 return pa_operation_ref(o
);
592 struct pa_operation
* pa_context_set_sink_volume_by_name(struct pa_context
*c
, const char *name
, pa_volume_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
593 struct pa_operation
*o
;
594 struct pa_tagstruct
*t
;
598 o
= pa_operation_new(c
, NULL
);
600 o
->userdata
= userdata
;
602 t
= pa_tagstruct_new(NULL
, 0);
603 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
604 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
605 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
606 pa_tagstruct_puts(t
, name
);
607 pa_tagstruct_putu32(t
, volume
);
608 pa_pstream_send_tagstruct(c
->pstream
, t
);
609 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
611 return pa_operation_ref(o
);
614 struct pa_operation
* pa_context_set_sink_input_volume(struct pa_context
*c
, uint32_t index
, pa_volume_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
615 struct pa_operation
*o
;
616 struct pa_tagstruct
*t
;
618 assert(c
&& index
!= PA_INVALID_INDEX
);
620 o
= pa_operation_new(c
, NULL
);
622 o
->userdata
= userdata
;
624 t
= pa_tagstruct_new(NULL
, 0);
625 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_INPUT_VOLUME
);
626 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
627 pa_tagstruct_putu32(t
, index
);
628 pa_tagstruct_putu32(t
, volume
);
629 pa_pstream_send_tagstruct(c
->pstream
, t
);
630 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
632 return pa_operation_ref(o
);
637 static void context_get_sample_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
638 struct pa_operation
*o
= userdata
;
640 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
642 if (command
!= PA_COMMAND_REPLY
) {
643 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
649 while (!pa_tagstruct_eof(t
)) {
650 struct pa_sample_info i
;
652 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
653 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
654 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
655 pa_tagstruct_get_usec(t
, &i
.duration
) < 0 ||
656 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
657 pa_tagstruct_getu32(t
, &i
.bytes
) < 0 ||
658 pa_tagstruct_get_boolean(t
, &i
.lazy
) < 0 ||
659 pa_tagstruct_gets(t
, &i
.filename
) < 0) {
660 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
665 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
666 cb(o
->context
, &i
, 0, o
->userdata
);
672 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
673 cb(o
->context
, NULL
, eof
, o
->userdata
);
677 pa_operation_done(o
);
678 pa_operation_unref(o
);
681 struct pa_operation
* pa_context_get_sample_info_by_name(struct pa_context
*c
, const char *name
, void (*cb
)(struct pa_context
*c
, const struct pa_sample_info
*i
, int is_last
, void *userdata
), void *userdata
) {
682 struct pa_tagstruct
*t
;
683 struct pa_operation
*o
;
685 assert(c
&& cb
&& name
);
687 o
= pa_operation_new(c
, NULL
);
689 o
->userdata
= userdata
;
691 t
= pa_tagstruct_new(NULL
, 0);
692 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
693 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
694 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
695 pa_tagstruct_puts(t
, name
);
696 pa_pstream_send_tagstruct(c
->pstream
, t
);
697 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
699 return pa_operation_ref(o
);
702 struct pa_operation
* pa_context_get_sample_info_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_sample_info
*i
, int is_last
, void *userdata
), void *userdata
) {
703 struct pa_tagstruct
*t
;
704 struct pa_operation
*o
;
708 o
= pa_operation_new(c
, NULL
);
710 o
->userdata
= userdata
;
712 t
= pa_tagstruct_new(NULL
, 0);
713 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
714 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
715 pa_tagstruct_putu32(t
, index
);
716 pa_tagstruct_puts(t
, "");
717 pa_pstream_send_tagstruct(c
->pstream
, t
);
718 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
720 return pa_operation_ref(o
);
723 struct pa_operation
* pa_context_get_sample_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_sample_info
*i
, int is_last
, void *userdata
), void *userdata
) {
724 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, cb
, userdata
);
727 static struct pa_operation
* command_kill(struct pa_context
*c
, uint32_t command
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
728 struct pa_operation
*o
;
729 struct pa_tagstruct
*t
;
731 assert(c
&& index
!= PA_INVALID_INDEX
);
733 o
= pa_operation_new(c
, NULL
);
735 o
->userdata
= userdata
;
737 t
= pa_tagstruct_new(NULL
, 0);
738 pa_tagstruct_putu32(t
, command
);
739 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
740 pa_tagstruct_putu32(t
, index
);
741 pa_pstream_send_tagstruct(c
->pstream
, t
);
742 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
744 return pa_operation_ref(o
);
747 struct pa_operation
* pa_context_kill_client(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
748 return command_kill(c
, PA_COMMAND_KILL_CLIENT
, index
, cb
, userdata
);
751 struct pa_operation
* pa_context_kill_sink_input(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
752 return command_kill(c
, PA_COMMAND_KILL_SINK_INPUT
, index
, cb
, userdata
);
755 struct pa_operation
* pa_context_kill_source_output(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
756 return command_kill(c
, PA_COMMAND_KILL_SOURCE_OUTPUT
, index
, cb
, userdata
);
759 static void load_module_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
760 struct pa_operation
*o
= userdata
;
762 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
764 if (command
!= PA_COMMAND_REPLY
) {
765 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
768 } else if (pa_tagstruct_getu32(t
, &index
) < 0 ||
769 !pa_tagstruct_eof(t
)) {
770 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
775 void (*cb
)(struct pa_context
*c
, uint32_t index
, void *userdata
) = o
->callback
;
776 cb(o
->context
, index
, o
->userdata
);
780 pa_operation_done(o
);
781 pa_operation_unref(o
);
784 struct pa_operation
* pa_context_load_module(struct pa_context
*c
, const char*name
, const char *argument
, void (*cb
)(struct pa_context
*c
, uint32_t index
, void *userdata
), void *userdata
) {
785 struct pa_operation
*o
;
786 struct pa_tagstruct
*t
;
788 assert(c
&& name
&& argument
);
790 o
= pa_operation_new(c
, NULL
);
792 o
->userdata
= userdata
;
794 t
= pa_tagstruct_new(NULL
, 0);
795 pa_tagstruct_putu32(t
, PA_COMMAND_LOAD_MODULE
);
796 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
797 pa_tagstruct_puts(t
, name
);
798 pa_tagstruct_puts(t
, argument
);
799 pa_pstream_send_tagstruct(c
->pstream
, t
);
800 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, load_module_callback
, o
);
802 return pa_operation_ref(o
);
805 struct pa_operation
* pa_context_unload_module(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
806 return command_kill(c
, PA_COMMAND_UNLOAD_MODULE
, index
, cb
, userdata
);
809 /*** Autoload stuff ***/
811 static void context_get_autoload_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
812 struct pa_operation
*o
= userdata
;
814 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
816 if (command
!= PA_COMMAND_REPLY
) {
817 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
823 while (!pa_tagstruct_eof(t
)) {
824 struct pa_autoload_info i
;
826 if (pa_tagstruct_gets(t
, &i
.name
) < 0 ||
827 pa_tagstruct_getu32(t
, &i
.type
) < 0 ||
828 pa_tagstruct_gets(t
, &i
.module
) < 0 ||
829 pa_tagstruct_gets(t
, &i
.argument
) < 0) {
830 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
835 void (*cb
)(struct pa_context
*s
, const struct pa_autoload_info
*i
, int eof
, void *userdata
) = o
->callback
;
836 cb(o
->context
, &i
, 0, o
->userdata
);
842 void (*cb
)(struct pa_context
*s
, const struct pa_autoload_info
*i
, int eof
, void *userdata
) = o
->callback
;
843 cb(o
->context
, NULL
, eof
, o
->userdata
);
847 pa_operation_done(o
);
848 pa_operation_unref(o
);
851 struct pa_operation
* pa_context_get_autoload_info(struct pa_context
*c
, const char *name
, enum pa_autoload_type type
, void (*cb
)(struct pa_context
*c
, const struct pa_autoload_info
*i
, int is_last
, void *userdata
), void *userdata
) {
852 struct pa_tagstruct
*t
;
853 struct pa_operation
*o
;
855 assert(c
&& cb
&& name
);
857 o
= pa_operation_new(c
, NULL
);
859 o
->userdata
= userdata
;
861 t
= pa_tagstruct_new(NULL
, 0);
862 pa_tagstruct_putu32(t
, PA_COMMAND_GET_AUTOLOAD_INFO
);
863 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
864 pa_tagstruct_puts(t
, name
);
865 pa_tagstruct_putu32(t
, type
);
866 pa_pstream_send_tagstruct(c
->pstream
, t
);
867 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_autoload_info_callback
, o
);
869 return pa_operation_ref(o
);
872 struct pa_operation
* pa_context_get_autoload_info_list(struct pa_context
*c
, void (*cb
)(struct pa_context
*c
, const struct pa_autoload_info
*i
, int is_last
, void *userdata
), void *userdata
) {
873 return pa_context_send_simple_command(c
, PA_COMMAND_GET_AUTOLOAD_INFO_LIST
, context_get_autoload_info_callback
, cb
, userdata
);
876 struct pa_operation
* pa_context_add_autoload(struct pa_context
*c
, const char *name
, enum pa_autoload_type type
, const char *module
, const char*argument
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void* userdata
) {
877 struct pa_operation
*o
;
878 struct pa_tagstruct
*t
;
880 assert(c
&& name
&& module
&& argument
);
882 o
= pa_operation_new(c
, NULL
);
884 o
->userdata
= userdata
;
886 t
= pa_tagstruct_new(NULL
, 0);
887 pa_tagstruct_putu32(t
, PA_COMMAND_ADD_AUTOLOAD
);
888 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
889 pa_tagstruct_puts(t
, name
);
890 pa_tagstruct_putu32(t
, type
);
891 pa_tagstruct_puts(t
, module
);
892 pa_tagstruct_puts(t
, argument
);
893 pa_pstream_send_tagstruct(c
->pstream
, t
);
894 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
896 return pa_operation_ref(o
);
899 struct pa_operation
* pa_context_remove_autoload(struct pa_context
*c
, const char *name
, enum pa_autoload_type type
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void* userdata
) {
900 struct pa_operation
*o
;
901 struct pa_tagstruct
*t
;
905 o
= pa_operation_new(c
, NULL
);
907 o
->userdata
= userdata
;
909 t
= pa_tagstruct_new(NULL
, 0);
910 pa_tagstruct_putu32(t
, PA_COMMAND_REMOVE_AUTOLOAD
);
911 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
912 pa_tagstruct_puts(t
, name
);
913 pa_tagstruct_putu32(t
, type
);
914 pa_pstream_send_tagstruct(c
->pstream
, t
);
915 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
917 return pa_operation_ref(o
);