]> code.delx.au - pulseaudio/blob - polyp/cli-text.c
* fix include file names in installed header files
[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
41 char *pa_module_list_to_string(struct pa_core *c) {
42 struct pa_strbuf *s;
43 struct pa_module *m;
44 uint32_t index = PA_IDXSET_INVALID;
45 assert(c);
46
47 s = pa_strbuf_new();
48 assert(s);
49
50 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_ncontents(c->modules));
51
52 for (m = pa_idxset_first(c->modules, &index); m; m = pa_idxset_next(c->modules, &index))
53 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");
54
55 return pa_strbuf_tostring_free(s);
56 }
57
58 char *pa_client_list_to_string(struct pa_core *c) {
59 struct pa_strbuf *s;
60 struct pa_client *client;
61 uint32_t index = PA_IDXSET_INVALID;
62 char tid[5];
63 assert(c);
64
65 s = pa_strbuf_new();
66 assert(s);
67
68 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_ncontents(c->clients));
69
70 for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index)) {
71 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)));
72
73 if (client->owner)
74 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
75 }
76
77 return pa_strbuf_tostring_free(s);
78 }
79
80 char *pa_sink_list_to_string(struct pa_core *c) {
81 struct pa_strbuf *s;
82 struct pa_sink *sink;
83 uint32_t index = PA_IDXSET_INVALID;
84 char tid[5];
85 assert(c);
86
87 s = pa_strbuf_new();
88 assert(s);
89
90 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_ncontents(c->sinks));
91
92 for (sink = pa_idxset_first(c->sinks, &index); sink; sink = pa_idxset_next(c->sinks, &index)) {
93 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
94 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec);
95 assert(sink->monitor_source);
96 pa_strbuf_printf(
97 s,
98 " %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",
99 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
100 sink->index, sink->name,
101 pa_typeid_to_string(sink->typeid, tid, sizeof(tid)),
102 (unsigned) sink->volume,
103 pa_volume_to_dB(sink->volume),
104 (float) pa_sink_get_latency(sink),
105 sink->monitor_source->index,
106 ss);
107
108 if (sink->owner)
109 pa_strbuf_printf(s, "\towner module: <%u>\n", sink->owner->index);
110 if (sink->description)
111 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
112 }
113
114 return pa_strbuf_tostring_free(s);
115 }
116
117 char *pa_source_list_to_string(struct pa_core *c) {
118 struct pa_strbuf *s;
119 struct pa_source *source;
120 uint32_t index = PA_IDXSET_INVALID;
121 char tid[5];
122 assert(c);
123
124 s = pa_strbuf_new();
125 assert(s);
126
127 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_ncontents(c->sources));
128
129 for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) {
130 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
131 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec);
132 pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\ttype: <%s>\n\tlatency: <%0.0f usec>\n\tsample_spec: <%s>\n",
133 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
134 source->index,
135 source->name,
136 pa_typeid_to_string(source->typeid, tid, sizeof(tid)),
137 (float) pa_source_get_latency(source),
138 ss);
139
140 if (source->monitor_of)
141 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
142 if (source->owner)
143 pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index);
144 if (source->description)
145 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
146 }
147
148 return pa_strbuf_tostring_free(s);
149 }
150
151
152 char *pa_source_output_list_to_string(struct pa_core *c) {
153 struct pa_strbuf *s;
154 struct pa_source_output *o;
155 uint32_t index = PA_IDXSET_INVALID;
156 char tid[5];
157 static const char* const state_table[] = {
158 "RUNNING",
159 "CORKED",
160 "DISCONNECTED"
161 };
162 assert(c);
163
164 s = pa_strbuf_new();
165 assert(s);
166
167 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_ncontents(c->source_outputs));
168
169 for (o = pa_idxset_first(c->source_outputs, &index); o; o = pa_idxset_next(c->source_outputs, &index)) {
170 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
171 const char *rm;
172 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec);
173 assert(o->source);
174
175 if (!(rm = pa_resample_method_to_string(pa_source_output_get_resample_method(o))))
176 rm = "invalid";
177
178 pa_strbuf_printf(
179 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",
180 o->index,
181 o->name,
182 pa_typeid_to_string(o->typeid, tid, sizeof(tid)),
183 state_table[o->state],
184 o->source->index, o->source->name,
185 ss,
186 rm);
187 if (o->owner)
188 pa_strbuf_printf(s, "\towner module: <%u>\n", o->owner->index);
189 if (o->client)
190 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
191 }
192
193 return pa_strbuf_tostring_free(s);
194 }
195
196 char *pa_sink_input_list_to_string(struct pa_core *c) {
197 struct pa_strbuf *s;
198 struct pa_sink_input *i;
199 uint32_t index = PA_IDXSET_INVALID;
200 char tid[5];
201 static const char* const state_table[] = {
202 "RUNNING",
203 "CORKED",
204 "DISCONNECTED"
205 };
206
207 assert(c);
208 s = pa_strbuf_new();
209 assert(s);
210
211 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_ncontents(c->sink_inputs));
212
213 for (i = pa_idxset_first(c->sink_inputs, &index); i; i = pa_idxset_next(c->sink_inputs, &index)) {
214 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
215 const char *rm;
216
217 if (!(rm = pa_resample_method_to_string(pa_sink_input_get_resample_method(i))))
218 rm = "invalid";
219
220 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
221 assert(i->sink);
222 pa_strbuf_printf(
223 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",
224 i->index,
225 i->name,
226 pa_typeid_to_string(i->typeid, tid, sizeof(tid)),
227 state_table[i->state],
228 i->sink->index, i->sink->name,
229 (unsigned) i->volume,
230 pa_volume_to_dB(i->volume),
231 (float) pa_sink_input_get_latency(i),
232 ss,
233 rm);
234
235 if (i->owner)
236 pa_strbuf_printf(s, "\towner module: <%u>\n", i->owner->index);
237 if (i->client)
238 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
239 }
240
241 return pa_strbuf_tostring_free(s);
242 }
243
244 char *pa_scache_list_to_string(struct pa_core *c) {
245 struct pa_strbuf *s;
246 assert(c);
247
248 s = pa_strbuf_new();
249 assert(s);
250
251 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_ncontents(c->scache) : 0);
252
253 if (c->scache) {
254 struct pa_scache_entry *e;
255 uint32_t index = PA_IDXSET_INVALID;
256
257 for (e = pa_idxset_first(c->scache, &index); e; e = pa_idxset_next(c->scache, &index)) {
258 double l = 0;
259 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a";
260
261 if (e->memchunk.memblock) {
262 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
263 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
264 }
265
266 pa_strbuf_printf(
267 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",
268 e->name,
269 e->index,
270 ss,
271 e->memchunk.memblock ? e->memchunk.length : 0,
272 l,
273 e->volume,
274 e->lazy ? "yes" : "no",
275 e->filename ? e->filename : "n/a");
276 }
277 }
278
279 return pa_strbuf_tostring_free(s);
280 }
281
282 char *pa_autoload_list_to_string(struct pa_core *c) {
283 struct pa_strbuf *s;
284 assert(c);
285
286 s = pa_strbuf_new();
287 assert(s);
288
289 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_ncontents(c->autoload_hashmap) : 0);
290
291 if (c->autoload_hashmap) {
292 struct pa_autoload_entry *e;
293 void *state = NULL;
294
295 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
296 pa_strbuf_printf(
297 s, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
298 e->name,
299 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
300 e->index,
301 e->module,
302 e->argument);
303
304 }
305 }
306
307 return pa_strbuf_tostring_free(s);
308 }