]> code.delx.au - pulseaudio/blob - polyp/modinfo.c
2847c63cd512ca2cb2844996b2e73cd9203b5323
[pulseaudio] / polyp / modinfo.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU 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 polypaudio 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 General Public License
17 along with polypaudio; 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 #include <assert.h>
28
29 #include "xmalloc.h"
30 #include "util.h"
31 #include "modinfo.h"
32 #include "log.h"
33
34 #define PA_SYMBOL_AUTHOR "pa__get_author"
35 #define PA_SYMBOL_DESCRIPTION "pa__get_description"
36 #define PA_SYMBOL_USAGE "pa__get_usage"
37 #define PA_SYMBOL_VERSION "pa__get_version"
38
39 struct pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) {
40 struct pa_modinfo *i;
41 const char* (*func)(void);
42 assert(dl);
43
44 i = pa_xmalloc0(sizeof(struct pa_modinfo));
45
46 if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_AUTHOR)))
47 i->author = pa_xstrdup(func());
48
49 if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_DESCRIPTION)))
50 i->description = pa_xstrdup(func());
51
52 if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_USAGE)))
53 i->usage = pa_xstrdup(func());
54
55 if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_VERSION)))
56 i->version = pa_xstrdup(func());
57
58 return i;
59 }
60
61 struct pa_modinfo *pa_modinfo_get_by_name(const char *name) {
62 lt_dlhandle dl;
63 struct pa_modinfo *i;
64 assert(name);
65
66 if (!(dl = lt_dlopenext(name))) {
67 pa_log(__FILE__": Failed to open module \"%s\": %s\n", name, lt_dlerror());
68 return NULL;
69 }
70
71 i = pa_modinfo_get_by_handle(dl);
72 lt_dlclose(dl);
73
74 return i;
75 }
76
77 void pa_modinfo_free(struct pa_modinfo *i) {
78 assert(i);
79 pa_xfree(i->author);
80 pa_xfree(i->description);
81 pa_xfree(i->usage);
82 pa_xfree(i->version);
83 pa_xfree(i);
84 }