daemon: add nice value in service file to improve performance
[platform/upstream/pulseaudio.git] / src / pulsecore / modinfo.c
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, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <ltdl.h>
25
26 #include <pulse/xmalloc.h>
27
28 #include <pulsecore/log.h>
29 #include <pulsecore/macro.h>
30 #include <pulsecore/ltdl-helper.h>
31
32 #include "modinfo.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 #define PA_SYMBOL_DEPRECATED "pa__get_deprecated"
39 #define PA_SYMBOL_LOAD_ONCE "pa__load_once"
40
41 pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl, const char *module_name) {
42     pa_modinfo *i;
43     const char* (*func)(void);
44     bool (*func2) (void);
45
46     pa_assert(dl);
47
48     i = pa_xnew0(pa_modinfo, 1);
49
50     if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_AUTHOR)))
51         i->author = pa_xstrdup(func());
52
53     if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_DESCRIPTION)))
54         i->description = pa_xstrdup(func());
55
56     if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_USAGE)))
57         i->usage = pa_xstrdup(func());
58
59     if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_VERSION)))
60         i->version = pa_xstrdup(func());
61
62     if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_DEPRECATED)))
63         i->deprecated = pa_xstrdup(func());
64
65     if ((func2 = (bool (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_LOAD_ONCE)))
66         i->load_once = func2();
67
68     return i;
69 }
70
71 pa_modinfo *pa_modinfo_get_by_name(const char *name) {
72     lt_dlhandle dl;
73     pa_modinfo *i;
74
75     pa_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, name);
83     lt_dlclose(dl);
84
85     return i;
86 }
87
88 void pa_modinfo_free(pa_modinfo *i) {
89     pa_assert(i);
90
91     pa_xfree(i->author);
92     pa_xfree(i->description);
93     pa_xfree(i->usage);
94     pa_xfree(i->version);
95     pa_xfree(i->deprecated);
96     pa_xfree(i);
97 }