+
+static void foreach_start(GQuark key, Plugin *p, gpointer *foo)
+{
+ p->startup();
+}
+
+void plugin_startall()
+{
+ g_datalist_foreach(&plugins, (GDataForeachFunc)foreach_start, NULL);
+}
+
+void plugin_loadall()
+{
+ GIOChannel *io;
+ GError *err;
+ char *path, *name;
+
+ path = g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL);
+ err = NULL;
+ io = g_io_channel_new_file(path, "r", &err);
+ g_free(path);
+
+ if (io == NULL) {
+ path = g_build_filename(RCDIR, "pluginrc", NULL);
+ err = NULL;
+ io = g_io_channel_new_file(path, "r", &err);
+ g_free(path);
+ }
+
+ if (io == NULL) {
+ /* load the default plugins */
+ plugin_open("keyboard");
+ plugin_open("mouse");
+ plugin_open("placement");
+ plugin_open("resistance");
+
+ /* XXX rm me when the parser loads me magically */
+ plugin_open("client_menu");
+ } else {
+ /* load the plugins in the rc file */
+ while (g_io_channel_read_line(io, &name, NULL, NULL, &err) ==
+ G_IO_STATUS_NORMAL) {
+ g_strstrip(name);
+ if (name[0] != '\0' && name[0] != '#')
+ plugin_open(name);
+ g_free(name);
+ }
+ g_io_channel_unref(io);
+ }
+}
+
+void *plugin_create(char *name, void *data)
+{
+ Plugin *p = (Plugin *)g_datalist_get_data(&plugins, name);
+
+ if (p == NULL) {
+ g_warning("Unable to find plugin for create: %s", name);
+ return NULL;
+ }
+
+ if (p->create == NULL || p->destroy == NULL) {
+ g_critical("Unsupported create/destroy: %s", name);
+ return NULL;
+ }
+
+ return p->create(data);
+}
+
+void plugin_destroy(char *name, void *data)
+{
+ Plugin *p = (Plugin *)g_datalist_get_data(&plugins, name);
+
+ if (p == NULL) {
+ g_critical("Unable to find plugin for destroy: %s", name);
+ /* really shouldn't happen, but attempt to free something anyway? */
+ g_free(data);
+ return;
+ }
+
+ if (p->destroy == NULL || p->create == NULL) {
+ g_critical("Unsupported create/destroy: %s", name);
+ /* really, really shouldn't happen, but attempt to free anyway? */
+ g_free(data);
+ return;
+ }
+
+ p->destroy(data);
+}