[glib] GDBus: Add `return' debug option



commit d52e1c33f71a28908dac3658a8d5394e333324fc
Author: David Zeuthen <davidz redhat com>
Date:   Wed Aug 4 16:59:26 2010 -0400

    GDBus: Add `return' debug option
    
    This prints all GDBusMethodInvocation API usage and is normally used
    with the `incoming' option. Example:
    
     # G_DBUS_DEBUG=incoming,return ./polkitd --replace
     Entering main event loop
     Connected to the system bus
     Registering null backend at priority -10
     [...]
     Acquired the name org.freedesktop.PolicyKit1
     [...]
    
     ========================================================================
     GDBus-debug:Incoming:
      <<<< METHOD INVOCATION org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
           on object /org/freedesktop/PolicyKit1/Authority
           invoked by name :1.26
           serial 299
     ========================================================================
     GDBus-debug:Return:
      >>>> METHOD ERROR org.freedesktop.PolicyKit1.Error.Failed
           message `Cannot determine session the caller is in'
           in response to org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
           on object /org/freedesktop/PolicyKit1/Authority
           to name :1.26
           reply-serial 299
    
     [...]
    
     ========================================================================
     GDBus-debug:Incoming:
      <<<< METHOD INVOCATION org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
           on object /org/freedesktop/PolicyKit1/Authority
           invoked by name :1.2402
           serial 25
     ========================================================================
     GDBus-debug:Return:
      >>>> METHOD RETURN
           in response to org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
           on object /org/freedesktop/PolicyKit1/Authority
           to name :1.2402
           reply-serial 25
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 docs/reference/gio/overview.xml |   10 ++++++++--
 gio/gdbusconnection.c           |    6 ++++--
 gio/gdbusmethodinvocation.c     |   37 +++++++++++++++++++++++++++++++++++++
 gio/gdbusprivate.c              |   13 +++++++++++--
 gio/gdbusprivate.h              |    1 +
 5 files changed, 61 insertions(+), 6 deletions(-)
---
diff --git a/docs/reference/gio/overview.xml b/docs/reference/gio/overview.xml
index 5f7be19..5b7a570 100644
--- a/docs/reference/gio/overview.xml
+++ b/docs/reference/gio/overview.xml
@@ -360,6 +360,10 @@
              <listitem><para>Show when an incoming D-Bus method call is received</para></listitem>
            </varlistentry>
            <varlistentry>
+             <term>return</term>
+             <listitem><para>Show when a reply is returned via the #GDBusMethodInvocation API</para></listitem>
+           </varlistentry>
+           <varlistentry>
              <term>emission</term>
              <listitem><para>Trace g_dbus_connection_emit_signal() API usage</para></listitem>
            </varlistentry>
@@ -372,8 +376,10 @@
              <listitem><para>Show information about D-Bus address lookups and autolaunching</para></listitem>
            </varlistentry>
          </variablelist>
-         The special value <literal>all</literal> can be used to turn on
-         all debug options.
+         The special value <literal>all</literal> can be used to turn
+         on all debug options. The special value
+         <literal>help</literal> can be used to print a list of
+         supported options to standard output.
       </para>
    </formalpara>
 
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index 6974510..6a37203 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -5883,10 +5883,12 @@ distribute_method_call (GDBusConnection *connection,
                "GDBus-debug:Incoming:\n"
                " <<<< METHOD INVOCATION %s.%s()\n"
                "      on object %s\n"
-               "      invoked by name %s\n",
+               "      invoked by name %s\n"
+               "      serial %d\n",
                interface_name, member,
                path,
-               g_dbus_message_get_sender (message) != NULL ? g_dbus_message_get_sender (message) : "(none)");
+               g_dbus_message_get_sender (message) != NULL ? g_dbus_message_get_sender (message) : "(none)",
+               g_dbus_message_get_serial (message));
       _g_dbus_debug_print_unlock ();
     }
 
diff --git a/gio/gdbusmethodinvocation.c b/gio/gdbusmethodinvocation.c
index aea0b6d..a9ea05b 100644
--- a/gio/gdbusmethodinvocation.c
+++ b/gio/gdbusmethodinvocation.c
@@ -381,6 +381,23 @@ g_dbus_method_invocation_return_value (GDBusMethodInvocation *invocation,
       g_variant_type_free (type);
     }
 
+  if (G_UNLIKELY (_g_dbus_debug_return ()))
+    {
+      _g_dbus_debug_print_lock ();
+      g_print ("========================================================================\n"
+               "GDBus-debug:Return:\n"
+               " >>>> METHOD RETURN\n"
+               "      in response to %s.%s()\n"
+               "      on object %s\n"
+               "      to name %s\n"
+               "      reply-serial %d\n",
+               invocation->interface_name, invocation->method_name,
+               invocation->object_path,
+               invocation->sender,
+               g_dbus_message_get_serial (invocation->message));
+      _g_dbus_debug_print_unlock ();
+    }
+
   reply = g_dbus_message_new_method_reply (invocation->message);
   g_dbus_message_set_body (reply, parameters);
   error = NULL;
@@ -560,6 +577,26 @@ g_dbus_method_invocation_return_dbus_error (GDBusMethodInvocation *invocation,
   g_return_if_fail (error_name != NULL && g_dbus_is_name (error_name));
   g_return_if_fail (error_message != NULL);
 
+  if (G_UNLIKELY (_g_dbus_debug_return ()))
+    {
+      _g_dbus_debug_print_lock ();
+      g_print ("========================================================================\n"
+               "GDBus-debug:Return:\n"
+               " >>>> METHOD ERROR %s\n"
+               "      message `%s'\n"
+               "      in response to %s.%s()\n"
+               "      on object %s\n"
+               "      to name %s\n"
+               "      reply-serial %d\n",
+               error_name,
+               error_message,
+               invocation->interface_name, invocation->method_name,
+               invocation->object_path,
+               invocation->sender,
+               g_dbus_message_get_serial (invocation->message));
+      _g_dbus_debug_print_unlock ();
+    }
+
   reply = g_dbus_message_new_method_error_literal (invocation->message,
                                                    error_name,
                                                    error_message);
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index cacbf68..cd6eb91 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -1178,8 +1178,9 @@ _g_dbus_worker_flush_sync (GDBusWorker    *worker,
 #define G_DBUS_DEBUG_CALL           (1<<3)
 #define G_DBUS_DEBUG_SIGNAL         (1<<4)
 #define G_DBUS_DEBUG_INCOMING       (1<<5)
-#define G_DBUS_DEBUG_EMISSION       (1<<6)
-#define G_DBUS_DEBUG_ADDRESS        (1<<7)
+#define G_DBUS_DEBUG_RETURN         (1<<6)
+#define G_DBUS_DEBUG_EMISSION       (1<<7)
+#define G_DBUS_DEBUG_ADDRESS        (1<<8)
 
 static gint _gdbus_debug_flags = 0;
 
@@ -1226,6 +1227,13 @@ _g_dbus_debug_incoming (void)
 }
 
 gboolean
+_g_dbus_debug_return (void)
+{
+  _g_dbus_initialize ();
+  return (_gdbus_debug_flags & G_DBUS_DEBUG_RETURN) != 0;
+}
+
+gboolean
 _g_dbus_debug_emission (void)
 {
   _g_dbus_initialize ();
@@ -1283,6 +1291,7 @@ _g_dbus_initialize (void)
             { "call",           G_DBUS_DEBUG_CALL           },
             { "signal",         G_DBUS_DEBUG_SIGNAL         },
             { "incoming",       G_DBUS_DEBUG_INCOMING       },
+            { "return",         G_DBUS_DEBUG_RETURN         },
             { "emission",       G_DBUS_DEBUG_EMISSION       },
             { "address",        G_DBUS_DEBUG_ADDRESS        }
           };
diff --git a/gio/gdbusprivate.h b/gio/gdbusprivate.h
index a879fab..a226623 100644
--- a/gio/gdbusprivate.h
+++ b/gio/gdbusprivate.h
@@ -85,6 +85,7 @@ gboolean _g_dbus_debug_payload (void);
 gboolean _g_dbus_debug_call    (void);
 gboolean _g_dbus_debug_signal  (void);
 gboolean _g_dbus_debug_incoming (void);
+gboolean _g_dbus_debug_return (void);
 gboolean _g_dbus_debug_emission (void);
 gboolean _g_dbus_debug_address (void);
 



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