]>
Dogcows Code - chaz/openbox/blob - openbox/plugin.c
1 #include "plugins/interface.h"
10 PluginSetupConfig config
;
11 PluginStartup startup
;
12 PluginShutdown shutdown
;
14 PluginDestroy destroy
;
17 static gpointer
load_sym(GModule
*module, char *name
, char *symbol
,
21 if (!g_module_symbol(module, symbol
, &var
)) {
23 g_warning("Failed to load symbol '%s' from plugin '%s'",
30 static Plugin
*plugin_new(char *name
)
37 path
= g_build_filename(g_get_home_dir(), ".openbox", "plugins", name
,
39 p
->module = g_module_open(path
, 0);
42 if (p
->module == NULL
) {
43 path
= g_build_filename(PLUGINDIR
, name
, NULL
);
44 p
->module = g_module_open(path
, 0);
48 if (p
->module == NULL
) {
49 g_warning(g_module_error());
54 p
->config
= (PluginSetupConfig
)load_sym(p
->module, name
,
55 "plugin_setup_config", FALSE
);
56 p
->startup
= (PluginStartup
)load_sym(p
->module, name
, "plugin_startup",
58 p
->shutdown
= (PluginShutdown
)load_sym(p
->module, name
, "plugin_shutdown",
60 p
->create
= (PluginCreate
)load_sym(p
->module, name
, "plugin_create", TRUE
);
61 p
->destroy
= (PluginDestroy
)load_sym(p
->module, name
, "plugin_destroy",
64 if (p
->config
== NULL
|| p
->startup
== NULL
|| p
->shutdown
== NULL
) {
65 g_module_close(p
->module);
70 p
->name
= g_strdup(name
);
74 static void plugin_free(Plugin
*p
)
79 g_module_close(p
->module);
83 static GData
*plugins
= NULL
;
87 g_datalist_init(&plugins
);
90 void plugin_shutdown()
92 g_datalist_clear(&plugins
);
95 gboolean
plugin_open_full(char *name
, gboolean reopen
)
99 if (g_datalist_get_data(&plugins
, name
) != NULL
) {
101 g_warning("plugin '%s' already loaded, can't load again", name
);
105 p
= plugin_new(name
);
107 g_warning("failed to load plugin '%s'", name
);
112 g_datalist_set_data_full(&plugins
, name
, p
, (GDestroyNotify
) plugin_free
);
116 gboolean
plugin_open(char *name
) {
117 return plugin_open_full(name
, FALSE
);
120 gboolean
plugin_open_reopen(char *name
) {
121 return plugin_open_full(name
, TRUE
);
124 void plugin_close(char *name
)
126 g_datalist_remove_data(&plugins
, name
);
129 static void foreach_start(GQuark key
, Plugin
*p
, gpointer
*foo
)
134 void plugin_startall()
136 g_datalist_foreach(&plugins
, (GDataForeachFunc
)foreach_start
, NULL
);
139 void plugin_loadall()
145 path
= g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL
);
147 io
= g_io_channel_new_file(path
, "r", &err
);
151 path
= g_build_filename(RCDIR
, "pluginrc", NULL
);
153 io
= g_io_channel_new_file(path
, "r", &err
);
158 /* load the default plugins */
159 plugin_open("keyboard");
160 plugin_open("mouse");
161 plugin_open("placement");
162 plugin_open("resistance");
164 /* XXX rm me when the parser loads me magically */
165 plugin_open("client_menu");
167 /* load the plugins in the rc file */
168 while (g_io_channel_read_line(io
, &name
, NULL
, NULL
, &err
) ==
169 G_IO_STATUS_NORMAL
) {
171 if (name
[0] != '\0' && name
[0] != '#')
175 g_io_channel_unref(io
);
179 void *plugin_create(char *name
, void *data
)
181 Plugin
*p
= (Plugin
*)g_datalist_get_data(&plugins
, name
);
184 g_warning("Unable to find plugin for create: %s", name
);
188 if (p
->create
== NULL
|| p
->destroy
== NULL
) {
189 g_critical("Unsupported create/destroy: %s", name
);
193 return p
->create(data
);
196 void plugin_destroy(char *name
, void *data
)
198 Plugin
*p
= (Plugin
*)g_datalist_get_data(&plugins
, name
);
201 g_critical("Unable to find plugin for destroy: %s", name
);
202 /* really shouldn't happen, but attempt to free something anyway? */
207 if (p
->destroy
== NULL
|| p
->create
== NULL
) {
208 g_critical("Unsupported create/destroy: %s", name
);
209 /* really, really shouldn't happen, but attempt to free anyway? */
This page took 0.047459 seconds and 4 git commands to generate.