2011-11-15 05:43:51

by Lucas De Marchi

[permalink] [raw]
Subject: [RFC 0/2] gdbus: Add names to arguments

Hey, this is an RFC regarding the following issue: people doing clients for
BlueZ/oFono/ConnMan would like to be able to see the argument names in the XML
generated by D-Bus introspection. It allows better code generated by codegen
tools.

First patch changes gdbus to allow the argument names to be added and the
second patch takes a random interface to show how it would like. The bad thing
is that all the interfaces would need to be changed to accomplish the goal of
having the names in introspection.

Below a piece of the XML generated by introspection before this patch:

<interface name="org.bluez.Manager">
<method name="GetProperties">
<arg type="a{sv}" direction="out"/>
</method>
<method name="DefaultAdapter">
<arg type="o" direction="out"/>
</method>
<method name="FindAdapter">
<arg type="s" direction="in"/>
<arg type="o" direction="out"/>
</method>
<...>
</interface>

And after it:

<interface name="org.bluez.Manager">
<method name="GetProperties">
<arg type="a{sv}" direction="out"/>
</method>
<method name="DefaultAdapter">
<arg type="o" direction="out"/>
</method>
<method name="FindAdapter">
<arg name="pattern" type="s" direction="in"/>
<arg type="o" direction="out"/>
</method>
<...>
</interface>


Regards,
Lucas De Marchi

Lucas De Marchi (2):
gdbus: Add argument name to introspection xml
manager: add argument name

gdbus/gdbus.h | 1 +
gdbus/object.c | 37 ++++++++++++++++++++++++++-----------
src/manager.c | 3 ++-
3 files changed, 29 insertions(+), 12 deletions(-)

--
1.7.7.3



2011-11-15 05:43:53

by Lucas De Marchi

[permalink] [raw]
Subject: [RFC 2/2] manager: add argument name

---
src/manager.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index 464b0ca..2ea0d51 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -199,7 +199,8 @@ static DBusMessage *get_properties(DBusConnection *conn,
static GDBusMethodTable manager_methods[] = {
{ "GetProperties", "", "a{sv}",get_properties },
{ "DefaultAdapter", "", "o", default_adapter },
- { "FindAdapter", "s", "o", find_adapter },
+ { "FindAdapter", "s", "o", find_adapter,
+ .arg_names = "pattern" },
{ "ListAdapters", "", "ao", list_adapters,
G_DBUS_METHOD_FLAG_DEPRECATED},
{ }
--
1.7.7.3


2011-11-15 05:43:52

by Lucas De Marchi

[permalink] [raw]
Subject: [RFC 1/2] gdbus: Add argument name to introspection xml

---
gdbus/gdbus.h | 1 +
gdbus/object.c | 37 ++++++++++++++++++++++++++-----------
2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index a0583e6..dcd6c1e 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -89,6 +89,7 @@ typedef struct {
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
+ const char *arg_names;
} GDBusMethodTable;

typedef struct {
diff --git a/gdbus/object.c b/gdbus/object.c
index 8bc12f5..d7108d6 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -60,11 +60,15 @@ struct security_data {
};

static void print_arguments(GString *gstr, const char *sig,
- const char *direction)
+ const char *arg_names, const char *direction)
{
- int i;
+ int i, j;
+ gchar **names;
+
+ if (arg_names != NULL)
+ names = g_strsplit(arg_names, ",", 0);

- for (i = 0; sig[i]; i++) {
+ for (j = 0, i = 0; sig[i]; i++) {
char type[32];
int struct_level, dict_level;
unsigned int len;
@@ -107,16 +111,26 @@ static void print_arguments(GString *gstr, const char *sig,
break;
}

+ if (arg_names != NULL && names[j] != NULL) {
+ g_string_append_printf(gstr,
+ "\t\t\t<arg name=\"%s\" type=\"%s\"",
+ names[j], type);
+ j++;
+ } else
+ g_string_append_printf(gstr,
+ "\t\t\t<arg type=\"%s\"",
+ type);

if (direction)
g_string_append_printf(gstr,
- "\t\t\t<arg type=\"%s\" direction=\"%s\"/>\n",
- type, direction);
+ " direction=\"%s\"/>\n",
+ direction);
else
- g_string_append_printf(gstr,
- "\t\t\t<arg type=\"%s\"/>\n",
- type);
+ g_string_append_printf(gstr, "/>\n");
}
+
+ if (arg_names != NULL)
+ g_strfreev(names);
}

static void generate_interface_xml(GString *gstr, struct interface_data *iface)
@@ -131,8 +145,9 @@ static void generate_interface_xml(GString *gstr, struct interface_data *iface)
else {
g_string_append_printf(gstr, "\t\t<method name=\"%s\">\n",
method->name);
- print_arguments(gstr, method->signature, "in");
- print_arguments(gstr, method->reply, "out");
+ print_arguments(gstr, method->signature,
+ method->arg_names, "in");
+ print_arguments(gstr, method->reply, NULL, "out");
g_string_append_printf(gstr, "\t\t</method>\n");
}
}
@@ -144,7 +159,7 @@ static void generate_interface_xml(GString *gstr, struct interface_data *iface)
else {
g_string_append_printf(gstr, "\t\t<signal name=\"%s\">\n",
signal->name);
- print_arguments(gstr, signal->signature, NULL);
+ print_arguments(gstr, signal->signature, NULL, NULL);
g_string_append_printf(gstr, "\t\t</signal>\n");
}
}
--
1.7.7.3