Add copyright notices to all relevant files. (based on svn log)
[profile/ivi/pulseaudio.git] / 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 #include <assert.h>
30
31 #include <pulse/xmalloc.h>
32
33 #include <pulsecore/core-util.h>
34 #include <pulsecore/log.h>
35
36 #include "modinfo.h"
37
38 #define PA_SYMBOL_AUTHOR "pa__get_author"
39 #define PA_SYMBOL_DESCRIPTION "pa__get_description"
40 #define PA_SYMBOL_USAGE "pa__get_usage"
41 #define PA_SYMBOL_VERSION "pa__get_version"
42
43 /* lt_dlsym() violates ISO C, so confide the breakage into this function to
44  * avoid warnings. */
45 typedef void (*fnptr)(void);
46 static inline fnptr lt_dlsym_fn(lt_dlhandle handle, const char *symbol) {
47     return (fnptr) (long) lt_dlsym(handle, symbol);
48 }
49
50 pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) {
51     pa_modinfo *i;
52     const char* (*func)(void);
53     assert(dl);
54
55     i = pa_xnew0(pa_modinfo, 1);
56
57     if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_AUTHOR)))
58         i->author = pa_xstrdup(func());
59
60     if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_DESCRIPTION)))
61         i->description = pa_xstrdup(func());
62
63     if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_USAGE)))
64         i->usage = pa_xstrdup(func());
65
66     if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_VERSION)))
67         i->version = pa_xstrdup(func());
68
69     return i;
70 }
71
72 pa_modinfo *pa_modinfo_get_by_name(const char *name) {
73     lt_dlhandle dl;
74     pa_modinfo *i;
75     assert(name);
76
77     if (!(dl = lt_dlopenext(name))) {
78         pa_log("Failed to open module \"%s\": %s", name, lt_dlerror());
79         return NULL;
80     }
81
82     i = pa_modinfo_get_by_handle(dl);
83     lt_dlclose(dl);
84
85     return i;
86 }
87
88 void pa_modinfo_free(pa_modinfo *i) {
89     assert(i);
90     pa_xfree(i->author);
91     pa_xfree(i->description);
92     pa_xfree(i->usage);
93     pa_xfree(i->version);
94     pa_xfree(i);
95 }