* improve our debug-over-dbus a bit; added methods
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 10 Jan 2008 10:22:17 +0000 (10:22 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 10 Jan 2008 10:22:17 +0000 (10:22 +0000)
DumpAccounts, DumpSendQueues and DumpOperationQueue
  which will dump the given thing.

it can be used from the commandline as:

dbus-send --print-reply --dest='com.nokia.modest' /com/nokia/modest com.nokia.modest.DumpSendQueues

  (in sbox you'll need run-standalone.sh)

pmo-trunk-r4007

src/dbus_api/modest-dbus-api.h
src/dbus_api/modest-dbus-callbacks.c
src/modest-tny-account-store.h
src/modest-tny-send-queue.c
src/modest-tny-send-queue.h

index db20fc8..4e980bc 100644 (file)
@@ -78,8 +78,15 @@ enum ModestDbusDeleteMessageArguments
 
 #define MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX "OpenDefaultInbox"
 
+/*
+ * these methods are for debugging only, and should _not_ be
+ * exported through libmodest-dbus-client
+ */
+#define MODEST_DBUS_METHOD_DUMP_OPERATION_QUEUE   "DumpOperationQueue"
+#define MODEST_DBUS_METHOD_DUMP_ACCOUNTS          "DumpAccounts"
+#define MODEST_DBUS_METHOD_DUMP_SEND_QUEUES       "DumpSendQueues"
+
 
-#define MODEST_DBUS_METHOD_DUMP "Dump"
 
 /* These are handle via normal D-Bus instead of osso-rpc: */
 #define MODEST_DBUS_METHOD_SEARCH "Search"
index 9c76e81..929cfba 100644 (file)
@@ -55,6 +55,7 @@
 #include <tny-iterator.h>
 #include <tny-simple-list.h>
 #include <tny-merge-folder.h>
+#include <tny-account.h>
 
 #include <modest-text-utils.h>
 
@@ -700,8 +701,75 @@ on_idle_send_receive(gpointer user_data)
 }
 
 
+
 static gint 
-on_dbus_method_dump (DBusConnection *con, DBusMessage *message)
+on_dbus_method_dump_send_queues (DBusConnection *con, DBusMessage *message)
+{
+       gchar *str;
+       
+       DBusMessage *reply;
+       dbus_uint32_t serial = 0;
+
+       GSList *account_names, *cursor;
+
+       str = g_strdup("\nsend queues\n"
+                      "===========\n");
+
+       cursor = account_names = modest_account_mgr_account_names
+               (modest_runtime_get_account_mgr(), TRUE); /* only enabled accounts */
+
+       while (cursor) {
+               TnyAccount *acc;
+               gchar *tmp, *accname = (gchar*)cursor->data;
+               
+               tmp = g_strdup_printf ("%s", str);
+               g_free (str);
+               str = tmp;
+               
+               /* transport */
+               acc = modest_tny_account_store_get_server_account (
+                       modest_runtime_get_account_store(), accname,
+                       TNY_ACCOUNT_TYPE_TRANSPORT);
+               if (TNY_IS_ACCOUNT(acc)) {
+                       gchar *tmp, *url = tny_account_get_url_string (acc);
+                       ModestTnySendQueue *sendqueue =
+                               modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(acc));
+                       gchar *queue_str = modest_tny_send_queue_to_string (sendqueue);
+                       
+                       tmp = g_strdup_printf ("%s[%s]: '%s': %s\n%s",
+                                              str, accname, tny_account_get_id (acc), url,
+                                              queue_str);
+                       g_free(queue_str);
+                       g_free (url);
+                       g_free (str);
+                       str = tmp;
+
+                       g_object_unref (acc);
+               }
+               
+               cursor = g_slist_next (cursor);
+       }
+       modest_account_mgr_free_account_names (account_names);
+                                                        
+       g_printerr (str);
+       
+       reply = dbus_message_new_method_return (message);
+       if (reply) {
+               dbus_message_append_args (reply,
+                                         DBUS_TYPE_STRING, &str,
+                                         DBUS_TYPE_INVALID);
+               dbus_connection_send (con, reply, &serial);
+               dbus_connection_flush (con);
+               dbus_message_unref (reply);
+       }
+       
+       g_free (str);
+       return OSSO_OK;
+}
+
+
+static gint 
+on_dbus_method_dump_operation_queue (DBusConnection *con, DBusMessage *message)
 {
        gchar *str;
        gchar *op_queue_str;
@@ -713,8 +781,8 @@ on_dbus_method_dump (DBusConnection *con, DBusMessage *message)
        op_queue_str = modest_mail_operation_queue_to_string
                (modest_runtime_get_mail_operation_queue ());
                
-       str = g_strdup_printf ("\nmodest debug dump\n"
-                              "=================\n"
+       str = g_strdup_printf ("\noperation queue\n"
+                              "===============\n"
                               "status: %s\n"
                               "%s\n",
                               tny_device_is_online (modest_runtime_get_device ()) ? "online" : "offline",
@@ -738,6 +806,82 @@ on_dbus_method_dump (DBusConnection *con, DBusMessage *message)
 }
 
 
+
+static gint 
+on_dbus_method_dump_accounts (DBusConnection *con, DBusMessage *message)
+{
+       gchar *str;
+       
+       DBusMessage *reply;
+       dbus_uint32_t serial = 0;
+
+       GSList *account_names, *cursor;
+
+       str = g_strdup ("\naccounts\n========\n");
+
+       cursor = account_names = modest_account_mgr_account_names
+               (modest_runtime_get_account_mgr(), TRUE); /* only enabled accounts */
+
+       while (cursor) {
+               TnyAccount *acc;
+               gchar *tmp, *accname = (gchar*)cursor->data;
+
+               tmp = g_strdup_printf ("%s[%s]\n", str, accname);
+               g_free (str);
+               str = tmp;
+               
+               /* store */
+               acc = modest_tny_account_store_get_server_account (
+                       modest_runtime_get_account_store(), accname,
+                       TNY_ACCOUNT_TYPE_STORE);
+               if (TNY_IS_ACCOUNT(acc)) {
+                       gchar *tmp, *url = tny_account_get_url_string (acc);
+                       tmp = g_strdup_printf ("%sstore    : '%s': %s\n",
+                                              str, tny_account_get_id (acc), url);
+                       g_free (str);
+                       str = tmp;
+                       g_free (url);
+                       g_object_unref (acc);
+               }
+               
+               /* transport */
+               acc = modest_tny_account_store_get_server_account (
+                       modest_runtime_get_account_store(), accname,
+                       TNY_ACCOUNT_TYPE_TRANSPORT);
+               if (TNY_IS_ACCOUNT(acc)) {
+                       gchar *tmp, *url = tny_account_get_url_string (acc);
+                       tmp = g_strdup_printf ("%stransport: '%s': %s\n",
+                                              str, tny_account_get_id (acc), url);
+                       g_free (str);
+                       str = tmp;
+                       g_free (url);
+                       g_object_unref (acc);
+               }
+               
+               cursor = g_slist_next (cursor);
+       }
+       
+       modest_account_mgr_free_account_names (account_names);
+                                                        
+       g_printerr (str);
+       
+       reply = dbus_message_new_method_return (message);
+       if (reply) {
+               dbus_message_append_args (reply,
+                                         DBUS_TYPE_STRING, &str,
+                                         DBUS_TYPE_INVALID);
+               dbus_connection_send (con, reply, &serial);
+               dbus_connection_flush (con);
+               dbus_message_unref (reply);
+       }
+       
+       g_free (str);
+       return OSSO_OK;
+}
+
+
+
+
 static gint 
 on_send_receive(GArray *arguments, gpointer data, osso_rpc_t * retval)
 {      
@@ -1435,8 +1579,18 @@ modest_dbus_req_filter (DBusConnection *con,
                handled = TRUE;                         
        } else if (dbus_message_is_method_call (message,
                                                MODEST_DBUS_IFACE,
-                                               MODEST_DBUS_METHOD_DUMP)) {
-               on_dbus_method_dump (con, message);
+                                               MODEST_DBUS_METHOD_DUMP_OPERATION_QUEUE)) {
+               on_dbus_method_dump_operation_queue (con, message);
+               handled = TRUE;
+       } else if (dbus_message_is_method_call (message,
+                                               MODEST_DBUS_IFACE,
+                                               MODEST_DBUS_METHOD_DUMP_ACCOUNTS)) {
+               on_dbus_method_dump_accounts (con, message);
+               handled = TRUE;
+       } else if (dbus_message_is_method_call (message,
+                                               MODEST_DBUS_IFACE,
+                                               MODEST_DBUS_METHOD_DUMP_SEND_QUEUES)) {
+               on_dbus_method_dump_send_queues (con, message);
                handled = TRUE;
        } else {
                /* Note that this mentions methods that were already handled in modest_dbus_req_handler(). */
index 3f1f52f..a7f7c5d 100644 (file)
@@ -125,7 +125,7 @@ TnyAccount* modest_tny_account_store_get_tny_account_by  (ModestTnyAccountStore
  * modest_tny_account_store_get_server_account
  * @self: a ModestTnyAccountStore instance
  * @account_name: a modest account name
- * @type: the tny account type (store or transport)
+ * @type: the tny account type (#TNY_ACCOUNT_TYPE_STORE or #TNY_ACCOUNT_TYPE_STORE)
  * 
  * Get the tny account corresponding to one of the server_accounts for account with @account_name
  * 
index 5a0e150..162da3d 100644 (file)
@@ -125,11 +125,25 @@ modest_tny_send_queue_info_free(SendInfo *info)
        g_slice_free(SendInfo, info);
 }
 
+static GList*
+modest_tny_send_queue_lookup_info (ModestTnySendQueue *self, const gchar *msg_id)
+{
+       ModestTnySendQueuePrivate *priv;
+       priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+       
+       return g_queue_find_custom (priv->queue, msg_id, on_modest_tny_send_queue_compare_id);
+}
+
+
 static void
-print_queue_item (gpointer data, gpointer user_data)
+queue_item_to_string (gpointer data, gchar **user_data)
 {
        SendInfo *info = (SendInfo*)data;
        const gchar *status;
+       gchar *tmp;
+       
+       if (!(user_data && *user_data))
+               return;
        
        switch (info->status) {
        case MODEST_TNY_SEND_QUEUE_UNKNOWN: status = "UNKNOWN"; break;
@@ -140,22 +154,27 @@ print_queue_item (gpointer data, gpointer user_data)
        default: status= "UNEXPECTED"; break;
        }
 
-       g_debug ("\"%s\" => [%s]", info->msg_id, status);
+       tmp = g_strdup_printf ("%s\"%s\" => [%s]\n",
+                              *user_data, info->msg_id, status);
+       g_free (*user_data);
+       *user_data = tmp;
 }
 
-static GList*
-modest_tny_send_queue_lookup_info (ModestTnySendQueue *self, const gchar *msg_id)
+gchar*
+modest_tny_send_queue_to_string (ModestTnySendQueue *self)
 {
+       gchar *str;
        ModestTnySendQueuePrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_TNY_SEND_QUEUE(self), NULL);
        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);
-       );
+       str = g_strdup_printf ("items in the send queue: %d\n",
+                              g_queue_get_length (priv->queue));
        
-       return g_queue_find_custom (priv->queue, msg_id, on_modest_tny_send_queue_compare_id);
+       g_queue_foreach (priv->queue, (GFunc)queue_item_to_string, &str);
+
+       return str;
 }
 
 static void
index 345cf64..87eeb39 100644 (file)
@@ -155,6 +155,18 @@ modest_tny_send_queue_get_msg_id (TnyHeader *header);
 ModestTnySendQueueStatus
 modest_tny_all_send_queues_get_msg_status (TnyHeader *header);
 
+
+/**
+ * modest_tny_send_queue_to_string:
+ * @self: a valid #ModestTnySendQueue instance
+ *
+ * get a string representation of a send queue (for debugging)
+ *
+ * Returns: a newly allocated string, or NULL in case of error
+ */
+gchar* modest_tny_send_queue_to_string (ModestTnySendQueue *self);
+
+
 G_END_DECLS
 
 #endif /* __MODEST_TNY_SEND_QUEUE_H__ */