]>
Dogcows Code - chaz/openbox/blob - openbox/plugin.c
4 typedef void (*PluginSetupConfig
)();
5 typedef void (*PluginStartup
)();
6 typedef void (*PluginShutdown
)();
7 typedef void *(*PluginCreate
)(/* TODO */);
8 typedef void (*PluginDestroy
)(void *);
14 PluginSetupConfig config
;
15 PluginStartup startup
;
16 PluginShutdown shutdown
;
18 PluginDestroy destroy
;
21 static gpointer
load_sym(GModule
*module, char *name
, char *symbol
,
25 if (!g_module_symbol(module, symbol
, &var
)) {
27 g_warning("Failed to load symbol '%s' from plugin '%s'",
34 static Plugin
*plugin_new(char *name
)
41 path
= g_build_filename(g_get_home_dir(), ".openbox", "plugins", name
,
43 p
->module = g_module_open(path
, 0);
46 if (p
->module == NULL
) {
47 path
= g_build_filename(PLUGINDIR
, name
, NULL
);
48 p
->module = g_module_open(path
, 0);
52 if (p
->module == NULL
) {
53 g_warning(g_module_error());
58 p
->config
= (PluginSetupConfig
)load_sym(p
->module, name
,
59 "plugin_setup_config", FALSE
);
60 p
->startup
= (PluginStartup
)load_sym(p
->module, name
, "plugin_startup",
62 p
->shutdown
= (PluginShutdown
)load_sym(p
->module, name
, "plugin_shutdown",
64 p
->create
= (PluginCreate
)load_sym(p
->module, name
, "plugin_create", TRUE
);
65 p
->destroy
= (PluginDestroy
)load_sym(p
->module, name
, "plugin_destroy",
68 if (p
->config
== NULL
|| p
->startup
== NULL
|| p
->shutdown
== NULL
) {
69 g_module_close(p
->module);
74 p
->name
= g_strdup(name
);
78 static void plugin_free(Plugin
*p
)
83 g_module_close(p
->module);
87 static GData
*plugins
= NULL
;
91 g_datalist_init(&plugins
);
94 void plugin_shutdown()
96 g_datalist_clear(&plugins
);
99 gboolean
plugin_open_full(char *name
, gboolean reopen
)
103 if (g_datalist_get_data(&plugins
, name
) != NULL
) {
105 g_warning("plugin '%s' already loaded, can't load again", name
);
109 p
= plugin_new(name
);
111 g_warning("failed to load plugin '%s'", name
);
116 g_datalist_set_data_full(&plugins
, name
, p
, (GDestroyNotify
) plugin_free
);
120 gboolean
plugin_open(char *name
) {
121 return plugin_open_full(name
, FALSE
);
124 gboolean
plugin_open_reopen(char *name
) {
125 return plugin_open_full(name
, TRUE
);
128 void plugin_close(char *name
)
130 g_datalist_remove_data(&plugins
, name
);
133 static void foreach_start(GQuark key
, Plugin
*p
, gpointer
*foo
)
138 void plugin_startall()
140 g_datalist_foreach(&plugins
, (GDataForeachFunc
)foreach_start
, NULL
);
143 void plugin_loadall()
149 path
= g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL
);
151 io
= g_io_channel_new_file(path
, "r", &err
);
155 path
= g_build_filename(RCDIR
, "pluginrc", NULL
);
157 io
= g_io_channel_new_file(path
, "r", &err
);
162 /* load the default plugins */
163 plugin_open("keyboard");
164 plugin_open("mouse");
165 plugin_open("placement");
166 plugin_open("resistance");
168 /* load the plugins in the rc file */
169 while (g_io_channel_read_line(io
, &name
, NULL
, NULL
, &err
) ==
170 G_IO_STATUS_NORMAL
) {
172 if (name
[0] != '\0' && name
[0] != '#')
176 g_io_channel_unref(io
);
180 void *plugin_create(char *name
/* TODO */)
182 Plugin
*p
= (Plugin
*)g_datalist_get_data(&plugins
, name
);
185 g_warning("Unable to find plugin for create: %s", name
);
189 if (p
->create
== NULL
|| p
->destroy
== NULL
) {
190 g_critical("Unsupported create/destroy: %s", name
);
197 void plugin_destroy(char *name
, void *data
)
199 Plugin
*p
= (Plugin
*)g_datalist_get_data(&plugins
, name
);
202 g_critical("Unable to find plugin for destroy: %s", name
);
203 /* really shouldn't happen, but attempt to free something anyway? */
208 if (p
->destroy
== NULL
|| p
->create
== NULL
) {
209 g_critical("Unsupported create/destroy: %s", name
);
210 /* really, really shouldn't happen, but attempt to free anyway? */
This page took 0.04506 seconds and 4 git commands to generate.