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