[Vortex] vortex_channel_close - chan no, but for what connection?

Sam Roberts sroberts at uniserve.com
Mon Dec 4 02:01:35 CET 2006


Hi Francis,

I've had a number of problems with my email lately, sorry.

Anyhow, vortex_channel_close doesn't have any user_data, which is
inconvenient, but it also gives a channel number in the message, but
without any indication of the connection the channel was associated
with, so you don't actually know which channel was closed, or have a way
of associating the closed callback with an action specific to the
channel.

Attached is a bundled patch for this, vortex_channel_close_full(). It's
backwards compatible. The code doesn't follow your coding standards
exactly because I tried to minimize the size of the diff.

Do you have any other suggestions?

Sam

-------------- next part --------------
Index: src/vortex_connection.c
===================================================================
--- src/vortex_connection.c	(revision 2405)
+++ src/vortex_connection.c	(working copy)
@@ -1133,7 +1133,7 @@
  * must use \ref vortex_connection_is_ok to check if you are already
  * connected.
  */
-VortexConnection * vortex_connection_new (gchar * host, gchar * port, 
+VortexConnection * vortex_connection_new (const gchar * host, const gchar * port, 
 					  VortexConnectionNew on_connected,
 					  gpointer user_data)
 {
@@ -2144,7 +2144,7 @@
  * 
  * @return the host the given connection is connected to or NULL if something fail.
  */
-gchar            * vortex_connection_get_host             (VortexConnection * connection)
+const gchar      * vortex_connection_get_host             (VortexConnection * connection)
 {
 	g_return_val_if_fail (connection, NULL);
 
@@ -2179,7 +2179,7 @@
  * 
  * @return the port or NULL if something fails.
  */
-gchar            * vortex_connection_get_port             (VortexConnection * connection)
+const gchar      * vortex_connection_get_port             (VortexConnection * connection)
 {
 	g_return_val_if_fail (connection, NULL);
 
Index: src/vortex_connection.h
===================================================================
--- src/vortex_connection.h	(revision 2405)
+++ src/vortex_connection.h	(working copy)
@@ -41,7 +41,7 @@
 #include <vortex.h>
 
 
-VortexConnection  * vortex_connection_new                    (gchar * host, gchar * port,
+VortexConnection  * vortex_connection_new                    (const gchar * host, const gchar * port,
 							      VortexConnectionNew on_connected, 
 							      gpointer user_data);
 
@@ -111,9 +111,9 @@
 void                vortex_connection_remove_channel         (VortexConnection * connection, 
 							      VortexChannel * channel);
 
-gchar             * vortex_connection_get_host               (VortexConnection * connection);
+const gchar       * vortex_connection_get_host               (VortexConnection * connection);
 
-gchar             * vortex_connection_get_port               (VortexConnection * connection);
+const gchar       * vortex_connection_get_port               (VortexConnection * connection);
 
 gint                vortex_connection_get_id                 (VortexConnection * connection);
 
Index: src/vortex_handlers.h
===================================================================
--- src/vortex_handlers.h	(revision 2405)
+++ src/vortex_handlers.h	(working copy)
@@ -173,7 +173,8 @@
  * @param connection  Connection where the channel creation request was received.
  * @param serverName  Value for this optional start message attribute. This is used 
  * @param profile_content Optional profile content received inside the channel start message.
- * @param profile_content_reply Optional profile content reply to be used for channel start reply.
+ * @param profile_content_reply Optional profile content reply to be used for channel start reply,
+ * it will be freed by the library after the reply is sent.
  * @param encoding Encoding used for the profile content. 
  * @param user_data User defined data to be passed in to the handler when it is executed.
  * 
@@ -386,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 2405)
+++ src/vortex_channel.c	(working copy)
@@ -343,6 +343,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);
@@ -942,10 +943,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,
@@ -973,7 +974,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;
 	
@@ -1645,7 +1646,7 @@
  * @return TRUE if channel was sent or FALSE if not.
  */
 gboolean    __vortex_channel_send_msg_common (VortexChannel   * channel,
-					      gchar           * message,
+					      const gchar     * message,
 					      gint              message_size,
 					      gint            * msg_no,
 					      WaitReplyData   * wait_reply)
@@ -1771,7 +1772,7 @@
  * @return TRUE if message could be sent, FALSE if fail
  */
 gboolean        vortex_channel_send_msg   (VortexChannel * channel,
-					   gchar         * message,
+					   const gchar   * message,
 					   gint            message_size,
 					   gint          * msg_no)
 {
@@ -1856,7 +1857,7 @@
  * @return the same as \ref vortex_channel_send_msg
  */
 gboolean           vortex_channel_send_msg_and_wait               (VortexChannel   * channel,
-								   gchar           * message,
+								   const gchar     * message,
 								   gint              message_size,
 								   gint            * msg_no,
 								   WaitReplyData   * wait_reply)
@@ -2993,6 +2994,8 @@
 typedef struct {
 	VortexChannel              * channel;
 	VortexOnClosedNotification   on_closed;
+	VortexOnClosedNotificationFull on_closed_full;
+	gpointer                     user_data;
 	gboolean                     threaded;
 } VortexChannelCloseData;
 
@@ -3320,6 +3323,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;
@@ -3336,6 +3341,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 */
@@ -3466,6 +3473,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);
 	}
 
@@ -3499,6 +3510,8 @@
 	return result ? GINT_TO_POINTER (result) : NULL;
 }
 
+gboolean vortex_channel_close__ (VortexChannel *, VortexOnClosedNotification, VortexOnClosedNotificationFull, gpointer user_data);
+
 /** 
  * @brief Close the given channel. 
  *
@@ -3547,15 +3560,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;
 	
@@ -3571,6 +3590,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.");
@@ -3588,7 +3611,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) {
@@ -3600,7 +3625,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 2405)
+++ 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);
 
@@ -196,7 +199,7 @@
 								   gpointer key);
 
 gboolean           vortex_channel_send_msg                        (VortexChannel * channel,
-								   gchar         * message,
+								   const gchar   * message,
 								   gint            message_size,
 								   gint          * msg_no);
 
@@ -206,7 +209,7 @@
 								   ...);
 
 gboolean           vortex_channel_send_msg_and_wait               (VortexChannel   * channel,
-								   gchar           * message,
+								   const gchar     * message,
 								   gint              message_size,
 								   gint            * msg_no,
 								   WaitReplyData   * wait_reply);
Index: src/vortex.c
===================================================================
--- src/vortex.c	(revision 2405)
+++ 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
Index: autogen.sh
===================================================================
--- autogen.sh	(revision 2405)
+++ autogen.sh	(working copy)
@@ -37,6 +37,13 @@
 #         info at aspl.es - http://fact.aspl.es
 #
 
+set -v
+
+which aclocal
+which autoheader
+which automake
+which autoconf
+
 PACKAGE="LibVortex:  A BEEP (RFC3080/RFC3081) implementation."
 
 (automake --version) < /dev/null > /dev/null 2>&1 || {
@@ -57,7 +64,7 @@
 echo; 
 
 touch NEWS README AUTHORS ChangeLog 
-libtoolize --force;
+glibtoolize --force;
 aclocal $ACLOCAL_FLAGS; 
 autoheader; 
 automake --add-missing; 


More information about the Vortex mailing list