From: Dirk-Jan C. Binnema Date: Tue, 8 Jan 2008 14:46:53 +0000 (+0000) Subject: * enable getting debug information over dbus; for now X-Git-Tag: git_migration_finished~1852 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=6c444592d419f655429195f1e8cf87c3d3adad63 * enable getting debug information over dbus; for now we can get the operation-queue contents; other things can be added later. it can be retrieved (from cmdline): run-standalone.sh dbus-send --print-reply --dest='com.nokia.modest' /com/nokia/modest com.nokia.modest.Dump this will print it to stderr wherever that is for modest, and also return it as a string over dbus. if you're lucky, you get something like: modest debug dump ================= mail operation queue (01) ------------------------- 0x82e7c00 "NokiaID_store" (RECEIVE) [IN-PROGRESS] {1/100} '' pmo-trunk-r3991 --- diff --git a/src/dbus_api/modest-dbus-api.h b/src/dbus_api/modest-dbus-api.h index cacc0d0..db20fc8 100644 --- a/src/dbus_api/modest-dbus-api.h +++ b/src/dbus_api/modest-dbus-api.h @@ -78,6 +78,9 @@ enum ModestDbusDeleteMessageArguments #define MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX "OpenDefaultInbox" + +#define MODEST_DBUS_METHOD_DUMP "Dump" + /* These are handle via normal D-Bus instead of osso-rpc: */ #define MODEST_DBUS_METHOD_SEARCH "Search" #define MODEST_DBUS_METHOD_GET_FOLDERS "GetFolders" diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index a30fdfa..15a3f31 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -699,6 +699,39 @@ on_idle_send_receive(gpointer user_data) return FALSE; } + +static gint +on_dbus_method_dump (DBusConnection *con, DBusMessage *message) +{ + gchar *str; + gchar *op_queue_str; + DBusMessage *reply; + dbus_uint32_t serial = 0; + + op_queue_str = modest_mail_operation_queue_to_string + (modest_runtime_get_mail_operation_queue ()); + + str = g_strdup_printf ("\nmodest debug dump\n=================\n%s\n", + op_queue_str); + g_free (op_queue_str); + + 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) { @@ -820,7 +853,7 @@ modest_dbus_req_handler(const gchar * interface, const gchar * method, } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_TOP_APPLICATION) == 0) { if (arguments->len != 0) goto param_error; - return on_top_application (arguments, data, retval); + return on_top_application (arguments, data, retval); } else { /* We need to return INVALID here so * libosso will return DBUS_HANDLER_RESULT_NOT_YET_HANDLED, @@ -1390,12 +1423,16 @@ modest_dbus_req_filter (DBusConnection *con, on_dbus_method_search (con, message); handled = TRUE; } else if (dbus_message_is_method_call (message, - MODEST_DBUS_IFACE, - MODEST_DBUS_METHOD_GET_FOLDERS)) { + MODEST_DBUS_IFACE, + MODEST_DBUS_METHOD_GET_FOLDERS)) { on_dbus_method_get_folders (con, message); handled = TRUE; - } - else { + } else if (dbus_message_is_method_call (message, + MODEST_DBUS_IFACE, + MODEST_DBUS_METHOD_DUMP)) { + on_dbus_method_dump (con, message); + handled = TRUE; + } else { /* Note that this mentions methods that were already handled in modest_dbus_req_handler(). */ /* g_debug (" debug: %s: Unexpected (maybe already handled) D-Bus method:\n Interface=%s, Member=%s\n", diff --git a/src/modest-mail-operation-queue.c b/src/modest-mail-operation-queue.c index 02b1f1a..f00e992 100644 --- a/src/modest-mail-operation-queue.c +++ b/src/modest-mail-operation-queue.c @@ -441,3 +441,34 @@ modest_mail_operation_queue_get_by_source ( return found_operations; } + +static void +accumulate_mail_op_strings (ModestMailOperation *op, gchar **str) +{ + *str = g_strdup_printf ("%s\n%s", *str, modest_mail_operation_to_string (op)); +} + + +gchar* +modest_mail_operation_queue_to_string (ModestMailOperationQueue *self) +{ + gchar *str; + guint len; + ModestMailOperationQueuePrivate *priv; + + g_return_val_if_fail (MODEST_IS_MAIL_OPERATION_QUEUE (self), NULL); + + priv = MODEST_MAIL_OPERATION_QUEUE_GET_PRIVATE(self); + + len = g_queue_get_length (priv->op_queue); + str = g_strdup_printf ("mail operation queue (%02d)\n-------------------------", len); + if (len == 0) + str = g_strdup_printf ("%s\n%s", str, ""); + else { + g_mutex_lock (priv->queue_lock); + g_queue_foreach (priv->op_queue, (GFunc)accumulate_mail_op_strings, &str); + g_mutex_unlock (priv->queue_lock); + } + + return str; +} diff --git a/src/modest-mail-operation-queue.h b/src/modest-mail-operation-queue.h index fccb9b5..0a1e08f 100644 --- a/src/modest-mail-operation-queue.h +++ b/src/modest-mail-operation-queue.h @@ -129,8 +129,18 @@ void modest_mail_operation_queue_cancel_all (ModestMailOperationQueue *op_que * * Returns a list with the #ModestMailOperation that have the given source **/ -GSList* -modest_mail_operation_queue_get_by_source (ModestMailOperationQueue *op_queue, GObject *source); +GSList* modest_mail_operation_queue_get_by_source (ModestMailOperationQueue *op_queue, GObject *source); + + +/** + * modest_mail_operation_queue_get_by_source: + * @op_queue: a #ModestMailOperationQueue + * + * Returns a string representation of the operation queue (for debugging) + * + * Returns: a newly allocated string, or NULL in case of error + **/ +gchar* modest_mail_operation_queue_to_string (ModestMailOperationQueue *self); G_END_DECLS