From a5c2b6e886997f91216a352dae08c7b03f44848a Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 20 Dec 2012 19:35:05 +0200 Subject: [PATCH] obexd: Align client and server spec of org.bluez.obex.Transfer1 --- doc/obexd-api.txt | 20 +++++++++-- obexd/src/manager.c | 101 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 107 insertions(+), 14 deletions(-) diff --git a/doc/obexd-api.txt b/doc/obexd-api.txt index 98f5a95ee..24af2337a 100644 --- a/doc/obexd-api.txt +++ b/doc/obexd-api.txt @@ -39,8 +39,6 @@ Methods void Cancel() Stops the current transference. -Signals Progress(int32 total, int32 transfered) - Properties string Status [readonly] Inform the current status of the transfer. @@ -48,6 +46,24 @@ Properties string Status [readonly] Possible values: "queued", "in-progress", "complete" or "error" + string Name [readonly] + + Name of the transferred object. + + uint64 Size [readonly] + + Size of the transferred object. If the size is + unknown, then this property will not be present. + + string Filename [readonly, optional] + + Complete name of the file being received or sent. + + uint64 Progress [readonly, optional] + + Number of bytes transferred. For queued transfers, this + value will not be present. + Session hierarchy =============== diff --git a/obexd/src/manager.c b/obexd/src/manager.c index 0faf09ce1..d55e46461 100644 --- a/obexd/src/manager.c +++ b/obexd/src/manager.c @@ -337,6 +337,87 @@ static gboolean transfer_get_status(const GDBusPropertyTable *property, return TRUE; } +static gboolean transfer_name_exists(const GDBusPropertyTable *property, + void *data) +{ + struct obex_transfer *transfer = data; + struct obex_session *session = transfer->session; + + return session->name != NULL; +} + +static gboolean transfer_get_name(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct obex_transfer *transfer = data; + struct obex_session *session = transfer->session; + + if (session->name == NULL) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &session->name); + + return TRUE; +} + +static gboolean transfer_size_exists(const GDBusPropertyTable *property, + void *data) +{ + struct obex_transfer *transfer = data; + struct obex_session *session = transfer->session; + + return session->size != OBJECT_SIZE_UNKNOWN; +} + +static gboolean transfer_get_size(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct obex_transfer *transfer = data; + struct obex_session *session = transfer->session; + + if (session->size == OBJECT_SIZE_UNKNOWN) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &session->size); + + return TRUE; +} + +static gboolean transfer_filename_exists(const GDBusPropertyTable *property, + void *data) +{ + struct obex_transfer *transfer = data; + struct obex_session *session = transfer->session; + + return session->path != NULL; +} + +static gboolean transfer_get_filename(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct obex_transfer *transfer = data; + struct obex_session *session = transfer->session; + + if (session->path == NULL) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &session->path); + + return TRUE; +} + +static gboolean transfer_get_progress(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct obex_transfer *transfer = data; + struct obex_session *session = transfer->session; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, + &session->offset); + + return TRUE; +} + static const GDBusMethodTable manager_methods[] = { { GDBUS_METHOD("RegisterAgent", GDBUS_ARGS({ "agent", "o" }), NULL, register_agent) }, @@ -350,14 +431,13 @@ static const GDBusMethodTable transfer_methods[] = { { } }; -static const GDBusSignalTable transfer_signals[] = { - { GDBUS_SIGNAL("Progress", GDBUS_ARGS({ "total", "i" }, - { "transferred", "i" })) }, - { } -}; - static const GDBusPropertyTable transfer_properties[] = { { "Status", "s", transfer_get_status }, + { "Name", "s", transfer_get_name, NULL, transfer_name_exists }, + { "Size", "t", transfer_get_size, NULL, transfer_size_exists }, + { "Filename", "s", transfer_get_filename, NULL, + transfer_filename_exists }, + { "Progress", "t", transfer_get_progress }, { } }; @@ -422,7 +502,7 @@ void manager_emit_transfer_started(struct obex_transfer *transfer) if (!g_dbus_register_interface(connection, transfer->path, TRANSFER_INTERFACE, - transfer_methods, transfer_signals, + transfer_methods, NULL, transfer_properties, transfer, NULL)) { error("Cannot register Transfer interface."); g_free(transfer->path); @@ -449,11 +529,8 @@ static void emit_transfer_progress(struct obex_transfer *transfer, if (transfer->path == NULL) return; - g_dbus_emit_signal(connection, transfer->path, - TRANSFER_INTERFACE, "Progress", - DBUS_TYPE_INT32, &total, - DBUS_TYPE_INT32, &transferred, - DBUS_TYPE_INVALID); + g_dbus_emit_property_changed(connection, transfer->path, + TRANSFER_INTERFACE, "Progress"); } static void transfer_free(struct obex_transfer *transfer) -- 2.11.0