]> code.delx.au - pulseaudio/blob - src/daemon/dumpmodules.c
big s/polyp/pulse/g
[pulseaudio] / src / daemon / dumpmodules.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser 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 PulseAudio 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 Lesser General Public License
17 along with PulseAudio; 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 <string.h>
27 #include <getopt.h>
28 #include <assert.h>
29 #include <stdio.h>
30 #include <ltdl.h>
31
32 #include <pulse/util.h>
33
34 #include <pulsecore/modinfo.h>
35
36 #include "dumpmodules.h"
37
38 #define PREFIX "module-"
39
40 static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) {
41 assert(name && i);
42 printf("%-40s%s\n", name, i->description ? i->description : "n/a");
43 }
44
45 static void long_info(const char *name, const char *path, pa_modinfo *i) {
46 static int nl = 0;
47 assert(name && i);
48
49 if (nl)
50 printf("\n");
51
52 nl = 1;
53
54 printf("Name: %s\n", name);
55
56 if (!i->description && !i->version && !i->author && !i->usage)
57 printf("No module information available\n");
58 else {
59 if (i->version)
60 printf("Version: %s\n", i->version);
61 if (i->description)
62 printf("Description: %s\n", i->description);
63 if (i->author)
64 printf("Author: %s\n", i->author);
65 if (i->usage)
66 printf("Usage: %s\n", i->usage);
67 }
68
69 if (path)
70 printf("Path: %s\n", path);
71 }
72
73 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
74 pa_modinfo *i;
75
76 if ((i = pa_modinfo_get_by_name(path ? path : name))) {
77 info(name, path, i);
78 pa_modinfo_free(i);
79 }
80 }
81
82 extern const lt_dlsymlist lt_preloaded_symbols[];
83
84 static int is_preloaded(const char *name) {
85 const lt_dlsymlist *l;
86
87 for (l = lt_preloaded_symbols; l->name; l++) {
88 char buf[64], *e;
89
90 if (l->address)
91 continue;
92
93 snprintf(buf, sizeof(buf), "%s", l->name);
94 if ((e = strrchr(buf, '.')))
95 *e = 0;
96
97 if (!strcmp(name, buf))
98 return 1;
99 }
100
101 return 0;
102 }
103
104 static int callback(const char *path, lt_ptr data) {
105 const char *e;
106 pa_daemon_conf *c = (data);
107
108 e = pa_path_get_filename(path);
109
110 if (strlen(e) <= sizeof(PREFIX)-1 || strncmp(e, PREFIX, sizeof(PREFIX)-1))
111 return 0;
112
113 if (is_preloaded(e))
114 return 0;
115
116 show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info);
117 return 0;
118 }
119
120 void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
121 if (argc > 0) {
122 int i;
123 for (i = 0; i < argc; i++)
124 show_info(argv[i], NULL, long_info);
125 } else {
126 const lt_dlsymlist *l;
127
128 for (l = lt_preloaded_symbols; l->name; l++) {
129 char buf[64], *e;
130
131 if (l->address)
132 continue;
133
134 if (strlen(l->name) <= sizeof(PREFIX)-1 || strncmp(l->name, PREFIX, sizeof(PREFIX)-1))
135 continue;
136
137 snprintf(buf, sizeof(buf), "%s", l->name);
138 if ((e = strrchr(buf, '.')))
139 *e = 0;
140
141 show_info(buf, NULL, c->log_level >= PA_LOG_INFO ? long_info : short_info);
142 }
143
144 lt_dlforeachfile(NULL, callback, c);
145 }
146 }