* add debugging code to the send-queue and the operations-queue;
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 8 Jan 2008 08:58:49 +0000 (08:58 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 8 Jan 2008 08:58:49 +0000 (08:58 +0000)
  lots of interesting info when your run modest with
"MODEST_DEBUG="debug-code"

pmo-trunk-r3986

src/modest-mail-operation-queue.c
src/modest-mail-operation-queue.h
src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-main.c
src/modest-tny-send-queue.c

index a05c8fd..02b1f1a 100644 (file)
@@ -31,6 +31,7 @@
 #include "modest-marshal.h"
 #include "modest-mail-operation-queue.h"
 #include "modest-runtime.h"
 #include "modest-marshal.h"
 #include "modest-mail-operation-queue.h"
 #include "modest-runtime.h"
+#include "modest-debug.h"
 
 /* 'private'/'protected' functions */
 static void modest_mail_operation_queue_class_init (ModestMailOperationQueueClass *klass);
 
 /* 'private'/'protected' functions */
 static void modest_mail_operation_queue_class_init (ModestMailOperationQueueClass *klass);
@@ -148,6 +149,16 @@ modest_mail_operation_queue_init (ModestMailOperationQueue *obj)
 }
 
 static void
 }
 
 static void
+print_queue_item (ModestMailOperation *op, const gchar* prefix)
+{
+       gchar *op_str = modest_mail_operation_to_string (op);
+       g_debug ("%s: %s",
+                prefix ? prefix : "",
+                op_str);
+       g_free (op_str);
+}
+
+static void
 on_finalize_foreach(gpointer op,
                     gpointer user_data)
 {
 on_finalize_foreach(gpointer op,
                     gpointer user_data)
 {
@@ -164,6 +175,8 @@ on_finalize_foreach(gpointer op,
         * the lock acquired. */
        g_signal_handlers_disconnect_by_func (mail_op, G_CALLBACK (on_operation_finished), user_data);
 
         * the lock acquired. */
        g_signal_handlers_disconnect_by_func (mail_op, G_CALLBACK (on_operation_finished), user_data);
 
+       MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "cancel/remove"););
+       
        modest_mail_operation_cancel (mail_op);
        g_queue_remove (priv->op_queue, mail_op);
        g_object_unref (G_OBJECT (mail_op));
        modest_mail_operation_cancel (mail_op);
        g_queue_remove (priv->op_queue, mail_op);
        g_object_unref (G_OBJECT (mail_op));
@@ -178,6 +191,13 @@ modest_mail_operation_queue_finalize (GObject *obj)
 
        g_mutex_lock (priv->queue_lock);
 
 
        g_mutex_lock (priv->queue_lock);
 
+       MODEST_DEBUG_BLOCK (
+               g_debug ("%s; items in queue: %d",
+                        __FUNCTION__, g_queue_get_length (priv->op_queue));
+               g_queue_foreach (priv->op_queue, (GFunc)print_queue_item, "in queue");
+       );
+
+       
        if (priv->op_queue) {
                /* Cancel all */
                if (!g_queue_is_empty (priv->op_queue)) {
        if (priv->op_queue) {
                /* Cancel all */
                if (!g_queue_is_empty (priv->op_queue)) {
@@ -227,6 +247,8 @@ modest_mail_operation_queue_add (ModestMailOperationQueue *self,
        g_mutex_lock (priv->queue_lock);
        g_queue_push_tail (priv->op_queue, g_object_ref (mail_op));
        g_mutex_unlock (priv->queue_lock);
        g_mutex_lock (priv->queue_lock);
        g_queue_push_tail (priv->op_queue, g_object_ref (mail_op));
        g_mutex_unlock (priv->queue_lock);
+       
+       MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "add"););
 
        /* Get notified when the operation ends to remove it from the
           queue. We connect it using the *after* because we want to
 
        /* Get notified when the operation ends to remove it from the
           queue. We connect it using the *after* because we want to
@@ -258,6 +280,8 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
        g_queue_remove (priv->op_queue, mail_op);
        g_mutex_unlock (priv->queue_lock);
 
        g_queue_remove (priv->op_queue, mail_op);
        g_mutex_unlock (priv->queue_lock);
 
+       MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "remove"););
+
        g_signal_handlers_disconnect_by_func (G_OBJECT (mail_op),
                                              G_CALLBACK (on_operation_finished),
                                              self);
        g_signal_handlers_disconnect_by_func (G_OBJECT (mail_op),
                                              G_CALLBACK (on_operation_finished),
                                              self);
@@ -327,6 +351,8 @@ modest_mail_operation_queue_cancel (ModestMailOperationQueue *self,
 
        priv = MODEST_MAIL_OPERATION_QUEUE_GET_PRIVATE(self);
 
 
        priv = MODEST_MAIL_OPERATION_QUEUE_GET_PRIVATE(self);
 
+       MODEST_DEBUG_BLOCK (print_queue_item (mail_op, "cancel"););
+       
        /* This triggers a progess_changed signal in which we remove
         * the operation from the queue. */
        modest_mail_operation_cancel (mail_op);
        /* This triggers a progess_changed signal in which we remove
         * the operation from the queue. */
        modest_mail_operation_cancel (mail_op);
index 2d9d6c1..fccb9b5 100644 (file)
@@ -68,6 +68,7 @@ struct _ModestMailOperationQueueClass {
        void (*queue_empty) (ModestMailOperationQueue *self);
 };
 
        void (*queue_empty) (ModestMailOperationQueue *self);
 };
 
+
 /* member functions */
 GType                   modest_mail_operation_queue_get_type      (void) G_GNUC_CONST;
 
 /* member functions */
 GType                   modest_mail_operation_queue_get_type      (void) G_GNUC_CONST;
 
index 9186d21..48f3c14 100644 (file)
@@ -3010,3 +3010,41 @@ modest_mail_operation_noop (ModestMailOperation *self)
        modest_mail_operation_notify_start (self);
        modest_mail_operation_notify_end (self);
 }
        modest_mail_operation_notify_start (self);
        modest_mail_operation_notify_end (self);
 }
+
+
+gchar*
+modest_mail_operation_to_string (ModestMailOperation *self)
+{
+       const gchar *type, *status, *account_id;
+       ModestMailOperationPrivate *priv = NULL;
+       
+       g_return_val_if_fail (self, NULL);
+
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
+       
+       switch (priv->op_type) {
+       case MODEST_MAIL_OPERATION_TYPE_SEND:    type= "SEND";    break;
+       case MODEST_MAIL_OPERATION_TYPE_RECEIVE: type= "RECEIVE"; break;
+       case MODEST_MAIL_OPERATION_TYPE_OPEN:    type= "OPEN";    break;
+       case MODEST_MAIL_OPERATION_TYPE_DELETE:  type= "DELETE";  break;
+       case MODEST_MAIL_OPERATION_TYPE_INFO:    type= "INFO";    break;
+       case MODEST_MAIL_OPERATION_TYPE_UNKNOWN: type= "UNKNOWN"; break;
+       default: type = "UNEXPECTED"; break;
+       }
+
+       switch (priv->status) {
+       case MODEST_MAIL_OPERATION_STATUS_INVALID:              status= "INVALID"; break;
+       case MODEST_MAIL_OPERATION_STATUS_SUCCESS:              status= "SUCCESS"; break;
+       case MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS: status= "FINISHED-WITH-ERRORS"; break;
+       case MODEST_MAIL_OPERATION_STATUS_FAILED:               status= "FAILED"; break;
+       case MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS:          status= "IN-PROGRESS"; break;
+       case MODEST_MAIL_OPERATION_STATUS_CANCELED:             status= "CANCELLED"; break;
+       default:                                                status= "UNEXPECTED"; break;
+       } 
+
+       account_id = priv->account ? tny_account_get_id (priv->account) : "";
+       
+       return g_strdup_printf ("%p \"%s\" (%s) [%s] {%d/%d} '%s'", self, account_id,type, status,
+                               priv->done, priv->total,
+                               priv->error && priv->error->message ? priv->error->message : "");
+}
index f6c5fca..f86812a 100644 (file)
@@ -716,6 +716,18 @@ TnyAccount *modest_mail_operation_get_account   (ModestMailOperation *self);
  **/
 void modest_mail_operation_noop (ModestMailOperation *self);
 
  **/
 void modest_mail_operation_noop (ModestMailOperation *self);
 
+
+/**
+ * modest_mail_operation_to_string:
+ * @self: a #ModestMailOperation
+ * 
+ * get a string representation of the mail operation (for debugging)
+ *
+ * Returns: a newly allocated string
+ **/
+gchar* modest_mail_operation_to_string (ModestMailOperation *self);
+
+
 G_END_DECLS
 
 #endif /* __MODEST_MAIL_OPERATION_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_MAIL_OPERATION_H__ */
index 10df9ed..563fe29 100644 (file)
@@ -92,8 +92,7 @@ main (int argc, char *argv[])
        }
 
        if (!show_ui_without_top_application_method) {
        }
 
        if (!show_ui_without_top_application_method) {
-               g_print ("modest: not showing UI\n");
-               g_print ("modest: use 'modest showui' to start with UI\n");
+               g_print ("modest: use 'modest showui' to start from cmdline  with UI\n");
        }       
                
        if (!g_thread_supported())
        }       
                
        if (!g_thread_supported())
index 0c8b199..5a0e150 100644 (file)
@@ -40,6 +40,7 @@
 #include <modest-platform.h>
 #include <widgets/modest-window-mgr.h>
 #include <modest-marshal.h>
 #include <modest-platform.h>
 #include <widgets/modest-window-mgr.h>
 #include <modest-marshal.h>
+#include <modest-debug.h>
 #include <string.h> /* strcmp */
 
 /* 'private'/'protected' functions */
 #include <string.h> /* strcmp */
 
 /* 'private'/'protected' functions */
@@ -124,12 +125,36 @@ modest_tny_send_queue_info_free(SendInfo *info)
        g_slice_free(SendInfo, info);
 }
 
        g_slice_free(SendInfo, info);
 }
 
+static void
+print_queue_item (gpointer data, gpointer user_data)
+{
+       SendInfo *info = (SendInfo*)data;
+       const gchar *status;
+       
+       switch (info->status) {
+       case MODEST_TNY_SEND_QUEUE_UNKNOWN: status = "UNKNOWN"; break;
+       case MODEST_TNY_SEND_QUEUE_WAITING: status = "WAITING"; break;
+       case MODEST_TNY_SEND_QUEUE_SUSPENDED: status = "SUSPENDED"; break;
+       case MODEST_TNY_SEND_QUEUE_SENDING: status = "SENDING"; break;
+       case MODEST_TNY_SEND_QUEUE_FAILED: status = "FAILED"; break;
+       default: status= "UNEXPECTED"; break;
+       }
+
+       g_debug ("\"%s\" => [%s]", info->msg_id, status);
+}
+
 static GList*
 modest_tny_send_queue_lookup_info (ModestTnySendQueue *self, const gchar *msg_id)
 {
        ModestTnySendQueuePrivate *priv;
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
 
 static GList*
 modest_tny_send_queue_lookup_info (ModestTnySendQueue *self, const gchar *msg_id)
 {
        ModestTnySendQueuePrivate *priv;
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
 
+       MODEST_DEBUG_BLOCK (
+               g_debug ("items in the send queue (%d):",
+                        g_queue_get_length (priv->queue));
+               g_queue_foreach (priv->queue, print_queue_item, NULL);
+       );
+       
        return g_queue_find_custom (priv->queue, msg_id, on_modest_tny_send_queue_compare_id);
 }
 
        return g_queue_find_custom (priv->queue, msg_id, on_modest_tny_send_queue_compare_id);
 }
 
@@ -552,7 +577,8 @@ _on_msg_start_sending (TnySendQueue *self,
        /* Get status info */
        item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
        if (!item) 
        /* Get status info */
        item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
        if (!item) 
-               g_warning  ("%s: item should not be NULL", __FUNCTION__);
+               g_warning  ("%s: item (%s) should not be NULL",
+                           __FUNCTION__, msg_id ? msg_id : "<none>");
        else {
                info = item->data;
                info->status = MODEST_TNY_SEND_QUEUE_SENDING;
        else {
                info = item->data;
                info->status = MODEST_TNY_SEND_QUEUE_SENDING;