23 plugin_new(char *plugin)
26 if (! g_module_supported()) {
29 ret=g_new0(struct plugin, 1);
30 ret->name=g_strdup(plugin);
36 plugin_load(struct plugin *pl)
43 g_warning("can't load '%s', already loaded\n", pl->name);
46 mod=g_module_open(pl->name, G_MODULE_BIND_LOCAL | (pl->lazy ? G_MODULE_BIND_LAZY : 0));
48 g_warning("can't load '%s', Error '%s'\n", pl->name, g_module_error());
51 if (!g_module_symbol(mod, "plugin_init", &init)) {
52 g_warning("can't load '%s', plugin_init not found\n", pl->name);
63 plugin_get_name(struct plugin *pl)
69 plugin_get_active(struct plugin *pl)
75 plugin_set_active(struct plugin *pl, int active)
81 plugin_set_lazy(struct plugin *pl, int lazy)
87 plugin_call_init(struct plugin *pl)
93 plugin_unload(struct plugin *pl)
95 g_module_close(pl->mod);
100 plugin_destroy(struct plugin *pl)
108 struct plugins *ret=g_new0(struct plugins, 1);
109 ret->hash=g_hash_table_new(g_str_hash, g_str_equal);
114 plugins_add_path(struct plugins *pls, const char *path, int active, int lazy)
116 struct file_wordexp *we;
122 we=file_wordexp_new(path);
123 count=file_wordexp_get_count(we);
124 array=file_wordexp_get_array(we);
125 for (i = 0 ; i < count ; i++) {
127 if (! (pl=g_hash_table_lookup(pls->hash, name))) {
130 g_warning("failed to create plugin '%s'\n", name);
133 g_hash_table_insert(pls->hash, plugin_get_name(pl), pl);
134 pls->list=g_list_append(pls->list, pl);
136 pls->list=g_list_remove(pls->list, pl);
137 pls->list=g_list_append(pls->list, pl);
139 plugin_set_active(pl, active);
140 plugin_set_lazy(pl, lazy);
142 file_wordexp_destroy(we);
146 plugins_init(struct plugins *pls)
155 if (plugin_get_active(pl))
156 if (!plugin_load(pl))
157 plugin_set_active(pl, 0);
163 if (plugin_get_active(pl))
164 plugin_call_init(pl);
171 plugins_destroy(struct plugins *pls)
182 g_list_free(pls->list);
183 g_hash_table_destroy(pls->hash);
188 plugin_get_type(enum plugin_type type, const char *name)
192 l=plugin_types[type];
195 if (!g_ascii_strcasecmp(nv->name, name))