From: <the...@us...> - 2006-07-17 05:50:31
|
Revision: 16503 Author: thekingant Date: 2006-07-16 22:50:28 -0700 (Sun, 16 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16503&view=rev Log Message: ----------- 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? Modified Paths: -------------- trunk/plugins/dbus-example.c trunk/src/core.c trunk/src/dbus-server.c trunk/src/dbus-server.h Modified: trunk/plugins/dbus-example.c =================================================================== --- trunk/plugins/dbus-example.c 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/plugins/dbus-example.c 2006-07-17 05:50:28 UTC (rev 16503) @@ -37,8 +37,9 @@ #include "internal.h" +#include "blist.h" +#include "notify.h" #include "plugin.h" -#include "blist.h" #include "version.h" #include <stdio.h> @@ -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. */ Modified: trunk/src/core.c =================================================================== --- trunk/src/core.c 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/src/core.c 2006-07-17 05:50:28 UTC (rev 16503) @@ -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; Modified: trunk/src/dbus-server.c =================================================================== --- trunk/src/dbus-server.c 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/src/dbus-server.c 2006-07-17 05:50:28 UTC (rev 16503) @@ -36,6 +36,7 @@ #include "dbus-bindings.h" #include "debug.h" #include "core.h" +#include "internal.h" #include "savedstatuses.h" #include "value.h" @@ -59,7 +60,9 @@ 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; + return &handle; +} - - -gboolean gaim_dbus_init(void) +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; +} Modified: trunk/src/dbus-server.h =================================================================== --- trunk/src/dbus-server.h 2006-07-17 04:33:32 UTC (rev 16502) +++ trunk/src/dbus-server.h 2006-07-17 05:50:28 UTC (rev 16503) @@ -135,14 +135,20 @@ 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. * - * @return TRUE if successful, FALSE otherwise. + * This function should be called by any DBUS plugin before trying + * to use the DBUS API. See plugins/dbus-example.c for usage. + * + * @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,7 +157,18 @@ 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 available to other applications through DBUS. If This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |