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