241076c66b44b0867fc87858f511dfd28b9dc260
[profile/ivi/pulseaudio.git] / src / polypcore / 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 Lesser General Public License as
8   published by the Free Software Foundation; either version 2 of the
9   License, 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 Lesser General Public
17   License 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 <polyp/xmalloc.h>
30
31 #include <polypcore/util.h>
32 #include <polypcore/log.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
41 pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) {
42     pa_modinfo *i;
43     const char* (*func)(void);
44     assert(dl);
45
46     i = pa_xnew0(pa_modinfo, 1);
47
48     if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_AUTHOR)))
49         i->author = pa_xstrdup(func());
50
51     if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_DESCRIPTION)))
52         i->description = pa_xstrdup(func());
53
54     if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_USAGE)))
55         i->usage = pa_xstrdup(func());
56
57     if ((func = (const char* (*)(void)) lt_dlsym(dl, PA_SYMBOL_VERSION)))
58         i->version = pa_xstrdup(func());
59
60     return i;
61 }
62
63 pa_modinfo *pa_modinfo_get_by_name(const char *name) {
64     lt_dlhandle dl;
65     pa_modinfo *i;
66     assert(name);
67
68     if (!(dl = lt_dlopenext(name))) {
69         pa_log(__FILE__": Failed to open module \"%s\": %s", name, lt_dlerror());
70         return NULL;
71     }
72
73     i = pa_modinfo_get_by_handle(dl);
74     lt_dlclose(dl);
75
76     return i;
77 }
78
79 void pa_modinfo_free(pa_modinfo *i) {
80     assert(i);
81     pa_xfree(i->author);
82     pa_xfree(i->description);
83     pa_xfree(i->usage);
84     pa_xfree(i->version);
85     pa_xfree(i);
86 }