diff src/dbus-server.c @ 13955:2d6f7ac4b6f2

[gaim-migrate @ 16503] Get rid of an assertion failure when trying to load our D-BUS example plugin if the D-BUS subsystem is not initialized for whatever reason. Not only that, the plugin gracefully fails to load and prints an error message. These error messages could be improved. If you're familiar with how D-BUS works then go for it. Also, do we need to be uninitializing any of the D-BUS stuff? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 17 Jul 2006 05:50:28 +0000
parents fd708f52defd
children f7cfaee79982
line wrap: on
line diff
--- a/src/dbus-server.c	Mon Jul 17 04:33:32 2006 +0000
+++ b/src/dbus-server.c	Mon Jul 17 05:50:28 2006 +0000
@@ -36,6 +36,7 @@
 #include "dbus-bindings.h"
 #include "debug.h"
 #include "core.h"
+#include "internal.h"
 #include "savedstatuses.h"
 #include "value.h"
 
@@ -59,6 +60,8 @@
 static GHashTable *map_id_node; 
 static GHashTable *map_id_type; 
 
+static gchar *init_error;
+
 
 /* This function initializes the pointer-id traslation system.  It
    creates the three above hashtables and defines parents of some types.
@@ -229,7 +232,7 @@
 	    DBusMessageIter *sub;
 	    sub = va_arg (var_args, DBusMessageIter*);
 	    dbus_message_iter_recurse(iter, sub);
-	    g_print("subiter %i:%i\n", (int) sub, * (int*) sub);
+	    gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub);
 	    break;		/* for testing only! */
 	}
 	
@@ -383,12 +386,6 @@
 
 #include "dbus-bindings.c"
 
-void *gaim_dbus_get_handle(void) {
-    static int handle;
-
-    return &handle;
-}
-
 static gboolean
 gaim_dbus_dispatch_cb(DBusConnection *connection,
 		   DBusMessage *message,
@@ -437,7 +434,7 @@
 }
 
 
-static const char *gettext(const char **ptr) {
+static const char *dbus_gettext(const char **ptr) {
     const char *text = *ptr;
     *ptr += strlen(text) + 1;
     return text;
@@ -478,9 +475,9 @@
 	    while (*text) {		
 		const char *name, *direction, *type;
 		
-		direction = gettext(&text);
-		type = gettext(&text);
-		name = gettext(&text);
+		direction = dbus_gettext(&text);
+		type = dbus_gettext(&text);
+		name = dbus_gettext(&text);
 		
 		g_string_append_printf(str, 
 				       "<arg name='%s' type='%s' direction='%s'/>\n",
@@ -539,7 +536,7 @@
 
 
 
-static gboolean gaim_dbus_dispatch_init(void) 
+static void gaim_dbus_dispatch_init(void) 
 {
     static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL};
 
@@ -550,17 +547,17 @@
     gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error);    
 
     if (gaim_dbus_connection == NULL) {
-	gaim_debug_error("dbus", "Failed to get connection\n");
+	init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message);
 	dbus_error_free(&error);
-	return FALSE;
+	return;
     }
 
     if (!dbus_connection_register_object_path (gaim_dbus_connection,
 					       DBUS_PATH_GAIM, &vtable, NULL))
     {
-	gaim_debug_error("dbus", "Failed to get name: %s\n", error.name);
+	init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name);
         dbus_error_free(&error);
-	return FALSE;
+	return;
     }
 	    
 
@@ -571,8 +568,8 @@
 	dbus_connection_unref(gaim_dbus_connection);
 	dbus_error_free(&error);
 	gaim_dbus_connection = NULL;
-	gaim_debug_error("dbus", "Failed to get serv name: %s\n", error.name);
-	return FALSE;
+	init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name);
+	return;
     }
 	
     dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL);
@@ -590,8 +587,6 @@
 			 gaim_value_new_outgoing(GAIM_TYPE_POINTER));
 
     GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle());
-
-    return TRUE;
 }
 
 
@@ -709,15 +704,37 @@
     dbus_message_unref(signal);
 }
 
-
-
+const char *
+gaim_dbus_get_init_error(void)
+{
+	return init_error;
+}
 
-
+void *
+gaim_dbus_get_handle(void)
+{
+    static int handle;
 
-gboolean gaim_dbus_init(void) 
+    return &handle;
+}
+
+void
+gaim_dbus_init(void)
 {
     gaim_dbus_init_ids();
-    return gaim_dbus_dispatch_init() ;
+
+	g_free(init_error);
+	init_error = NULL;
+	gaim_dbus_dispatch_init();
+	if (init_error != NULL)
+		gaim_debug_error("dbus", "%s\n", init_error);
 }
 
+void
+gaim_dbus_uninit(void)
+{
+	/* Surely we must do SOME kind of uninitialization? */
 
+	g_free(init_error);
+	init_error = NULL;
+}