~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/pulsecore/modinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2006-11-12 20:00:18 UTC
  • Revision ID: james.westby@ubuntu.com-20061112200018-oji9njq7rr3te53k
Tags: upstream-0.9.5
ImportĀ upstreamĀ versionĀ 0.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: modinfo.c 1272 2006-08-18 21:38:40Z lennart $ */
 
2
 
 
3
/***
 
4
  This file is part of PulseAudio.
 
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 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
#include <assert.h>
 
28
 
 
29
#include <pulse/xmalloc.h>
 
30
 
 
31
#include <pulsecore/core-util.h>
 
32
#include <pulsecore/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
/* lt_dlsym() violates ISO C, so confide the breakage into this function to
 
42
 * avoid warnings. */
 
43
typedef void (*fnptr)(void);
 
44
static inline fnptr lt_dlsym_fn(lt_dlhandle handle, const char *symbol) {
 
45
    return (fnptr) (long) lt_dlsym(handle, symbol);
 
46
}
 
47
 
 
48
pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) {
 
49
    pa_modinfo *i;
 
50
    const char* (*func)(void);
 
51
    assert(dl);
 
52
 
 
53
    i = pa_xnew0(pa_modinfo, 1);
 
54
 
 
55
    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_AUTHOR)))
 
56
        i->author = pa_xstrdup(func());
 
57
 
 
58
    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_DESCRIPTION)))
 
59
        i->description = pa_xstrdup(func());
 
60
 
 
61
    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_USAGE)))
 
62
        i->usage = pa_xstrdup(func());
 
63
 
 
64
    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_VERSION)))
 
65
        i->version = pa_xstrdup(func());
 
66
 
 
67
    return i;
 
68
}
 
69
 
 
70
pa_modinfo *pa_modinfo_get_by_name(const char *name) {
 
71
    lt_dlhandle dl;
 
72
    pa_modinfo *i;
 
73
    assert(name);
 
74
 
 
75
    if (!(dl = lt_dlopenext(name))) {
 
76
        pa_log("Failed to open module \"%s\": %s", name, lt_dlerror());
 
77
        return NULL;
 
78
    }
 
79
 
 
80
    i = pa_modinfo_get_by_handle(dl);
 
81
    lt_dlclose(dl);
 
82
 
 
83
    return i;
 
84
}
 
85
 
 
86
void pa_modinfo_free(pa_modinfo *i) {
 
87
    assert(i);
 
88
    pa_xfree(i->author);
 
89
    pa_xfree(i->description);
 
90
    pa_xfree(i->usage);
 
91
    pa_xfree(i->version);
 
92
    pa_xfree(i);
 
93
}