[evolution/mail-mt-cleanup: 2/7] Use an enum to track MailMsg activity state



commit ae2b93fbeba2382b4d1f1e989dc00da926142170
Author: Jonathon Jongsma <jonathon quotidian org>
Date:   Tue Dec 29 15:32:24 2009 -0600

    Use an enum to track MailMsg activity state
    
    Instead of using magic numbers to keep track of the state of an activity, use
    enumerations so the code can be a bit more self-explanatory.

 mail/mail-mt.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/mail/mail-mt.c b/mail/mail-mt.c
index 4c7c049..69a1eab 100644
--- a/mail/mail-mt.c
+++ b/mail/mail-mt.c
@@ -45,6 +45,14 @@ const gchar *shell_builtin_backend = "mail";
 
 static void mail_operation_status(CamelOperation *op, const gchar *what, gint pc, gpointer data);
 
+enum
+{
+	ACTIVITY_STATE_UNINITIALIZED = 0,
+	ACTIVITY_STATE_INITIALIZING,
+	ACTIVITY_STATE_ACTIVE,
+	ACTIVITY_STATE_REMOVED
+};
+
 /* background operation status stuff */
 struct _MailMsgPrivate {
 	gint activity_state;	/* sigh sigh sigh, we need to keep track of the state external to the
@@ -76,6 +84,7 @@ mail_msg_new (MailMsgInfo *info)
 	camel_exception_init(&msg->ex);
 	msg->priv = g_slice_new0 (MailMsgPrivate);
 	msg->priv->cancelable = TRUE;
+	msg->priv->activity_state = ACTIVITY_STATE_UNINITIALIZED;
 
 	g_hash_table_insert(mail_msg_active_table, GINT_TO_POINTER(msg->seq), msg);
 
@@ -190,11 +199,11 @@ mail_msg_unref (gpointer msg)
 	g_cond_broadcast (mail_msg_cond);
 
 	/* We need to make sure we dont lose a reference here YUCK YUCK */
-	/* This is tightly integrated with the code in do_op_status,
-	   as it closely relates to the CamelOperation setup in msg_new() above */
-	if (mail_msg->priv->activity_state == 1) {
+	/* This is tightly integrated with the code in op_status_exec,
+	   as it closely relates to the CamelOperation setup in mail_msg_new() above */
+	if (mail_msg->priv->activity_state == ACTIVITY_STATE_INITIALIZING) {
 		/* tell the other to free it itself */
-		mail_msg->priv->activity_state = 3;
+		mail_msg->priv->activity_state = ACTIVITY_STATE_REMOVED;
 		g_mutex_unlock (mail_msg_lock);
 		return;
 	} else {
@@ -870,11 +879,12 @@ op_status_exec (struct _op_status_msg *m)
 		gchar *what;
 
 		/* its being created/removed?  well leave it be */
-		if (data->activity_state == 1 || data->activity_state == 3) {
+		if (data->activity_state == ACTIVITY_STATE_INITIALIZING ||
+		    data->activity_state == ACTIVITY_STATE_REMOVED) {
 			g_mutex_unlock (mail_msg_lock);
 			return;
 		} else {
-			data->activity_state = 1;
+			data->activity_state = ACTIVITY_STATE_INITIALIZING;
 
 			g_mutex_unlock (mail_msg_lock);
 			if (msg->info->desc)
@@ -898,7 +908,7 @@ op_status_exec (struct _op_status_msg *m)
 
 			g_free (what);
 			g_mutex_lock (mail_msg_lock);
-			if (data->activity_state == 3) {
+			if (data->activity_state == ACTIVITY_STATE_REMOVED) {
 				EActivity *activity;
 
 				activity = g_object_ref (data->activity);
@@ -911,7 +921,7 @@ op_status_exec (struct _op_status_msg *m)
 						mail_async_event, MAIL_ASYNC_GUI, (MailAsyncFunc) end_event_callback,
 								NULL, activity, NULL);
 			} else {
-				data->activity_state = 2;
+				data->activity_state = ACTIVITY_STATE_ACTIVE;
 				g_mutex_unlock (mail_msg_lock);
 			}
 			return;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]