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