Branch data Line data Source code
1 : : /***
2 : : This file is part of PulseAudio.
3 : :
4 : : Copyright 2004-2006 Lennart Poettering
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
8 : : published by the Free Software Foundation; either version 2.1 of the
9 : : License, 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
17 : : License 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 <ltdl.h>
27 : :
28 : : #include <pulse/xmalloc.h>
29 : :
30 : : #include <pulsecore/log.h>
31 : : #include <pulsecore/macro.h>
32 : : #include <pulsecore/ltdl-helper.h>
33 : :
34 : : #include "modinfo.h"
35 : :
36 : : #define PA_SYMBOL_AUTHOR "pa__get_author"
37 : : #define PA_SYMBOL_DESCRIPTION "pa__get_description"
38 : : #define PA_SYMBOL_USAGE "pa__get_usage"
39 : : #define PA_SYMBOL_VERSION "pa__get_version"
40 : : #define PA_SYMBOL_DEPRECATED "pa__get_deprecated"
41 : : #define PA_SYMBOL_LOAD_ONCE "pa__load_once"
42 : :
43 : 0 : pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl, const char *module_name) {
44 : : pa_modinfo *i;
45 : : const char* (*func)(void);
46 : : pa_bool_t (*func2) (void);
47 : :
48 [ # # ]: 0 : pa_assert(dl);
49 : :
50 : 0 : i = pa_xnew0(pa_modinfo, 1);
51 : :
52 [ # # ]: 0 : if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_AUTHOR)))
53 : 0 : i->author = pa_xstrdup(func());
54 : :
55 [ # # ]: 0 : if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_DESCRIPTION)))
56 : 0 : i->description = pa_xstrdup(func());
57 : :
58 [ # # ]: 0 : if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_USAGE)))
59 : 0 : i->usage = pa_xstrdup(func());
60 : :
61 [ # # ]: 0 : if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_VERSION)))
62 : 0 : i->version = pa_xstrdup(func());
63 : :
64 [ # # ]: 0 : if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_DEPRECATED)))
65 : 0 : i->deprecated = pa_xstrdup(func());
66 : :
67 [ # # ]: 0 : if ((func2 = (pa_bool_t (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_LOAD_ONCE)))
68 : 0 : i->load_once = func2();
69 : :
70 : 0 : return i;
71 : : }
72 : :
73 : 0 : pa_modinfo *pa_modinfo_get_by_name(const char *name) {
74 : : lt_dlhandle dl;
75 : : pa_modinfo *i;
76 : :
77 [ # # ]: 0 : pa_assert(name);
78 : :
79 [ # # ]: 0 : if (!(dl = lt_dlopenext(name))) {
80 : 0 : pa_log("Failed to open module \"%s\": %s", name, lt_dlerror());
81 : 0 : return NULL;
82 : : }
83 : :
84 : 0 : i = pa_modinfo_get_by_handle(dl, name);
85 : 0 : lt_dlclose(dl);
86 : :
87 : 0 : return i;
88 : : }
89 : :
90 : 0 : void pa_modinfo_free(pa_modinfo *i) {
91 [ # # ]: 0 : pa_assert(i);
92 : :
93 : 0 : pa_xfree(i->author);
94 : 0 : pa_xfree(i->description);
95 : 0 : pa_xfree(i->usage);
96 : 0 : pa_xfree(i->version);
97 : 0 : pa_xfree(i->deprecated);
98 : 0 : pa_xfree(i);
99 : 0 : }
|