From 9695c23d4c29e79afbe14e3584b6c42e98e8f0d9 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Wed, 12 May 2010 22:09:18 -0400 Subject: [PATCH] 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 ce5e5dba1..96a66ca80 100644 --- a/gio/gdbus-tool.c +++ b/gio/gdbus-tool.c @@ -881,6 +881,20 @@ 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, @@ -888,6 +902,14 @@ dump_arg (const GDBusArgInfo *o, 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 eb0d6e459..a943f6555 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[] = "" " " + " " + " " " " + " " " " " " " " " " - " " + " " + " " + " " " " " " " " + " " " " - " " + " " + " " + " " " " - " " + " " + " " + " " + " " + " " " " " " " "