mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-15 08:56:34 -05:00
module dependencie foo
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@7 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
8584356bbc
commit
aae40dcea2
6 changed files with 80 additions and 2 deletions
70
src/module.c
70
src/module.c
|
|
@ -1,9 +1,68 @@
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void free_deps(struct dependency_module** deps) {
|
||||||
|
assert(deps);
|
||||||
|
|
||||||
|
while (*deps) {
|
||||||
|
struct dependency_module *next = (*deps)->next;
|
||||||
|
lt_dlclose((*deps)->dl);
|
||||||
|
free(deps);
|
||||||
|
*deps = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int load_deps(const char *fname, struct dependency_module **deps) {
|
||||||
|
char line[PATH_MAX];
|
||||||
|
FILE *f;
|
||||||
|
char depfile[PATH_MAX];
|
||||||
|
assert(fname && deps);
|
||||||
|
|
||||||
|
snprintf(depfile, sizeof(depfile), "%s.moddep", fname);
|
||||||
|
|
||||||
|
if (!(f = fopen(depfile, "r")))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
while (fgets(line, sizeof(line)-1, f)) {
|
||||||
|
lt_dlhandle dl;
|
||||||
|
char *p;
|
||||||
|
size_t l;
|
||||||
|
struct dependency_module* d;
|
||||||
|
|
||||||
|
p = line + strspn(line, " \t");
|
||||||
|
|
||||||
|
l = strlen(p);
|
||||||
|
if (p[l-1] == '\n')
|
||||||
|
p[l-1] = 0;
|
||||||
|
|
||||||
|
if (*p == '#' || *p == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
load_deps(p, deps);
|
||||||
|
|
||||||
|
if (!(dl = lt_dlopenext(p))) {
|
||||||
|
free_deps(deps);
|
||||||
|
fclose(f);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
d = malloc(sizeof(struct dependency_module));
|
||||||
|
assert(d);
|
||||||
|
d->dl = dl;
|
||||||
|
d->next = *deps;
|
||||||
|
*deps = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct module* module_load(struct core *c, const char *name, const char *argument) {
|
struct module* module_load(struct core *c, const char *name, const char *argument) {
|
||||||
struct module *m = NULL;
|
struct module *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
@ -13,6 +72,12 @@ struct module* module_load(struct core *c, const char *name, const char *argumen
|
||||||
m = malloc(sizeof(struct module));
|
m = malloc(sizeof(struct module));
|
||||||
assert(m);
|
assert(m);
|
||||||
|
|
||||||
|
m->dl = NULL;
|
||||||
|
|
||||||
|
m->dependencies = NULL;
|
||||||
|
if (load_deps(name, &m->dependencies) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
if (!(m->dl = lt_dlopenext(name)))
|
if (!(m->dl = lt_dlopenext(name)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
@ -34,7 +99,6 @@ struct module* module_load(struct core *c, const char *name, const char *argumen
|
||||||
if (!c->modules)
|
if (!c->modules)
|
||||||
c->modules = idxset_new(NULL, NULL);
|
c->modules = idxset_new(NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
assert(c->modules);
|
assert(c->modules);
|
||||||
r = idxset_put(c->modules, m, &m->index);
|
r = idxset_put(c->modules, m, &m->index);
|
||||||
assert(r >= 0 && m->index != IDXSET_INVALID);
|
assert(r >= 0 && m->index != IDXSET_INVALID);
|
||||||
|
|
@ -45,6 +109,7 @@ fail:
|
||||||
if (m->dl)
|
if (m->dl)
|
||||||
lt_dlclose(m->dl);
|
lt_dlclose(m->dl);
|
||||||
|
|
||||||
|
free_deps(&m->dependencies);
|
||||||
free(m);
|
free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,11 +121,13 @@ static void module_free(struct module *m) {
|
||||||
m->done(m->core, m);
|
m->done(m->core, m);
|
||||||
|
|
||||||
lt_dlclose(m->dl);
|
lt_dlclose(m->dl);
|
||||||
|
free_deps(&m->dependencies);
|
||||||
free(m->name);
|
free(m->name);
|
||||||
free(m->argument);
|
free(m->argument);
|
||||||
free(m);
|
free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void module_unload(struct core *c, struct module *m) {
|
void module_unload(struct core *c, struct module *m) {
|
||||||
assert(c && m);
|
assert(c && m);
|
||||||
|
|
||||||
|
|
@ -82,7 +149,6 @@ void module_unload_by_index(struct core *c, uint32_t index) {
|
||||||
module_free(m);
|
module_free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void free_callback(void *p, void *userdata) {
|
void free_callback(void *p, void *userdata) {
|
||||||
struct module *m = p;
|
struct module *m = p;
|
||||||
assert(m);
|
assert(m);
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,19 @@
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
|
||||||
|
struct dependency_module {
|
||||||
|
lt_dlhandle dl;
|
||||||
|
struct dependency_module *next;
|
||||||
|
};
|
||||||
|
|
||||||
struct module {
|
struct module {
|
||||||
struct core *core;
|
struct core *core;
|
||||||
char *name, *argument;
|
char *name, *argument;
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
|
|
||||||
lt_dlhandle dl;
|
lt_dlhandle dl;
|
||||||
|
struct dependency_module *dependencies;
|
||||||
|
|
||||||
|
|
||||||
int (*init)(struct core *c, struct module*m);
|
int (*init)(struct core *c, struct module*m);
|
||||||
void (*done)(struct core *c, struct module*m);
|
void (*done)(struct core *c, struct module*m);
|
||||||
|
|
|
||||||
2
src/protocol-simple-tcp.moddep
Normal file
2
src/protocol-simple-tcp.moddep
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
socket-server
|
||||||
|
protocol-simple
|
||||||
1
src/protocol-simple.moddep
Normal file
1
src/protocol-simple.moddep
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
socket-server
|
||||||
1
src/sink-pipe.moddep
Normal file
1
src/sink-pipe.moddep
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
iochannel
|
||||||
1
src/socket-server.moddep
Normal file
1
src/socket-server.moddep
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
iochannel
|
||||||
Loading…
Add table
Add a link
Reference in a new issue