]> code.delx.au - pulseaudio/blob - src/pulsecore/modinfo.c
merge 'lennart' branch back into trunk.
[pulseaudio] / src / pulsecore / modinfo.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 Copyright 2004-2006 Lennart Poettering
7
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 USA.
22 ***/
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <ltdl.h>
29
30 #include <pulse/xmalloc.h>
31
32 #include <pulsecore/core-util.h>
33 #include <pulsecore/log.h>
34 #include <pulsecore/macro.h>
35 #include <pulsecore/ltdl-helper.h>
36
37 #include "modinfo.h"
38
39 #define PA_SYMBOL_AUTHOR "pa__get_author"
40 #define PA_SYMBOL_DESCRIPTION "pa__get_description"
41 #define PA_SYMBOL_USAGE "pa__get_usage"
42 #define PA_SYMBOL_VERSION "pa__get_version"
43
44 pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl, const char *module_name) {
45 pa_modinfo *i;
46 const char* (*func)(void);
47
48 pa_assert(dl);
49
50 i = pa_xnew0(pa_modinfo, 1);
51
52 if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_AUTHOR)))
53 i->author = pa_xstrdup(func());
54
55 if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_DESCRIPTION)))
56 i->description = pa_xstrdup(func());
57
58 if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_USAGE)))
59 i->usage = pa_xstrdup(func());
60
61 if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_VERSION)))
62 i->version = pa_xstrdup(func());
63
64 return i;
65 }
66
67 pa_modinfo *pa_modinfo_get_by_name(const char *name) {
68 lt_dlhandle dl;
69 pa_modinfo *i;
70
71 pa_assert(name);
72
73 if (!(dl = lt_dlopenext(name))) {
74 pa_log("Failed to open module \"%s\": %s", name, lt_dlerror());
75 return NULL;
76 }
77
78 i = pa_modinfo_get_by_handle(dl, name);
79 lt_dlclose(dl);
80
81 return i;
82 }
83
84 void pa_modinfo_free(pa_modinfo *i) {
85 pa_assert(i);
86
87 pa_xfree(i->author);
88 pa_xfree(i->description);
89 pa_xfree(i->usage);
90 pa_xfree(i->version);
91 pa_xfree(i);
92 }