# HG changeset patch # User Mark Doliner # Date 1153115428 0 # Node ID 2d6f7ac4b6f2844eae9b5d7b0fb82861f8bfe6b3 # Parent 3cd3886136249c0f631a96c827c5b0da8335807f [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 diff -r 3cd388613624 -r 2d6f7ac4b6f2 plugins/dbus-example.c --- a/plugins/dbus-example.c Mon Jul 17 04:33:32 2006 +0000 +++ b/plugins/dbus-example.c Mon Jul 17 05:50:28 2006 +0000 @@ -37,8 +37,9 @@ #include "internal.h" +#include "blist.h" +#include "notify.h" #include "plugin.h" -#include "blist.h" #include "version.h" #include @@ -108,6 +109,17 @@ static gboolean plugin_load(GaimPlugin *plugin) { + const char *dbus_init_error; + + dbus_init_error = gaim_dbus_get_init_error(); + if (dbus_init_error != NULL) + { + gaim_notify_error(NULL, _("Unable to Load Plugin"), + _("Gaim's D-BUS server is not running for the reason listed below"), + _(dbus_init_error)); + return FALSE; + } + /* First, we have to register our four exported functions with the main gaim dbus loop. Without this statement, the gaim dbus code wouldn't know about our functions. */ diff -r 3cd388613624 -r 2d6f7ac4b6f2 src/core.c --- a/src/core.c Mon Jul 17 04:33:32 2006 +0000 +++ b/src/core.c Mon Jul 17 05:50:28 2006 +0000 @@ -99,7 +99,6 @@ gaim_dbus_init(); #endif - /* Initialize all static protocols. */ static_proto_init(); @@ -193,6 +192,10 @@ gaim_plugins_uninit(); gaim_signals_uninit(); +#ifdef HAVE_DBUS + gaim_dbus_uninit(); +#endif + if (core->ui != NULL) { g_free(core->ui); core->ui = NULL; diff -r 3cd388613624 -r 2d6f7ac4b6f2 src/dbus-server.c --- 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, "\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; +} diff -r 3cd388613624 -r 2d6f7ac4b6f2 src/dbus-server.h --- a/src/dbus-server.h Mon Jul 17 04:33:32 2006 +0000 +++ b/src/dbus-server.h Mon Jul 17 05:50:28 2006 +0000 @@ -135,13 +135,19 @@ GaimValue **values, va_list vargs); /** - * Starts the gaim DBUS server. It is responsible for handling DBUS - * requests from other applications. + * Returns whether Gaim's D-BUS subsystem is up and running. If it's + * NOT running then gaim_dbus_dispatch_init() failed for some reason, + * and a message should have been gaim_debug_error()'ed. + * + * This function should be called by any DBUS plugin before trying + * to use the DBUS API. See plugins/dbus-example.c for usage. * - * @return TRUE if successful, FALSE otherwise. + * @return If the D-BUS subsystem started with no problems then this + * will return NULL and everything will be hunky dory. If + * there was an error initializing the D-BUS subsystem then + * this will return an error message explaining why. */ -gboolean gaim_dbus_init(void); - +const char *gaim_dbus_get_init_error(void); /** * Returns the dbus subsystem handle. @@ -151,6 +157,17 @@ void *gaim_dbus_get_handle(void); /** + * Starts Gaim's D-BUS server. It is responsible for handling DBUS + * requests from other applications. + */ +void gaim_dbus_init(void); + +/** + * Uninitializes Gaim's D-BUS server. + */ +void gaim_dbus_uninit(void); + +/** Macro #DBUS_EXPORT expands to nothing. It is used to indicate to the dbus-analize-functions.py script that the given function should be