2012-05-18 18:32:00

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 1/9] gdbus: remove extra const after constification

---
gdbus/object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index 88afd66..2ddc574 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -496,7 +496,7 @@ done:
g_free(parent_path);
}

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



2012-05-18 18:49:56

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH obexd 1/9] gdbus: remove extra const after constification

Hi Lucas,

> ---
> gdbus/object.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

all 9 patches have been applied.

Regards

Marcel



2012-05-18 18:32:08

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 9/9] gdbus: do not check signature twice

Message signature is already checked in generic_message(), so there's no
need to check again in the callback.
---
gdbus/object.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/gdbus/object.c b/gdbus/object.c
index dacbe58..2dd7c0e 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -174,11 +174,6 @@ static DBusMessage *introspect(DBusConnection *connection,
struct generic_data *data = user_data;
DBusMessage *reply;

- if (!dbus_message_has_signature(message, DBUS_TYPE_INVALID_AS_STRING)) {
- error("Unexpected signature to introspect call");
- return NULL;
- }
-
if (data->introspect == NULL)
generate_introspection_xml(connection, data,
dbus_message_get_path(message));
--
1.7.10.2


2012-05-18 18:32:07

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 8/9] gdbus: add Method.NoReply annotation in introspection

---
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.10.2


2012-05-18 18:32:06

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 7/9] gdbus: add Deprecated annotation in introspection

---
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.10.2


2012-05-18 18:32:05

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 6/9] gdbus: remove signature and reply from tables

---
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.10.2


2012-05-18 18:32:04

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 5/9] Do not set signature and reply in GDBus tables

Use GDBUS_* macros, so signature and reply fields are not set in each
method/signal.
---
client/ftp.c | 16 ++++++++--------
client/manager.c | 12 ++++++------
client/map.c | 6 +++---
client/pbap.c | 22 +++++++++++-----------
client/session.c | 6 +++---
client/sync.c | 6 +++---
client/transfer.c | 4 ++--
src/manager.c | 25 +++++++++++--------------
8 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/client/ftp.c b/client/ftp.c
index d08591a..8585566 100644
--- a/client/ftp.c
+++ b/client/ftp.c
@@ -436,25 +436,25 @@ static DBusMessage *delete(DBusConnection *connection,
}

static const GDBusMethodTable ftp_methods[] = {
- { _GDBUS_ASYNC_METHOD("ChangeFolder", "s", "",
+ { GDBUS_ASYNC_METHOD("ChangeFolder",
GDBUS_ARGS({ "folder", "s" }), NULL, change_folder) },
- { _GDBUS_ASYNC_METHOD("CreateFolder", "s", "",
+ { GDBUS_ASYNC_METHOD("CreateFolder",
GDBUS_ARGS({ "folder", "s" }), NULL, create_folder) },
- { _GDBUS_ASYNC_METHOD("ListFolder", "", "aa{sv}",
+ { GDBUS_ASYNC_METHOD("ListFolder",
NULL, GDBUS_ARGS({ "folderinfo", "aa{sv}" }), list_folder) },
- { _GDBUS_ASYNC_METHOD("GetFile", "ss", "",
+ { GDBUS_ASYNC_METHOD("GetFile",
GDBUS_ARGS({ "targetfile", "s" }, { "sourcefile", "s" }), NULL,
get_file) },
- { _GDBUS_ASYNC_METHOD("PutFile", "ss", "",
+ { GDBUS_ASYNC_METHOD("PutFile",
GDBUS_ARGS({ "sourcefile", "s" }, { "targetfile", "s" }), NULL,
put_file) },
- { _GDBUS_ASYNC_METHOD("CopyFile", "ss", "",
+ { GDBUS_ASYNC_METHOD("CopyFile",
GDBUS_ARGS({ "sourcefile", "s" }, { "targetfile", "s" }), NULL,
copy_file) },
- { _GDBUS_ASYNC_METHOD("MoveFile", "ss", "",
+ { GDBUS_ASYNC_METHOD("MoveFile",
GDBUS_ARGS({ "sourcefile", "s" }, { "targetfile", "s" }), NULL,
move_file) },
- { _GDBUS_ASYNC_METHOD("Delete", "s", "",
+ { GDBUS_ASYNC_METHOD("Delete",
GDBUS_ARGS({ "file", "s" }), NULL, delete) },
{ }
};
diff --git a/client/manager.c b/client/manager.c
index c2c5ec1..d896ba4 100644
--- a/client/manager.c
+++ b/client/manager.c
@@ -582,22 +582,22 @@ static DBusMessage *get_capabilities(DBusConnection *connection,
}

static const GDBusMethodTable client_methods[] = {
- { _GDBUS_ASYNC_METHOD("SendFiles", "a{sv}aso", "",
+ { GDBUS_ASYNC_METHOD("SendFiles",
GDBUS_ARGS({ "device", "a{sv}" }, { "files", "as" },
{ "agent", "o" }), NULL, send_files) },
- { _GDBUS_ASYNC_METHOD("PullBusinessCard", "a{sv}s", "",
+ { GDBUS_ASYNC_METHOD("PullBusinessCard",
GDBUS_ARGS({ "device", "a{sv}" }, { "file", "s" }), NULL,
pull_business_card) },
- { _GDBUS_ASYNC_METHOD("ExchangeBusinessCards", "a{sv}ss", "",
+ { GDBUS_ASYNC_METHOD("ExchangeBusinessCards",
GDBUS_ARGS({ "device", "a{sv}" },
{ "clientfile", "s" }, { "file", "s" }),
NULL, exchange_business_cards) },
- { _GDBUS_ASYNC_METHOD("CreateSession", "a{sv}", "o",
+ { GDBUS_ASYNC_METHOD("CreateSession",
GDBUS_ARGS({ "devices", "a{sv}" }),
GDBUS_ARGS({ "session", "o" }), create_session) },
- { _GDBUS_ASYNC_METHOD("RemoveSession", "o", "",
+ { GDBUS_ASYNC_METHOD("RemoveSession",
GDBUS_ARGS({ "session", "o" }), NULL, remove_session) },
- { _GDBUS_ASYNC_METHOD("GetCapabilities", "a{sv}", "s",
+ { GDBUS_ASYNC_METHOD("GetCapabilities",
GDBUS_ARGS({ "device", "a{sv}" }),
GDBUS_ARGS({ "capabilities", "s" }),
get_capabilities) },
diff --git a/client/map.c b/client/map.c
index fce7924..52b7c68 100644
--- a/client/map.c
+++ b/client/map.c
@@ -190,14 +190,14 @@ fail:
}

static const GDBusMethodTable map_methods[] = {
- { _GDBUS_ASYNC_METHOD("SetFolder", "s", "",
+ { GDBUS_ASYNC_METHOD("SetFolder",
GDBUS_ARGS({ "name", "string" }), NULL,
map_setpath) },
- { _GDBUS_ASYNC_METHOD("GetFolderListing", "a{ss}", "s",
+ { GDBUS_ASYNC_METHOD("GetFolderListing",
GDBUS_ARGS({ "dummy", "a{ss}" }),
GDBUS_ARGS({ "content", "s" }),
map_get_folder_listing) },
- { _GDBUS_ASYNC_METHOD("GetMessageListing", "sa{ss}", "s",
+ { GDBUS_ASYNC_METHOD("GetMessageListing",
GDBUS_ARGS({ "folder", "s" }, { "dummy", "a{ss}" }),
GDBUS_ARGS({ "messages", "s" }),
map_get_message_listing) },
diff --git a/client/pbap.c b/client/pbap.c
index 36b9a28..3a771ab 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -981,39 +981,39 @@ static DBusMessage *pbap_list_filter_fields(DBusConnection *connection,
}

static const GDBusMethodTable pbap_methods[] = {
- { _GDBUS_ASYNC_METHOD("Select", "ss", "",
+ { GDBUS_ASYNC_METHOD("Select",
GDBUS_ARGS({ "location", "s" }, { "phonebook", "s" }),
NULL, pbap_select) },
- { _GDBUS_ASYNC_METHOD("PullAll", "", "s",
+ { GDBUS_ASYNC_METHOD("PullAll",
NULL, GDBUS_ARGS({ "phonebook", "s" }),
pbap_pull_all) },
- { _GDBUS_ASYNC_METHOD("Pull", "s", "s",
+ { GDBUS_ASYNC_METHOD("Pull",
GDBUS_ARGS({ "phonebook_object", "s" }),
GDBUS_ARGS({ "vcard", "s" }),
pbap_pull_vcard) },
- { _GDBUS_ASYNC_METHOD("List", "", "a(ss)",
+ { GDBUS_ASYNC_METHOD("List",
NULL, GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
pbap_list) },
- { _GDBUS_ASYNC_METHOD("Search", "ss", "a(ss)",
+ { GDBUS_ASYNC_METHOD("Search",
GDBUS_ARGS({ "field", "s" }, { "value", "s" }),
GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
pbap_search) },
- { _GDBUS_ASYNC_METHOD("GetSize", "", "q",
+ { GDBUS_ASYNC_METHOD("GetSize",
NULL, GDBUS_ARGS({ "size", "q" }),
pbap_get_size) },
- { _GDBUS_METHOD("SetFormat", "s", "",
+ { GDBUS_METHOD("SetFormat",
GDBUS_ARGS({ "format", "s" }), NULL,
pbap_set_format) },
- { _GDBUS_METHOD("SetOrder", "s", "",
+ { GDBUS_METHOD("SetOrder",
GDBUS_ARGS({ "order", "s" }), NULL,
pbap_set_order) },
- { _GDBUS_METHOD("SetFilter", "as", "",
+ { GDBUS_METHOD("SetFilter",
GDBUS_ARGS({ "fields", "as" }), NULL,
pbap_set_filter) },
- { _GDBUS_METHOD("GetFilter", "", "as",
+ { GDBUS_METHOD("GetFilter",
NULL, GDBUS_ARGS({ "fields", "as" }),
pbap_get_filter) },
- { _GDBUS_METHOD("ListFilterFields", "", "as",
+ { GDBUS_METHOD("ListFilterFields",
NULL, GDBUS_ARGS({ "fields", "as" }),
pbap_list_filter_fields) },
{ }
diff --git a/client/session.c b/client/session.c
index d528452..d4ec55d 100644
--- a/client/session.c
+++ b/client/session.c
@@ -649,13 +649,13 @@ static DBusMessage *session_get_properties(DBusConnection *connection,
}

static const GDBusMethodTable session_methods[] = {
- { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ { GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
session_get_properties) },
- { _GDBUS_METHOD("AssignAgent", "o", "",
+ { GDBUS_METHOD("AssignAgent",
GDBUS_ARGS({ "agent", "o" }), NULL,
assign_agent) },
- { _GDBUS_METHOD("ReleaseAgent", "o", "",
+ { GDBUS_METHOD("ReleaseAgent",
GDBUS_ARGS({ "agent", "o" }), NULL,
release_agent) },
{ }
diff --git a/client/sync.c b/client/sync.c
index cd663fb..d56e066 100644
--- a/client/sync.c
+++ b/client/sync.c
@@ -193,13 +193,13 @@ fail:
}

static const GDBusMethodTable sync_methods[] = {
- { _GDBUS_METHOD("SetLocation", "s", "",
+ { GDBUS_METHOD("SetLocation",
GDBUS_ARGS({ "location", "s" }), NULL,
sync_setlocation) },
- { _GDBUS_ASYNC_METHOD("GetPhonebook", "", "s",
+ { GDBUS_ASYNC_METHOD("GetPhonebook",
NULL, GDBUS_ARGS({ "obj", "s" }),
sync_getphonebook) },
- { _GDBUS_ASYNC_METHOD("PutPhonebook", "s", "",
+ { GDBUS_ASYNC_METHOD("PutPhonebook",
GDBUS_ARGS({ "obj", "s" }), NULL,
sync_putphonebook) },
{ }
diff --git a/client/transfer.c b/client/transfer.c
index 1991c7d..3065c9c 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -206,10 +206,10 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
}

static const GDBusMethodTable obc_transfer_methods[] = {
- { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ { GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
obc_transfer_get_properties) },
- { _GDBUS_ASYNC_METHOD("Cancel", "", "", NULL, NULL,
+ { GDBUS_ASYNC_METHOD("Cancel", NULL, NULL,
obc_transfer_cancel) },
{ }
};
diff --git a/src/manager.c b/src/manager.c
index 9f38bf4..f649035 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -311,38 +311,35 @@ static DBusMessage *transfer_cancel(DBusConnection *connection,
}

static const GDBusMethodTable manager_methods[] = {
- { _GDBUS_METHOD("RegisterAgent", "o", "",
+ { GDBUS_METHOD("RegisterAgent",
GDBUS_ARGS({ "agent", "o" }), NULL, register_agent) },
- { _GDBUS_METHOD("UnregisterAgent", "o", "",
+ { GDBUS_METHOD("UnregisterAgent",
GDBUS_ARGS({ "agent", "o" }), NULL, unregister_agent) },
{ }
};

static const GDBusSignalTable manager_signals[] = {
- { _GDBUS_SIGNAL("TransferStarted", "o",
- GDBUS_ARGS({ "transfer", "o"})) },
- { _GDBUS_SIGNAL("TransferCompleted", "ob",
- GDBUS_ARGS({ "transfer", "o" }, { "success", "b" })) },
- { _GDBUS_SIGNAL("SessionCreated", "o",
- GDBUS_ARGS({ "session", "o" })) },
- { _GDBUS_SIGNAL("SessionRemoved", "o",
- GDBUS_ARGS({ "session", "o" })) },
+ { GDBUS_SIGNAL("TransferStarted", GDBUS_ARGS({ "transfer", "o"})) },
+ { GDBUS_SIGNAL("TransferCompleted", GDBUS_ARGS({ "transfer", "o" },
+ { "success", "b" })) },
+ { GDBUS_SIGNAL("SessionCreated", GDBUS_ARGS({ "session", "o" })) },
+ { GDBUS_SIGNAL("SessionRemoved", GDBUS_ARGS({ "session", "o" })) },
{ }
};

static const GDBusMethodTable transfer_methods[] = {
- { _GDBUS_METHOD("Cancel", "", "", NULL, NULL, transfer_cancel) },
+ { GDBUS_METHOD("Cancel", NULL, NULL, transfer_cancel) },
{ }
};

static const GDBusSignalTable transfer_signals[] = {
- { _GDBUS_SIGNAL("Progress", "ii",
- GDBUS_ARGS({ "total", "i" }, { "transferred", "i" })) },
+ { GDBUS_SIGNAL("Progress", GDBUS_ARGS({ "total", "i" },
+ { "transferred", "i" })) },
{ }
};

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


2012-05-18 18:32:03

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 4/9] gdbus: loop over args to check message signature

---
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.10.2


2012-05-18 18:32:01

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 2/9] Convert GDBus methods to use macro helpers

With these macro helpers we can separate in/out arguments and use their
own vector.
---
client/ftp.c | 36 ++++++++++++++++++++----------------
client/manager.c | 31 +++++++++++++++++++------------
client/map.c | 17 +++++++++++------
client/pbap.c | 52 +++++++++++++++++++++++++++++++++++-----------------
client/session.c | 12 +++++++++---
client/sync.c | 16 ++++++++++------
client/transfer.c | 7 +++++--
src/manager.c | 27 ++++++++++++++++++---------
8 files changed, 127 insertions(+), 71 deletions(-)

diff --git a/client/ftp.c b/client/ftp.c
index 40c85b2..d08591a 100644
--- a/client/ftp.c
+++ b/client/ftp.c
@@ -436,22 +436,26 @@ static DBusMessage *delete(DBusConnection *connection,
}

static const GDBusMethodTable ftp_methods[] = {
- { "ChangeFolder", "s", "", change_folder,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "CreateFolder", "s", "", create_folder,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "ListFolder", "", "aa{sv}", list_folder,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "GetFile", "ss", "", get_file,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "PutFile", "ss", "", put_file,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "CopyFile", "ss", "", copy_file,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "MoveFile", "ss", "", move_file,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "Delete", "s", "", delete,
- G_DBUS_METHOD_FLAG_ASYNC },
+ { _GDBUS_ASYNC_METHOD("ChangeFolder", "s", "",
+ GDBUS_ARGS({ "folder", "s" }), NULL, change_folder) },
+ { _GDBUS_ASYNC_METHOD("CreateFolder", "s", "",
+ GDBUS_ARGS({ "folder", "s" }), NULL, create_folder) },
+ { _GDBUS_ASYNC_METHOD("ListFolder", "", "aa{sv}",
+ NULL, GDBUS_ARGS({ "folderinfo", "aa{sv}" }), list_folder) },
+ { _GDBUS_ASYNC_METHOD("GetFile", "ss", "",
+ GDBUS_ARGS({ "targetfile", "s" }, { "sourcefile", "s" }), NULL,
+ get_file) },
+ { _GDBUS_ASYNC_METHOD("PutFile", "ss", "",
+ GDBUS_ARGS({ "sourcefile", "s" }, { "targetfile", "s" }), NULL,
+ put_file) },
+ { _GDBUS_ASYNC_METHOD("CopyFile", "ss", "",
+ GDBUS_ARGS({ "sourcefile", "s" }, { "targetfile", "s" }), NULL,
+ copy_file) },
+ { _GDBUS_ASYNC_METHOD("MoveFile", "ss", "",
+ GDBUS_ARGS({ "sourcefile", "s" }, { "targetfile", "s" }), NULL,
+ move_file) },
+ { _GDBUS_ASYNC_METHOD("Delete", "s", "",
+ GDBUS_ARGS({ "file", "s" }), NULL, delete) },
{ }
};

diff --git a/client/manager.c b/client/manager.c
index 9f26cb0..c2c5ec1 100644
--- a/client/manager.c
+++ b/client/manager.c
@@ -582,18 +582,25 @@ static DBusMessage *get_capabilities(DBusConnection *connection,
}

static const GDBusMethodTable client_methods[] = {
- { "SendFiles", "a{sv}aso", "", send_files,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "PullBusinessCard", "a{sv}s", "", pull_business_card,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "ExchangeBusinessCards", "a{sv}ss", "", exchange_business_cards,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "CreateSession", "a{sv}", "o", create_session,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "RemoveSession", "o", "", remove_session,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "GetCapabilities", "a{sv}", "s", get_capabilities,
- G_DBUS_METHOD_FLAG_ASYNC },
+ { _GDBUS_ASYNC_METHOD("SendFiles", "a{sv}aso", "",
+ GDBUS_ARGS({ "device", "a{sv}" }, { "files", "as" },
+ { "agent", "o" }), NULL, send_files) },
+ { _GDBUS_ASYNC_METHOD("PullBusinessCard", "a{sv}s", "",
+ GDBUS_ARGS({ "device", "a{sv}" }, { "file", "s" }), NULL,
+ pull_business_card) },
+ { _GDBUS_ASYNC_METHOD("ExchangeBusinessCards", "a{sv}ss", "",
+ GDBUS_ARGS({ "device", "a{sv}" },
+ { "clientfile", "s" }, { "file", "s" }),
+ NULL, exchange_business_cards) },
+ { _GDBUS_ASYNC_METHOD("CreateSession", "a{sv}", "o",
+ GDBUS_ARGS({ "devices", "a{sv}" }),
+ GDBUS_ARGS({ "session", "o" }), create_session) },
+ { _GDBUS_ASYNC_METHOD("RemoveSession", "o", "",
+ GDBUS_ARGS({ "session", "o" }), NULL, remove_session) },
+ { _GDBUS_ASYNC_METHOD("GetCapabilities", "a{sv}", "s",
+ GDBUS_ARGS({ "device", "a{sv}" }),
+ GDBUS_ARGS({ "capabilities", "s" }),
+ get_capabilities) },
{ }
};

diff --git a/client/map.c b/client/map.c
index c4afe0e..fce7924 100644
--- a/client/map.c
+++ b/client/map.c
@@ -190,12 +190,17 @@ fail:
}

static const GDBusMethodTable map_methods[] = {
- { "SetFolder", "s", "", map_setpath,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "GetFolderListing", "a{ss}", "s", map_get_folder_listing,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "GetMessageListing", "sa{ss}", "s", map_get_message_listing,
- G_DBUS_METHOD_FLAG_ASYNC },
+ { _GDBUS_ASYNC_METHOD("SetFolder", "s", "",
+ GDBUS_ARGS({ "name", "string" }), NULL,
+ map_setpath) },
+ { _GDBUS_ASYNC_METHOD("GetFolderListing", "a{ss}", "s",
+ GDBUS_ARGS({ "dummy", "a{ss}" }),
+ GDBUS_ARGS({ "content", "s" }),
+ map_get_folder_listing) },
+ { _GDBUS_ASYNC_METHOD("GetMessageListing", "sa{ss}", "s",
+ GDBUS_ARGS({ "folder", "s" }, { "dummy", "a{ss}" }),
+ GDBUS_ARGS({ "messages", "s" }),
+ map_get_message_listing) },
{ }
};

diff --git a/client/pbap.c b/client/pbap.c
index add9057..36b9a28 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -981,23 +981,41 @@ static DBusMessage *pbap_list_filter_fields(DBusConnection *connection,
}

static const GDBusMethodTable pbap_methods[] = {
- { "Select", "ss", "", pbap_select,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "PullAll", "", "s", pbap_pull_all,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "Pull", "s", "s", pbap_pull_vcard,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "List", "", "a(ss)", pbap_list,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "Search", "ss", "a(ss)", pbap_search,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "GetSize", "", "q", pbap_get_size,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "SetFormat", "s", "", pbap_set_format },
- { "SetOrder", "s", "", pbap_set_order },
- { "SetFilter", "as", "", pbap_set_filter },
- { "GetFilter", "", "as", pbap_get_filter },
- { "ListFilterFields", "", "as", pbap_list_filter_fields },
+ { _GDBUS_ASYNC_METHOD("Select", "ss", "",
+ GDBUS_ARGS({ "location", "s" }, { "phonebook", "s" }),
+ NULL, pbap_select) },
+ { _GDBUS_ASYNC_METHOD("PullAll", "", "s",
+ NULL, GDBUS_ARGS({ "phonebook", "s" }),
+ pbap_pull_all) },
+ { _GDBUS_ASYNC_METHOD("Pull", "s", "s",
+ GDBUS_ARGS({ "phonebook_object", "s" }),
+ GDBUS_ARGS({ "vcard", "s" }),
+ pbap_pull_vcard) },
+ { _GDBUS_ASYNC_METHOD("List", "", "a(ss)",
+ NULL, GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
+ pbap_list) },
+ { _GDBUS_ASYNC_METHOD("Search", "ss", "a(ss)",
+ GDBUS_ARGS({ "field", "s" }, { "value", "s" }),
+ GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
+ pbap_search) },
+ { _GDBUS_ASYNC_METHOD("GetSize", "", "q",
+ NULL, GDBUS_ARGS({ "size", "q" }),
+ pbap_get_size) },
+ { _GDBUS_METHOD("SetFormat", "s", "",
+ GDBUS_ARGS({ "format", "s" }), NULL,
+ pbap_set_format) },
+ { _GDBUS_METHOD("SetOrder", "s", "",
+ GDBUS_ARGS({ "order", "s" }), NULL,
+ pbap_set_order) },
+ { _GDBUS_METHOD("SetFilter", "as", "",
+ GDBUS_ARGS({ "fields", "as" }), NULL,
+ pbap_set_filter) },
+ { _GDBUS_METHOD("GetFilter", "", "as",
+ NULL, GDBUS_ARGS({ "fields", "as" }),
+ pbap_get_filter) },
+ { _GDBUS_METHOD("ListFilterFields", "", "as",
+ NULL, GDBUS_ARGS({ "fields", "as" }),
+ pbap_list_filter_fields) },
{ }
};

diff --git a/client/session.c b/client/session.c
index 5e49f23..d528452 100644
--- a/client/session.c
+++ b/client/session.c
@@ -649,9 +649,15 @@ static DBusMessage *session_get_properties(DBusConnection *connection,
}

static const GDBusMethodTable session_methods[] = {
- { "GetProperties", "", "a{sv}", session_get_properties },
- { "AssignAgent", "o", "", assign_agent },
- { "ReleaseAgent", "o", "", release_agent },
+ { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+ session_get_properties) },
+ { _GDBUS_METHOD("AssignAgent", "o", "",
+ GDBUS_ARGS({ "agent", "o" }), NULL,
+ assign_agent) },
+ { _GDBUS_METHOD("ReleaseAgent", "o", "",
+ GDBUS_ARGS({ "agent", "o" }), NULL,
+ release_agent) },
{ }
};

diff --git a/client/sync.c b/client/sync.c
index 1d71667..cd663fb 100644
--- a/client/sync.c
+++ b/client/sync.c
@@ -193,12 +193,16 @@ fail:
}

static const GDBusMethodTable sync_methods[] = {
- { "SetLocation", "s", "", sync_setlocation },
- { "GetPhonebook", "", "s", sync_getphonebook,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "PutPhonebook", "s", "", sync_putphonebook,
- G_DBUS_METHOD_FLAG_ASYNC },
- {}
+ { _GDBUS_METHOD("SetLocation", "s", "",
+ GDBUS_ARGS({ "location", "s" }), NULL,
+ sync_setlocation) },
+ { _GDBUS_ASYNC_METHOD("GetPhonebook", "", "s",
+ NULL, GDBUS_ARGS({ "obj", "s" }),
+ sync_getphonebook) },
+ { _GDBUS_ASYNC_METHOD("PutPhonebook", "s", "",
+ GDBUS_ARGS({ "obj", "s" }), NULL,
+ sync_putphonebook) },
+ { }
};

static void sync_free(void *data)
diff --git a/client/transfer.c b/client/transfer.c
index 932010c..1991c7d 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -206,8 +206,11 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
}

static const GDBusMethodTable obc_transfer_methods[] = {
- { "GetProperties", "", "a{sv}", obc_transfer_get_properties },
- { "Cancel", "", "", obc_transfer_cancel, G_DBUS_METHOD_FLAG_ASYNC },
+ { _GDBUS_METHOD("GetProperties", "", "a{sv}",
+ NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+ obc_transfer_get_properties) },
+ { _GDBUS_ASYNC_METHOD("Cancel", "", "", NULL, NULL,
+ obc_transfer_cancel) },
{ }
};

diff --git a/src/manager.c b/src/manager.c
index 46c8884..9f38bf4 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -311,31 +311,40 @@ static DBusMessage *transfer_cancel(DBusConnection *connection,
}

static const GDBusMethodTable manager_methods[] = {
- { "RegisterAgent", "o", "", register_agent },
- { "UnregisterAgent", "o", "", unregister_agent },
+ { _GDBUS_METHOD("RegisterAgent", "o", "",
+ GDBUS_ARGS({ "agent", "o" }), NULL, register_agent) },
+ { _GDBUS_METHOD("UnregisterAgent", "o", "",
+ GDBUS_ARGS({ "agent", "o" }), NULL, unregister_agent) },
{ }
};

static const GDBusSignalTable manager_signals[] = {
- { "TransferStarted", "o" },
- { "TransferCompleted", "ob" },
- { "SessionCreated", "o" },
- { "SessionRemoved", "o" },
+ { _GDBUS_SIGNAL("TransferStarted", "o",
+ GDBUS_ARGS({ "transfer", "o"})) },
+ { _GDBUS_SIGNAL("TransferCompleted", "ob",
+ GDBUS_ARGS({ "transfer", "o" }, { "success", "b" })) },
+ { _GDBUS_SIGNAL("SessionCreated", "o",
+ GDBUS_ARGS({ "session", "o" })) },
+ { _GDBUS_SIGNAL("SessionRemoved", "o",
+ GDBUS_ARGS({ "session", "o" })) },
{ }
};

static const GDBusMethodTable transfer_methods[] = {
- { "Cancel", "", "", transfer_cancel },
+ { _GDBUS_METHOD("Cancel", "", "", NULL, NULL, transfer_cancel) },
{ }
};

static const GDBusSignalTable transfer_signals[] = {
- { "Progress", "ii" },
+ { _GDBUS_SIGNAL("Progress", "ii",
+ GDBUS_ARGS({ "total", "i" }, { "transferred", "i" })) },
{ }
};

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

--
1.7.10.2


2012-05-18 18:32:02

by Lucas De Marchi

[permalink] [raw]
Subject: [PATCH obexd 3/9] gdbus: use GDBusArgInfo to generate introspection

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.10.2