mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-20 01:18:21 +01:00
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';
};
};
This commit is contained in:
@@ -881,6 +881,20 @@ handle_call (gint *argc,
|
|||||||
|
|
||||||
/* TODO: dump annotations */
|
/* 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
|
static void
|
||||||
dump_arg (const GDBusArgInfo *o,
|
dump_arg (const GDBusArgInfo *o,
|
||||||
guint indent,
|
guint indent,
|
||||||
@@ -888,6 +902,14 @@ dump_arg (const GDBusArgInfo *o,
|
|||||||
gboolean ignore_indent,
|
gboolean ignore_indent,
|
||||||
gboolean include_newline)
|
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",
|
g_print ("%*s%s%s %s%s",
|
||||||
ignore_indent ? 0 : indent, "",
|
ignore_indent ? 0 : indent, "",
|
||||||
direction,
|
direction,
|
||||||
@@ -917,6 +939,10 @@ dump_method (const GDBusMethodInfo *o,
|
|||||||
guint m;
|
guint m;
|
||||||
guint name_len;
|
guint name_len;
|
||||||
guint total_num_args;
|
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);
|
g_print ("%*s%s(", indent, "", o->name);
|
||||||
name_len = strlen (o->name);
|
name_len = strlen (o->name);
|
||||||
total_num_args = count_args (o->in_args) + count_args (o->out_args);
|
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 ignore_indent = (m == 0);
|
||||||
gboolean include_newline = (m != total_num_args - 1);
|
gboolean include_newline = (m != total_num_args - 1);
|
||||||
|
|
||||||
dump_arg (o->in_args[n],
|
dump_arg (o->in_args[n],
|
||||||
indent + name_len + 1,
|
indent + name_len + 1,
|
||||||
"in ",
|
"in ",
|
||||||
@@ -950,6 +977,10 @@ dump_signal (const GDBusSignalInfo *o,
|
|||||||
guint n;
|
guint n;
|
||||||
guint name_len;
|
guint name_len;
|
||||||
guint total_num_args;
|
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);
|
g_print ("%*s%s(", indent, "", o->name);
|
||||||
name_len = strlen (o->name);
|
name_len = strlen (o->name);
|
||||||
total_num_args = count_args (o->args);
|
total_num_args = count_args (o->args);
|
||||||
@@ -972,6 +1003,8 @@ dump_property (const GDBusPropertyInfo *o,
|
|||||||
GVariant *value)
|
GVariant *value)
|
||||||
{
|
{
|
||||||
const gchar *access;
|
const gchar *access;
|
||||||
|
guint n;
|
||||||
|
|
||||||
if (o->flags == G_DBUS_PROPERTY_INFO_FLAGS_READABLE)
|
if (o->flags == G_DBUS_PROPERTY_INFO_FLAGS_READABLE)
|
||||||
access = "readonly";
|
access = "readonly";
|
||||||
else if (o->flags == G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE)
|
else if (o->flags == G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE)
|
||||||
@@ -980,6 +1013,10 @@ dump_property (const GDBusPropertyInfo *o,
|
|||||||
access = "readwrite";
|
access = "readwrite";
|
||||||
else
|
else
|
||||||
g_assert_not_reached ();
|
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)
|
if (value != NULL)
|
||||||
{
|
{
|
||||||
gchar *s = g_variant_print (value, FALSE);
|
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);
|
g_print ("%*sinterface %s {\n", indent, "", o->name);
|
||||||
if (o->methods != NULL)
|
if (o->methods != NULL)
|
||||||
{
|
{
|
||||||
@@ -1117,6 +1157,9 @@ dump_node (GDBusConnection *c,
|
|||||||
if (o->path != NULL)
|
if (o->path != NULL)
|
||||||
object_path_to_print = o->path;
|
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)");
|
g_print ("%*snode %s", indent, "", object_path_to_print != NULL ? object_path_to_print : "(not set)");
|
||||||
if (o->interfaces != NULL || o->nodes != NULL)
|
if (o->interfaces != NULL || o->nodes != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,19 +14,31 @@ static GDBusNodeInfo *introspection_data = NULL;
|
|||||||
static const gchar introspection_xml[] =
|
static const gchar introspection_xml[] =
|
||||||
"<node>"
|
"<node>"
|
||||||
" <interface name='org.gtk.GDBus.TestInterface'>"
|
" <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'>"
|
" <method name='HelloWorld'>"
|
||||||
|
" <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>"
|
||||||
" <arg type='s' name='greeting' direction='in'/>"
|
" <arg type='s' name='greeting' direction='in'/>"
|
||||||
" <arg type='s' name='response' direction='out'/>"
|
" <arg type='s' name='response' direction='out'/>"
|
||||||
" </method>"
|
" </method>"
|
||||||
" <method name='EmitSignal'>"
|
" <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>"
|
||||||
" <method name='GimmeStdout'/>"
|
" <method name='GimmeStdout'/>"
|
||||||
" <signal name='VelocityChanged'>"
|
" <signal name='VelocityChanged'>"
|
||||||
|
" <annotation name='org.gtk.GDBus.Annotation' value='Onsignal'/>"
|
||||||
" <arg type='d' name='speed_in_mph'/>"
|
" <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>"
|
" </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='Title' access='readwrite'/>"
|
||||||
" <property type='s' name='ReadingAlwaysThrowsError' access='read'/>"
|
" <property type='s' name='ReadingAlwaysThrowsError' access='read'/>"
|
||||||
" <property type='s' name='WritingAlwaysThrowsError' access='readwrite'/>"
|
" <property type='s' name='WritingAlwaysThrowsError' access='readwrite'/>"
|
||||||
|
|||||||
Reference in New Issue
Block a user