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