Patch: change in send queue behaviour when notifying the user



Hi,

it was not really possible to know with a high level of accuracy when
the TnyCamelSendQueue was doing something or not. We had the
"queue-start" and "queue-stop" signals, but they both have a "problem"
and it's that they're emitted in an idle, so it could happen that a
message was already sent when "the queue-start" is received by the client.

With this new behaviour the user could be sure that the message will be
sent after the "queue-start" signal is received.

Br
Index: libtinymail-camel/tny-camel-send-queue.c
===================================================================
--- libtinymail-camel/tny-camel-send-queue.c	(revision 3792)
+++ libtinymail-camel/tny-camel-send-queue.c	(working copy)
@@ -68,6 +68,9 @@
 	TnyHeader *header;
 	gint i, total;
 	guint signal_id;
+	GCond *condition;
+	GMutex *mutex;
+	gboolean had_callback;
 } ControlInfo;
 
 
@@ -308,6 +311,13 @@
 	if (apriv)
 		tny_lockable_unlock (apriv->session->priv->ui_lock);
 
+	if (info->mutex) {
+		g_mutex_lock (info->mutex);
+		g_cond_broadcast (info->condition);
+		info->had_callback = TRUE;
+		g_mutex_unlock (info->mutex);
+	}
+
 	return FALSE;
 }
 
@@ -567,6 +577,32 @@
 	g_slice_free (SyncSync, info);
 }
 
+static void
+wait_for_queue_start_notification (TnySendQueue *self)
+{
+	ControlInfo *info = g_slice_new0 (ControlInfo);
+
+	info->mutex = g_mutex_new ();
+	info->condition = g_cond_new ();
+	info->had_callback = FALSE;
+
+	info->self = g_object_ref (self);
+	info->signal_id = TNY_SEND_QUEUE_START;
+
+	g_idle_add (emit_queue_control_signals_on_mainloop, info);
+
+	g_mutex_lock (info->mutex);
+	if (!info->had_callback)
+		g_cond_wait (info->condition, info->mutex);
+	g_mutex_unlock (info->mutex);
+
+	g_mutex_free (info->mutex);
+	g_cond_free (info->condition);
+
+	g_slice_free (GetHeadersSync, info);
+}
+
+
 static gpointer
 thread_main (gpointer data)
 {
@@ -578,6 +614,9 @@
 	TnyDevice *device = info->device;
 	GHashTable *failed_headers = NULL;
 
+	/* Wait here until the user receives the queue-start notification */
+	wait_for_queue_start_notification (self);
+
 	priv->is_running = TRUE;
 	list = tny_simple_list_new ();
 
@@ -871,12 +910,9 @@
 				_tny_camel_folder_reason (spriv);
 			}
 
-			emit_queue_control_signals (self, TNY_SEND_QUEUE_START);
-
 			priv->thread = g_thread_create (thread_main, info, FALSE, NULL);
 
 			if (priv->thread == NULL) {
-				emit_queue_control_signals (self, TNY_SEND_QUEUE_STOP);
 			        if (TNY_IS_CAMEL_FOLDER (info->outbox)) {
 		        	        TnyCamelFolderPriv *opriv = TNY_CAMEL_FOLDER_GET_PRIVATE (info->outbox);
 					_tny_camel_folder_unreason (opriv);


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