]>
Dogcows Code - chaz/openbox/blob - openbox/plugin.c
4 typedef void (*PluginSetupConfig
)();
5 typedef void (*PluginStartup
)();
6 typedef void (*PluginShutdown
)();
12 PluginSetupConfig config
;
13 PluginStartup startup
;
14 PluginShutdown shutdown
;
17 static gpointer
load_sym(GModule
*module, char *name
, char *symbol
)
20 if (!g_module_symbol(module, symbol
, &var
)) {
21 g_warning("Failed to load symbol '%s' from plugin '%s'",
28 static Plugin
*plugin_new(char *name
)
35 path
= g_build_filename(g_get_home_dir(), ".openbox", "plugins", name
,
37 p
->module = g_module_open(path
, 0);
40 if (p
->module == NULL
) {
41 path
= g_build_filename(PLUGINDIR
, name
, NULL
);
42 p
->module = g_module_open(path
, 0);
46 if (p
->module == NULL
) {
51 p
->config
= (PluginSetupConfig
)load_sym(p
->module, name
,
52 "plugin_setup_config");
53 p
->startup
= (PluginStartup
)load_sym(p
->module, name
, "plugin_startup");
54 p
->shutdown
= (PluginShutdown
)load_sym(p
->module, name
, "plugin_shutdown");
56 if (p
->config
== NULL
|| p
->startup
== NULL
|| p
->shutdown
== NULL
) {
57 g_module_close(p
->module);
62 p
->name
= g_strdup(name
);
66 static void plugin_free(Plugin
*p
)
71 g_module_close(p
->module);
75 static GData
*plugins
= NULL
;
79 g_datalist_init(&plugins
);
82 void plugin_shutdown()
84 g_datalist_clear(&plugins
);
87 gboolean
plugin_open(char *name
)
91 if (g_datalist_get_data(&plugins
, name
) != NULL
) {
92 g_warning("plugin '%s' already loaded, can't load again", name
);
98 g_warning("failed to load plugin '%s'", name
);
103 g_datalist_set_data_full(&plugins
, name
, p
, (GDestroyNotify
) plugin_free
);
107 void plugin_close(char *name
)
109 g_datalist_remove_data(&plugins
, name
);
112 static void foreach_start(GQuark key
, Plugin
*p
, gpointer
*foo
)
117 void plugin_startall()
119 g_datalist_foreach(&plugins
, (GDataForeachFunc
)foreach_start
, NULL
);
122 void plugin_loadall()
128 path
= g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL
);
130 io
= g_io_channel_new_file(path
, "r", &err
);
134 path
= g_build_filename(RCDIR
, "pluginrc", NULL
);
136 io
= g_io_channel_new_file(path
, "r", &err
);
141 /* load the default plugins */
142 plugin_open("focus");
143 plugin_open("keyboard");
144 plugin_open("mouse");
145 plugin_open("placement");
146 plugin_open("resistance");
148 /* load the plugins in the rc file */
149 while (g_io_channel_read_line(io
, &name
, NULL
, NULL
, &err
) ==
150 G_IO_STATUS_NORMAL
) {
155 g_io_channel_unref(io
);
This page took 0.039057 seconds and 4 git commands to generate.