changeset 13956:f61428cc4019

[gaim-migrate @ 16505] Change the music messaging plugin to not try to load if our D-BUS stuff is not initialized. Also extracted the gaim_notify_error() message code to a #define in src/dbus-server.c And print a debug warning if something tries to register a callback for a signal using a handle that we don't have any registered signals for committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 17 Jul 2006 06:21:53 +0000
parents 2d6f7ac4b6f2
children 421259b9e06d
files plugins/dbus-example.c plugins/musicmessaging/musicmessaging.c src/dbus-server.h src/signals.c
diffstat 4 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/dbus-example.c	Mon Jul 17 05:50:28 2006 +0000
+++ b/plugins/dbus-example.c	Mon Jul 17 06:21:53 2006 +0000
@@ -109,16 +109,7 @@
 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;
-	}
+	GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin);
 
     /* First, we have to register our four exported functions with the
        main gaim dbus loop.  Without this statement, the gaim dbus
--- a/plugins/musicmessaging/musicmessaging.c	Mon Jul 17 05:50:28 2006 +0000
+++ b/plugins/musicmessaging/musicmessaging.c	Mon Jul 17 06:21:53 2006 +0000
@@ -259,6 +259,8 @@
 plugin_load(GaimPlugin *plugin) {
 	void *conv_list_handle;
 
+	GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin);
+
     /* 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. */
--- a/src/dbus-server.h	Mon Jul 17 05:50:28 2006 +0000
+++ b/src/dbus-server.h	Mon Jul 17 06:21:53 2006 +0000
@@ -74,6 +74,17 @@
 #define GAIM_DBUS_DEFINE_INHERITING_TYPE(type, parent) \
     GaimDBusType GAIM_DBUS_TYPE_##type = { GAIM_DBUS_TYPE(parent) };
 
+#define GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin) \
+	if (gaim_dbus_get_init_error() != NULL) \
+	{ \
+		gchar *title; \
+		title = g_strdup_printf("Unable to Load %s Plugin", plugin->info->name); \
+		gaim_notify_error(NULL, title, \
+				_("Gaim's D-BUS server is not running for the reason listed below"), \
+				_(gaim_dbus_get_init_error())); \
+		g_free(title); \
+		return FALSE; \
+	}
 
 /**
    Initializes gaim dbus pointer registration engine.
@@ -139,8 +150,9 @@
  * 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.
+ * Gaim plugins that use D-BUS should use the
+ * GAIM_DBUS_RETURN_FALSE_IF_DISABLED macro to short-circuit
+ * initialization if Gaim's D-BUS subsystem is not running.
  *
  * @return If the D-BUS subsystem started with no problems then this
  *         will return NULL and everything will be hunky dory.  If
--- a/src/signals.c	Mon Jul 17 05:50:28 2006 +0000
+++ b/src/signals.c	Mon Jul 17 06:21:53 2006 +0000
@@ -267,7 +267,13 @@
 	instance_data =
 		(GaimInstanceData *)g_hash_table_lookup(instance_table, instance);
 
-	g_return_val_if_fail(instance_data != NULL, 0);
+	if (instance_data == NULL)
+	{
+		gaim_debug_warning("signals", "Something tried to register a callback "
+				"for the '%s' signal, but we do not have any signals "
+				"registered with the given handle\n", signal);
+		g_return_val_if_reached(0);
+	}
 
 	/* Get the signal data */
 	signal_data =