Subject: [PATCH 00/11] gdbus: Better D-Bus introspection

Introspection patches to neard

Henrique Dante de Almeida (4):
Constify GDBus method tables
Constify GDBus signal tables
Convert GDBus methods and signals to use macro helpers
Do not set signature and reply in GDBus tables

Lucas De Marchi (7):
gdbus: add argument info to methods and signals
gdbus: add and use helpers for table declarations
gdbus: use GDBusArgInfo to generate introspection
gdbus: loop over args to check message signature
gdbus: remove signature and reply from tables
gdbus: add Deprecated annotation in introspection
gdbus: add Method.NoReply annotation in introspection

gdbus/gdbus.h | 47 +++++++++++++++++++-
gdbus/object.c | 132 +++++++++++++++++++++++++++-----------------------------
src/adapter.c | 23 ++++++----
src/device.c | 19 +++++---
src/manager.c | 19 +++++---
src/ndef.c | 6 ++-
src/tag.c | 18 +++++---
7 files changed, 163 insertions(+), 101 deletions(-)

--
1.7.9.5



2012-05-23 13:28:19

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 00/11] gdbus: Better D-Bus introspection

Hi Henrique,

> Introspection patches to neard
>
> Henrique Dante de Almeida (4):
> Constify GDBus method tables
> Constify GDBus signal tables
> Convert GDBus methods and signals to use macro helpers
> Do not set signature and reply in GDBus tables
>
> Lucas De Marchi (7):
> gdbus: add argument info to methods and signals
> gdbus: add and use helpers for table declarations
> gdbus: use GDBusArgInfo to generate introspection
> gdbus: loop over args to check message signature
> gdbus: remove signature and reply from tables
> gdbus: add Deprecated annotation in introspection
> gdbus: add Method.NoReply annotation in introspection
>
> gdbus/gdbus.h | 47 +++++++++++++++++++-
> gdbus/object.c | 132 +++++++++++++++++++++++++++-----------------------------
> src/adapter.c | 23 ++++++----
> src/device.c | 19 +++++---
> src/manager.c | 19 +++++---
> src/ndef.c | 6 ++-
> src/tag.c | 18 +++++---
> 7 files changed, 163 insertions(+), 101 deletions(-)

wrong mailing list, but I applied all 11 patches now.

Regards

Marcel



Subject: [PATCH 02/11] Constify GDBus signal tables

Constify signal tables with the following command:

find . -name '*.[ch]' -exec \
sed -i 's/\(GDBusSignalTable .* =\)/const \1/g' {} \;
---
src/adapter.c | 2 +-
src/device.c | 2 +-
src/manager.c | 2 +-
src/tag.c | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index ca662dc..8574d52 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -470,7 +470,7 @@ static const GDBusMethodTable adapter_methods[] = {
{ },
};

-static GDBusSignalTable adapter_signals[] = {
+static const GDBusSignalTable adapter_signals[] = {
{ "PropertyChanged", "sv" },
{ "TagFound", "o" },
{ "TagLost", "o" },
diff --git a/src/device.c b/src/device.c
index b550c9b..b53e24d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -240,7 +240,7 @@ static const GDBusMethodTable device_methods[] = {
{ },
};

-static GDBusSignalTable device_signals[] = {
+static const GDBusSignalTable device_signals[] = {
{ "PropertyChanged", "sv" },
{ }
};
diff --git a/src/manager.c b/src/manager.c
index 4aff3a7..241c472 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -139,7 +139,7 @@ static const GDBusMethodTable manager_methods[] = {
{ },
};

-static GDBusSignalTable manager_signals[] = {
+static const GDBusSignalTable manager_signals[] = {
{ "PropertyChanged", "sv" },
{ "AdapterAdded", "o" },
{ "AdapterRemoved", "o" },
diff --git a/src/tag.c b/src/tag.c
index 1d85814..d660749 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -329,7 +329,7 @@ static const GDBusMethodTable tag_methods[] = {
{ },
};

-static GDBusSignalTable tag_signals[] = {
+static const GDBusSignalTable tag_signals[] = {
{ "PropertyChanged", "sv" },
{ }
};
--
1.7.9.5


Subject: [PATCH 10/11] gdbus: add Deprecated annotation in introspection

From: Lucas De Marchi <[email protected]>

---
gdbus/object.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index fcdd6ec..95947f3 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -82,7 +82,11 @@ static void generate_interface_xml(GString *gstr, struct interface_data *iface)
const GDBusSignalTable *signal;

for (method = iface->methods; method && method->name; method++) {
- if (!(method->in_args && method->in_args->name) &&
+ gboolean deprecated = method->flags &
+ G_DBUS_METHOD_FLAG_DEPRECATED;
+
+ if (!deprecated &&
+ !(method->in_args && method->in_args->name) &&
!(method->out_args && method->out_args->name))
g_string_append_printf(gstr, "\t\t<method name=\"%s\"/>\n",
method->name);
@@ -91,18 +95,29 @@ static void generate_interface_xml(GString *gstr, struct interface_data *iface)
method->name);
print_arguments(gstr, method->in_args, "in");
print_arguments(gstr, method->out_args, "out");
+
+ if (deprecated)
+ g_string_append_printf(gstr, "\t\t\t<annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n");
+
g_string_append_printf(gstr, "\t\t</method>\n");
}
}

for (signal = iface->signals; signal && signal->name; signal++) {
- if (!(signal->args && signal->args->name))
+ gboolean deprecated = signal->flags &
+ G_DBUS_SIGNAL_FLAG_DEPRECATED;
+
+ if (!deprecated && !(signal->args && signal->args->name))
g_string_append_printf(gstr, "\t\t<signal name=\"%s\"/>\n",
signal->name);
else {
g_string_append_printf(gstr, "\t\t<signal name=\"%s\">\n",
signal->name);
print_arguments(gstr, signal->args, NULL);
+
+ if (deprecated)
+ g_string_append_printf(gstr, "\t\t\t<annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n");
+
g_string_append_printf(gstr, "\t\t</signal>\n");
}
}
--
1.7.9.5


Subject: [PATCH 11/11] gdbus: add Method.NoReply annotation in introspection

From: Lucas De Marchi <[email protected]>

---
gdbus/object.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 95947f3..dacbe58 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -84,8 +84,10 @@ static void generate_interface_xml(GString *gstr, struct interface_data *iface)
for (method = iface->methods; method && method->name; method++) {
gboolean deprecated = method->flags &
G_DBUS_METHOD_FLAG_DEPRECATED;
+ gboolean noreply = method->flags &
+ G_DBUS_METHOD_FLAG_NOREPLY;

- if (!deprecated &&
+ if (!deprecated && !noreply &&
!(method->in_args && method->in_args->name) &&
!(method->out_args && method->out_args->name))
g_string_append_printf(gstr, "\t\t<method name=\"%s\"/>\n",
@@ -99,6 +101,9 @@ static void generate_interface_xml(GString *gstr, struct interface_data *iface)
if (deprecated)
g_string_append_printf(gstr, "\t\t\t<annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n");

+ if (noreply)
+ g_string_append_printf(gstr, "\t\t\t<annotation name=\"org.freedesktop.DBus.Method.NoReply\" value=\"true\"/>\n");
+
g_string_append_printf(gstr, "\t\t</method>\n");
}
}
--
1.7.9.5


Subject: [PATCH 09/11] gdbus: remove signature and reply from tables

From: Lucas De Marchi <[email protected]>

---
gdbus/gdbus.h | 51 ---------------------------------------------------
gdbus/object.c | 2 +-
2 files changed, 1 insertion(+), 52 deletions(-)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index 8354633..e2e160d 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -89,8 +89,6 @@ typedef struct {

typedef struct {
const char *name;
- const char *signature;
- const char *reply;
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
@@ -100,7 +98,6 @@ typedef struct {

typedef struct {
const char *name;
- const char *signature;
GDBusSignalFlags flags;
const GDBusArgInfo *args;
} GDBusSignalTable;
@@ -120,54 +117,6 @@ typedef struct {

#define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }

-#define _GDBUS_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
- .name = _name, \
- .signature = _signature, \
- .reply = _reply, \
- .in_args = _in_args, \
- .out_args = _out_args, \
- .function = _function
-
-#define _GDBUS_ASYNC_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
- .name = _name, \
- .signature = _signature, \
- .reply = _reply, \
- .in_args = _in_args, \
- .out_args = _out_args, \
- .function = _function, \
- .flags = G_DBUS_METHOD_FLAG_ASYNC
-
-#define _GDBUS_DEPRECATED_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
- .name = _name, \
- .signature = _signature, \
- .reply = _reply, \
- .in_args = _in_args, \
- .out_args = _out_args, \
- .function = _function, \
- .flags = G_DBUS_METHOD_FLAG_DEPRECATED
-
-#define _GDBUS_DEPRECATED_ASYNC_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
- .name = _name, \
- .signature = _signature, \
- .reply = _reply, \
- .in_args = _in_args, \
- .out_args = _out_args, \
- .function = _function, \
- .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
-
-#define _GDBUS_SIGNAL(_name, _signature, _args) \
- .name = _name, \
- .signature = _signature, \
- .args = _args
-
-#define _GDBUS_DEPRECATED_SIGNAL(_name, _signature, _args) \
- .name = _name, \
- .signature = _signature, \
- .args = _args, \
- .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
-
-/* Helpers with no signature and reply */
-
#define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
.name = _name, \
.in_args = _in_args, \
diff --git a/gdbus/object.c b/gdbus/object.c
index b187bb5..fcdd6ec 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -471,7 +471,7 @@ done:
}

static const GDBusMethodTable introspect_methods[] = {
- { _GDBUS_METHOD("Introspect", "", "s", NULL,
+ { GDBUS_METHOD("Introspect", NULL,
GDBUS_ARGS({ "xml", "s" }), introspect) },
{ }
};
--
1.7.9.5


Subject: [PATCH 07/11] gdbus: loop over args to check message signature

From: Lucas De Marchi <[email protected]>

---
gdbus/object.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 3ac6a0b..b187bb5 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -374,6 +374,27 @@ static struct interface_data *find_interface(GSList *interfaces,
return NULL;
}

+static gboolean g_dbus_args_have_signature(const GDBusArgInfo *args,
+ DBusMessage *message)
+{
+ const char *sig = dbus_message_get_signature(message);
+ const char *p = NULL;
+
+ for (; args && args->signature && *sig; args++) {
+ p = args->signature;
+
+ for (; *sig && *p; sig++, p++) {
+ if (*p != *sig)
+ return FALSE;
+ }
+ }
+
+ if (*sig || (p && *p) || (args && args->signature))
+ return FALSE;
+
+ return TRUE;
+}
+
static DBusHandlerResult generic_message(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -394,8 +415,8 @@ static DBusHandlerResult generic_message(DBusConnection *connection,
method->name) == FALSE)
continue;

- if (dbus_message_has_signature(message,
- method->signature) == FALSE)
+ if (g_dbus_args_have_signature(method->in_args,
+ message) == FALSE)
continue;

if (check_privilege(connection, message, method,
@@ -552,7 +573,7 @@ static void object_path_unref(DBusConnection *connection, const char *path)

static gboolean check_signal(DBusConnection *conn, const char *path,
const char *interface, const char *name,
- const char **args)
+ const GDBusArgInfo **args)
{
struct generic_data *data = NULL;
struct interface_data *iface;
@@ -575,7 +596,7 @@ static gboolean check_signal(DBusConnection *conn, const char *path,

for (signal = iface->signals; signal && signal->name; signal++) {
if (!strcmp(signal->name, name)) {
- *args = signal->signature;
+ *args = signal->args;
break;
}
}
@@ -597,7 +618,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
{
DBusMessage *signal;
dbus_bool_t ret;
- const char *signature, *args;
+ const GDBusArgInfo *args;

if (!check_signal(conn, path, interface, name, &args))
return FALSE;
@@ -612,8 +633,7 @@ static dbus_bool_t emit_signal_valist(DBusConnection *conn,
if (!ret)
goto fail;

- signature = dbus_message_get_signature(signal);
- if (strcmp(args, signature) != 0) {
+ if (g_dbus_args_have_signature(args, signal) == FALSE) {
error("%s.%s: expected signature'%s' but got '%s'",
interface, name, args, signature);
ret = FALSE;
--
1.7.9.5


Subject: [PATCH 08/11] Do not set signature and reply in GDBus tables

Use GDBUS_* macros, so signature and reply fields are not set in each
method/signal.
---
src/adapter.c | 14 +++++++-------
src/device.c | 8 ++++----
src/manager.c | 12 +++++-------
src/ndef.c | 2 +-
src/tag.c | 11 +++++------
5 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 5cbafa1..bea2fcf 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -463,22 +463,22 @@ static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx,
}

static const GDBusMethodTable adapter_methods[] = {
- { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ { GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({"properties", "a{sv}"}),
get_properties) },
- { _GDBUS_METHOD("SetProperty", "sv", "",
+ { GDBUS_METHOD("SetProperty",
GDBUS_ARGS({"name", "s"}, {"value", "v"}),
NULL, set_property) },
- { _GDBUS_METHOD("StartPoll", "", "", NULL, NULL, start_poll) },
- { _GDBUS_METHOD("StopPoll", "", "", NULL, NULL, stop_poll) },
+ { GDBUS_METHOD("StartPoll", NULL, NULL, start_poll) },
+ { GDBUS_METHOD("StopPoll", NULL, NULL, stop_poll) },
{ },
};

static const GDBusSignalTable adapter_signals[] = {
- { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ { GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
- { _GDBUS_SIGNAL("TagFound", "o", GDBUS_ARGS({"address", "o"})) },
- { _GDBUS_SIGNAL("TagLost", "o", GDBUS_ARGS({"address", "o"})) },
+ { GDBUS_SIGNAL("TagFound", GDBUS_ARGS({"address", "o"})) },
+ { GDBUS_SIGNAL("TagLost", GDBUS_ARGS({"address", "o"})) },
{ }
};

diff --git a/src/device.c b/src/device.c
index 2b1527d..a873fb1 100644
--- a/src/device.c
+++ b/src/device.c
@@ -234,20 +234,20 @@ error:
}

static const GDBusMethodTable device_methods[] = {
- { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ { GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({"properties", "a{sv}"}),
get_properties) },
- { _GDBUS_METHOD("SetProperty", "sv", "",
+ { GDBUS_METHOD("SetProperty",
GDBUS_ARGS({"name", "s"}, {"value", "v"}),
NULL, set_property) },
- { _GDBUS_METHOD("Push", "a{sv}", "",
+ { GDBUS_METHOD("Push",
GDBUS_ARGS({"attributes", "a{sv}"}),
NULL, push_ndef) },
{ },
};

static const GDBusSignalTable device_signals[] = {
- { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ { GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
{ }
};
diff --git a/src/manager.c b/src/manager.c
index f1ac5ea..cb62260 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -134,22 +134,20 @@ void __near_manager_adapter_remove(uint32_t idx)
}

static const GDBusMethodTable manager_methods[] = {
- { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ { GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({"properties", "a{sv}"}),
get_properties) },
- { _GDBUS_METHOD("SetProperty", "sv", "",
+ { GDBUS_METHOD("SetProperty",
GDBUS_ARGS({"name", "s"}, {"value", "v"}),
NULL, set_property) },
{ },
};

static const GDBusSignalTable manager_signals[] = {
- { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ { GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
- { _GDBUS_SIGNAL("AdapterAdded", "o",
- GDBUS_ARGS({"adapter", "o" })) },
- { _GDBUS_SIGNAL("AdapterRemoved", "o",
- GDBUS_ARGS({"adapter", "o" })) },
+ { GDBUS_SIGNAL("AdapterAdded", GDBUS_ARGS({"adapter", "o" })) },
+ { GDBUS_SIGNAL("AdapterRemoved", GDBUS_ARGS({"adapter", "o" })) },
{ }
};

diff --git a/src/ndef.c b/src/ndef.c
index a23c508..9a0a4cf 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -419,7 +419,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
}

static const GDBusMethodTable record_methods[] = {
- { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ { GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({"properties", "a{sv}"}),
get_properties) },
{ },
diff --git a/src/tag.c b/src/tag.c
index f3ab092..6a21d39 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -323,20 +323,19 @@ fail:
}

static const GDBusMethodTable tag_methods[] = {
- { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ { GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({"properties", "a{sv}"}),
get_properties) },
- { _GDBUS_METHOD("SetProperty", "sv", "",
+ { GDBUS_METHOD("SetProperty",
GDBUS_ARGS({"name", "s"}, {"value", "v"}),
NULL, set_property) },
- { _GDBUS_METHOD("Write", "a{sv}", "",
- GDBUS_ARGS({"attributes", "a{sv}"}),
- NULL, write_ndef) },
+ { GDBUS_METHOD("Write", GDBUS_ARGS({"attributes", "a{sv}"}),
+ NULL, write_ndef) },
{ },
};

static const GDBusSignalTable tag_signals[] = {
- { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ { GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
{ }
};
--
1.7.9.5


Subject: [PATCH 06/11] gdbus: use GDBusArgInfo to generate introspection

From: Lucas De Marchi <[email protected]>

By using GDBusArgInfo in methods and signals, the introspection
generation is much simpler and we can add each argument name.
---
gdbus/object.c | 75 +++++++++++---------------------------------------------
1 file changed, 14 insertions(+), 61 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 2ddc574..3ac6a0b 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -59,68 +59,20 @@ struct security_data {
void *iface_user_data;
};

-static void print_arguments(GString *gstr, const char *sig,
+static void print_arguments(GString *gstr, const GDBusArgInfo *args,
const char *direction)
{
- int i;
-
- for (i = 0; sig[i]; i++) {
- char type[32];
- int struct_level, dict_level;
- unsigned int len;
- gboolean complete;
-
- complete = FALSE;
- struct_level = dict_level = 0;
-
- /* Gather enough data to have a single complete type */
- for (len = 0; len < (sizeof(type) - 1) && sig[i]; len++, i++) {
- switch (sig[i]) {
- case '(':
- struct_level++;
- break;
- case ')':
- struct_level--;
- if (struct_level <= 0 && dict_level <= 0)
- complete = TRUE;
- break;
- case '{':
- dict_level++;
- break;
- case '}':
- dict_level--;
- if (struct_level <= 0 && dict_level <= 0)
- complete = TRUE;
- break;
- case 'a':
- break;
- default:
- if (struct_level <= 0 && dict_level <= 0)
- complete = TRUE;
- break;
- }
-
- type[len] = sig[i];
-
- if (complete)
- break;
- }
-
- type[len + 1] = '\0';
-
- if (!complete) {
- error("Unexpected signature: %s", sig);
- return;
- }
+ for (; args && args->name; args++) {
+ g_string_append_printf(gstr,
+ "\t\t\t<arg name=\"%s\" type=\"%s\"",
+ args->name, args->signature);

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");
+
}
}

@@ -130,26 +82,27 @@ static void generate_interface_xml(GString *gstr, struct interface_data *iface)
const GDBusSignalTable *signal;

for (method = iface->methods; method && method->name; method++) {
- if (!strlen(method->signature) && !strlen(method->reply))
+ if (!(method->in_args && method->in_args->name) &&
+ !(method->out_args && method->out_args->name))
g_string_append_printf(gstr, "\t\t<method name=\"%s\"/>\n",
method->name);
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->in_args, "in");
+ print_arguments(gstr, method->out_args, "out");
g_string_append_printf(gstr, "\t\t</method>\n");
}
}

for (signal = iface->signals; signal && signal->name; signal++) {
- if (!strlen(signal->signature))
+ if (!(signal->args && signal->args->name))
g_string_append_printf(gstr, "\t\t<signal name=\"%s\"/>\n",
signal->name);
else {
g_string_append_printf(gstr, "\t\t<signal name=\"%s\">\n",
signal->name);
- print_arguments(gstr, signal->signature, NULL);
+ print_arguments(gstr, signal->args, NULL);
g_string_append_printf(gstr, "\t\t</signal>\n");
}
}
--
1.7.9.5


Subject: [PATCH 05/11] Convert GDBus methods and signals to use macro helpers

With these macro helpers we can separate in/out arguments and use their
own vector.
---
src/adapter.c | 19 ++++++++++++-------
src/device.c | 15 +++++++++++----
src/manager.c | 17 ++++++++++++-----
src/ndef.c | 4 +++-
src/tag.c | 15 +++++++++++----
5 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8574d52..5cbafa1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -463,17 +463,22 @@ static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx,
}

static const GDBusMethodTable adapter_methods[] = {
- { "GetProperties", "", "a{sv}", get_properties },
- { "SetProperty", "sv", "", set_property },
- { "StartPoll", "", "", start_poll },
- { "StopPoll", "", "", stop_poll },
+ { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ NULL, GDBUS_ARGS({"properties", "a{sv}"}),
+ get_properties) },
+ { _GDBUS_METHOD("SetProperty", "sv", "",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"}),
+ NULL, set_property) },
+ { _GDBUS_METHOD("StartPoll", "", "", NULL, NULL, start_poll) },
+ { _GDBUS_METHOD("StopPoll", "", "", NULL, NULL, stop_poll) },
{ },
};

static const GDBusSignalTable adapter_signals[] = {
- { "PropertyChanged", "sv" },
- { "TagFound", "o" },
- { "TagLost", "o" },
+ { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
+ { _GDBUS_SIGNAL("TagFound", "o", GDBUS_ARGS({"address", "o"})) },
+ { _GDBUS_SIGNAL("TagLost", "o", GDBUS_ARGS({"address", "o"})) },
{ }
};

diff --git a/src/device.c b/src/device.c
index b53e24d..2b1527d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -234,14 +234,21 @@ error:
}

static const GDBusMethodTable device_methods[] = {
- { "GetProperties", "", "a{sv}", get_properties },
- { "SetProperty", "sv", "", set_property },
- { "Push", "a{sv}", "", push_ndef },
+ { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ NULL, GDBUS_ARGS({"properties", "a{sv}"}),
+ get_properties) },
+ { _GDBUS_METHOD("SetProperty", "sv", "",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"}),
+ NULL, set_property) },
+ { _GDBUS_METHOD("Push", "a{sv}", "",
+ GDBUS_ARGS({"attributes", "a{sv}"}),
+ NULL, push_ndef) },
{ },
};

static const GDBusSignalTable device_signals[] = {
- { "PropertyChanged", "sv" },
+ { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
{ }
};

diff --git a/src/manager.c b/src/manager.c
index 241c472..f1ac5ea 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -134,15 +134,22 @@ void __near_manager_adapter_remove(uint32_t idx)
}

static const GDBusMethodTable manager_methods[] = {
- { "GetProperties", "", "a{sv}", get_properties },
- { "SetProperty", "sv", "", set_property },
+ { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ NULL, GDBUS_ARGS({"properties", "a{sv}"}),
+ get_properties) },
+ { _GDBUS_METHOD("SetProperty", "sv", "",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"}),
+ NULL, set_property) },
{ },
};

static const GDBusSignalTable manager_signals[] = {
- { "PropertyChanged", "sv" },
- { "AdapterAdded", "o" },
- { "AdapterRemoved", "o" },
+ { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
+ { _GDBUS_SIGNAL("AdapterAdded", "o",
+ GDBUS_ARGS({"adapter", "o" })) },
+ { _GDBUS_SIGNAL("AdapterRemoved", "o",
+ GDBUS_ARGS({"adapter", "o" })) },
{ }
};

diff --git a/src/ndef.c b/src/ndef.c
index 029941a..a23c508 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -419,7 +419,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
}

static const GDBusMethodTable record_methods[] = {
- { "GetProperties", "", "a{sv}", get_properties },
+ { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ NULL, GDBUS_ARGS({"properties", "a{sv}"}),
+ get_properties) },
{ },
};

diff --git a/src/tag.c b/src/tag.c
index d660749..f3ab092 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -323,14 +323,21 @@ fail:
}

static const GDBusMethodTable tag_methods[] = {
- { "GetProperties", "", "a{sv}", get_properties },
- { "SetProperty", "sv", "", set_property },
- { "Write", "a{sv}", "", write_ndef },
+ { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ NULL, GDBUS_ARGS({"properties", "a{sv}"}),
+ get_properties) },
+ { _GDBUS_METHOD("SetProperty", "sv", "",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"}),
+ NULL, set_property) },
+ { _GDBUS_METHOD("Write", "a{sv}", "",
+ GDBUS_ARGS({"attributes", "a{sv}"}),
+ NULL, write_ndef) },
{ },
};

static const GDBusSignalTable tag_signals[] = {
- { "PropertyChanged", "sv" },
+ { _GDBUS_SIGNAL("PropertyChanged", "sv",
+ GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
{ }
};

--
1.7.9.5


Subject: [PATCH 04/11] gdbus: add and use helpers for table declarations

From: Lucas De Marchi <[email protected]>

---
gdbus/gdbus.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
gdbus/object.c | 3 +-
2 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index e5e7938..8354633 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -118,6 +118,92 @@ typedef struct {
GDBusSecurityFunction function;
} GDBusSecurityTable;

+#define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
+
+#define _GDBUS_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
+ .name = _name, \
+ .signature = _signature, \
+ .reply = _reply, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function
+
+#define _GDBUS_ASYNC_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
+ .name = _name, \
+ .signature = _signature, \
+ .reply = _reply, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function, \
+ .flags = G_DBUS_METHOD_FLAG_ASYNC
+
+#define _GDBUS_DEPRECATED_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
+ .name = _name, \
+ .signature = _signature, \
+ .reply = _reply, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function, \
+ .flags = G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define _GDBUS_DEPRECATED_ASYNC_METHOD(_name, _signature, _reply, _in_args, _out_args, _function) \
+ .name = _name, \
+ .signature = _signature, \
+ .reply = _reply, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function, \
+ .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define _GDBUS_SIGNAL(_name, _signature, _args) \
+ .name = _name, \
+ .signature = _signature, \
+ .args = _args
+
+#define _GDBUS_DEPRECATED_SIGNAL(_name, _signature, _args) \
+ .name = _name, \
+ .signature = _signature, \
+ .args = _args, \
+ .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
+
+/* Helpers with no signature and reply */
+
+#define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
+ .name = _name, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function
+
+#define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+ .name = _name, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function, \
+ .flags = G_DBUS_METHOD_FLAG_ASYNC
+
+#define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
+ .name = _name, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function, \
+ .flags = G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+ .name = _name, \
+ .in_args = _in_args, \
+ .out_args = _out_args, \
+ .function = _function, \
+ .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_SIGNAL(_name, _args) \
+ .name = _name, \
+ .args = _args
+
+#define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
+ .name = _name, \
+ .args = _args, \
+ .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
+
gboolean g_dbus_register_interface(DBusConnection *connection,
const char *path, const char *name,
const GDBusMethodTable *methods,
diff --git a/gdbus/object.c b/gdbus/object.c
index 0ef6c80..2ddc574 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -497,7 +497,8 @@ done:
}

static const GDBusMethodTable introspect_methods[] = {
- { "Introspect", "", "s", introspect },
+ { _GDBUS_METHOD("Introspect", "", "s", NULL,
+ GDBUS_ARGS({ "xml", "s" }), introspect) },
{ }
};

--
1.7.9.5


Subject: [PATCH 03/11] gdbus: add argument info to methods and signals

From: Lucas De Marchi <[email protected]>

---
gdbus/gdbus.h | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index a0583e6..e5e7938 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -85,16 +85,24 @@ typedef enum {
typedef struct {
const char *name;
const char *signature;
+} GDBusArgInfo;
+
+typedef struct {
+ const char *name;
+ const char *signature;
const char *reply;
GDBusMethodFunction function;
GDBusMethodFlags flags;
unsigned int privilege;
+ const GDBusArgInfo *in_args;
+ const GDBusArgInfo *out_args;
} GDBusMethodTable;

typedef struct {
const char *name;
const char *signature;
GDBusSignalFlags flags;
+ const GDBusArgInfo *args;
} GDBusSignalTable;

typedef struct {
--
1.7.9.5


Subject: [PATCH 01/11] Constify GDBus method tables

Constify method tables with the following command:

find . -name '*.[ch]' -exec \
sed -i 's/\(GDBusMethodTable .* =\)/const \1/g' {} \;
---
src/adapter.c | 2 +-
src/device.c | 2 +-
src/manager.c | 2 +-
src/ndef.c | 2 +-
src/tag.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 3300968..ca662dc 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -462,7 +462,7 @@ static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx,
check_presence, adapter);
}

-static GDBusMethodTable adapter_methods[] = {
+static const GDBusMethodTable adapter_methods[] = {
{ "GetProperties", "", "a{sv}", get_properties },
{ "SetProperty", "sv", "", set_property },
{ "StartPoll", "", "", start_poll },
diff --git a/src/device.c b/src/device.c
index bb86d27..b550c9b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -233,7 +233,7 @@ error:
return __near_error_failed(msg, -err);
}

-static GDBusMethodTable device_methods[] = {
+static const GDBusMethodTable device_methods[] = {
{ "GetProperties", "", "a{sv}", get_properties },
{ "SetProperty", "sv", "", set_property },
{ "Push", "a{sv}", "", push_ndef },
diff --git a/src/manager.c b/src/manager.c
index d5ea970..4aff3a7 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -133,7 +133,7 @@ void __near_manager_adapter_remove(uint32_t idx)
NULL);
}

-static GDBusMethodTable manager_methods[] = {
+static const GDBusMethodTable manager_methods[] = {
{ "GetProperties", "", "a{sv}", get_properties },
{ "SetProperty", "sv", "", set_property },
{ },
diff --git a/src/ndef.c b/src/ndef.c
index 87d82ec..029941a 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -418,7 +418,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
return reply;
}

-static GDBusMethodTable record_methods[] = {
+static const GDBusMethodTable record_methods[] = {
{ "GetProperties", "", "a{sv}", get_properties },
{ },
};
diff --git a/src/tag.c b/src/tag.c
index d4de24f..1d85814 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -322,7 +322,7 @@ fail:
return __near_error_failed(msg, ENOMEM);
}

-static GDBusMethodTable tag_methods[] = {
+static const GDBusMethodTable tag_methods[] = {
{ "GetProperties", "", "a{sv}", get_properties },
{ "SetProperty", "sv", "", set_property },
{ "Write", "a{sv}", "", write_ndef },
--
1.7.9.5