Add copyright notices to all relevant files. (based on svn log)
[profile/ivi/pulseaudio.git] / 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 <assert.h>
32 #include <stdio.h>
33 #include <ltdl.h>
34
35 #include <pulse/util.h>
36
37 #include <pulsecore/modinfo.h>
38
39 #include "dumpmodules.h"
40
41 #define PREFIX "module-"
42
43 static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) {
44     assert(name && i);
45     printf("%-40s%s\n", name, i->description ? i->description : "n/a");
46 }
47
48 static void long_info(const char *name, const char *path, pa_modinfo *i) {
49     static int nl = 0;
50     assert(name && i);
51
52     if (nl)
53         printf("\n");
54
55     nl = 1;
56
57     printf("Name: %s\n", name);
58
59     if (!i->description && !i->version && !i->author && !i->usage)
60         printf("No module information available\n");
61     else {
62         if (i->version)
63             printf("Version: %s\n", i->version);
64         if (i->description)
65             printf("Description: %s\n", i->description);
66         if (i->author)
67             printf("Author: %s\n", i->author);
68         if (i->usage)
69             printf("Usage: %s\n", i->usage);
70     }
71
72     if (path)
73         printf("Path: %s\n", path);
74 }
75
76 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
77     pa_modinfo *i;
78
79     if ((i = pa_modinfo_get_by_name(path ? path : name))) {
80         info(name, path, i);
81         pa_modinfo_free(i);
82     }
83 }
84
85 extern const lt_dlsymlist lt_preloaded_symbols[];
86
87 static int is_preloaded(const char *name) {
88     const lt_dlsymlist *l;
89
90     for (l = lt_preloaded_symbols; l->name; l++) {
91         char buf[64], *e;
92
93         if (l->address)
94             continue;
95
96         snprintf(buf, sizeof(buf), "%s", l->name);
97         if ((e = strrchr(buf, '.')))
98             *e = 0;
99
100         if (!strcmp(name, buf))
101             return 1;
102     }
103
104     return 0;
105 }
106
107 static int callback(const char *path, lt_ptr data) {
108     const char *e;
109     pa_daemon_conf *c = (data);
110
111     e = pa_path_get_filename(path);
112
113     if (strlen(e) <= sizeof(PREFIX)-1 || strncmp(e, PREFIX, sizeof(PREFIX)-1))
114         return 0;
115
116     if (is_preloaded(e))
117         return 0;
118
119     show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info);
120     return 0;
121 }
122
123 void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
124     if (argc > 0) {
125         int i;
126         for (i = 0; i < argc; i++)
127             show_info(argv[i], NULL, long_info);
128     } else {
129         const lt_dlsymlist *l;
130
131         for (l = lt_preloaded_symbols; l->name; l++) {
132             char buf[64], *e;
133
134             if (l->address)
135                 continue;
136
137             if (strlen(l->name) <= sizeof(PREFIX)-1 || strncmp(l->name, PREFIX, sizeof(PREFIX)-1))
138                 continue;
139
140             snprintf(buf, sizeof(buf), "%s", l->name);
141             if ((e = strrchr(buf, '.')))
142                 *e = 0;
143
144             show_info(buf, NULL, c->log_level >= PA_LOG_INFO ? long_info : short_info);
145         }
146
147         lt_dlforeachfile(NULL, callback, c);
148     }
149 }