Re: Experimental patch to implement sent and sending signal on tny-camel-send-queue
- From: Javier Fernandez <jfernandez igalia com>
- To: tinymail-devel-list gnome org
- Subject: Re: Experimental patch to implement sent and sending signal on tny-camel-send-queue
- Date: Tue, 10 Jul 2007 13:24:11 +0200
El jue, 21-06-2007 a las 08:37 +0200, Javier Fernandez escribió:
This version of patch only implements msg-sending and msg-sent
signal emission, but observer pattern is still pending.
--
Index: libtinymail-camel/tny-camel-send-queue.c
===================================================================
--- libtinymail-camel/tny-camel-send-queue.c (revision 2442)
+++ libtinymail-camel/tny-camel-send-queue.c (working copy)
@@ -54,6 +54,14 @@
gint i, total;
} ErrorInfo;
+typedef struct {
+ TnySendQueue *self;
+ TnyMsg *msg;
+ TnyHeader *header;
+ gint i, total;
+ guint signal_id;
+} ControlInfo;
+
static gboolean
emit_error_on_mainloop (gpointer data)
{
@@ -101,6 +109,54 @@
return;
}
+
+static gboolean
+emit_control_signals_on_mainloop (gpointer data)
+{
+ ControlInfo *info = data;
+ g_signal_emit (info->self, tny_send_queue_signals [info->signal_id],
+ 0, info->header, info->msg, info->i, info->total);
+ return FALSE;
+}
+
+static void
+destroy_control_info (gpointer data)
+{
+ ControlInfo *info = data;
+
+ if (info->msg)
+ g_object_unref (G_OBJECT (info->msg));
+ if (info->header)
+ g_object_unref (G_OBJECT (info->header));
+ if (info->self)
+ g_object_unref (G_OBJECT (info->self));
+
+ g_slice_free (ControlInfo, info);
+}
+
+static void
+emit_control (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, guint signal_id, int i, int total)
+{
+ ControlInfo *info = g_slice_new0 (ControlInfo);
+
+ if (self)
+ info->self = TNY_SEND_QUEUE (g_object_ref (G_OBJECT (self)));
+ if (msg)
+ info->msg = TNY_MSG (g_object_ref (G_OBJECT (msg)));
+ if (header)
+ info->header = TNY_HEADER (g_object_ref (G_OBJECT (header)));
+
+ info->signal_id = signal_id;
+ info->i = i;
+ info->total = total;
+
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ emit_control_signals_on_mainloop, info, destroy_control_info);
+
+ return;
+}
+
+
static gpointer
thread_main (gpointer data)
{
@@ -151,7 +207,7 @@
while (length > 0 && priv->do_continue)
{
- TnyHeader *header;
+ TnyHeader *header = NULL;
TnyMsg *msg = NULL;
g_mutex_lock (priv->sending_lock);
@@ -229,9 +285,9 @@
tny_list_prepend (hassent, G_OBJECT (header));
msg = tny_folder_get_msg (outbox, header, &err);
- /* hassent is owner now */
- g_object_unref (G_OBJECT (header));
-
+ /* Emits msg-sending signal to inform a new msg is being sent */
+ emit_control (self, header, msg, TNY_SEND_QUEUE_MSG_SENDING, i, priv->total);
+
if (err == NULL)
{
tny_transport_account_send (priv->trans_account, msg, &err);
@@ -267,7 +323,13 @@
if (err != NULL)
g_error_free (err);
- i++;
+ /* Emits msg-sent signal to inform msg has been sent */
+ emit_control (self, header, msg, TNY_SEND_QUEUE_MSG_SENT, i, priv->total);
+
+ i++;
+
+ /* hassent is owner now */
+ g_object_unref (G_OBJECT (header));
} else
{
/* Not good, let's just kill this thread */
Index: libtinymail/tny-signals-marshal.list
===================================================================
--- libtinymail/tny-signals-marshal.list (revision 2442)
+++ libtinymail/tny-signals-marshal.list (working copy)
@@ -1 +1,2 @@
VOID:OBJECT,OBJECT,POINTER
+VOID:OBJECT,OBJECT,INT,INT
Index: libtinymail/tny-send-queue.c
===================================================================
--- libtinymail/tny-send-queue.c (revision 2442)
+++ libtinymail/tny-send-queue.c (working copy)
@@ -140,9 +140,29 @@
{
static gboolean initialized = FALSE;
- if (!initialized)
- {
+ if (!initialized) {
/**
+ * TnySendQueue::msg-sending
+ * @self: the object on which the signal is emitted
+ * @arg1: The message that is being
+ * @arg2: The current nth number of the message that is being sending
+ * @arg3: The total amount of messages currently being processed
+ *
+ * API WARNING: This API might change
+ *
+ * Emitted when a message is being proccessed to sending it
+ **/
+ tny_send_queue_signals[TNY_SEND_QUEUE_MSG_SENDING] =
+ g_signal_new ("msg_sending",
+ TNY_TYPE_SEND_QUEUE,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TnySendQueueIface, msg_sending),
+ NULL, NULL,
+ tny_marshal_VOID__OBJECT_OBJECT_INT_INT,
+ G_TYPE_NONE, 4, TNY_TYPE_HEADER, TNY_TYPE_MSG, G_TYPE_UINT, G_TYPE_UINT);
+
+
+/**
* TnySendQueue::msg-sent
* @self: the object on which the signal is emitted
* @arg1: The message that got sent
@@ -151,14 +171,14 @@
* Emitted when a message got sent
**/
tny_send_queue_signals[TNY_SEND_QUEUE_MSG_SENT] =
- g_signal_new ("msg_sent",
- TNY_TYPE_SEND_QUEUE,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (TnySendQueueIface, msg_sent),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, TNY_TYPE_MSG);
-
+ g_signal_new ("msg_sent",
+ TNY_TYPE_SEND_QUEUE,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TnySendQueueIface, msg_sent),
+ NULL, NULL,
+ tny_marshal_VOID__OBJECT_OBJECT_INT_INT,
+ G_TYPE_NONE, 4, TNY_TYPE_HEADER, TNY_TYPE_MSG, G_TYPE_UINT, G_TYPE_UINT);
+
/**
* TnySendQueue::error-happened
* @self: the object on which the signal is emitted
@@ -171,14 +191,14 @@
* Emitted when a message didn't get sent because of an error
**/
tny_send_queue_signals[TNY_SEND_QUEUE_ERROR_HAPPENED] =
- g_signal_new ("error_happened",
- TNY_TYPE_SEND_QUEUE,
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (TnySendQueueIface, error_happened),
- NULL, NULL,
- tny_marshal_VOID__OBJECT_OBJECT_POINTER,
- G_TYPE_NONE, 3, TNY_TYPE_HEADER, TNY_TYPE_MSG, G_TYPE_POINTER);
-
+ g_signal_new ("error_happened",
+ TNY_TYPE_SEND_QUEUE,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TnySendQueueIface, error_happened),
+ NULL, NULL,
+ tny_marshal_VOID__OBJECT_OBJECT_POINTER,
+ G_TYPE_NONE, 3, TNY_TYPE_HEADER, TNY_TYPE_MSG, G_TYPE_POINTER);
+
initialized = TRUE;
}
}
Index: libtinymail/tny-send-queue.h
===================================================================
--- libtinymail/tny-send-queue.h (revision 2442)
+++ libtinymail/tny-send-queue.h (working copy)
@@ -40,6 +40,7 @@
enum _TnySendQueueSignal
{
+ TNY_SEND_QUEUE_MSG_SENDING,
TNY_SEND_QUEUE_MSG_SENT,
TNY_SEND_QUEUE_ERROR_HAPPENED,
TNY_SEND_QUEUE_LAST_SIGNAL
@@ -53,7 +54,8 @@
GTypeInterface parent;
/* Signals */
- void (*msg_sent) (TnySendQueue *self, TnyMsg *msg, gpointer user_data);
+ void (*msg_sending) (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, guint nth, guint total);
+ void (*msg_sent) (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, guint nth, guint total);
void (*error_happened) (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, gpointer user_data);
/* methods */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]