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_count
) < 0 ||
46 pa_tagstruct_getu32(t
, &i
.memblock_total
) < 0 ||
47 !pa_tagstruct_eof(t
)) {
48 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
53 void (*cb
)(struct pa_context
*s
, const struct pa_stat_info
*i
, void *userdata
) = o
->callback
;
54 cb(o
->context
, p
, o
->userdata
);
59 pa_operation_unref(o
);
62 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
) {
63 return pa_context_send_simple_command(c
, PA_COMMAND_STAT
, context_stat_callback
, cb
, userdata
);
68 static void context_get_server_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
69 struct pa_operation
*o
= userdata
;
70 struct pa_server_info i
, *p
= &i
;
71 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
73 if (command
!= PA_COMMAND_REPLY
) {
74 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
78 } else if (pa_tagstruct_gets(t
, &i
.server_name
) < 0 ||
79 pa_tagstruct_gets(t
, &i
.server_version
) < 0 ||
80 pa_tagstruct_gets(t
, &i
.user_name
) < 0 ||
81 pa_tagstruct_gets(t
, &i
.host_name
) < 0 ||
82 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
83 !pa_tagstruct_eof(t
)) {
84 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
89 void (*cb
)(struct pa_context
*s
, const struct pa_server_info
*i
, void *userdata
) = o
->callback
;
90 cb(o
->context
, p
, o
->userdata
);
95 pa_operation_unref(o
);
98 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
) {
99 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SERVER_INFO
, context_get_server_info_callback
, cb
, userdata
);
104 static void context_get_sink_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
105 struct pa_operation
*o
= userdata
;
107 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
109 if (command
!= PA_COMMAND_REPLY
) {
110 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
116 while (!pa_tagstruct_eof(t
)) {
117 struct pa_sink_info i
;
119 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
120 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
121 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
122 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
123 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
124 pa_tagstruct_getu32(t
, &i
.volume
) < 0 ||
125 pa_tagstruct_getu32(t
, &i
.monitor_source
) < 0 ||
126 pa_tagstruct_gets(t
, &i
.monitor_source_name
) < 0 ||
127 pa_tagstruct_getu32(t
, &i
.latency
) < 0) {
128 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
133 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
134 cb(o
->context
, &i
, 0, o
->userdata
);
140 void (*cb
)(struct pa_context
*s
, const struct pa_sink_info
*i
, int eof
, void *userdata
) = o
->callback
;
141 cb(o
->context
, NULL
, eof
, o
->userdata
);
145 pa_operation_done(o
);
146 pa_operation_unref(o
);
149 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
) {
150 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SINK_INFO_LIST
, context_get_sink_info_callback
, cb
, userdata
);
153 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
) {
154 struct pa_tagstruct
*t
;
155 struct pa_operation
*o
;
159 o
= pa_operation_new(c
, NULL
);
161 o
->userdata
= userdata
;
163 t
= pa_tagstruct_new(NULL
, 0);
164 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SINK_INFO
);
165 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
166 pa_tagstruct_putu32(t
, index
);
167 pa_tagstruct_puts(t
, "");
168 pa_pstream_send_tagstruct(c
->pstream
, t
);
169 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_sink_info_callback
, o
);
171 return pa_operation_ref(o
);
174 /*** Source info ***/
176 static void context_get_source_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
177 struct pa_operation
*o
= userdata
;
179 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
181 if (command
!= PA_COMMAND_REPLY
) {
182 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
188 while (!pa_tagstruct_eof(t
)) {
189 struct pa_source_info i
;
191 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
192 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
193 pa_tagstruct_gets(t
, &i
.description
) < 0 ||
194 pa_tagstruct_get_sample_spec(t
, &i
.sample_spec
) < 0 ||
195 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0 ||
196 pa_tagstruct_getu32(t
, &i
.monitor_of_sink
) < 0 ||
197 pa_tagstruct_gets(t
, &i
.monitor_of_sink_name
) < 0) {
198 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
203 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
204 cb(o
->context
, &i
, 0, o
->userdata
);
210 void (*cb
)(struct pa_context
*s
, const struct pa_source_info
*i
, int eof
, void *userdata
) = o
->callback
;
211 cb(o
->context
, NULL
, eof
, o
->userdata
);
215 pa_operation_done(o
);
216 pa_operation_unref(o
);
219 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
) {
220 return pa_context_send_simple_command(c
, PA_COMMAND_GET_SOURCE_INFO_LIST
, context_get_source_info_callback
, cb
, userdata
);
223 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
) {
224 struct pa_tagstruct
*t
;
225 struct pa_operation
*o
;
229 o
= pa_operation_new(c
, NULL
);
231 o
->userdata
= userdata
;
233 t
= pa_tagstruct_new(NULL
, 0);
234 pa_tagstruct_putu32(t
, PA_COMMAND_GET_SOURCE_INFO
);
235 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
236 pa_tagstruct_putu32(t
, index
);
237 pa_tagstruct_puts(t
, "");
238 pa_pstream_send_tagstruct(c
->pstream
, t
);
239 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_source_info_callback
, o
);
241 return pa_operation_ref(o
);
244 /*** Client info ***/
246 static void context_get_client_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
247 struct pa_operation
*o
= userdata
;
249 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
251 if (command
!= PA_COMMAND_REPLY
) {
252 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
258 while (!pa_tagstruct_eof(t
)) {
259 struct pa_client_info i
;
261 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
262 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
263 pa_tagstruct_gets(t
, &i
.protocol_name
) < 0 ||
264 pa_tagstruct_getu32(t
, &i
.owner_module
) < 0) {
265 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
270 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
271 cb(o
->context
, &i
, 0, o
->userdata
);
277 void (*cb
)(struct pa_context
*s
, const struct pa_client_info
*i
, int eof
, void *userdata
) = o
->callback
;
278 cb(o
->context
, NULL
, eof
, o
->userdata
);
282 pa_operation_done(o
);
283 pa_operation_unref(o
);
286 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
) {
287 struct pa_tagstruct
*t
;
288 struct pa_operation
*o
;
292 o
= pa_operation_new(c
, NULL
);
294 o
->userdata
= userdata
;
296 t
= pa_tagstruct_new(NULL
, 0);
297 pa_tagstruct_putu32(t
, PA_COMMAND_GET_CLIENT_INFO
);
298 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
299 pa_tagstruct_putu32(t
, index
);
300 pa_tagstruct_puts(t
, "");
301 pa_pstream_send_tagstruct(c
->pstream
, t
);
302 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_client_info_callback
, o
);
304 return pa_operation_ref(o
);
307 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
) {
308 return pa_context_send_simple_command(c
, PA_COMMAND_GET_CLIENT_INFO_LIST
, context_get_client_info_callback
, cb
, userdata
);
311 /*** Module info ***/
313 static void context_get_module_info_callback(struct pa_pdispatch
*pd
, uint32_t command
, uint32_t tag
, struct pa_tagstruct
*t
, void *userdata
) {
314 struct pa_operation
*o
= userdata
;
316 assert(pd
&& o
&& o
->context
&& o
->ref
>= 1);
318 if (command
!= PA_COMMAND_REPLY
) {
319 if (pa_context_handle_error(o
->context
, command
, t
) < 0)
325 while (!pa_tagstruct_eof(t
)) {
326 struct pa_module_info i
;
328 if (pa_tagstruct_getu32(t
, &i
.index
) < 0 ||
329 pa_tagstruct_gets(t
, &i
.name
) < 0 ||
330 pa_tagstruct_gets(t
, &i
.argument
) < 0 ||
331 pa_tagstruct_getu32(t
, &i
.n_used
) < 0 ||
332 pa_tagstruct_getu32(t
, &i
.auto_unload
) < 0) {
333 pa_context_fail(o
->context
, PA_ERROR_PROTOCOL
);
338 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
339 cb(o
->context
, &i
, 0, o
->userdata
);
345 void (*cb
)(struct pa_context
*s
, const struct pa_module_info
*i
, int eof
, void *userdata
) = o
->callback
;
346 cb(o
->context
, NULL
, eof
, o
->userdata
);
350 pa_operation_done(o
);
351 pa_operation_unref(o
);
354 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
) {
355 struct pa_tagstruct
*t
;
356 struct pa_operation
*o
;
360 o
= pa_operation_new(c
, NULL
);
362 o
->userdata
= userdata
;
364 t
= pa_tagstruct_new(NULL
, 0);
365 pa_tagstruct_putu32(t
, PA_COMMAND_GET_MODULE_INFO
);
366 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
367 pa_tagstruct_putu32(t
, index
);
368 pa_pstream_send_tagstruct(c
->pstream
, t
);
369 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, context_get_module_info_callback
, o
);
371 return pa_operation_ref(o
);
374 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
) {
375 return pa_context_send_simple_command(c
, PA_COMMAND_GET_MODULE_INFO_LIST
, context_get_module_info_callback
, cb
, userdata
);
378 /*** Volume manipulation ***/
380 struct pa_operation
* pa_context_set_sink_volume_by_index(struct pa_context
*c
, uint32_t index
, uint32_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
381 struct pa_operation
*o
;
382 struct pa_tagstruct
*t
;
384 assert(c
&& index
!= PA_INVALID_INDEX
);
386 o
= pa_operation_new(c
, NULL
);
388 o
->userdata
= userdata
;
390 t
= pa_tagstruct_new(NULL
, 0);
391 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
392 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
393 pa_tagstruct_putu32(t
, index
);
394 pa_tagstruct_puts(t
, "");
395 pa_tagstruct_putu32(t
, volume
);
396 pa_pstream_send_tagstruct(c
->pstream
, t
);
397 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
399 return pa_operation_ref(o
);
402 struct pa_operation
* pa_context_set_sink_volume_by_name(struct pa_context
*c
, const char *name
, uint32_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
403 struct pa_operation
*o
;
404 struct pa_tagstruct
*t
;
408 o
= pa_operation_new(c
, NULL
);
410 o
->userdata
= userdata
;
412 t
= pa_tagstruct_new(NULL
, 0);
413 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_VOLUME
);
414 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
415 pa_tagstruct_putu32(t
, PA_INVALID_INDEX
);
416 pa_tagstruct_puts(t
, name
);
417 pa_tagstruct_putu32(t
, volume
);
418 pa_pstream_send_tagstruct(c
->pstream
, t
);
419 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
421 return pa_operation_ref(o
);
424 struct pa_operation
* pa_context_set_sink_input_volume(struct pa_context
*c
, uint32_t index
, uint32_t volume
, void (*cb
)(struct pa_context
*c
, int success
, void *userdata
), void *userdata
) {
425 struct pa_operation
*o
;
426 struct pa_tagstruct
*t
;
428 assert(c
&& index
!= PA_INVALID_INDEX
);
430 o
= pa_operation_new(c
, NULL
);
432 o
->userdata
= userdata
;
434 t
= pa_tagstruct_new(NULL
, 0);
435 pa_tagstruct_putu32(t
, PA_COMMAND_SET_SINK_INPUT_VOLUME
);
436 pa_tagstruct_putu32(t
, tag
= c
->ctag
++);
437 pa_tagstruct_putu32(t
, index
);
438 pa_tagstruct_putu32(t
, volume
);
439 pa_pstream_send_tagstruct(c
->pstream
, t
);
440 pa_pdispatch_register_reply(c
->pdispatch
, tag
, DEFAULT_TIMEOUT
, pa_context_simple_ack_callback
, o
);
442 return pa_operation_ref(o
);