]>
Dogcows Code - chaz/openbox/blob - openbox/plugin.c
4 typedef void (*PluginStartup
)();
5 typedef void (*PluginShutdown
)();
11 PluginStartup startup
;
12 PluginShutdown shutdown
;
15 static gpointer
load_sym(GModule
*module, char *name
, char *symbol
)
18 if (!g_module_symbol(module, symbol
, &var
)) {
19 g_warning("Failed to load symbol '%s' from plugin '%s'",
26 static Plugin
*plugin_new(char *name
)
33 path
= g_build_filename(PLUGINDIR
, name
, NULL
);
34 p
->module = g_module_open(path
, 0);
37 if (p
->module == NULL
) {
38 path
= g_build_filename(g_get_home_dir(), ".openbox", "plugins", name
,
40 p
->module = g_module_open(path
, 0);
44 if (p
->module == NULL
) {
49 p
->startup
= load_sym(p
->module, name
, "plugin_startup");
50 p
->shutdown
= load_sym(p
->module, name
, "plugin_shutdown");
52 if (p
->startup
== NULL
|| p
->shutdown
== NULL
) {
53 g_module_close(p
->module);
58 p
->name
= g_strdup(name
);
62 static void plugin_free(Plugin
*p
)
67 g_module_close(p
->module);
71 static GData
*plugins
= NULL
;
75 g_datalist_init(&plugins
);
78 void plugin_shutdown()
80 g_datalist_clear(&plugins
);
83 gboolean
plugin_open(char *name
)
87 if (g_datalist_get_data(&plugins
, name
) != NULL
) {
88 g_warning("plugin '%s' already loaded, can't load again", name
);
94 g_warning("failed to load plugin '%s'", name
);
98 g_datalist_set_data_full(&plugins
, name
, p
, (GDestroyNotify
) plugin_free
);
103 void plugin_close(char *name
)
105 g_datalist_remove_data(&plugins
, name
);
This page took 0.036747 seconds and 4 git commands to generate.