add new option --realtime
[pulseaudio.git] / src / daemon / dumpmodules.c
blobad7fab20f73cded8a415e379aca029933b36efd0
1 /* $Id$ */
3 /***
4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
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.
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.
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 ***/
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
29 #include <string.h>
30 #include <getopt.h>
31 #include <stdio.h>
32 #include <ltdl.h>
34 #include <pulse/util.h>
36 #include <pulsecore/modinfo.h>
37 #include <pulsecore/core-util.h>
38 #include <pulsecore/macro.h>
40 #include "dumpmodules.h"
42 #define PREFIX "module-"
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);
48 printf("%-40s%s\n", name, i->description ? i->description : "n/a");
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);
56 if (nl)
57 printf("\n");
59 nl = 1;
61 printf("Name: %s\n", name);
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);
76 if (path)
77 printf("Path: %s\n", path);
80 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
81 pa_modinfo *i;
83 pa_assert(name);
85 if ((i = pa_modinfo_get_by_name(path ? path : name))) {
86 info(name, path, i);
87 pa_modinfo_free(i);
91 extern const lt_dlsymlist lt_preloaded_symbols[];
93 static int is_preloaded(const char *name) {
94 const lt_dlsymlist *l;
96 for (l = lt_preloaded_symbols; l->name; l++) {
97 char buf[64], *e;
99 if (l->address)
100 continue;
102 pa_snprintf(buf, sizeof(buf), "%s", l->name);
103 if ((e = strrchr(buf, '.')))
104 *e = 0;
106 if (!strcmp(name, buf))
107 return 1;
110 return 0;
113 static int callback(const char *path, lt_ptr data) {
114 const char *e;
115 pa_daemon_conf *c = (data);
117 e = pa_path_get_filename(path);
119 if (strlen(e) <= sizeof(PREFIX)-1 || strncmp(e, PREFIX, sizeof(PREFIX)-1))
120 return 0;
122 if (is_preloaded(e))
123 return 0;
125 show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info);
126 return 0;
129 void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
130 pa_assert(c);
132 if (argc > 0) {
133 int i;
134 for (i = 0; i < argc; i++)
135 show_info(argv[i], NULL, long_info);
136 } else {
137 const lt_dlsymlist *l;
139 for (l = lt_preloaded_symbols; l->name; l++) {
140 char buf[64], *e;
142 if (l->address)
143 continue;
145 if (strlen(l->name) <= sizeof(PREFIX)-1 || strncmp(l->name, PREFIX, sizeof(PREFIX)-1))
146 continue;
148 pa_snprintf(buf, sizeof(buf), "%s", l->name);
149 if ((e = strrchr(buf, '.')))
150 *e = 0;
152 show_info(buf, NULL, c->log_level >= PA_LOG_INFO ? long_info : short_info);
155 lt_dlforeachfile(NULL, callback, c);