]> code.delx.au - pulseaudio/blob - polyp/clitext.c
rename src to polyp
[pulseaudio] / polyp / clitext.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
28 #include "clitext.h"
29 #include "module.h"
30 #include "client.h"
31 #include "sink.h"
32 #include "source.h"
33 #include "sink-input.h"
34 #include "source-output.h"
35 #include "strbuf.h"
36 #include "sample-util.h"
37
38 char *pa_module_list_to_string(struct pa_core *c) {
39 struct pa_strbuf *s;
40 struct pa_module *m;
41 uint32_t index = PA_IDXSET_INVALID;
42 assert(c);
43
44 s = pa_strbuf_new();
45 assert(s);
46
47 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_ncontents(c->modules));
48
49 for (m = pa_idxset_first(c->modules, &index); m; m = pa_idxset_next(c->modules, &index))
50 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\targument: <%s>\n", m->index, m->name, m->argument);
51
52 return pa_strbuf_tostring_free(s);
53 }
54
55 char *pa_client_list_to_string(struct pa_core *c) {
56 struct pa_strbuf *s;
57 struct pa_client *client;
58 uint32_t index = PA_IDXSET_INVALID;
59 assert(c);
60
61 s = pa_strbuf_new();
62 assert(s);
63
64 pa_strbuf_printf(s, "%u client(s).\n", pa_idxset_ncontents(c->clients));
65
66 for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index)) {
67 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\tprotocol_name: <%s>\n", client->index, client->name, client->protocol_name);
68
69 if (client->owner)
70 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
71 }
72
73 return pa_strbuf_tostring_free(s);
74 }
75
76 char *pa_sink_list_to_string(struct pa_core *c) {
77 struct pa_strbuf *s;
78 struct pa_sink *sink, *default_sink;
79 uint32_t index = PA_IDXSET_INVALID;
80 assert(c);
81
82 s = pa_strbuf_new();
83 assert(s);
84
85 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_ncontents(c->sinks));
86
87 default_sink = pa_sink_get_default(c);
88
89 for (sink = pa_idxset_first(c->sinks, &index); sink; sink = pa_idxset_next(c->sinks, &index)) {
90 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
91 pa_sample_snprint(ss, sizeof(ss), &sink->sample_spec);
92 assert(sink->monitor_source);
93 pa_strbuf_printf(
94 s,
95 " %c index: %u\n\tname: <%s>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tmonitor_source: <%u>\n\tsample_spec: <%s>\n",
96 sink == default_sink ? '*' : ' ',
97 sink->index, sink->name,
98 (unsigned) sink->volume,
99 pa_sink_get_latency(sink),
100 sink->monitor_source->index,
101 ss);
102
103 if (sink->owner)
104 pa_strbuf_printf(s, "\towner module: <%u>\n", sink->owner->index);
105 if (sink->description)
106 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
107 }
108
109 return pa_strbuf_tostring_free(s);
110 }
111
112 char *pa_source_list_to_string(struct pa_core *c) {
113 struct pa_strbuf *s;
114 struct pa_source *source, *default_source;
115 uint32_t index = PA_IDXSET_INVALID;
116 assert(c);
117
118 s = pa_strbuf_new();
119 assert(s);
120
121 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_ncontents(c->sources));
122
123 default_source = pa_source_get_default(c);
124
125 for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) {
126 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
127 pa_sample_snprint(ss, sizeof(ss), &source->sample_spec);
128 pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>\n", source == default_source ? '*' : ' ', source->index, source->name, ss);
129
130 if (source->monitor_of)
131 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
132 if (source->owner)
133 pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index);
134 if (source->description)
135 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
136 }
137
138 return pa_strbuf_tostring_free(s);
139 }
140
141
142 char *pa_source_output_list_to_string(struct pa_core *c) {
143 struct pa_strbuf *s;
144 struct pa_source_output *o;
145 uint32_t index = PA_IDXSET_INVALID;
146 assert(c);
147
148 s = pa_strbuf_new();
149 assert(s);
150
151 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_ncontents(c->source_outputs));
152
153 for (o = pa_idxset_first(c->source_outputs, &index); o; o = pa_idxset_next(c->source_outputs, &index)) {
154 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
155 pa_sample_snprint(ss, sizeof(ss), &o->sample_spec);
156 assert(o->source);
157 pa_strbuf_printf(
158 s, " index: %u\n\tname: <%s>\n\tsource: <%u>\n\tsample_spec: <%s>\n",
159 o->index,
160 o->name,
161 o->source->index,
162 ss);
163 if (o->owner)
164 pa_strbuf_printf(s, "\towner module: <%u>\n", o->owner->index);
165 if (o->client)
166 pa_strbuf_printf(s, "\tclient: <%u>\n", o->client->index);
167 }
168
169 return pa_strbuf_tostring_free(s);
170 }
171
172 char *pa_sink_input_list_to_string(struct pa_core *c) {
173 struct pa_strbuf *s;
174 struct pa_sink_input *i;
175 uint32_t index = PA_IDXSET_INVALID;
176 assert(c);
177
178 s = pa_strbuf_new();
179 assert(s);
180
181 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_ncontents(c->sink_inputs));
182
183 for (i = pa_idxset_first(c->sink_inputs, &index); i; i = pa_idxset_next(c->sink_inputs, &index)) {
184 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
185 pa_sample_snprint(ss, sizeof(ss), &i->sample_spec);
186 assert(i->sink);
187 pa_strbuf_printf(
188 s, " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n",
189 i->index,
190 i->name,
191 i->sink->index,
192 (unsigned) i->volume,
193 pa_sink_input_get_latency(i),
194 ss);
195
196 if (i->owner)
197 pa_strbuf_printf(s, "\towner module: <%u>\n", i->owner->index);
198 if (i->client)
199 pa_strbuf_printf(s, "\tclient: <%u>\n", i->client->index);
200 }
201
202 return pa_strbuf_tostring_free(s);
203 }