[Vortex] on_closed_full patch

Sam Roberts sroberts at uniserve.com
Wed Dec 6 07:46:29 CET 2006


This is against latest head. Hope I've got the tab-style right.

Thanks,
Sam

p.s. No chance to try the new ref counting api for channel/frame yet,
but I wonder, since channel objects have a ref to connections, don't
they need to increase the ref count for the connections?

-------------- next part --------------
Index: src/vortex_handlers.h
===================================================================
--- src/vortex_handlers.h	(revision 2407)
+++ src/vortex_handlers.h	(working copy)
@@ -387,11 +387,22 @@
  * not closed) code hold error code returned and msg the message
  * returned by remote peer. 
  *
+ * @param connection the connection on which the channel was closed
  * @param channel_num the channel num identifying the channel closed
  * @param was_closed status for the channel close process.
  * @param code the code representing the channel close process.
  * @param msg the message representing the channel close process.
+ * @param user_data A user defined pointer established at function
+ * which received this handler.
  */
+typedef void     (*VortexOnClosedNotificationFull) (VortexConnection*connection,
+						gint            channel_num,
+						gboolean        was_closed,
+						const gchar   * code,
+						const gchar   * msg,
+						gpointer        user_data);
+
+/** @deprecated */
 typedef void     (*VortexOnClosedNotification) (gint            channel_num,
 						gboolean        was_closed,
 						gchar         * code,
Index: src/vortex_channel.c
===================================================================
--- src/vortex_channel.c	(revision 2407)
+++ src/vortex_channel.c	(working copy)
@@ -355,6 +355,7 @@
 		return;
 	if (data->serverName)
 		g_free (data->serverName);
+		g_free (data->profile); /* Freeing NULL is allowed in ANSI C, and glib */
 	if (data->profile_content)
 		g_free (data->profile_content);
 	g_free (data);
@@ -954,10 +955,10 @@
  */
 VortexChannel * vortex_channel_new_full (VortexConnection      * connection,
 					 gint                    channel_num, 
-					 gchar                 * serverName,
-					 gchar                 * profile,
+					 const gchar           * serverName,
+					 const gchar           * profile,
 					 VortexEncoding          encoding,
-					 gchar                 * profile_content,
+					 const gchar           * profile_content,
 					 gint                    profile_content_size,
 					 VortexOnCloseChannel    close,
 					 gpointer                close_user_data,
@@ -985,7 +986,7 @@
 	data->serverName            = g_strdup (serverName);
 
 	/* profile stuff */
-	data->profile               = profile;
+	data->profile               = g_strdup(profile);
 	data->encoding              = encoding;
 	data->profile_content_size  = profile_content_size;
 	
@@ -3068,6 +3069,8 @@
 typedef struct {
 	VortexChannel              * channel;
 	VortexOnClosedNotification   on_closed;
+	VortexOnClosedNotificationFull on_closed_full;
+	gpointer                     user_data;
 	gboolean                     threaded;
 } VortexChannelCloseData;
 
@@ -3393,6 +3396,8 @@
 	VortexConnection           * connection  = NULL;
 	WaitReplyData              * wait_reply  = NULL;
 	VortexOnClosedNotification   on_closed   = NULL;
+	VortexOnClosedNotificationFull on_closed_full = NULL;
+	gpointer                     user_data   = NULL;
 	
 	/* TRUE channel is closed, FALSE not. */
 	gboolean                     result      = FALSE;
@@ -3409,6 +3414,8 @@
 	 * vortex_channel_close) */
 	channel    = data->channel;
 	on_closed  = data->on_closed;
+	on_closed_full = data->on_closed_full;
+	user_data  = data->user_data;
 	threaded   = data->threaded;
 
 	/* free data */
@@ -3539,6 +3546,10 @@
  __vortex_channel_close_invoke_caller:
 	if (threaded) {
 		/* invoke handler */
+		if(on_closed_full)
+			on_closed_full(channel->connection, channel->channel_num, result, code, msg, user_data);
+		else
+		if(on_closed)
 		on_closed (channel->channel_num, result, code, msg);
 	}
 
@@ -3572,6 +3583,8 @@
 	return result ? GINT_TO_POINTER (result) : NULL;
 }
 
+gboolean vortex_channel_close__ (VortexChannel *, VortexOnClosedNotification, VortexOnClosedNotificationFull, gpointer user_data);
+
 /** 
  * @brief Close the given channel. 
  *
@@ -3620,15 +3633,21 @@
  * 
  * @param channel the channel to free
  * @param on_closed a optional handler notification
+ * @param user_data a optional handler notification
  * 
  * @return TRUE if the channel was closed or FALSE if not. On
  * threaded mode, activated by defining the <i>on_closed</i> handler,
  * always return TRUE. Actual close process result is notified on
  * <i>on_closed</i>
  */
-gboolean vortex_channel_close (VortexChannel * channel, 
-			       VortexOnClosedNotification on_closed)
+gboolean vortex_channel_close_full (VortexChannel * channel, 
+			       VortexOnClosedNotificationFull on_closed, gpointer user_data)
 {
+	return vortex_channel_close__(channel, NULL, on_closed, user_data);
+}
+
+gboolean vortex_channel_close__ (VortexChannel * channel, VortexOnClosedNotification on_closed, VortexOnClosedNotificationFull on_closed_full, gpointer user_data)
+{
 	
 	VortexChannelCloseData * data;
 	
@@ -3644,6 +3663,10 @@
 		g_mutex_unlock (channel->close_mutex);
 
 		/* return that the channel is closed */
+		if (on_closed_full != NULL) {
+			/* notify if a handler is provided */
+			on_closed_full (vortex_channel_get_connection(channel), channel->channel_num, FALSE, "554", "Channel in process on being closed before calling to this function.", user_data);
+		}
 		if (on_closed != NULL) {
 			/* notify if a handler is provided */
 			on_closed (channel->channel_num, FALSE, "554", "Channel in process on being closed before calling to this function.");
@@ -3661,7 +3684,9 @@
 	data            = g_new0 (VortexChannelCloseData, 1);
 	data->channel   = channel;
 	data->on_closed = on_closed;
-	data->threaded  = (on_closed != NULL);
+	data->on_closed_full = on_closed_full;
+	data->user_data = user_data;
+	data->threaded  = (on_closed != NULL) || (on_closed_full != NULL);
 
 	/* launch threaded mode */
 	if (data->threaded) {
@@ -3673,7 +3698,15 @@
 	return (__vortex_channel_close (data) != NULL);
 }
 
+/** @deprecated */
+gboolean vortex_channel_close (VortexChannel * channel, 
+			       VortexOnClosedNotification on_closed)
+{
+	return vortex_channel_close__ (channel, on_closed, NULL, NULL);
+}
 
+
+
 /** 
  * @brief Returns the current profile the channel is running.
  * 
Index: src/vortex_channel.h
===================================================================
--- src/vortex_channel.h	(revision 2407)
+++ src/vortex_channel.h	(working copy)
@@ -52,10 +52,10 @@
 
 VortexChannel     * vortex_channel_new_full                    (VortexConnection      * connection,
 								gint                    channel_num, 
-								gchar                 * serverName,
-								gchar                 * profile,
+								const gchar           * serverName,
+								const gchar           * profile,
 								VortexEncoding          encoding,
-								gchar                 * profile_content,
+								const gchar           * profile_content,
 								gint                    profile_content_size,
 								VortexOnCloseChannel    close,
 								gpointer                close_user_data,
@@ -76,6 +76,9 @@
 								gchar                 * profile_content_format, 
 								...);
 
+gboolean vortex_channel_close_full (VortexChannel * channel, 
+			       VortexOnClosedNotificationFull on_closed, gpointer user_data);
+
 gboolean           vortex_channel_close                        (VortexChannel * channel,
 								VortexOnClosedNotification on_closed);
 
Index: src/vortex.c
===================================================================
--- src/vortex.c	(revision 2407)
+++ src/vortex.c	(working copy)
@@ -122,6 +122,9 @@
 /** 
  * @brief Enable console color log. 
  *
+ * Note that this doesn't enable logging, just selects color messages if
+ * logging is already enabled, see vortex_log_enable().
+ *
  * This is mainly useful to hunt messages using its color: 
  *  - red:  errors, critical 
  *  - yellow: warnings


More information about the Vortex mailing list