10 struct module* module_load(struct core *c, const char *name, const char *argument) {
11 struct module *m = NULL;
16 m = malloc(sizeof(struct module));
19 if (!(m->dl = lt_dlopenext(name)))
22 if (!(m->init = lt_dlsym(m->dl, "module_init")))
25 if (!(m->done = lt_dlsym(m->dl, "module_done")))
28 m->name = strdup(name);
29 m->argument = argument ? strdup(argument) : NULL;
34 if (m->init(c, m) < 0)
38 c->modules = idxset_new(NULL, NULL);
41 r = idxset_put(c->modules, m, &m->index);
42 assert(r >= 0 && m->index != IDXSET_INVALID);
44 fprintf(stderr, "module: loaded %u \"%s\" with argument \"%s\".\n", m->index, m->name, m->argument);
62 static void module_free(struct module *m) {
63 assert(m && m->done && m->core);
68 fprintf(stderr, "module: unloaded %u \"%s\".\n", m->index, m->name);
76 void module_unload(struct core *c, struct module *m) {
80 if (!(m = idxset_remove_by_data(c->modules, m, NULL)))
86 void module_unload_by_index(struct core *c, uint32_t index) {
88 assert(c && index != IDXSET_INVALID);
91 if (!(m = idxset_remove_by_index(c->modules, index)))
97 void free_callback(void *p, void *userdata) {
103 void module_unload_all(struct core *c) {
109 idxset_free(c->modules, free_callback, NULL);