changeset 21364:5a7202fa43a0

I figured a signal firing on a connection error would be useful.
author Will Thompson <will.thompson@collabora.co.uk>
date Wed, 24 Oct 2007 17:33:12 +0000
parents b4833db5eed0
children 3a269007711e
files ChangeLog.API libpurple/connection.c libpurple/plugins/signals-test.c libpurple/signals.c libpurple/signals.h
diffstat 5 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Wed Oct 24 14:48:58 2007 +0000
+++ b/ChangeLog.API	Wed Oct 24 17:33:12 2007 +0000
@@ -26,6 +26,8 @@
 		  implemented by UIs (rather than .report_disconnect) if
 		  they want to use the reported PurpleDisconnectReason
 		  to give a more specific error.
+		* A connection-error signal, fired just after the UiOp is
+		  called.
 		* purple_connection_reason_is_fatal(), acting as a hint
 		  to whether automatic reconnection should be attempted
 		  after a connection error (rather than checking
--- a/libpurple/connection.c	Wed Oct 24 14:48:58 2007 +0000
+++ b/libpurple/connection.c	Wed Oct 24 17:33:12 2007 +0000
@@ -541,6 +541,9 @@
 			ops->report_disconnect (gc, description);
 	}
 
+	purple_signal_emit(purple_connections_get_handle(), "connection-error",
+		gc, reason, description);
+
 	gc->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb,
 			purple_connection_get_account(gc));
 }
@@ -658,6 +661,14 @@
 						 purple_marshal_VOID__POINTER, NULL, 1,
 						 purple_value_new(PURPLE_TYPE_SUBTYPE,
 										PURPLE_SUBTYPE_CONNECTION));
+
+	purple_signal_register(handle, "connection-error",
+	                       purple_marshal_VOID__POINTER_INT_POINTER, NULL, 1,
+	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
+	                                        PURPLE_SUBTYPE_CONNECTION),
+	                       purple_value_new(PURPLE_TYPE_ENUM),
+	                       purple_value_new(PURPLE_TYPE_STRING));
+
 }
 
 void
--- a/libpurple/plugins/signals-test.c	Wed Oct 24 14:48:58 2007 +0000
+++ b/libpurple/plugins/signals-test.c	Wed Oct 24 17:33:12 2007 +0000
@@ -226,6 +226,18 @@
 					purple_account_get_username(purple_connection_get_account(gc)));
 }
 
+static void
+connection_error_cb(PurpleConnection *gc,
+                    PurpleConnectionError err,
+                    const gchar *desc,
+                    void *data)
+{
+	const gchar *username =
+		purple_account_get_username(purple_connection_get_account(gc));
+	purple_debug_misc("signals test", "connection-error (%s, %u, %s)\n",
+		username, err, desc);
+}
+
 /**************************************************************************
  * Conversation subsystem signal callbacks
  **************************************************************************/
@@ -626,6 +638,8 @@
 						plugin, PURPLE_CALLBACK(signing_off_cb), NULL);
 	purple_signal_connect(conn_handle, "signed-off",
 						plugin, PURPLE_CALLBACK(signed_off_cb), NULL);
+	purple_signal_connect(conn_handle, "connection-error",
+						plugin, PURPLE_CALLBACK(connection_error_cb), NULL);
 
 	/* Conversations subsystem signals */
 	purple_signal_connect(conv_handle, "writing-im-msg",
--- a/libpurple/signals.c	Wed Oct 24 14:48:58 2007 +0000
+++ b/libpurple/signals.c	Wed Oct 24 17:33:12 2007 +0000
@@ -649,6 +649,16 @@
 	((void (*)(void *, gint, gint, void *))cb)(arg1, arg2, arg3, data);
 }
 
+void purple_marshal_VOID__POINTER_INT_POINTER(PurpleCallback cb, va_list args,
+                                              void *data, void **return_val)
+{
+	void *arg1 = va_arg(args, void *);
+	gint arg2 = va_arg(args, gint);
+	void *arg3 = va_arg(args, void *);
+
+	((void (*)(void *, gint, void *, void *))cb)(arg1, arg2, arg3, data);
+}
+
 void
 purple_marshal_VOID__POINTER_POINTER(PurpleCallback cb, va_list args,
 								   void *data, void **return_val)
--- a/libpurple/signals.h	Wed Oct 24 14:48:58 2007 +0000
+++ b/libpurple/signals.h	Wed Oct 24 17:33:12 2007 +0000
@@ -284,6 +284,8 @@
 		PurpleCallback cb, va_list args, void *data, void **return_val);
 void purple_marshal_VOID__POINTER_INT_INT(
 		PurpleCallback cb, va_list args, void *data, void **return_val);
+void purple_marshal_VOID__POINTER_INT_POINTER(
+		PurpleCallback cb, va_list args, void *data, void **return_val);
 void purple_marshal_VOID__POINTER_POINTER(
 		PurpleCallback cb, va_list args, void *data, void **return_val);
 void purple_marshal_VOID__POINTER_POINTER_UINT(