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