[glib/gdbus-merge] GDBus: Make gdbus(1) print annotations when introspecting data



commit 9695c23d4c29e79afbe14e3584b6c42e98e8f0d9
Author: David Zeuthen <davidz redhat com>
Date:   Wed May 12 22:09:18 2010 -0400

    GDBus: Make gdbus(1) print annotations when introspecting data
    
    Also make the gdbus-example-server include some example
    annotations. The output looks like this:
    
    $ gdbus introspect --session --dest org.gtk.GDBus.TestServer --object-path /org/gtk/GDBus/TestObject
    node /org/gtk/GDBus/TestObject {
      interface org.freedesktop.DBus.Properties {
        methods:
          Get(in  s interface_name,
              in  s property_name,
              out v value);
          GetAll(in  s interface_name,
                 out a{sv} properties);
          Set(in  s interface_name,
              in  s property_name,
              in  v value);
        signals:
          PropertiesChanged(s interface_name,
                            a{sv} changed_properties);
      };
      interface org.freedesktop.DBus.Introspectable {
        methods:
          Introspect(out s xml_data);
      };
      interface org.freedesktop.DBus.Peer {
        methods:
          Ping();
          GetMachineId(out s machine_uuid);
      };
      @org.gtk.GDBus.Annotation("OnInterface")
      @org.gtk.GDBus.Annotation("AlsoOnInterface")
      interface org.gtk.GDBus.TestInterface {
        methods:
          @org.gtk.GDBus.Annotation("OnMethod")
          HelloWorld(in  s greeting,
                     out s response);
          EmitSignal(@org.gtk.GDBus.Annotation.("OnArg")
                     in  d speed_in_mph);
          GimmeStdout();
        signals:
          @org.gtk.GDBus.Annotation("Onsignal")
          VelocityChanged(d speed_in_mph,
                          @org.gtk.GDBus.Annotation.("OnArg_NonFirst")
                          s speed_as_string);
        properties:
          @org.gtk.GDBus.Annotation("OnProperty")
            @org.gtk.GDBus.Annotation("OnAnnotation_YesThisIsCrazy")
          readonly s FluxCapicitorName = 'DeLorean';
          readwrite s Title = 'Back To C!';
          readonly s ReadingAlwaysThrowsError;
          readwrite s WritingAlwaysThrowsError = "There's no home like home";
          writeonly s OnlyWritable;
          readonly s Foo = 'Tick';
          readonly s Bar = 'Tock';
      };
    };

 gio/gdbus-tool.c                 |   43 ++++++++++++++++++++++++++++++++++++++
 gio/tests/gdbus-example-server.c |   18 +++++++++++++--
 2 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/gio/gdbus-tool.c b/gio/gdbus-tool.c
index ce5e5db..96a66ca 100644
--- a/gio/gdbus-tool.c
+++ b/gio/gdbus-tool.c
@@ -882,12 +882,34 @@ handle_call (gint        *argc,
 /* TODO: dump annotations */
 
 static void
+dump_annotation (const GDBusAnnotationInfo *o,
+                 guint indent,
+                 gboolean ignore_indent)
+{
+  guint n;
+  g_print ("%*s %s(\"%s\")\n",
+           ignore_indent ? 0 : indent, "",
+           o->key,
+           o->value);
+  for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)
+    dump_annotation (o->annotations[n], indent + 2, FALSE);
+}
+
+static void
 dump_arg (const GDBusArgInfo *o,
           guint indent,
           const gchar *direction,
           gboolean ignore_indent,
           gboolean include_newline)
 {
+  guint n;
+
+  for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)
+    {
+      dump_annotation (o->annotations[n], indent, ignore_indent);
+      ignore_indent = FALSE;
+    }
+
   g_print ("%*s%s%s %s%s",
            ignore_indent ? 0 : indent, "",
            direction,
@@ -917,6 +939,10 @@ dump_method (const GDBusMethodInfo *o,
   guint m;
   guint name_len;
   guint total_num_args;
+
+  for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)
+    dump_annotation (o->annotations[n], indent, FALSE);
+
   g_print ("%*s%s(", indent, "", o->name);
   name_len = strlen (o->name);
   total_num_args = count_args (o->in_args) + count_args (o->out_args);
@@ -924,6 +950,7 @@ dump_method (const GDBusMethodInfo *o,
     {
       gboolean ignore_indent = (m == 0);
       gboolean include_newline = (m != total_num_args - 1);
+
       dump_arg (o->in_args[n],
                 indent + name_len + 1,
                 "in  ",
@@ -950,6 +977,10 @@ dump_signal (const GDBusSignalInfo *o,
   guint n;
   guint name_len;
   guint total_num_args;
+
+  for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)
+    dump_annotation (o->annotations[n], indent, FALSE);
+
   g_print ("%*s%s(", indent, "", o->name);
   name_len = strlen (o->name);
   total_num_args = count_args (o->args);
@@ -972,6 +1003,8 @@ dump_property (const GDBusPropertyInfo *o,
                GVariant                *value)
 {
   const gchar *access;
+  guint n;
+
   if (o->flags == G_DBUS_PROPERTY_INFO_FLAGS_READABLE)
     access = "readonly";
   else if (o->flags == G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE)
@@ -980,6 +1013,10 @@ dump_property (const GDBusPropertyInfo *o,
     access = "readwrite";
   else
     g_assert_not_reached ();
+
+  for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)
+    dump_annotation (o->annotations[n], indent, FALSE);
+
   if (value != NULL)
     {
       gchar *s = g_variant_print (value, FALSE);
@@ -1074,6 +1111,9 @@ dump_interface (GDBusConnection          *c,
         }
     }
 
+  for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)
+    dump_annotation (o->annotations[n], indent, FALSE);
+
   g_print ("%*sinterface %s {\n", indent, "", o->name);
   if (o->methods != NULL)
     {
@@ -1117,6 +1157,9 @@ dump_node (GDBusConnection      *c,
   if (o->path != NULL)
     object_path_to_print = o->path;
 
+  for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)
+    dump_annotation (o->annotations[n], indent, FALSE);
+
   g_print ("%*snode %s", indent, "", object_path_to_print != NULL ? object_path_to_print : "(not set)");
   if (o->interfaces != NULL || o->nodes != NULL)
     {
diff --git a/gio/tests/gdbus-example-server.c b/gio/tests/gdbus-example-server.c
index eb0d6e4..a943f65 100644
--- a/gio/tests/gdbus-example-server.c
+++ b/gio/tests/gdbus-example-server.c
@@ -14,19 +14,31 @@ static GDBusNodeInfo *introspection_data = NULL;
 static const gchar introspection_xml[] =
   "<node>"
   "  <interface name='org.gtk.GDBus.TestInterface'>"
+  "    <annotation name='org.gtk.GDBus.Annotation' value='OnInterface'/>"
+  "    <annotation name='org.gtk.GDBus.Annotation' value='AlsoOnInterface'/>"
   "    <method name='HelloWorld'>"
+  "      <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>"
   "      <arg type='s' name='greeting' direction='in'/>"
   "      <arg type='s' name='response' direction='out'/>"
   "    </method>"
   "    <method name='EmitSignal'>"
-  "      <arg type='d' name='speed_in_mph' direction='in'/>"
+  "      <arg type='d' name='speed_in_mph' direction='in'>"
+  "        <annotation name='org.gtk.GDBus.Annotation' value='OnArg'/>"
+  "      </arg>"
   "    </method>"
   "    <method name='GimmeStdout'/>"
   "    <signal name='VelocityChanged'>"
+  "      <annotation name='org.gtk.GDBus.Annotation' value='Onsignal'/>"
   "      <arg type='d' name='speed_in_mph'/>"
-  "      <arg type='s' name='speed_as_string'/>"
+  "      <arg type='s' name='speed_as_string'>"
+  "        <annotation name='org.gtk.GDBus.Annotation' value='OnArg_NonFirst'/>"
+  "      </arg>"
   "    </signal>"
-  "    <property type='s' name='FluxCapicitorName' access='read'/>"
+  "    <property type='s' name='FluxCapicitorName' access='read'>"
+  "      <annotation name='org.gtk.GDBus.Annotation' value='OnProperty'>"
+  "        <annotation name='org.gtk.GDBus.Annotation' value='OnAnnotation_YesThisIsCrazy'/>"
+  "      </annotation>"
+  "    </property>"
   "    <property type='s' name='Title' access='readwrite'/>"
   "    <property type='s' name='ReadingAlwaysThrowsError' access='read'/>"
   "    <property type='s' name='WritingAlwaysThrowsError' access='readwrite'/>"



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