]> code.delx.au - pulseaudio/blob - src/daemon/dumpmodules.c
Merge dead branch 'prepare-0.9.10'
[pulseaudio] / src / daemon / dumpmodules.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <string.h>
28 #include <getopt.h>
29 #include <stdio.h>
30 #include <ltdl.h>
31
32 #include <pulse/util.h>
33
34 #include <pulsecore/modinfo.h>
35 #include <pulsecore/core-util.h>
36 #include <pulsecore/macro.h>
37
38 #include "dumpmodules.h"
39
40 #define PREFIX "module-"
41
42 static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) {
43 pa_assert(name);
44 pa_assert(i);
45
46 printf("%-40s%s\n", name, i->description ? i->description : "n/a");
47 }
48
49 static void long_info(const char *name, const char *path, pa_modinfo *i) {
50 static int nl = 0;
51 pa_assert(name);
52 pa_assert(i);
53
54 if (nl)
55 printf("\n");
56
57 nl = 1;
58
59 printf("Name: %s\n", name);
60
61 if (!i->description && !i->version && !i->author && !i->usage)
62 printf("No module information available\n");
63 else {
64 if (i->version)
65 printf("Version: %s\n", i->version);
66 if (i->description)
67 printf("Description: %s\n", i->description);
68 if (i->author)
69 printf("Author: %s\n", i->author);
70 if (i->usage)
71 printf("Usage: %s\n", i->usage);
72 printf("Load Once: %s\n", pa_yes_no(i->load_once));
73 }
74
75 if (path)
76 printf("Path: %s\n", path);
77 }
78
79 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
80 pa_modinfo *i;
81
82 pa_assert(name);
83
84 if ((i = pa_modinfo_get_by_name(path ? path : name))) {
85 info(name, path, i);
86 pa_modinfo_free(i);
87 }
88 }
89
90 extern const lt_dlsymlist lt_preloaded_symbols[];
91
92 static int is_preloaded(const char *name) {
93 const lt_dlsymlist *l;
94
95 for (l = lt_preloaded_symbols; l->name; l++) {
96 char buf[64], *e;
97
98 if (l->address)
99 continue;
100
101 pa_snprintf(buf, sizeof(buf), "%s", l->name);
102 if ((e = strrchr(buf, '.')))
103 *e = 0;
104
105 if (!strcmp(name, buf))
106 return 1;
107 }
108
109 return 0;
110 }
111
112 static int callback(const char *path, lt_ptr data) {
113 const char *e;
114 pa_daemon_conf *c = (data);
115
116 e = pa_path_get_filename(path);
117
118 if (strlen(e) <= sizeof(PREFIX)-1 || strncmp(e, PREFIX, sizeof(PREFIX)-1))
119 return 0;
120
121 if (is_preloaded(e))
122 return 0;
123
124 show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info);
125 return 0;
126 }
127
128 void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
129 pa_assert(c);
130
131 if (argc > 0) {
132 int i;
133 for (i = 0; i < argc; i++)
134 show_info(argv[i], NULL, long_info);
135 } else {
136 const lt_dlsymlist *l;
137
138 for (l = lt_preloaded_symbols; l->name; l++) {
139 char buf[64], *e;
140
141 if (l->address)
142 continue;
143
144 if (strlen(l->name) <= sizeof(PREFIX)-1 || strncmp(l->name, PREFIX, sizeof(PREFIX)-1))
145 continue;
146
147 pa_snprintf(buf, sizeof(buf), "%s", l->name);
148 if ((e = strrchr(buf, '.')))
149 *e = 0;
150
151 show_info(buf, NULL, c->log_level >= PA_LOG_INFO ? long_info : short_info);
152 }
153
154 lt_dlforeachfile(NULL, callback, c);
155 }
156 }