diff src/plugins.c @ 94:9f6ce50ffb78

[gaim-migrate @ 104] Woohoo, the landing of the plugins. Nearly everything necessary is here. The only thing missing is that you can't load a plugin without signing on first (at least, not without some trickery). committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 09 Apr 2000 11:18:25 +0000
parents f3c6cf79f651
children 247f540ea6e1
line wrap: on
line diff
--- a/src/plugins.c	Sun Apr 09 08:25:15 2000 +0000
+++ b/src/plugins.c	Sun Apr 09 11:18:25 2000 +0000
@@ -44,7 +44,11 @@
 
 #include <dlfcn.h>
 
-/* ------------------ Local Variables -------------------------*/
+/* ------------------ Global Variables ----------------------- */
+
+GList *callbacks = NULL;
+
+/* ------------------ Local Variables ------------------------ */
 
 static GtkWidget *plugin_dialog = NULL;
 static GList     *plugins = NULL;
@@ -53,12 +57,15 @@
 static GtkWidget *plugtext;
 static GtkWidget *plugwindow;
 
-/* --------------- Function Declarations -------------------- */
+/* --------------- Function Declarations --------------------- */
 
        void load_plugin  (GtkWidget *, gpointer);
        void unload_plugin(GtkWidget *, gpointer);
        void show_plugins (GtkWidget *, gpointer);
 
+       void gaim_signal_connect   (void *, enum gaim_event, void *, void *);
+       void gaim_signal_disconnect(void *, enum gaim_event, void *);
+
 static void destroy_plugins  (GtkWidget *, gpointer);
 static void load_which_plugin(GtkWidget *, gpointer);
 static void unload           (GtkWidget *, gpointer);
@@ -140,7 +147,7 @@
 	}
 
 	plugins = g_list_append(plugins, plug);
-	(*gaim_plugin_init)();
+	(*gaim_plugin_init)(plug->handle);
 
 	cfunc = dlsym(plug->handle, "name");
 	if ((error = dlerror()) == NULL)
@@ -299,6 +306,8 @@
 	struct gaim_plugin *p;
 	void (*gaim_plugin_remove)();
 	char *error;
+	GList *c = callbacks;
+	struct gaim_callback *g;
 
 	i = GTK_LIST(pluglist)->selection;
 
@@ -309,6 +318,14 @@
 	gaim_plugin_remove = dlsym(p->handle, "gaim_plugin_remove");
 	if ((error = dlerror()) == NULL)
 		(*gaim_plugin_remove)();
+	while (c) {
+		g = (struct gaim_callback *)c->data;
+		if (g->handle == p->handle) {
+			callbacks = g_list_remove(callbacks, c);
+			g_free(g);
+		}
+		c = c->next;
+	}
 	dlclose(p->handle);
 
 	plugins = g_list_remove(plugins, p);
@@ -334,4 +351,28 @@
 	plugwindow = NULL;
 }
 
+void gaim_signal_connect(void *handle, enum gaim_event which,
+			 void *func, void *data) {
+	struct gaim_callback *call = g_malloc(sizeof *call);
+	call->handle = handle;
+	call->event = which;
+	call->function = func;
+	call->data = data;
+
+	callbacks = g_list_append(callbacks, call);
+}
+
+void gaim_signal_disconnect(void *handle, enum gaim_event which, void *func) {
+	GList *c = callbacks;
+	struct gaim_callback *g = NULL;
+	while (c) {
+		g = (struct gaim_callback *)c->data;
+		if (handle == g->handle && func == g->function) {
+			callbacks = g_list_remove(callbacks, g);
+			g_free(g);
+		}
+		c = c->next;
+	}
+}
+
 #endif /* GAIM_PLUGINS */