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
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_getu32(t
, &i
.cookie
) < 0 ||
89 !pa_tagstruct_eof(t
)) {
91 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
96 void (*cb
)(struct pa_context
*s
, const struct pa_server_info
*i
, void *userdata
) = o
->callback
;
97 cb(o
->context
, p
, o
->userdata
);
101 pa_operation_done(o
);
102 pa_operation_unref(o
);
105 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
) {
106 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SERVER_INFO
, context_get_server_info_callback
, cb
, userdata
);
111 static void context_get_sink_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
112 struct pa_operation
*o
= userdata
;
114 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
116 if (command
!= PA_COMMAND_REPLY
) {
117 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
123 while (!pa_tagstruct_eof(t
)) {
124 struct pa_sink_info i
;
126 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
127 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
128 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
129 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
130 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
131 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
132 pa_tagstruct_getu32(t
, &i
.monitor_source
) < 0 ||
133 pa_tagstruct_gets(t
, &i
.monitor_source_name
) < 0 ||
134 pa_tagstruct_get_usec(t
, &i
.latency
) < 0 ||
135 pa_tagstruct_getu32(t
, &i
._typeid
) < 0) {
137 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
142 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
143 cb(o
->context
, &i
, 0, o
->userdata
);
149 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
150 cb(o
->context
, NULL
, eof
, o
->userdata
);
154 pa_operation_done(o
);
155 pa_operation_unref(o
);
158 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
) {
159 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INFO_LIST
, context_get_sink_info_callback
, cb
, userdata
);
162 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
) {
163 struct pa_tagstruct
*t
;
164 struct pa_operation
*o
;
168 o
= pa_operation_new(c
, NULL
);
170 o
->userdata
= userdata
;
172 t
= pa_tagstruct_new(NULL
, 0);
173 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INFO
);
174 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
175 pa_tagstruct_putu32(t
, index
);
176 pa_tagstruct_puts(t
, NULL
);
177 pa_pstream_send_tagstruct(c
->pstream
, t
);
178 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, o
);
180 return pa_operation_ref(o
);
183 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
) {
184 struct pa_tagstruct
*t
;
185 struct pa_operation
*o
;
189 o
= pa_operation_new(c
, NULL
);
191 o
->userdata
= userdata
;
193 t
= pa_tagstruct_new(NULL
, 0);
194 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INFO
);
195 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
196 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
197 pa_tagstruct_puts(t
, name
);
198 pa_pstream_send_tagstruct(c
->pstream
, t
);
199 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, o
);
201 return pa_operation_ref(o
);
204 /*** Source info ***/
206 static void context_get_source_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
207 struct pa_operation
*o
= userdata
;
209 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
211 if (command
!= PA_COMMAND_REPLY
) {
212 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
218 while (!pa_tagstruct_eof(t
)) {
219 struct pa_source_info i
;
221 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
222 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
223 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
224 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
225 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
226 pa_tagstruct_getu32(t
, &i
.monitor_of_sink
) < 0 ||
227 pa_tagstruct_gets(t
, &i
.monitor_of_sink_name
) < 0 ||
228 pa_tagstruct_get_usec(t
, &i
.latency
) < 0 ||
229 pa_tagstruct_getu32(t
, &i
._typeid
) < 0) {
231 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
236 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
237 cb(o
->context
, &i
, 0, o
->userdata
);
243 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
244 cb(o
->context
, NULL
, eof
, o
->userdata
);
248 pa_operation_done(o
);
249 pa_operation_unref(o
);
252 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
) {
253 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_INFO_LIST
, context_get_source_info_callback
, cb
, userdata
);
256 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
) {
257 struct pa_tagstruct
*t
;
258 struct pa_operation
*o
;
262 o
= pa_operation_new(c
, NULL
);
264 o
->userdata
= userdata
;
266 t
= pa_tagstruct_new(NULL
, 0);
267 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_INFO
);
268 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
269 pa_tagstruct_putu32(t
, index
);
270 pa_tagstruct_puts(t
, NULL
);
271 pa_pstream_send_tagstruct(c
->pstream
, t
);
272 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, o
);
274 return pa_operation_ref(o
);
277 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
) {
278 struct pa_tagstruct
*t
;
279 struct pa_operation
*o
;
283 o
= pa_operation_new(c
, NULL
);
285 o
->userdata
= userdata
;
287 t
= pa_tagstruct_new(NULL
, 0);
288 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_INFO
);
289 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
290 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
291 pa_tagstruct_puts(t
, name
);
292 pa_pstream_send_tagstruct(c
->pstream
, t
);
293 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, o
);
295 return pa_operation_ref(o
);
298 /*** Client info ***/
300 static void context_get_client_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
301 struct pa_operation
*o
= userdata
;
303 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
305 if (command
!= PA_COMMAND_REPLY
) {
306 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
312 while (!pa_tagstruct_eof(t
)) {
313 struct pa_client_info i
;
315 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
316 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
317 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
318 pa_tagstruct_getu32(t
, &i
._typeid
) < 0 ) {
319 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
324 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
325 cb(o
->context
, &i
, 0, o
->userdata
);
331 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
332 cb(o
->context
, NULL
, eof
, o
->userdata
);
336 pa_operation_done(o
);
337 pa_operation_unref(o
);
340 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
) {
341 struct pa_tagstruct
*t
;
342 struct pa_operation
*o
;
346 o
= pa_operation_new(c
, NULL
);
348 o
->userdata
= userdata
;
350 t
= pa_tagstruct_new(NULL
, 0);
351 pa_tagstruct_putu32(t
, PA_COMMAND_GET_CLIENT_INFO
);
352 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
353 pa_tagstruct_putu32(t
, index
);
354 pa_pstream_send_tagstruct(c
->pstream
, t
);
355 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_client_info_callback
, o
);
357 return pa_operation_ref(o
);
360 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
) {
361 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CLIENT_INFO_LIST
, context_get_client_info_callback
, cb
, userdata
);
364 /*** Module info ***/
366 static void context_get_module_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
367 struct pa_operation
*o
= userdata
;
369 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
371 if (command
!= PA_COMMAND_REPLY
) {
372 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
378 while (!pa_tagstruct_eof(t
)) {
379 struct pa_module_info i
;
381 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
382 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
383 pa_tagstruct_gets(t
, &i
.argument
) < 0 ||
384 pa_tagstruct_getu32(t
, &i
.n_used
) < 0 ||
385 pa_tagstruct_get_boolean(t
, &i
.auto_unload
) < 0) {
386 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
391 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
392 cb(o
->context
, &i
, 0, o
->userdata
);
398 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
399 cb(o
->context
, NULL
, eof
, o
->userdata
);
403 pa_operation_done(o
);
404 pa_operation_unref(o
);
407 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
) {
408 struct pa_tagstruct
*t
;
409 struct pa_operation
*o
;
413 o
= pa_operation_new(c
, NULL
);
415 o
->userdata
= userdata
;
417 t
= pa_tagstruct_new(NULL
, 0);
418 pa_tagstruct_putu32(t
, PA_COMMAND_GET_MODULE_INFO
);
419 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
420 pa_tagstruct_putu32(t
, index
);
421 pa_pstream_send_tagstruct(c
->pstream
, t
);
422 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_module_info_callback
, o
);
424 return pa_operation_ref(o
);
427 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
) {
428 return pa_context_send_simple_command(c
, PA_COMMAND_GET_MODULE_INFO_LIST
, context_get_module_info_callback
, cb
, userdata
);
431 /*** Sink input info ***/
433 static void context_get_sink_input_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
434 struct pa_operation
*o
= userdata
;
436 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
438 if (command
!= PA_COMMAND_REPLY
) {
439 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
445 while (!pa_tagstruct_eof(t
)) {
446 struct pa_sink_input_info i
;
448 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
449 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
450 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
451 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
452 pa_tagstruct_getu32(t
, &i
.sink
) < 0 ||
453 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
454 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
455 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
456 pa_tagstruct_get_usec(t
, &i
.sink_usec
) < 0 ||
457 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
458 pa_tagstruct_getu32(t
, &i
._typeid
) < 0) {
460 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
465 void (*cb
)(struct pa_context
*s
, const struct pa_sink_input_info
*i
, int eof
, void *userdata
) = o
->callback
;
466 cb(o
->context
, &i
, 0, o
->userdata
);
472 void (*cb
)(struct pa_context
*s
, const struct pa_sink_input_info
*i
, int eof
, void *userdata
) = o
->callback
;
473 cb(o
->context
, NULL
, eof
, o
->userdata
);
477 pa_operation_done(o
);
478 pa_operation_unref(o
);
481 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
) {
482 struct pa_tagstruct
*t
;
483 struct pa_operation
*o
;
487 o
= pa_operation_new(c
, NULL
);
489 o
->userdata
= userdata
;
491 t
= pa_tagstruct_new(NULL
, 0);
492 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INPUT_INFO
);
493 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
494 pa_tagstruct_putu32(t
, index
);
495 pa_pstream_send_tagstruct(c
->pstream
, t
);
496 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_input_info_callback
, o
);
498 return pa_operation_ref(o
);
501 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
) {
502 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INPUT_INFO_LIST
, context_get_sink_input_info_callback
, cb
, userdata
);
505 /*** Source output info ***/
507 static void context_get_source_output_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
508 struct pa_operation
*o
= userdata
;
510 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
512 if (command
!= PA_COMMAND_REPLY
) {
513 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
519 while (!pa_tagstruct_eof(t
)) {
520 struct pa_source_output_info i
;
522 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
523 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
524 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
525 pa_tagstruct_getu32(t
, &i
.client
) < 0 ||
526 pa_tagstruct_getu32(t
, &i
.source
) < 0 ||
527 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
528 pa_tagstruct_get_usec(t
, &i
.buffer_usec
) < 0 ||
529 pa_tagstruct_get_usec(t
, &i
.source_usec
) < 0 ||
530 pa_tagstruct_gets(t
, &i
.resample_method
) < 0 ||
531 pa_tagstruct_getu32(t
, &i
._typeid
) < 0) {
533 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
538 void (*cb
)(struct pa_context
*s
, const struct pa_source_output_info
*i
, int eof
, void *userdata
) = o
->callback
;
539 cb(o
->context
, &i
, 0, o
->userdata
);
545 void (*cb
)(struct pa_context
*s
, const struct pa_source_output_info
*i
, int eof
, void *userdata
) = o
->callback
;
546 cb(o
->context
, NULL
, eof
, o
->userdata
);
550 pa_operation_done(o
);
551 pa_operation_unref(o
);
554 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
) {
555 struct pa_tagstruct
*t
;
556 struct pa_operation
*o
;
560 o
= pa_operation_new(c
, NULL
);
562 o
->userdata
= userdata
;
564 t
= pa_tagstruct_new(NULL
, 0);
565 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO
);
566 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
567 pa_tagstruct_putu32(t
, index
);
568 pa_pstream_send_tagstruct(c
->pstream
, t
);
569 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_output_info_callback
, o
);
571 return pa_operation_ref(o
);
574 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
) {
575 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST
, context_get_source_output_info_callback
, cb
, userdata
);
578 /*** Volume manipulation ***/
580 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
) {
581 struct pa_operation
*o
;
582 struct pa_tagstruct
*t
;
584 assert(c
&& index
!= PA_INVALID_INDEX
);
586 o
= pa_operation_new(c
, NULL
);
588 o
->userdata
= userdata
;
590 t
= pa_tagstruct_new(NULL
, 0);
591 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
592 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
593 pa_tagstruct_putu32(t
, index
);
594 pa_tagstruct_puts(t
, NULL
);
595 pa_tagstruct_putu32(t
, volume
);
596 pa_pstream_send_tagstruct(c
->pstream
, t
);
597 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
599 return pa_operation_ref(o
);
602 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
) {
603 struct pa_operation
*o
;
604 struct pa_tagstruct
*t
;
608 o
= pa_operation_new(c
, NULL
);
610 o
->userdata
= userdata
;
612 t
= pa_tagstruct_new(NULL
, 0);
613 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
614 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
615 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
616 pa_tagstruct_puts(t
, name
);
617 pa_tagstruct_putu32(t
, volume
);
618 pa_pstream_send_tagstruct(c
->pstream
, t
);
619 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
621 return pa_operation_ref(o
);
624 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
) {
625 struct pa_operation
*o
;
626 struct pa_tagstruct
*t
;
628 assert(c
&& index
!= PA_INVALID_INDEX
);
630 o
= pa_operation_new(c
, NULL
);
632 o
->userdata
= userdata
;
634 t
= pa_tagstruct_new(NULL
, 0);
635 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_INPUT_VOLUME
);
636 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
637 pa_tagstruct_putu32(t
, index
);
638 pa_tagstruct_putu32(t
, volume
);
639 pa_pstream_send_tagstruct(c
->pstream
, t
);
640 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
642 return pa_operation_ref(o
);
647 static void context_get_sample_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
648 struct pa_operation
*o
= userdata
;
650 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
652 if (command
!= PA_COMMAND_REPLY
) {
653 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
659 while (!pa_tagstruct_eof(t
)) {
660 struct pa_sample_info i
;
662 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
663 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
664 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
665 pa_tagstruct_get_usec(t
, &i
.duration
) < 0 ||
666 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
667 pa_tagstruct_getu32(t
, &i
.bytes
) < 0 ||
668 pa_tagstruct_get_boolean(t
, &i
.lazy
) < 0 ||
669 pa_tagstruct_gets(t
, &i
.filename
) < 0) {
671 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
676 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
677 cb(o
->context
, &i
, 0, o
->userdata
);
683 void (*cb
)(struct pa_context
*s
, const struct pa_sample_info
*i
, int eof
, void *userdata
) = o
->callback
;
684 cb(o
->context
, NULL
, eof
, o
->userdata
);
688 pa_operation_done(o
);
689 pa_operation_unref(o
);
692 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
) {
693 struct pa_tagstruct
*t
;
694 struct pa_operation
*o
;
696 assert(c
&& cb
&& name
);
698 o
= pa_operation_new(c
, NULL
);
700 o
->userdata
= userdata
;
702 t
= pa_tagstruct_new(NULL
, 0);
703 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
704 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
705 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
706 pa_tagstruct_puts(t
, name
);
707 pa_pstream_send_tagstruct(c
->pstream
, t
);
708 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
710 return pa_operation_ref(o
);
713 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
) {
714 struct pa_tagstruct
*t
;
715 struct pa_operation
*o
;
719 o
= pa_operation_new(c
, NULL
);
721 o
->userdata
= userdata
;
723 t
= pa_tagstruct_new(NULL
, 0);
724 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SAMPLE_INFO
);
725 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
726 pa_tagstruct_putu32(t
, index
);
727 pa_tagstruct_puts(t
, NULL
);
728 pa_pstream_send_tagstruct(c
->pstream
, t
);
729 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sample_info_callback
, o
);
731 return pa_operation_ref(o
);
734 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
) {
735 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SAMPLE_INFO_LIST
, context_get_sample_info_callback
, cb
, userdata
);
738 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
) {
739 struct pa_operation
*o
;
740 struct pa_tagstruct
*t
;
742 assert(c
&& index
!= PA_INVALID_INDEX
);
744 o
= pa_operation_new(c
, NULL
);
746 o
->userdata
= userdata
;
748 t
= pa_tagstruct_new(NULL
, 0);
749 pa_tagstruct_putu32(t
, command
);
750 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
751 pa_tagstruct_putu32(t
, index
);
752 pa_pstream_send_tagstruct(c
->pstream
, t
);
753 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
755 return pa_operation_ref(o
);
758 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
) {
759 return command_kill(c
, PA_COMMAND_KILL_CLIENT
, index
, cb
, userdata
);
762 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
) {
763 return command_kill(c
, PA_COMMAND_KILL_SINK_INPUT
, index
, cb
, userdata
);
766 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
) {
767 return command_kill(c
, PA_COMMAND_KILL_SOURCE_OUTPUT
, index
, cb
, userdata
);
770 static void load_module_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
771 struct pa_operation
*o
= userdata
;
773 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
775 if (command
!= PA_COMMAND_REPLY
) {
776 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
779 } else if (pa_tagstruct_getu32(t
, &index
) < 0 ||
780 !pa_tagstruct_eof(t
)) {
781 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
786 void (*cb
)(struct pa_context
*c
, uint32_t index
, void *userdata
) = o
->callback
;
787 cb(o
->context
, index
, o
->userdata
);
791 pa_operation_done(o
);
792 pa_operation_unref(o
);
795 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
) {
796 struct pa_operation
*o
;
797 struct pa_tagstruct
*t
;
799 assert(c
&& name
&& argument
);
801 o
= pa_operation_new(c
, NULL
);
803 o
->userdata
= userdata
;
805 t
= pa_tagstruct_new(NULL
, 0);
806 pa_tagstruct_putu32(t
, PA_COMMAND_LOAD_MODULE
);
807 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
808 pa_tagstruct_puts(t
, name
);
809 pa_tagstruct_puts(t
, argument
);
810 pa_pstream_send_tagstruct(c
->pstream
, t
);
811 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, load_module_callback
, o
);
813 return pa_operation_ref(o
);
816 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
) {
817 return command_kill(c
, PA_COMMAND_UNLOAD_MODULE
, index
, cb
, userdata
);
820 /*** Autoload stuff ***/
822 static void context_get_autoload_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
823 struct pa_operation
*o
= userdata
;
825 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
827 if (command
!= PA_COMMAND_REPLY
) {
828 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
834 while (!pa_tagstruct_eof(t
)) {
835 struct pa_autoload_info i
;
837 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
838 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
839 pa_tagstruct_getu32(t
, &i
.type
) < 0 ||
840 pa_tagstruct_gets(t
, &i
.module
) < 0 ||
841 pa_tagstruct_gets(t
, &i
.argument
) < 0) {
842 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
847 void (*cb
)(struct pa_context
*s
, const struct pa_autoload_info
*i
, int eof
, void *userdata
) = o
->callback
;
848 cb(o
->context
, &i
, 0, o
->userdata
);
854 void (*cb
)(struct pa_context
*s
, const struct pa_autoload_info
*i
, int eof
, void *userdata
) = o
->callback
;
855 cb(o
->context
, NULL
, eof
, o
->userdata
);
859 pa_operation_done(o
);
860 pa_operation_unref(o
);
863 struct pa_operation
* pa_context_get_autoload_info_by_name(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
) {
864 struct pa_tagstruct
*t
;
865 struct pa_operation
*o
;
867 assert(c
&& cb
&& name
);
869 o
= pa_operation_new(c
, NULL
);
871 o
->userdata
= userdata
;
873 t
= pa_tagstruct_new(NULL
, 0);
874 pa_tagstruct_putu32(t
, PA_COMMAND_GET_AUTOLOAD_INFO
);
875 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
876 pa_tagstruct_puts(t
, name
);
877 pa_tagstruct_putu32(t
, type
);
878 pa_pstream_send_tagstruct(c
->pstream
, t
);
879 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_autoload_info_callback
, o
);
881 return pa_operation_ref(o
);
884 struct pa_operation
* pa_context_get_autoload_info_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, const struct pa_autoload_info
*i
, int is_last
, void *userdata
), void *userdata
) {
885 struct pa_tagstruct
*t
;
886 struct pa_operation
*o
;
888 assert(c
&& cb
&& index
!= PA_INVALID_INDEX
);
890 o
= pa_operation_new(c
, NULL
);
892 o
->userdata
= userdata
;
894 t
= pa_tagstruct_new(NULL
, 0);
895 pa_tagstruct_putu32(t
, PA_COMMAND_GET_AUTOLOAD_INFO
);
896 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
897 pa_tagstruct_putu32(t
, index
);
898 pa_pstream_send_tagstruct(c
->pstream
, t
);
899 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_autoload_info_callback
, o
);
901 return pa_operation_ref(o
);
904 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
) {
905 return pa_context_send_simple_command(c
, PA_COMMAND_GET_AUTOLOAD_INFO_LIST
, context_get_autoload_info_callback
, cb
, userdata
);
908 static void context_add_autoload_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
909 struct pa_operation
*o
= userdata
;
911 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
913 if (command
!= PA_COMMAND_REPLY
) {
914 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
917 index
= PA_INVALID_INDEX
;
918 } else if (pa_tagstruct_getu32(t
, &index
) ||
919 !pa_tagstruct_eof(t
)) {
920 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
925 void (*cb
)(struct pa_context
*s
, uint32_t index
, void *userdata
) = o
->callback
;
926 cb(o
->context
, index
, o
->userdata
);
931 pa_operation_done(o
);
932 pa_operation_unref(o
);
936 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
) {
937 struct pa_operation
*o
;
938 struct pa_tagstruct
*t
;
940 assert(c
&& name
&& module
&& argument
);
942 o
= pa_operation_new(c
, NULL
);
944 o
->userdata
= userdata
;
946 t
= pa_tagstruct_new(NULL
, 0);
947 pa_tagstruct_putu32(t
, PA_COMMAND_ADD_AUTOLOAD
);
948 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
949 pa_tagstruct_puts(t
, name
);
950 pa_tagstruct_putu32(t
, type
);
951 pa_tagstruct_puts(t
, module
);
952 pa_tagstruct_puts(t
, argument
);
953 pa_pstream_send_tagstruct(c
->pstream
, t
);
954 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_add_autoload_callback
, o
);
956 return pa_operation_ref(o
);
959 struct pa_operation
* pa_context_remove_autoload_by_name(struct pa_context
*c
, const char *name
, enum pa_autoload_type type
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void* userdata
) {
960 struct pa_operation
*o
;
961 struct pa_tagstruct
*t
;
965 o
= pa_operation_new(c
, NULL
);
967 o
->userdata
= userdata
;
969 t
= pa_tagstruct_new(NULL
, 0);
970 pa_tagstruct_putu32(t
, PA_COMMAND_REMOVE_AUTOLOAD
);
971 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
972 pa_tagstruct_puts(t
, name
);
973 pa_tagstruct_putu32(t
, type
);
974 pa_pstream_send_tagstruct(c
->pstream
, t
);
975 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
977 return pa_operation_ref(o
);
980 struct pa_operation
* pa_context_remove_autoload_by_index(struct pa_context
*c
, uint32_t index
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void* userdata
) {
981 struct pa_operation
*o
;
982 struct pa_tagstruct
*t
;
984 assert(c
&& index
!= PA_INVALID_INDEX
);
986 o
= pa_operation_new(c
, NULL
);
988 o
->userdata
= userdata
;
990 t
= pa_tagstruct_new(NULL
, 0);
991 pa_tagstruct_putu32(t
, PA_COMMAND_REMOVE_AUTOLOAD
);
992 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
993 pa_tagstruct_putu32(t
, index
);
994 pa_pstream_send_tagstruct(c
->pstream
, t
);
995 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
997 return pa_operation_ref(o
);