]> code.delx.au - pulseaudio/blob - src/polypcore/cli-text.c
Cleaned up the includes after the restructuring. Indicate which headers are
[pulseaudio] / src / polypcore / cli-text.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27 #include <string.h>
28
29 #include <polyp/volume.h>
30 #include <polypcore/module.h>
31 #include <polypcore/client.h>
32 #include <polypcore/sink.h>
33 #include <polypcore/source.h>
34 #include <polypcore/sink-input.h>
35 #include <polypcore/source-output.h>
36 #include <polypcore/strbuf.h>
37 #include <polypcore/sample-util.h>
38 #include <polypcore/core-scache.h>
39 #include <polypcore/autoload.h>
40 #include <polypcore/xmalloc.h>
41
42 #include "cli-text.h"
43
44 char *pa_module_list_to_string(pa_core *c) {
45 pa_strbuf *s;
46 pa_module *m;
47 uint32_t idx = PA_IDXSET_INVALID;
48 assert(c);
49
50 s = pa_strbuf_new();
51 assert(s);
52
53 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
54
55 for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx))
56 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\targument: <%s>\n\tused: %i\n\tauto unload: %s\n", m->index, m->name, m->argument, m->n_used, m->auto_unload ? "yes" : "no");
57
58 return pa_strbuf_tostring_free(s);
59 }
60
61 char *pa_client_list_to_string(pa_core *c) {
62 pa_strbuf *s;
63 pa_client *client;
64 uint32_t idx = PA_IDXSET_INVALID;
65 assert(c);
66
67 s = pa_strbuf_new();
68 assert(s);
69
70 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
71
72 for (client = pa_idxset_first(c->clients, &idx); client; client = pa_idxset_next(c->clients, &idx)) {
73 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\tdriver: <%s>\n", client->index, client->name, client->driver);
74
75 if (client->owner)
76 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
77 }
78
79 return pa_strbuf_tostring_free(s);
80 }
81
82 char *pa_sink_list_to_string(pa_core *c) {
83 pa_strbuf *s;
84 pa_sink *sink;
85 uint32_t idx = PA_IDXSET_INVALID;
86 assert(c);
87
88 s = pa_strbuf_new();
89 assert(s);
90
91 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
92
93 for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) {
94 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
95
96 pa_strbuf_printf(
97 s,
98 " %c index: %u\n"
99 "\tname: <%s>\n"
100 "\tdriver: <%s>\n"
101 "\tvolume: <%s>\n"
102 "\tlatency: <%0.0f usec>\n"
103 "\tmonitor_source: <%u>\n"
104 "\tsample spec: <%s>\n"
105 "\tchannel map: <%s>\n",
106 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
107 sink->index, sink->name,
108 sink->driver,
109 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink, PA_MIXER_HARDWARE)),
110 (double) pa_sink_get_latency(sink),
111 sink->monitor_source->index,
112 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
113 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map));
114
115 if (sink->owner)
116 pa_strbuf_printf(s, "\towner module: <%u>\n", sink->owner->index);
117 if (sink->description)
118 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
119 }
120
121 return pa_strbuf_tostring_free(s);
122 }
123
124 char *pa_source_list_to_string(pa_core *c) {
125 pa_strbuf *s;
126 pa_source *source;
127 uint32_t idx = PA_IDXSET_INVALID;
128 assert(c);
129
130 s = pa_strbuf_new();
131 assert(s);
132
133 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
134
135 for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
136 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
137
138
139 pa_strbuf_printf(
140 s,
141 " %c index: %u\n"
142 "\tname: <%s>\n"
143 "\tdriver: <%s>\n"
144 "\tlatency: <%0.0f usec>\n"
145 "\tsample spec: <%s>\n"
146 "\tchannel map: <%s>\n",
147 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
148 source->index,
149 source->name,
150 source->driver,
151 (double) pa_source_get_latency(source),
152 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
153 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map));
154
155 if (source->monitor_of)
156 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
157 if (source->owner)
158 pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index);
159 if (source->description)
160 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
161 }
162
163 return pa_strbuf_tostring_free(s);
164 }
165
166
167 char *pa_source_output_list_to_string(pa_core *c) {
168 pa_strbuf *s;
169 pa_source_output *o;
170 uint32_t idx = PA_IDXSET_INVALID;
171 static const char* const state_table[] = {
172 "RUNNING",
173 "CORKED",
174 "DISCONNECTED"
175 };
176 assert(c);
177
178 s = pa_strbuf_new();
179 assert(s);
180
181 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
182
183 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
184 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
185
186 assert(o->source);
187
188 pa_strbuf_printf(
189 s,
190 " index: %u\n"
191 "\tname: '%s'\n"
192 "\tdriver: <%s>\n"
193 "\tstate: %s\n"
194 "\tsource: <%u> '%s'\n"
195 "\tsample spec: <%s>\n"
196 "\tchannel map: <%s>\n"
197 "\tresample method: %s\n",
198 o->index,
199 o->name,
200 o->driver,
201 state_table[o->state],
202 o->source->index, o->source->name,
203 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
204 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
205 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
206 if (o->owner)
207 pa_strbuf_printf(s, "\towner module: <%u>\n", o->owner->index);
208 if (o->client)
209 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
210 }
211
212 return pa_strbuf_tostring_free(s);
213 }
214
215 char *pa_sink_input_list_to_string(pa_core *c) {
216 pa_strbuf *s;
217 pa_sink_input *i;
218 uint32_t idx = PA_IDXSET_INVALID;
219 static const char* const state_table[] = {
220 "RUNNING",
221 "CORKED",
222 "DISCONNECTED"
223 };
224
225 assert(c);
226 s = pa_strbuf_new();
227 assert(s);
228
229 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
230
231 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
232 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
233
234 assert(i->sink);
235
236 pa_strbuf_printf(
237 s,
238 " index: %u\n"
239 "\tname: <%s>\n"
240 "\tdriver: <%s>\n"
241 "\tstate: %s\n"
242 "\tsink: <%u> '%s'\n"
243 "\tvolume: <%s>\n"
244 "\tlatency: <%0.0f usec>\n"
245 "\tsample spec: <%s>\n"
246 "\tchannel map: <%s>\n"
247 "\tresample method: %s\n",
248 i->index,
249 i->name,
250 i->driver,
251 state_table[i->state],
252 i->sink->index, i->sink->name,
253 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
254 (double) pa_sink_input_get_latency(i),
255 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
256 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
257 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
258
259 if (i->owner)
260 pa_strbuf_printf(s, "\towner module: <%u>\n", i->owner->index);
261 if (i->client)
262 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
263 }
264
265 return pa_strbuf_tostring_free(s);
266 }
267
268 char *pa_scache_list_to_string(pa_core *c) {
269 pa_strbuf *s;
270 assert(c);
271
272 s = pa_strbuf_new();
273 assert(s);
274
275 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
276
277 if (c->scache) {
278 pa_scache_entry *e;
279 uint32_t idx = PA_IDXSET_INVALID;
280
281 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
282 double l = 0;
283 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
284
285 if (e->memchunk.memblock) {
286 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
287 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
288 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
289 }
290
291 pa_strbuf_printf(
292 s,
293 " name: <%s>\n"
294 "\tindex: <%u>\n"
295 "\tsample spec: <%s>\n"
296 "\tchannel map: <%s>\n"
297 "\tlength: <%u>\n"
298 "\tduration: <%0.1fs>\n"
299 "\tvolume: <%s>\n"
300 "\tlazy: %s\n"
301 "\tfilename: %s\n",
302 e->name,
303 e->index,
304 ss,
305 cm,
306 e->memchunk.memblock ? e->memchunk.length : 0,
307 l,
308 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
309 e->lazy ? "yes" : "no",
310 e->filename ? e->filename : "n/a");
311 }
312 }
313
314 return pa_strbuf_tostring_free(s);
315 }
316
317 char *pa_autoload_list_to_string(pa_core *c) {
318 pa_strbuf *s;
319 assert(c);
320
321 s = pa_strbuf_new();
322 assert(s);
323
324 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
325
326 if (c->autoload_hashmap) {
327 pa_autoload_entry *e;
328 void *state = NULL;
329
330 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
331 pa_strbuf_printf(
332 s, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
333 e->name,
334 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
335 e->index,
336 e->module,
337 e->argument);
338
339 }
340 }
341
342 return pa_strbuf_tostring_free(s);
343 }
344
345 char *pa_full_status_string(pa_core *c) {
346 pa_strbuf *s;
347 int i;
348
349 s = pa_strbuf_new();
350
351 for (i = 0; i < 8; i++) {
352 char *t = NULL;
353
354 switch (i) {
355 case 0:
356 t = pa_sink_list_to_string(c);
357 break;
358 case 1:
359 t = pa_source_list_to_string(c);
360 break;
361 case 2:
362 t = pa_sink_input_list_to_string(c);
363 break;
364 case 3:
365 t = pa_source_output_list_to_string(c);
366 break;
367 case 4:
368 t = pa_client_list_to_string(c);
369 break;
370 case 5:
371 t = pa_module_list_to_string(c);
372 break;
373 case 6:
374 t = pa_scache_list_to_string(c);
375 break;
376 case 7:
377 t = pa_autoload_list_to_string(c);
378 break;
379 }
380
381 pa_strbuf_puts(s, t);
382 pa_xfree(t);
383 }
384
385 return pa_strbuf_tostring_free(s);
386 }