]> code.delx.au - pulseaudio/blob - polyp/cli-text.c
make clitext to cli-text renaming complete
[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).\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_SNPRINT_MAX_LENGTH];
92 pa_sample_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>\n\tlatency: <%u 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_sink_get_latency(sink),
101 sink->monitor_source->index,
102 ss);
103
104 if (sink->owner)
105 pa_strbuf_printf(s, "\towner module: <%u>\n", sink->owner->index);
106 if (sink->description)
107 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
108 }
109
110 return pa_strbuf_tostring_free(s);
111 }
112
113 char *pa_source_list_to_string(struct pa_core *c) {
114 struct pa_strbuf *s;
115 struct pa_source *source;
116 uint32_t index = PA_IDXSET_INVALID;
117 assert(c);
118
119 s = pa_strbuf_new();
120 assert(s);
121
122 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_ncontents(c->sources));
123
124 for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) {
125 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
126 pa_sample_snprint(ss, sizeof(ss), &source->sample_spec);
127 pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>\n",
128 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
129 source->index,
130 source->name,
131 ss);
132
133 if (source->monitor_of)
134 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
135 if (source->owner)
136 pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index);
137 if (source->description)
138 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
139 }
140
141 return pa_strbuf_tostring_free(s);
142 }
143
144
145 char *pa_source_output_list_to_string(struct pa_core *c) {
146 struct pa_strbuf *s;
147 struct pa_source_output *o;
148 uint32_t index = PA_IDXSET_INVALID;
149 assert(c);
150
151 s = pa_strbuf_new();
152 assert(s);
153
154 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_ncontents(c->source_outputs));
155
156 for (o = pa_idxset_first(c->source_outputs, &index); o; o = pa_idxset_next(c->source_outputs, &index)) {
157 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
158 pa_sample_snprint(ss, sizeof(ss), &o->sample_spec);
159 assert(o->source);
160 pa_strbuf_printf(
161 s, " index: %u\n\tname: <%s>\n\tsource: <%u>\n\tsample_spec: <%s>\n",
162 o->index,
163 o->name,
164 o->source->index,
165 ss);
166 if (o->owner)
167 pa_strbuf_printf(s, "\towner module: <%u>\n", o->owner->index);
168 if (o->client)
169 pa_strbuf_printf(s, "\tclient: <%u>\n", o->client->index);
170 }
171
172 return pa_strbuf_tostring_free(s);
173 }
174
175 char *pa_sink_input_list_to_string(struct pa_core *c) {
176 struct pa_strbuf *s;
177 struct pa_sink_input *i;
178 uint32_t index = PA_IDXSET_INVALID;
179 assert(c);
180
181 s = pa_strbuf_new();
182 assert(s);
183
184 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_ncontents(c->sink_inputs));
185
186 for (i = pa_idxset_first(c->sink_inputs, &index); i; i = pa_idxset_next(c->sink_inputs, &index)) {
187 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
188 pa_sample_snprint(ss, sizeof(ss), &i->sample_spec);
189 assert(i->sink);
190 pa_strbuf_printf(
191 s, " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n",
192 i->index,
193 i->name,
194 i->sink->index,
195 (unsigned) i->volume,
196 pa_sink_input_get_latency(i),
197 ss);
198
199 if (i->owner)
200 pa_strbuf_printf(s, "\towner module: <%u>\n", i->owner->index);
201 if (i->client)
202 pa_strbuf_printf(s, "\tclient: <%u>\n", i->client->index);
203 }
204
205 return pa_strbuf_tostring_free(s);
206 }
207
208 char *pa_scache_list_to_string(struct pa_core *c) {
209 struct pa_strbuf *s;
210 assert(c);
211
212 s = pa_strbuf_new();
213 assert(s);
214
215 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache_hashmap ? pa_hashmap_ncontents(c->scache_hashmap) : 0);
216
217 if (c->scache_hashmap) {
218 struct pa_scache_entry *e;
219 void *state = NULL;
220
221 while ((e = pa_hashmap_iterate(c->scache_hashmap, &state))) {
222 double l;
223 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
224 pa_sample_snprint(ss, sizeof(ss), &e->sample_spec);
225
226 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
227
228 pa_strbuf_printf(
229 s, " name: <%s>\n\tindex: <%i>\n\tsample_spec: <%s>\n\tlength: <%u>\n\tduration: <%0.1fs>\n\tvolume: <0x%04x>\n",
230 e->name,
231 e->index,
232 ss,
233 e->memchunk.length,
234 l,
235 e->volume);
236 }
237 }
238
239 return pa_strbuf_tostring_free(s);
240 }
241
242 char *pa_autoload_list_to_string(struct pa_core *c) {
243 struct pa_strbuf *s;
244 assert(c);
245
246 s = pa_strbuf_new();
247 assert(s);
248
249 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_ncontents(c->autoload_hashmap) : 0);
250
251 if (c->autoload_hashmap) {
252 struct pa_autoload_entry *e;
253 void *state = NULL;
254
255 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state))) {
256 pa_strbuf_printf(
257 s, " name: <%s>\n\ttype: <%s>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
258 e->name,
259 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
260 e->module,
261 e->argument);
262 }
263 }
264
265 return pa_strbuf_tostring_free(s);
266 }