From: Mikel Astiz <[email protected]>
In this second proposal patch 3 has been modified to use time-based control of D-Bus progress reporting, as proposed by Luiz. The PropertyChanged signal will be emitted once per second.
>From original cover letter:
This patchset includes a second set of D-Bus changes as part of a bigger API rewrite in obex-client. The original API proposal started around 6 months ago ([1]) and it has later been discussed and modified several times.
This second series focuses on the replacement of the D-Bus agent: the authorization part is entirely removed and the reporting part is now addressed using D-Bus signals. The resulting API is more BlueZ-style and easier to use.
A third and last patchset is left out for later discussion (not proposed yet in the ML). These should extend the D-Bus API such that the transfer-initiating methods will return relevant information (D-Bus path + properties, to be discussed) about the created transfer object.
This results in a transitional API problem regarding FileTransfer interface: once the agent is removed, and before the transfer path is reported, there is no proper way to get transfer notifications. This problem can be seen in patch v0 16/16, but hopefully it's acceptable during the API transition. The fix is not included here to keep a reasonable patchset size.
Mikel Astiz (16):
client: Add D-Bus helper library
client-doc: Add progress property to transfer
client: Add progress property to transfer
client-doc: Add transfer event-reporting signals
client: Add transfer event-reporting signals
client-doc: Remove D-Bus agent
client: Use transfer owner instead of agent
client: Remove D-Bus agent
client: Remove unused functions in transfer API
client: Remove internal transfer progress report
client: Remove obsolete authentication code
client: Make D-Bus exposure of transfers optional
client-doc: Add signal to report new transfers
client: Expose D-Bus data in internal transfer API
client: Add signal to report new transfers
client-test: Remove agent from ftp-client
Makefile.am | 2 +-
client/agent.c | 252 --------------------------------
client/agent.h | 43 ------
client/dbus.c | 256 ++++++++++++++++++++++++++++++++
client/dbus.h | 66 +++++++++
client/ftp.c | 48 ++-----
client/map.c | 6 +-
client/opp.c | 4 +-
client/pbap.c | 8 +-
client/session.c | 408 ++++++++++------------------------------------------
client/session.h | 6 +-
client/sync.c | 4 +-
client/transfer.c | 209 +++++++++++++++------------
client/transfer.h | 13 +-
doc/client-api.txt | 53 ++------
test/ftp-client | 49 ++-----
16 files changed, 565 insertions(+), 862 deletions(-)
delete mode 100644 client/agent.c
delete mode 100644 client/agent.h
create mode 100644 client/dbus.c
create mode 100644 client/dbus.h
--
1.7.7.6
Hi Luiz,
On Fri, May 25, 2012 at 12:55 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Mikel,
>
> On Fri, May 25, 2012 at 1:45 PM, Mikel Astiz <[email protected]> wrote:
>> Hi Luiz,
>>
>> On Fri, May 25, 2012 at 12:35 PM, Luiz Augusto von Dentz
>> <[email protected]> wrote:
>>> Hi Mikel,
>>>
>>> On Fri, May 25, 2012 at 1:11 PM, Mikel Astiz <[email protected]> wrote:
>>>
>>>> +static void transfer_notify_progress(struct obc_transfer *transfer)
>>>> +{
>>>> + ? ? ? gint64 now;
>>>> + ? ? ? gint64 notify;
>>>> +
>>>> + ? ? ? DBG("Transfer %p progress: %lu bytes", transfer, transfer->transferred);
>>>> +
>>>> + ? ? ? if (transfer->path == NULL)
>>>> + ? ? ? ? ? ? ? return;
>>>> +
>>>> + ? ? ? if (transfer->transferred == transfer->transferred_dbus)
>>>> + ? ? ? ? ? ? ? return;
>>>> +
>>>> + ? ? ? now = g_get_monotonic_time();
>>>> + ? ? ? notify = transfer->transferred_dbus_time +
>>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_PROGRESS_PERIOD * 1000;
>>>> +
>>>> + ? ? ? if ((transfer->transferred != transfer->size) && (now < notify))
>>>> + ? ? ? ? ? ? ? return;
>>>> +
>>>> + ? ? ? transfer->transferred_dbus = transfer->transferred;
>>>> + ? ? ? transfer->transferred_dbus_time = now;
>>>> +
>>>> + ? ? ? obex_dbus_signal_property_changed(transfer->conn,
>>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transfer->path,
>>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_INTERFACE, "Progress",
>>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DBUS_TYPE_INT64,
>>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &transfer->transferred_dbus);
>>>> +}
>>>
>>> I would suggest doing it in a different manner using
>>> g_timeout_add_seconds and storing the id, so you just need to know if
>>> the timer is running by checking the id, if there is no timer running
>>> you start it, if there is you just update the bytes transferred and
>>> wait the timeout to be fired where you emit the signal. If in the
>>> meantime the transfer is completed you just have to cleanup using
>>> g_source_remove, this should be simpler because you don't have to
>>> bother how much time has passed on every packet.
>>
>> That would certainly avoid a call to g_get_monotonic_time() every time
>> we receive a packet, but on the other hand we would be waking up the
>> process one additional time per second. I'm not sure if there is any
>> performance improvement there.
>>
>> From the implementation complexity point of view both approaches equally simple.
>
> Actually by using g_timeout_add_seconds we may wake up even less
> because it attempts to group wake-ups, see:
>
> https://live.gnome.org/GnomeGoals/UseTimeoutAddSeconds
That's why I said we would wake up one additional time per second, and
not per second and transfer. All existing transfers would be grouped
and signalled together.
So basically one wake-up per second should be irrelevant I guess, as
irrelevant as a bunch of calls to g_get_monotonic_time.
Anyway, I will implement your proposal in the next revision.
Cheers,
Mikel
Hi Luiz,
On Fri, May 25, 2012 at 12:50 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Mikel,
>
> On Fri, May 25, 2012 at 1:11 PM, Mikel Astiz <[email protected]> wrote:
>> From: Mikel Astiz <[email protected]>
>>
>> These signals replace the old agent-based notification mechanism.
>> ---
>> ?doc/client-api.txt | ? ?9 +++++++++
>> ?1 files changed, 9 insertions(+), 0 deletions(-)
>>
>> diff --git a/doc/client-api.txt b/doc/client-api.txt
>> index cc25543..527df05 100644
>> --- a/doc/client-api.txt
>> +++ b/doc/client-api.txt
>> @@ -322,6 +322,15 @@ Signals ? ? ? ? ? ?PropertyChanged(string name, variant value)
>> ? ? ? ? ? ? ? ? ? ? ? ?This signal indicates a changed value of the given
>> ? ? ? ? ? ? ? ? ? ? ? ?property.
>>
>> + ? ? ? ? ? ? ? void Complete()
>> +
>> + ? ? ? ? ? ? ? ? ? ? ? Informs that the transfer has completed successfully.
>> +
>> + ? ? ? ? ? ? ? void Error(string message)
>> +
>> + ? ? ? ? ? ? ? ? ? ? ? Informs that the transfer has been terminated because
>> + ? ? ? ? ? ? ? ? ? ? ? of some error.
>> +
>
> To avoid any possible confusion I would leave a single signal to tell
> it is complete e.g. Complete(string message), as for the error Johan
> suggested something more meaningful like D-Bus error which both error
> code and error message e.g. Complete(string code, string message),
> actually maybe we should give some other detail when the transfer is
> completed such as file location and other properties that might be
> useful since once this signal is emitted the transfer is gone so there
> is no way to retrieve this information again.
OK, I will change to Complete(string code, string message), although I
have to say I don't like it very much.
So in that case, we would emit Complete("", "") in case of success, right?
Regarding returning transfer properties, that should not be necessary
because, as we already discussed, the idea was to return these
properties in the transfer-initiating method.
Cheers,
Mikel
Hi Mikel,
On Fri, May 25, 2012 at 1:45 PM, Mikel Astiz <[email protected]> wrote:
> Hi Luiz,
>
> On Fri, May 25, 2012 at 12:35 PM, Luiz Augusto von Dentz
> <[email protected]> wrote:
>> Hi Mikel,
>>
>> On Fri, May 25, 2012 at 1:11 PM, Mikel Astiz <[email protected]> wrote:
>>
>>> +static void transfer_notify_progress(struct obc_transfer *transfer)
>>> +{
>>> + ? ? ? gint64 now;
>>> + ? ? ? gint64 notify;
>>> +
>>> + ? ? ? DBG("Transfer %p progress: %lu bytes", transfer, transfer->transferred);
>>> +
>>> + ? ? ? if (transfer->path == NULL)
>>> + ? ? ? ? ? ? ? return;
>>> +
>>> + ? ? ? if (transfer->transferred == transfer->transferred_dbus)
>>> + ? ? ? ? ? ? ? return;
>>> +
>>> + ? ? ? now = g_get_monotonic_time();
>>> + ? ? ? notify = transfer->transferred_dbus_time +
>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_PROGRESS_PERIOD * 1000;
>>> +
>>> + ? ? ? if ((transfer->transferred != transfer->size) && (now < notify))
>>> + ? ? ? ? ? ? ? return;
>>> +
>>> + ? ? ? transfer->transferred_dbus = transfer->transferred;
>>> + ? ? ? transfer->transferred_dbus_time = now;
>>> +
>>> + ? ? ? obex_dbus_signal_property_changed(transfer->conn,
>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transfer->path,
>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_INTERFACE, "Progress",
>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DBUS_TYPE_INT64,
>>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &transfer->transferred_dbus);
>>> +}
>>
>> I would suggest doing it in a different manner using
>> g_timeout_add_seconds and storing the id, so you just need to know if
>> the timer is running by checking the id, if there is no timer running
>> you start it, if there is you just update the bytes transferred and
>> wait the timeout to be fired where you emit the signal. If in the
>> meantime the transfer is completed you just have to cleanup using
>> g_source_remove, this should be simpler because you don't have to
>> bother how much time has passed on every packet.
>
> That would certainly avoid a call to g_get_monotonic_time() every time
> we receive a packet, but on the other hand we would be waking up the
> process one additional time per second. I'm not sure if there is any
> performance improvement there.
>
> From the implementation complexity point of view both approaches equally simple.
Actually by using g_timeout_add_seconds we may wake up even less
because it attempts to group wake-ups, see:
https://live.gnome.org/GnomeGoals/UseTimeoutAddSeconds
--
Luiz Augusto von Dentz
Hi Mikel,
On Fri, May 25, 2012 at 1:11 PM, Mikel Astiz <[email protected]> wrote:
> From: Mikel Astiz <[email protected]>
>
> These signals replace the old agent-based notification mechanism.
> ---
> ?doc/client-api.txt | ? ?9 +++++++++
> ?1 files changed, 9 insertions(+), 0 deletions(-)
>
> diff --git a/doc/client-api.txt b/doc/client-api.txt
> index cc25543..527df05 100644
> --- a/doc/client-api.txt
> +++ b/doc/client-api.txt
> @@ -322,6 +322,15 @@ Signals ? ? ? ? ? ?PropertyChanged(string name, variant value)
> ? ? ? ? ? ? ? ? ? ? ? ?This signal indicates a changed value of the given
> ? ? ? ? ? ? ? ? ? ? ? ?property.
>
> + ? ? ? ? ? ? ? void Complete()
> +
> + ? ? ? ? ? ? ? ? ? ? ? Informs that the transfer has completed successfully.
> +
> + ? ? ? ? ? ? ? void Error(string message)
> +
> + ? ? ? ? ? ? ? ? ? ? ? Informs that the transfer has been terminated because
> + ? ? ? ? ? ? ? ? ? ? ? of some error.
> +
To avoid any possible confusion I would leave a single signal to tell
it is complete e.g. Complete(string message), as for the error Johan
suggested something more meaningful like D-Bus error which both error
code and error message e.g. Complete(string code, string message),
actually maybe we should give some other detail when the transfer is
completed such as file location and other properties that might be
useful since once this signal is emitted the transfer is gone so there
is no way to retrieve this information again.
--
Luiz Augusto von Dentz
Hi Luiz,
On Fri, May 25, 2012 at 12:35 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Mikel,
>
> On Fri, May 25, 2012 at 1:11 PM, Mikel Astiz <[email protected]> wrote:
>
>> +static void transfer_notify_progress(struct obc_transfer *transfer)
>> +{
>> + ? ? ? gint64 now;
>> + ? ? ? gint64 notify;
>> +
>> + ? ? ? DBG("Transfer %p progress: %lu bytes", transfer, transfer->transferred);
>> +
>> + ? ? ? if (transfer->path == NULL)
>> + ? ? ? ? ? ? ? return;
>> +
>> + ? ? ? if (transfer->transferred == transfer->transferred_dbus)
>> + ? ? ? ? ? ? ? return;
>> +
>> + ? ? ? now = g_get_monotonic_time();
>> + ? ? ? notify = transfer->transferred_dbus_time +
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_PROGRESS_PERIOD * 1000;
>> +
>> + ? ? ? if ((transfer->transferred != transfer->size) && (now < notify))
>> + ? ? ? ? ? ? ? return;
>> +
>> + ? ? ? transfer->transferred_dbus = transfer->transferred;
>> + ? ? ? transfer->transferred_dbus_time = now;
>> +
>> + ? ? ? obex_dbus_signal_property_changed(transfer->conn,
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transfer->path,
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_INTERFACE, "Progress",
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DBUS_TYPE_INT64,
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &transfer->transferred_dbus);
>> +}
>
> I would suggest doing it in a different manner using
> g_timeout_add_seconds and storing the id, so you just need to know if
> the timer is running by checking the id, if there is no timer running
> you start it, if there is you just update the bytes transferred and
> wait the timeout to be fired where you emit the signal. If in the
> meantime the transfer is completed you just have to cleanup using
> g_source_remove, this should be simpler because you don't have to
> bother how much time has passed on every packet.
That would certainly avoid a call to g_get_monotonic_time() every time
we receive a packet, but on the other hand we would be waking up the
process one additional time per second. I'm not sure if there is any
performance improvement there.
>From the implementation complexity point of view both approaches equally simple.
Cheers,
Mikel
Hi Mikel,
On Fri, May 25, 2012 at 1:11 PM, Mikel Astiz <[email protected]> wrote:
> +static void transfer_notify_progress(struct obc_transfer *transfer)
> +{
> + ? ? ? gint64 now;
> + ? ? ? gint64 notify;
> +
> + ? ? ? DBG("Transfer %p progress: %lu bytes", transfer, transfer->transferred);
> +
> + ? ? ? if (transfer->path == NULL)
> + ? ? ? ? ? ? ? return;
> +
> + ? ? ? if (transfer->transferred == transfer->transferred_dbus)
> + ? ? ? ? ? ? ? return;
> +
> + ? ? ? now = g_get_monotonic_time();
> + ? ? ? notify = transfer->transferred_dbus_time +
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_PROGRESS_PERIOD * 1000;
> +
> + ? ? ? if ((transfer->transferred != transfer->size) && (now < notify))
> + ? ? ? ? ? ? ? return;
> +
> + ? ? ? transfer->transferred_dbus = transfer->transferred;
> + ? ? ? transfer->transferred_dbus_time = now;
> +
> + ? ? ? obex_dbus_signal_property_changed(transfer->conn,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transfer->path,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TRANSFER_INTERFACE, "Progress",
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DBUS_TYPE_INT64,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &transfer->transferred_dbus);
> +}
I would suggest doing it in a different manner using
g_timeout_add_seconds and storing the id, so you just need to know if
the timer is running by checking the id, if there is no timer running
you start it, if there is you just update the bytes transferred and
wait the timeout to be fired where you emit the signal. If in the
meantime the transfer is completed you just have to cleanup using
g_source_remove, this should be simpler because you don't have to
bother how much time has passed on every packet.
--
Luiz Augusto von Dentz
Hi all,
On Fri, May 25, 2012 at 12:11 PM, Mikel Astiz <[email protected]> wrote:
> From: Mikel Astiz <[email protected]>
>
> The number of transferred bytes is exposed in D-Bus using a specific
> property for this purpose.
>
> Internally, the value of this property does not necessarily match the
> internal progress counter. In order to avoid D-Bus overhead, the
> property will be updated at least every N bytes, where N is fixed and
> hardcoded (TRANSFER_PROGRESS_PERIOD).
> ---
> ?client/transfer.c | ? 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
> ?1 files changed, 49 insertions(+), 2 deletions(-)
>
I just realized the commit message needs to be updated here. I will
include the change in the next version after your reviews.
Cheers,
Mikel
From: Mikel Astiz <[email protected]>
These signals replace the old agent-based notification mechanism.
---
client/transfer.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index 2ac92c3..9c09aac 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -192,6 +192,8 @@ static const GDBusMethodTable obc_transfer_methods[] = {
static const GDBusSignalTable obc_transfer_signals[] = {
{ GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+ { GDBUS_SIGNAL("Complete", NULL) },
+ { GDBUS_SIGNAL("Error", GDBUS_ARGS({ "message", "s" })) },
{ }
};
@@ -455,12 +457,20 @@ static void xfer_complete(GObex *obex, GError *err, gpointer user_data)
transfer->xfer = 0;
- if (err)
- goto done;
+ if (err == NULL) {
+ transfer->size = transfer->transferred;
- transfer->size = transfer->transferred;
+ if (transfer->path != NULL)
+ g_dbus_emit_signal(transfer->conn, transfer->path,
+ TRANSFER_INTERFACE, "Complete",
+ DBUS_TYPE_INVALID);
+ } else if (transfer->path != NULL)
+ g_dbus_emit_signal(transfer->conn, transfer->path,
+ TRANSFER_INTERFACE, "Error",
+ DBUS_TYPE_STRING,
+ &err->message,
+ DBUS_TYPE_INVALID);
-done:
if (callback)
callback->func(transfer, transfer->size, err, callback->data);
}
--
1.7.7.6
From: Mikel Astiz <[email protected]>
The number of transferred bytes is exposed in D-Bus using a specific
property for this purpose.
Internally, the value of this property does not necessarily match the
internal progress counter. In order to avoid D-Bus overhead, the
property will be updated at least every N bytes, where N is fixed and
hardcoded (TRANSFER_PROGRESS_PERIOD).
---
client/transfer.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index 8292265..2ac92c3 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -44,6 +44,7 @@
#define TRANSFER_INTERFACE "org.openobex.Transfer"
#define TRANSFER_BASEPATH "/org/openobex"
+#define TRANSFER_PROGRESS_PERIOD 1000 /* Milliseconds */
#define OBC_TRANSFER_ERROR obc_transfer_error_quark()
@@ -75,6 +76,8 @@ struct obc_transfer {
guint xfer;
gint64 size;
gint64 transferred;
+ gint64 transferred_dbus;
+ gint64 transferred_dbus_time;
};
static GQuark obc_transfer_error_quark(void)
@@ -105,6 +108,10 @@ static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
obex_dbus_dict_append(&dict, "Filename", DBUS_TYPE_STRING,
&transfer->filename);
+ if (transfer->obex != NULL)
+ obex_dbus_dict_append(&dict, "Progress", DBUS_TYPE_UINT64,
+ &transfer->transferred_dbus);
+
dbus_message_iter_close_container(&iter, &dict);
return reply;
@@ -182,6 +189,12 @@ static const GDBusMethodTable obc_transfer_methods[] = {
{ }
};
+static const GDBusSignalTable obc_transfer_signals[] = {
+ { GDBUS_SIGNAL("PropertyChanged",
+ GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+ { }
+};
+
static void obc_transfer_free(struct obc_transfer *transfer)
{
DBG("%p", transfer);
@@ -260,8 +273,8 @@ gboolean obc_transfer_register(struct obc_transfer *transfer,
if (g_dbus_register_interface(transfer->conn, transfer->path,
TRANSFER_INTERFACE,
- obc_transfer_methods, NULL, NULL,
- transfer, NULL) == FALSE) {
+ obc_transfer_methods, obc_transfer_signals,
+ NULL, transfer, NULL) == FALSE) {
g_set_error(err, OBC_TRANSFER_ERROR, -EFAULT,
"Unable to register to D-Bus");
return FALSE;
@@ -380,6 +393,36 @@ void obc_transfer_unregister(struct obc_transfer *transfer)
obc_transfer_free(transfer);
}
+static void transfer_notify_progress(struct obc_transfer *transfer)
+{
+ gint64 now;
+ gint64 notify;
+
+ DBG("Transfer %p progress: %lu bytes", transfer, transfer->transferred);
+
+ if (transfer->path == NULL)
+ return;
+
+ if (transfer->transferred == transfer->transferred_dbus)
+ return;
+
+ now = g_get_monotonic_time();
+ notify = transfer->transferred_dbus_time +
+ TRANSFER_PROGRESS_PERIOD * 1000;
+
+ if ((transfer->transferred != transfer->size) && (now < notify))
+ return;
+
+ transfer->transferred_dbus = transfer->transferred;
+ transfer->transferred_dbus_time = now;
+
+ obex_dbus_signal_property_changed(transfer->conn,
+ transfer->path,
+ TRANSFER_INTERFACE, "Progress",
+ DBUS_TYPE_INT64,
+ &transfer->transferred_dbus);
+}
+
static gboolean get_xfer_progress(const void *buf, gsize len,
gpointer user_data)
{
@@ -400,6 +443,8 @@ static gboolean get_xfer_progress(const void *buf, gsize len,
callback->func(transfer, transfer->transferred, NULL,
callback->data);
+ transfer_notify_progress(transfer);
+
return TRUE;
}
@@ -497,6 +542,8 @@ static gssize put_xfer_progress(void *buf, gsize len, gpointer user_data)
transfer->transferred += size;
+ transfer_notify_progress(transfer);
+
return size;
}
--
1.7.7.6
From: Mikel Astiz <[email protected]>
---
client/session.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
client/transfer.c | 2 +-
client/transfer.h | 2 ++
3 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/client/session.c b/client/session.c
index bb20a61..fcaa97e 100644
--- a/client/session.c
+++ b/client/session.c
@@ -630,6 +630,12 @@ static const GDBusMethodTable session_methods[] = {
{ }
};
+static const GDBusSignalTable session_signals[] = {
+ { GDBUS_SIGNAL("TransferAdded",
+ GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
+ { }
+};
+
static gboolean session_queue_complete(gpointer data)
{
struct obc_session *session = data;
@@ -641,6 +647,34 @@ static gboolean session_queue_complete(gpointer data)
return FALSE;
}
+static gboolean emit_transfer_added(struct obc_session *session,
+ struct obc_transfer *transfer)
+{
+ DBusMessage *signal;
+ DBusMessageIter iter;
+ DBusMessageIter dict;
+ const char *path;
+
+ signal = dbus_message_new_signal(session->path, SESSION_INTERFACE,
+ "TransferAdded");
+ if (signal == NULL)
+ return FALSE;
+
+ dbus_message_iter_init_append(signal, &iter);
+
+ path = obc_transfer_get_path(transfer);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ OBC_PROPERTIES_ARRAY_SIGNATURE,
+ &dict);
+ obc_transfer_append_dbus_properties(transfer, &dict);
+ dbus_message_iter_close_container(&iter, &dict);
+
+ g_dbus_send_message(session->conn, signal);
+
+ return TRUE;
+}
+
guint obc_session_queue(struct obc_session *session,
struct obc_transfer *transfer,
session_callback_t func, void *user_data,
@@ -655,13 +689,19 @@ guint obc_session_queue(struct obc_session *session,
return 0;
}
- if (dbus_register)
+ if (dbus_register) {
if (!obc_transfer_register(transfer, session->conn,
session->owner, err)) {
obc_transfer_unregister(transfer);
return 0;
}
+ if (!emit_transfer_added(session, transfer)) {
+ obc_transfer_unregister(transfer);
+ return 0;
+ }
+ }
+
obc_transfer_set_callback(transfer, transfer_complete, session);
p = pending_request_new(session, transfer, func, user_data);
@@ -794,7 +834,8 @@ const char *obc_session_register(struct obc_session *session,
if (g_dbus_register_interface(session->conn, session->path,
SESSION_INTERFACE, session_methods,
- NULL, NULL, session, destroy) == FALSE)
+ session_signals, NULL, session,
+ destroy) == FALSE)
goto fail;
if (session->driver->probe && session->driver->probe(session) < 0) {
diff --git a/client/transfer.c b/client/transfer.c
index 2bba7a1..1232712 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -85,7 +85,7 @@ static GQuark obc_transfer_error_quark(void)
return g_quark_from_static_string("obc-transfer-error-quark");
}
-static void obc_transfer_append_dbus_properties(struct obc_transfer *transfer,
+void obc_transfer_append_dbus_properties(struct obc_transfer *transfer,
DBusMessageIter *dict)
{
obex_dbus_dict_append(dict, "Name", DBUS_TYPE_STRING, &transfer->name);
diff --git a/client/transfer.h b/client/transfer.h
index eb5275c..df01a2b 100644
--- a/client/transfer.h
+++ b/client/transfer.h
@@ -58,5 +58,7 @@ int obc_transfer_get_contents(struct obc_transfer *transfer, char **contents,
const char *obc_transfer_get_path(struct obc_transfer *transfer);
gint64 obc_transfer_get_size(struct obc_transfer *transfer);
+void obc_transfer_append_dbus_properties(struct obc_transfer *transfer,
+ DBusMessageIter *dict);
DBusMessage *obc_transfer_create_dbus_reply(struct obc_transfer *transfer,
DBusMessage *message);
--
1.7.7.6
From: Mikel Astiz <[email protected]>
Split internal methods logically and expose in transfer API the D-Bus
path and properties as should be returned by transfer-initiating D-Bus
methods.
---
client/transfer.c | 64 ++++++++++++++++++++++++++++++++++++++++++----------
client/transfer.h | 3 ++
2 files changed, 54 insertions(+), 13 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index 025109a..2bba7a1 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -85,6 +85,19 @@ static GQuark obc_transfer_error_quark(void)
return g_quark_from_static_string("obc-transfer-error-quark");
}
+static void obc_transfer_append_dbus_properties(struct obc_transfer *transfer,
+ DBusMessageIter *dict)
+{
+ obex_dbus_dict_append(dict, "Name", DBUS_TYPE_STRING, &transfer->name);
+ obex_dbus_dict_append(dict, "Size", DBUS_TYPE_UINT64, &transfer->size);
+ obex_dbus_dict_append(dict, "Filename", DBUS_TYPE_STRING,
+ &transfer->filename);
+
+ if (transfer->obex != NULL)
+ obex_dbus_dict_append(dict, "Progress", DBUS_TYPE_UINT64,
+ &transfer->transferred_dbus);
+}
+
static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -93,30 +106,55 @@ static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
DBusMessageIter iter, dict;
reply = dbus_message_new_method_return(message);
- if (!reply)
+ if (reply == NULL)
return NULL;
dbus_message_iter_init_append(reply, &iter);
-
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+ OBC_PROPERTIES_ARRAY_SIGNATURE,
+ &dict);
- obex_dbus_dict_append(&dict, "Name", DBUS_TYPE_STRING, &transfer->name);
- obex_dbus_dict_append(&dict, "Size", DBUS_TYPE_UINT64, &transfer->size);
- obex_dbus_dict_append(&dict, "Filename", DBUS_TYPE_STRING,
- &transfer->filename);
-
- if (transfer->obex != NULL)
- obex_dbus_dict_append(&dict, "Progress", DBUS_TYPE_UINT64,
- &transfer->transferred_dbus);
+ obc_transfer_append_dbus_properties(transfer, &dict);
dbus_message_iter_close_container(&iter, &dict);
return reply;
}
+static void obc_transfer_append_dbus_data(struct obc_transfer *transfer,
+ DBusMessageIter *iter)
+{
+ const char *path = transfer->path;
+ DBusMessageIter entry, dict;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH, &path);
+ dbus_message_iter_open_container(&entry, DBUS_TYPE_ARRAY,
+ OBC_PROPERTIES_ARRAY_SIGNATURE,
+ &dict);
+
+ obc_transfer_append_dbus_properties(transfer, &dict);
+
+ dbus_message_iter_close_container(&entry, &dict);
+ dbus_message_iter_close_container(iter, &entry);
+}
+
+DBusMessage *obc_transfer_create_dbus_reply(struct obc_transfer *transfer,
+ DBusMessage *message)
+{
+ DBusMessage *reply;
+ DBusMessageIter iter;
+
+ reply = dbus_message_new_method_return(message);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &iter);
+ obc_transfer_append_dbus_data(transfer, &iter);
+
+ return reply;
+}
+
static void abort_complete(GObex *obex, GError *err, gpointer user_data)
{
struct obc_transfer *transfer = user_data;
diff --git a/client/transfer.h b/client/transfer.h
index 15c157a..eb5275c 100644
--- a/client/transfer.h
+++ b/client/transfer.h
@@ -57,3 +57,6 @@ int obc_transfer_get_contents(struct obc_transfer *transfer, char **contents,
const char *obc_transfer_get_path(struct obc_transfer *transfer);
gint64 obc_transfer_get_size(struct obc_transfer *transfer);
+
+DBusMessage *obc_transfer_create_dbus_reply(struct obc_transfer *transfer,
+ DBusMessage *message);
--
1.7.7.6
From: Mikel Astiz <[email protected]>
The session API lets the modules decide if each transfer should be
exposed in D-Bus or not, instead of relying on a internal policy inside
transfer.c that would decide this based on the transfer type.
---
client/ftp.c | 6 +++---
client/map.c | 6 ++++--
client/opp.c | 4 ++--
client/pbap.c | 8 +++++---
client/session.c | 15 ++++++++-------
client/session.h | 2 +-
client/sync.c | 4 ++--
client/transfer.c | 7 -------
8 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/client/ftp.c b/client/ftp.c
index 9b2c51d..b7b5081 100644
--- a/client/ftp.c
+++ b/client/ftp.c
@@ -237,7 +237,7 @@ static DBusMessage *list_folder(DBusConnection *connection,
goto fail;
if (obc_session_queue(session, transfer, list_folder_callback,
- message, &err)) {
+ message, FALSE, &err)) {
dbus_message_ref(message);
return NULL;
}
@@ -271,7 +271,7 @@ static DBusMessage *get_file(DBusConnection *connection,
goto fail;
if (obc_session_queue(session, transfer, get_file_callback, message,
- &err)) {
+ TRUE, &err)) {
dbus_message_ref(message);
return NULL;
}
@@ -306,7 +306,7 @@ static DBusMessage *put_file(DBusConnection *connection,
if (transfer == NULL)
goto fail;
- if (obc_session_queue(session, transfer, NULL, NULL, &err))
+ if (obc_session_queue(session, transfer, NULL, NULL, TRUE, &err))
return dbus_message_new_method_return(message);
fail:
diff --git a/client/map.c b/client/map.c
index 52b7c68..add302a 100644
--- a/client/map.c
+++ b/client/map.c
@@ -143,7 +143,8 @@ static DBusMessage *map_get_folder_listing(DBusConnection *connection,
if (transfer == NULL)
goto fail;
- if (obc_session_queue(map->session, transfer, buffer_cb, map, &err)) {
+ if (obc_session_queue(map->session, transfer, buffer_cb, map, FALSE,
+ &err)) {
map->msg = dbus_message_ref(message);
return NULL;
}
@@ -177,7 +178,8 @@ static DBusMessage *map_get_message_listing(DBusConnection *connection,
if (transfer == NULL)
goto fail;
- if (obc_session_queue(map->session, transfer, buffer_cb, map, &err)) {
+ if (obc_session_queue(map->session, transfer, buffer_cb, map, FALSE,
+ &err)) {
map->msg = dbus_message_ref(message);
return NULL;
}
diff --git a/client/opp.c b/client/opp.c
index 67b01a9..f6ba398 100644
--- a/client/opp.c
+++ b/client/opp.c
@@ -88,7 +88,7 @@ static DBusMessage *opp_send_file(DBusConnection *connection,
goto fail;
if (!obc_session_queue(opp->session, transfer, send_file_callback,
- message, &err))
+ message, TRUE, &err))
goto fail;
dbus_message_ref(message);
@@ -144,7 +144,7 @@ static DBusMessage *opp_pull_business_card(DBusConnection *connection,
goto fail;
if (!obc_session_queue(opp->session, pull, pull_complete_callback,
- message, &err))
+ message, TRUE, &err))
goto fail;
dbus_message_ref(message);
diff --git a/client/pbap.c b/client/pbap.c
index 3a771ab..1945fad 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -500,7 +500,8 @@ static DBusMessage *pull_phonebook(struct pbap_data *pbap,
obc_transfer_set_params(transfer, &apparam, sizeof(apparam));
- if (obc_session_queue(pbap->session, transfer, func, request, &err))
+ if (obc_session_queue(pbap->session, transfer, func, request,
+ FALSE, &err))
return NULL;
pending_request_free(request);
@@ -567,7 +568,8 @@ static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
obc_transfer_set_params(transfer, apparam, apparam_size);
if (obc_session_queue(pbap->session, transfer,
- pull_vcard_listing_callback, request, &err))
+ pull_vcard_listing_callback, request,
+ FALSE, &err))
return NULL;
pending_request_free(request);
@@ -796,7 +798,7 @@ static DBusMessage *pbap_pull_vcard(DBusConnection *connection,
obc_transfer_set_params(transfer, &apparam, sizeof(apparam));
if (obc_session_queue(pbap->session, transfer, pull_phonebook_callback,
- request, &err))
+ request, FALSE, &err))
return NULL;
pending_request_free(request);
diff --git a/client/session.c b/client/session.c
index 9670968..bb20a61 100644
--- a/client/session.c
+++ b/client/session.c
@@ -604,7 +604,7 @@ static DBusMessage *get_capabilities(DBusConnection *connection,
goto fail;
if (!obc_session_queue(session, pull, capabilities_complete_callback,
- message, &gerr))
+ message, FALSE, &gerr))
goto fail;
dbus_message_ref(message);
@@ -644,7 +644,7 @@ static gboolean session_queue_complete(gpointer data)
guint obc_session_queue(struct obc_session *session,
struct obc_transfer *transfer,
session_callback_t func, void *user_data,
- GError **err)
+ gboolean dbus_register, GError **err)
{
struct pending_request *p;
@@ -655,11 +655,12 @@ guint obc_session_queue(struct obc_session *session,
return 0;
}
- if (!obc_transfer_register(transfer, session->conn, session->owner,
- err)) {
- obc_transfer_unregister(transfer);
- return 0;
- }
+ if (dbus_register)
+ if (!obc_transfer_register(transfer, session->conn,
+ session->owner, err)) {
+ obc_transfer_unregister(transfer);
+ return 0;
+ }
obc_transfer_set_callback(transfer, transfer_complete, session);
diff --git a/client/session.h b/client/session.h
index 7f37d29..1f77d56 100644
--- a/client/session.h
+++ b/client/session.h
@@ -56,7 +56,7 @@ const char *obc_session_register(struct obc_session *session,
guint obc_session_queue(struct obc_session *session,
struct obc_transfer *transfer,
session_callback_t func, void *user_data,
- GError **err);
+ gboolean dbus_register, GError **err);
guint obc_session_setpath(struct obc_session *session, const char *path,
session_callback_t func, void *user_data,
GError **err);
diff --git a/client/sync.c b/client/sync.c
index d56e066..032f400 100644
--- a/client/sync.c
+++ b/client/sync.c
@@ -146,7 +146,7 @@ static DBusMessage *sync_getphonebook(DBusConnection *connection,
if (obc_session_queue(sync->session, transfer,
sync_getphonebook_callback,
- sync, &err)) {
+ sync, TRUE, &err)) {
sync->msg = dbus_message_ref(message);
return NULL;
}
@@ -182,7 +182,7 @@ static DBusMessage *sync_putphonebook(DBusConnection *connection,
if (transfer == NULL)
goto fail;
- if (obc_session_queue(sync->session, transfer, NULL, NULL, &err))
+ if (obc_session_queue(sync->session, transfer, NULL, NULL, TRUE, &err))
return dbus_message_new_method_return(message);
fail:
diff --git a/client/transfer.c b/client/transfer.c
index 4599995..025109a 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -253,12 +253,6 @@ gboolean obc_transfer_register(struct obc_transfer *transfer,
const char *owner,
GError **err)
{
- /* for OBEX specific mime types we don't need to register a transfer */
- if (transfer->type != NULL &&
- (strncmp(transfer->type, "x-obex/", 7) == 0 ||
- strncmp(transfer->type, "x-bt/", 5) == 0))
- goto done;
-
transfer->owner = g_strdup(owner);
transfer->path = g_strdup_printf("%s/transfer%ju",
@@ -280,7 +274,6 @@ gboolean obc_transfer_register(struct obc_transfer *transfer,
return FALSE;
}
-done:
DBG("%p registered %s", transfer, transfer->path);
return TRUE;
--
1.7.7.6
From: Mikel Astiz <[email protected]>
This signal makes it possible to support transfer-monitoring
applications.
---
doc/client-api.txt | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/doc/client-api.txt b/doc/client-api.txt
index 656c492..e6647ff 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -56,6 +56,10 @@ Properties string Source [readonly]
byte Channel [readonly]
+Signals void TransferAdded(object path, dict properties)
+
+ Informs that a new transfer has been created (queued).
+
Object Push hierarchy
=====================
--
1.7.7.6
From: Mikel Astiz <[email protected]>
The authorization mechanism is entirely removed from the session, and
thus transfers are automatically started (once popped from the queue)
without confirmation and without any name/filename change.
---
Makefile.am | 1 -
client/agent.c | 252 ------------------------------------------------------
client/agent.h | 43 ---------
client/session.c | 218 +----------------------------------------------
client/session.h | 4 -
5 files changed, 2 insertions(+), 516 deletions(-)
delete mode 100644 client/agent.c
delete mode 100644 client/agent.h
diff --git a/Makefile.am b/Makefile.am
index 86f9ad1..5cc0603 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -124,7 +124,6 @@ client_obex_client_SOURCES = $(gdbus_sources) $(gobex_sources) \
client/opp.h client/opp.c \
client/map.h client/map.c \
client/transfer.h client/transfer.c \
- client/agent.h client/agent.c \
client/transport.h client/transport.c \
client/dbus.h client/dbus.c \
client/driver.h client/driver.c \
diff --git a/client/agent.c b/client/agent.c
deleted file mode 100644
index 929a05f..0000000
--- a/client/agent.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- *
- * OBEX Client
- *
- * Copyright (C) 2007-2010 Marcel Holtmann <[email protected]>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-
-#include "log.h"
-#include "agent.h"
-
-#define AGENT_INTERFACE "org.openobex.Agent"
-
-struct pending_request {
- DBusPendingCall *call;
- DBusPendingCallNotifyFunction function;
- void *data;
- DBusFreeFunction destroy;
-};
-
-struct obc_agent {
- DBusConnection *conn;
- char *name;
- char *path;
- guint watch;
- GFunc destroy;
- void *data;
- struct pending_request *pending;
-};
-
-static void pending_request_free(struct pending_request *req)
-{
- if (req->call)
- dbus_pending_call_unref(req->call);
-
- if (req->destroy)
- req->destroy(req->data);
-
- g_free(req);
-}
-
-void obc_agent_free(struct obc_agent *agent)
-{
- if (agent->watch)
- g_dbus_remove_watch(agent->conn, agent->watch);
-
- if (agent->pending) {
- if (agent->pending->call)
- dbus_pending_call_cancel(agent->pending->call);
- pending_request_free(agent->pending);
- }
-
- dbus_connection_unref(agent->conn);
- g_free(agent->name);
- g_free(agent->path);
- g_free(agent);
-}
-
-static void agent_disconnected(DBusConnection *connection, void *user_data)
-{
- struct obc_agent *agent = user_data;
-
- agent->watch = 0;
-
- if (agent->destroy)
- agent->destroy(agent, agent->data);
-
- obc_agent_free(agent);
-}
-
-struct obc_agent *obc_agent_create(DBusConnection *conn, const char *name,
- const char *path, GFunc destroy,
- void *user_data)
-{
- struct obc_agent *agent;
-
- agent = g_new0(struct obc_agent, 1);
- agent->conn = dbus_connection_ref(conn);
- agent->name = g_strdup(name);
- agent->path = g_strdup(path);
- agent->destroy = destroy;
- agent->data = user_data;
-
- agent->watch = g_dbus_add_disconnect_watch(conn, name,
- agent_disconnected,
- agent, NULL);
-
- return agent;
-}
-
-static void agent_request_reply(DBusPendingCall *call, void *user_data)
-{
- struct obc_agent *agent = user_data;
- struct pending_request *req = agent->pending;
-
- agent->pending = NULL;
-
- if (req->function)
- req->function(call, req->data);
-
- pending_request_free(req);
-}
-
-int obc_agent_request(struct obc_agent *agent, const char *path,
- DBusPendingCallNotifyFunction function,
- void *user_data, DBusFreeFunction destroy)
-{
- struct pending_request *req;
- DBusMessage *message;
-
- if (agent->pending)
- return -EBUSY;
-
- DBG("%s", path);
-
- message = dbus_message_new_method_call(agent->name,
- agent->path, AGENT_INTERFACE, "Request");
-
- dbus_message_append_args(message,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
- req = g_new0(struct pending_request, 1);
- req->function = function;
- req->destroy = destroy;
- req->data = user_data;
-
- if (!dbus_connection_send_with_reply(agent->conn, message,
- &req->call, -1)) {
- g_free(req);
- dbus_message_unref(message);
- return -ENOMEM;
- }
-
- agent->pending = req;
-
- dbus_message_unref(message);
-
- dbus_pending_call_set_notify(req->call, agent_request_reply,
- agent, NULL);
-
- return 0;
-}
-
-void obc_agent_notify_progress(struct obc_agent *agent, const char *path,
- guint64 transferred)
-{
- DBusMessage *message;
-
- DBG("%s", path);
-
- message = dbus_message_new_method_call(agent->name,
- agent->path, AGENT_INTERFACE, "Progress");
- if (message == NULL)
- return;
-
- dbus_message_set_no_reply(message, TRUE);
-
- dbus_message_append_args(message,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_UINT64, &transferred,
- DBUS_TYPE_INVALID);
-
- g_dbus_send_message(agent->conn, message);
-}
-
-void obc_agent_notify_complete(struct obc_agent *agent, const char *path)
-{
- DBusMessage *message;
-
- DBG("%s", path);
-
- message = dbus_message_new_method_call(agent->name,
- agent->path, AGENT_INTERFACE, "Complete");
- if (message == NULL)
- return;
-
- dbus_message_set_no_reply(message, TRUE);
-
- dbus_message_append_args(message,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
- g_dbus_send_message(agent->conn, message);
-}
-
-void obc_agent_notify_error(struct obc_agent *agent, const char *path,
- const char *err)
-{
- DBusMessage *message;
-
- DBG("%s", path);
-
- message = dbus_message_new_method_call(agent->name,
- agent->path, AGENT_INTERFACE, "Error");
- if (message == NULL)
- return;
-
- dbus_message_set_no_reply(message, TRUE);
-
- dbus_message_append_args(message,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_STRING, &err,
- DBUS_TYPE_INVALID);
-
- g_dbus_send_message(agent->conn, message);
-}
-
-void obc_agent_release(struct obc_agent *agent)
-{
- DBusMessage *message;
-
- DBG("");
-
- message = dbus_message_new_method_call(agent->name,
- agent->path, AGENT_INTERFACE, "Release");
-
- dbus_message_set_no_reply(message, TRUE);
-
- g_dbus_send_message(agent->conn, message);
-}
-
-const char *obc_agent_get_name(struct obc_agent *agent)
-{
- return agent->name;
-}
-
-const char *obc_agent_get_path(struct obc_agent *agent)
-{
- return agent->path;
-}
diff --git a/client/agent.h b/client/agent.h
deleted file mode 100644
index 69f2ffe..0000000
--- a/client/agent.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *
- * OBEX Client
- *
- * Copyright (C) 2007-2010 Intel Corporation
- * Copyright (C) 2007-2010 Marcel Holtmann <[email protected]>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#include <gdbus.h>
-
-struct obc_agent;
-
-struct obc_agent *obc_agent_create(DBusConnection *conn, const char *name,
- const char *path, GFunc destroy,
- void *user_data);
-void obc_agent_free(struct obc_agent *agent);
-const char *obc_agent_get_name(struct obc_agent *agent);
-const char *obc_agent_get_path(struct obc_agent *agent);
-int obc_agent_request(struct obc_agent *agent, const char *path,
- DBusPendingCallNotifyFunction function,
- void *user_data, DBusFreeFunction destroy);
-void obc_agent_notify_progress(struct obc_agent *agent, const char *path,
- guint64 transferred);
-void obc_agent_notify_complete(struct obc_agent *agent, const char *path);
-void obc_agent_notify_error(struct obc_agent *agent, const char *path,
- const char *err);
-void obc_agent_release(struct obc_agent *agent);
diff --git a/client/session.c b/client/session.c
index 9c4c9f0..989439c 100644
--- a/client/session.c
+++ b/client/session.c
@@ -41,7 +41,6 @@
#include "log.h"
#include "transfer.h"
#include "session.h"
-#include "agent.h"
#include "driver.h"
#include "transport.h"
@@ -92,7 +91,6 @@ struct obc_session {
gchar *path; /* Session path */
DBusConnection *conn;
GObex *obex;
- struct obc_agent *agent;
struct pending_request *p;
gchar *owner; /* Session owner */
guint watch;
@@ -175,11 +173,6 @@ static void session_free(struct obc_session *session)
{
DBG("%p", session);
- if (session->agent) {
- obc_agent_release(session->agent);
- obc_agent_free(session->agent);
- }
-
if (session->queue) {
g_queue_foreach(session->queue, (GFunc) pending_request_free,
NULL);
@@ -529,60 +522,6 @@ void obc_session_shutdown(struct obc_session *session)
obc_session_unref(session);
}
-static DBusMessage *assign_agent(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- struct obc_session *session = user_data;
- const gchar *sender, *path;
-
- if (dbus_message_get_args(message, NULL,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID) == FALSE)
- return g_dbus_create_error(message,
- "org.openobex.Error.InvalidArguments",
- "Invalid arguments in method call");
-
- sender = dbus_message_get_sender(message);
-
- if (obc_session_set_agent(session, sender, path) < 0)
- return g_dbus_create_error(message,
- "org.openobex.Error.AlreadyExists",
- "Already exists");
-
- return dbus_message_new_method_return(message);
-}
-
-static DBusMessage *release_agent(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- struct obc_session *session = user_data;
- struct obc_agent *agent = session->agent;
- const gchar *sender;
- gchar *path;
-
- if (dbus_message_get_args(message, NULL,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID) == FALSE)
- return g_dbus_create_error(message,
- "org.openobex.Error.InvalidArguments",
- "Invalid arguments in method call");
-
- sender = dbus_message_get_sender(message);
-
- if (agent == NULL)
- return dbus_message_new_method_return(message);
-
- if (g_str_equal(sender, obc_agent_get_name(agent)) == FALSE ||
- g_str_equal(path, obc_agent_get_path(agent)) == FALSE)
- return g_dbus_create_error(message,
- "org.openobex.Error.NotAuthorized",
- "Not Authorized");
-
- obc_agent_free(agent);
-
- return dbus_message_new_method_return(message);
-}
-
static DBusMessage *session_get_properties(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -685,79 +624,12 @@ static const GDBusMethodTable session_methods[] = {
{ GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
session_get_properties) },
- { GDBUS_METHOD("AssignAgent",
- GDBUS_ARGS({ "agent", "o" }), NULL,
- assign_agent) },
- { GDBUS_METHOD("ReleaseAgent",
- GDBUS_ARGS({ "agent", "o" }), NULL,
- release_agent) },
{ GDBUS_ASYNC_METHOD("GetCapabilities",
NULL, GDBUS_ARGS({ "capabilities", "s" }),
get_capabilities) },
{ }
};
-static void session_request_reply(DBusPendingCall *call, gpointer user_data)
-{
- struct obc_session *session = user_data;
- struct pending_request *p = session->p;
- struct obc_transfer *transfer = p->transfer;
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- const char *name;
- DBusError derr;
- int err;
-
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- GError *gerr = NULL;
-
- error("Replied with an error: %s, %s",
- derr.name, derr.message);
- dbus_error_free(&derr);
- dbus_message_unref(reply);
-
- g_set_error(&gerr, OBEX_IO_ERROR, -ECANCELED, "%s",
- derr.message);
- session_terminate_transfer(session, transfer, gerr);
- g_clear_error(&gerr);
-
- return;
- }
-
- dbus_message_get_args(reply, NULL,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
-
- DBG("Agent.Request() reply: %s", name);
-
- if (strlen(name) == 0)
- goto done;
-
- if (obc_transfer_get_operation(transfer) == G_OBEX_OP_PUT) {
- obc_transfer_set_name(transfer, name);
- goto done;
- }
-
- err = obc_transfer_set_filename(transfer, name);
- if (err < 0) {
- GError *gerr = NULL;
-
- g_set_error(&gerr, OBEX_IO_ERROR, err,
- "Unable to set filename");
- session_terminate_transfer(session, transfer, gerr);
- g_clear_error(&gerr);
- return;
- }
-
-done:
- if (p->auth_complete)
- p->auth_complete(session, transfer);
-
- dbus_message_unref(reply);
-
- return;
-}
-
static gboolean session_request_proceed(gpointer data)
{
struct obc_session *session = data;
@@ -772,19 +644,8 @@ static gboolean session_request_proceed(gpointer data)
static int pending_request_auth(struct pending_request *p)
{
- struct obc_session *session = p->session;
- struct obc_agent *agent = session->agent;
- const char *path;
-
- path = obc_transfer_get_path(p->transfer);
-
- if (agent == NULL || path == NULL) {
- g_idle_add(session_request_proceed, session);
- return 0;
- }
-
- return obc_agent_request(agent, path, session_request_reply, session,
- NULL);
+ g_idle_add(session_request_proceed, p->session);
+ return 0;
}
guint obc_session_queue(struct obc_session *session,
@@ -911,18 +772,6 @@ static void session_terminate_transfer(struct obc_session *session,
static void session_notify_complete(struct obc_session *session,
struct obc_transfer *transfer)
{
- struct obc_agent *agent = session->agent;
- const char *path;
-
- path = obc_transfer_get_path(transfer);
-
- if (agent == NULL || path == NULL)
- goto done;
-
- obc_agent_notify_complete(agent, path);
-
-done:
-
DBG("Transfer(%p) complete", transfer);
session_terminate_transfer(session, transfer, NULL);
@@ -932,16 +781,6 @@ static void session_notify_error(struct obc_session *session,
struct obc_transfer *transfer,
GError *err)
{
- struct obc_agent *agent = session->agent;
- const char *path;
-
- path = obc_transfer_get_path(transfer);
- if (agent == NULL || path == NULL)
- goto done;
-
- obc_agent_notify_error(agent, path, err->message);
-
-done:
error("Transfer(%p) Error: %s", transfer, err->message);
session_terminate_transfer(session, transfer, err);
@@ -951,16 +790,6 @@ static void session_notify_progress(struct obc_session *session,
struct obc_transfer *transfer,
gint64 transferred)
{
- struct obc_agent *agent = session->agent;
- const char *path;
-
- path = obc_transfer_get_path(transfer);
- if (agent == NULL || path == NULL)
- goto done;
-
- obc_agent_notify_progress(agent, path, transferred);
-
-done:
DBG("Transfer(%p) progress: %ld bytes", transfer,
(long int ) transferred);
@@ -1030,49 +859,6 @@ fail:
return NULL;
}
-static void agent_destroy(gpointer data, gpointer user_data)
-{
- struct obc_session *session = user_data;
-
- session->agent = NULL;
-}
-
-int obc_session_set_agent(struct obc_session *session, const char *name,
- const char *path)
-{
- struct obc_agent *agent;
-
- if (session == NULL)
- return -EINVAL;
-
- if (session->agent)
- return -EALREADY;
-
- agent = obc_agent_create(session->conn, name, path, agent_destroy,
- session);
-
- if (session->watch == 0)
- obc_session_set_owner(session, name, owner_disconnected);
-
- session->agent = agent;
-
- return 0;
-}
-
-const char *obc_session_get_agent(struct obc_session *session)
-{
- struct obc_agent *agent;
-
- if (session == NULL)
- return NULL;
-
- agent = session->agent;
- if (agent == NULL)
- return NULL;
-
- return obc_agent_get_name(session->agent);
-}
-
const char *obc_session_get_owner(struct obc_session *session)
{
if (session == NULL)
diff --git a/client/session.h b/client/session.h
index 2cac032..7f37d29 100644
--- a/client/session.h
+++ b/client/session.h
@@ -47,10 +47,6 @@ int obc_session_set_owner(struct obc_session *session, const char *name,
GDBusWatchFunction func);
const char *obc_session_get_owner(struct obc_session *session);
-int obc_session_set_agent(struct obc_session *session, const char *name,
- const char *path);
-const char *obc_session_get_agent(struct obc_session *session);
-
const char *obc_session_get_path(struct obc_session *session);
const char *obc_session_get_target(struct obc_session *session);
--
1.7.7.6
From: Mikel Astiz <[email protected]>
This updated test script is limited because the current transitional
D-Bus API is incomplete. The reason behind is that the transfer path is
not being returned by methods that initiate such a transfer. Therefore
the client cannot know when the transfer has succeeded or failed, and
neither can receive progress reports in a reliable way.
---
test/ftp-client | 49 +++++++++----------------------------------------
1 files changed, 9 insertions(+), 40 deletions(-)
diff --git a/test/ftp-client b/test/ftp-client
index 825f591..da15116 100755
--- a/test/ftp-client
+++ b/test/ftp-client
@@ -9,42 +9,6 @@ import dbus.mainloop.glib
import os.path
from optparse import OptionParser
-class Agent(dbus.service.Object):
- def __init__(self, conn=None, obj_path=None, verbose=False):
- dbus.service.Object.__init__(self, conn, obj_path)
- self.verbose = verbose
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="o", out_signature="s")
- def Request(self, path):
- return ""
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="ot", out_signature="")
- def Progress(self, path, transferred):
- if self.verbose:
- print "Transfer progress (%d bytes)" % (transferred)
- return
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="o", out_signature="")
- def Complete(self, path):
- if self.verbose:
- print "Transfer finished"
- mainloop.quit()
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="os", out_signature="")
- def Error(self, path, error):
- print "Transfer finished with an error: %s" % (error)
- mainloop.quit()
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="", out_signature="")
- def Release(self):
- mainloop.quit()
-
-
def parse_options():
parser.add_option("-d", "--device", dest="device",
help="Device to connect", metavar="DEVICE")
@@ -74,6 +38,9 @@ def error(err):
def void_reply():
pass
+def transfer_complete():
+ print "SOME transfer finished (could not check if path matches)"
+
def change_folder(session, new_dir):
for node in new_dir.split("/"):
session.ChangeFolder(node)
@@ -129,8 +96,12 @@ if __name__ == '__main__':
bus = dbus.SessionBus()
mainloop = gobject.MainLoop()
- path = "/test/agent"
- agent = Agent(bus, path, options.verbose)
+ bus.add_signal_receiver(transfer_complete,
+ dbus_interface="org.openobex.Transfer",
+ signal_name="Complete")
+ bus.add_signal_receiver(error,
+ dbus_interface="org.openobex.Transfer",
+ signal_name="Error")
client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
"org.openobex.Client")
@@ -140,8 +111,6 @@ if __name__ == '__main__':
session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.Session")
- session.AssignAgent(path)
-
ftp = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.FileTransfer")
--
1.7.7.6
From: Mikel Astiz <[email protected]>
The new D-Bus API uses signals to report the progress updates, so the
internal progress callback is not needed any more.
---
client/session.c | 25 ++++++-------------------
client/transfer.c | 18 +++---------------
client/transfer.h | 3 +--
3 files changed, 10 insertions(+), 36 deletions(-)
diff --git a/client/session.c b/client/session.c
index 989439c..8e21da4 100644
--- a/client/session.c
+++ b/client/session.c
@@ -103,9 +103,8 @@ static void session_start_transfer(gpointer data, gpointer user_data);
static void session_terminate_transfer(struct obc_session *session,
struct obc_transfer *transfer,
GError *gerr);
-static void transfer_progress(struct obc_transfer *transfer,
- gint64 transferred, GError *err,
- void *user_data);
+static void transfer_complete(struct obc_transfer *transfer,
+ GError *err, void *user_data);
static GQuark obex_io_error_quark(void)
{
@@ -669,7 +668,7 @@ guint obc_session_queue(struct obc_session *session,
return 0;
}
- obc_transfer_set_callback(transfer, transfer_progress, session);
+ obc_transfer_set_callback(transfer, transfer_complete, session);
p = pending_request_new(session, transfer, session_start_transfer,
func, user_data);
@@ -786,27 +785,15 @@ static void session_notify_error(struct obc_session *session,
session_terminate_transfer(session, transfer, err);
}
-static void session_notify_progress(struct obc_session *session,
- struct obc_transfer *transfer,
- gint64 transferred)
-{
- DBG("Transfer(%p) progress: %ld bytes", transfer,
- (long int ) transferred);
-
- if (transferred == obc_transfer_get_size(transfer))
- session_notify_complete(session, transfer);
-}
-
-static void transfer_progress(struct obc_transfer *transfer,
- gint64 transferred, GError *err,
- void *user_data)
+static void transfer_complete(struct obc_transfer *transfer,
+ GError *err, void *user_data)
{
struct obc_session *session = user_data;
if (err != 0)
goto fail;
- session_notify_progress(session, transfer, transferred);
+ session_notify_complete(session, transfer);
return;
diff --git a/client/transfer.c b/client/transfer.c
index f631843..4599995 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -136,15 +136,13 @@ static void abort_complete(GObex *obex, GError *err, gpointer user_data)
return;
if (err) {
- callback->func(transfer, transfer->transferred, err,
- callback->data);
+ callback->func(transfer, err, callback->data);
} else {
GError *abort_err;
abort_err = g_error_new(OBC_TRANSFER_ERROR, -ECANCELED, "%s",
"Transfer cancelled by user");
- callback->func(transfer, transfer->transferred, abort_err,
- callback->data);
+ callback->func(transfer, abort_err, callback->data);
g_error_free(abort_err);
}
}
@@ -429,7 +427,6 @@ static gboolean get_xfer_progress(const void *buf, gsize len,
gpointer user_data)
{
struct obc_transfer *transfer = user_data;
- struct transfer_callback *callback = transfer->callback;
if (transfer->fd > 0) {
gint w;
@@ -441,10 +438,6 @@ static gboolean get_xfer_progress(const void *buf, gsize len,
transfer->transferred += w;
}
- if (callback && transfer->transferred != transfer->size)
- callback->func(transfer, transfer->transferred, NULL,
- callback->data);
-
transfer_notify_progress(transfer);
return TRUE;
@@ -472,7 +465,7 @@ static void xfer_complete(GObex *obex, GError *err, gpointer user_data)
DBUS_TYPE_INVALID);
if (callback)
- callback->func(transfer, transfer->size, err, callback->data);
+ callback->func(transfer, err, callback->data);
}
static void get_xfer_progress_first(GObex *obex, GError *err, GObexPacket *rsp,
@@ -539,17 +532,12 @@ static void get_xfer_progress_first(GObex *obex, GError *err, GObexPacket *rsp,
static gssize put_xfer_progress(void *buf, gsize len, gpointer user_data)
{
struct obc_transfer *transfer = user_data;
- struct transfer_callback *callback = transfer->callback;
gssize size;
size = read(transfer->fd, buf, len);
if (size <= 0)
return size;
- if (callback)
- callback->func(transfer, transfer->transferred, NULL,
- callback->data);
-
transfer->transferred += size;
transfer_notify_progress(transfer);
diff --git a/client/transfer.h b/client/transfer.h
index bfa166d..15c157a 100644
--- a/client/transfer.h
+++ b/client/transfer.h
@@ -24,8 +24,7 @@
struct obc_transfer;
typedef void (*transfer_callback_t) (struct obc_transfer *transfer,
- gint64 transferred, GError *err,
- void *user_data);
+ GError *err, void *user_data);
struct obc_transfer *obc_transfer_get(const char *type, const char *name,
const char *filename, GError **err);
--
1.7.7.6
From: Mikel Astiz <[email protected]>
The security checks in the transfers' D-Bus API will consider check for
the transfer owner's path (session owner) instead of the agent path.
---
client/session.c | 9 ++-------
client/transfer.c | 10 +++++-----
client/transfer.h | 2 +-
3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/client/session.c b/client/session.c
index 94256b4..9c4c9f0 100644
--- a/client/session.c
+++ b/client/session.c
@@ -793,7 +793,6 @@ guint obc_session_queue(struct obc_session *session,
GError **err)
{
struct pending_request *p;
- const char *agent;
int perr;
if (session->obex == NULL) {
@@ -803,12 +802,8 @@ guint obc_session_queue(struct obc_session *session,
return 0;
}
- if (session->agent)
- agent = obc_agent_get_name(session->agent);
- else
- agent = NULL;
-
- if (!obc_transfer_register(transfer, session->conn, agent, err)) {
+ if (!obc_transfer_register(transfer, session->conn, session->owner,
+ err)) {
obc_transfer_unregister(transfer);
return 0;
}
diff --git a/client/transfer.c b/client/transfer.c
index 9c09aac..ab9f84a 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -67,7 +67,7 @@ struct obc_transfer {
struct transfer_callback *callback;
DBusConnection *conn;
DBusMessage *msg;
- char *agent; /* Transfer agent */
+ char *owner; /* Transfer initiator */
char *path; /* Transfer path */
gchar *filename; /* Transfer file location */
char *name; /* Transfer object name */
@@ -165,7 +165,7 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
const gchar *sender;
sender = dbus_message_get_sender(message);
- if (g_strcmp0(transfer->agent, sender) != 0)
+ if (g_strcmp0(transfer->owner, sender) != 0)
return g_dbus_create_error(message,
"org.openobex.Error.NotAuthorized",
"Not Authorized");
@@ -226,7 +226,7 @@ static void obc_transfer_free(struct obc_transfer *transfer)
g_obex_unref(transfer->obex);
g_free(transfer->callback);
- g_free(transfer->agent);
+ g_free(transfer->owner);
g_free(transfer->filename);
g_free(transfer->name);
g_free(transfer->type);
@@ -252,7 +252,7 @@ static struct obc_transfer *obc_transfer_create(guint8 op,
gboolean obc_transfer_register(struct obc_transfer *transfer,
DBusConnection *conn,
- const char *agent,
+ const char *owner,
GError **err)
{
/* for OBEX specific mime types we don't need to register a transfer */
@@ -261,7 +261,7 @@ gboolean obc_transfer_register(struct obc_transfer *transfer,
strncmp(transfer->type, "x-bt/", 5) == 0))
goto done;
- transfer->agent = g_strdup(agent);
+ transfer->owner = g_strdup(owner);
transfer->path = g_strdup_printf("%s/transfer%ju",
TRANSFER_BASEPATH, counter++);
diff --git a/client/transfer.h b/client/transfer.h
index bf40a4c..a65a2ed 100644
--- a/client/transfer.h
+++ b/client/transfer.h
@@ -36,7 +36,7 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
gboolean obc_transfer_register(struct obc_transfer *transfer,
DBusConnection *conn,
- const char *agent,
+ const char *owner,
GError **err);
void obc_transfer_unregister(struct obc_transfer *transfer);
--
1.7.7.6
From: Mikel Astiz <[email protected]>
After the removal of the agent, the implementation of the session can be
simplified by removing all authentication-related code.
---
client/session.c | 86 ++++++++++++++++-------------------------------------
1 files changed, 26 insertions(+), 60 deletions(-)
diff --git a/client/session.c b/client/session.c
index 8e21da4..9670968 100644
--- a/client/session.c
+++ b/client/session.c
@@ -68,7 +68,6 @@ struct pending_request {
guint req_id;
struct obc_session *session;
struct obc_transfer *transfer;
- GFunc auth_complete;
session_callback_t func;
void *data;
};
@@ -95,11 +94,12 @@ struct obc_session {
gchar *owner; /* Session owner */
guint watch;
GQueue *queue;
+ guint queue_complete_id;
};
static GSList *sessions = NULL;
-static void session_start_transfer(gpointer data, gpointer user_data);
+static void session_process_queue(struct obc_session *session);
static void session_terminate_transfer(struct obc_session *session,
struct obc_transfer *transfer,
GError *gerr);
@@ -139,7 +139,6 @@ static void session_unregistered(struct obc_session *session)
static struct pending_request *pending_request_new(struct obc_session *session,
struct obc_transfer *transfer,
- GFunc auth_complete,
session_callback_t func,
void *data)
{
@@ -150,7 +149,6 @@ static struct pending_request *pending_request_new(struct obc_session *session,
p->id = ++id;
p->session = obc_session_ref(session);
p->transfer = transfer;
- p->auth_complete = auth_complete;
p->func = func;
p->data = data;
@@ -172,6 +170,9 @@ static void session_free(struct obc_session *session)
{
DBG("%p", session);
+ if (session->queue_complete_id != 0)
+ g_source_remove(session->queue_complete_id);
+
if (session->queue) {
g_queue_foreach(session->queue, (GFunc) pending_request_free,
NULL);
@@ -629,22 +630,15 @@ static const GDBusMethodTable session_methods[] = {
{ }
};
-static gboolean session_request_proceed(gpointer data)
+static gboolean session_queue_complete(gpointer data)
{
struct obc_session *session = data;
- struct pending_request *p = session->p;
- struct obc_transfer *transfer = p->transfer;
- if (p->auth_complete)
- p->auth_complete(p->session, transfer);
+ session_process_queue(session);
- return FALSE;
-}
+ session->queue_complete_id = 0;
-static int pending_request_auth(struct pending_request *p)
-{
- g_idle_add(session_request_proceed, p->session);
- return 0;
+ return FALSE;
}
guint obc_session_queue(struct obc_session *session,
@@ -653,7 +647,6 @@ guint obc_session_queue(struct obc_session *session,
GError **err)
{
struct pending_request *p;
- int perr;
if (session->obex == NULL) {
obc_transfer_unregister(transfer);
@@ -670,21 +663,12 @@ guint obc_session_queue(struct obc_session *session,
obc_transfer_set_callback(transfer, transfer_complete, session);
- p = pending_request_new(session, transfer, session_start_transfer,
- func, user_data);
- if (session->p) {
- g_queue_push_tail(session->queue, p);
- return p->id;
- }
-
- perr = pending_request_auth(p);
- if (perr < 0) {
- g_set_error(err, OBEX_IO_ERROR, perr, "Authorization failed");
- pending_request_free(p);
- return 0;
- }
+ p = pending_request_new(session, transfer, func, user_data);
+ g_queue_push_tail(session->queue, p);
- session->p = p;
+ if (session->queue_complete_id == 0)
+ session->queue_complete_id = g_idle_add(
+ session_queue_complete, session);
return p->id;
}
@@ -702,22 +686,19 @@ static void session_process_queue(struct obc_session *session)
obc_session_ref(session);
while ((p = g_queue_pop_head(session->queue))) {
- int err;
+ GError *gerr = NULL;
+
+ DBG("Transfer(%p) started", p->transfer);
- err = pending_request_auth(p);
- if (err == 0) {
+ if (obc_transfer_start(p->transfer, session->obex, &gerr)) {
session->p = p;
break;
}
- if (p->func) {
- GError *gerr = NULL;
-
- g_set_error(&gerr, OBEX_IO_ERROR, err,
- "Authorization failed");
+ if (p->func)
p->func(session, p->transfer, gerr, p->data);
- g_error_free(gerr);
- }
+
+ g_clear_error(&gerr);
pending_request_free(p);
}
@@ -801,21 +782,6 @@ fail:
session_notify_error(session, transfer, err);
}
-static void session_start_transfer(gpointer data, gpointer user_data)
-{
- struct obc_session *session = data;
- struct obc_transfer *transfer = user_data;
- GError *err = NULL;
-
- if (!obc_transfer_start(transfer, session->obex, &err)) {
- session_notify_error(session, transfer, err);
- g_clear_error(&err);
- return;
- }
-
- DBG("Transfer(%p) started", transfer);
-}
-
const char *obc_session_register(struct obc_session *session,
GDBusDestroyFunction destroy)
{
@@ -950,7 +916,7 @@ guint obc_session_setpath(struct obc_session *session, const char *path,
data->user_data = user_data;
data->remaining = g_strsplit(path, "/", 3);
- p = pending_request_new(session, NULL, NULL, setpath_complete, data);
+ p = pending_request_new(session, NULL, setpath_complete, data);
/* Relative path */
if (path[0] != '/') {
@@ -1025,7 +991,7 @@ guint obc_session_mkdir(struct obc_session *session, const char *folder,
}
- p = pending_request_new(session, NULL, NULL, func, user_data);
+ p = pending_request_new(session, NULL, func, user_data);
p->req_id = g_obex_mkdir(session->obex, folder, async_cb, p, err);
if (*err != NULL) {
@@ -1054,7 +1020,7 @@ guint obc_session_copy(struct obc_session *session, const char *srcname,
return 0;
}
- p = pending_request_new(session, NULL, NULL, func, user_data);
+ p = pending_request_new(session, NULL, func, user_data);
p->req_id = g_obex_copy(session->obex, srcname, destname, async_cb, p,
err);
@@ -1084,7 +1050,7 @@ guint obc_session_move(struct obc_session *session, const char *srcname,
return 0;
}
- p = pending_request_new(session, NULL, NULL, func, user_data);
+ p = pending_request_new(session, NULL, func, user_data);
p->req_id = g_obex_move(session->obex, srcname, destname, async_cb, p,
err);
@@ -1114,7 +1080,7 @@ guint obc_session_delete(struct obc_session *session, const char *file,
return 0;
}
- p = pending_request_new(session, NULL, NULL, func, user_data);
+ p = pending_request_new(session, NULL, func, user_data);
p->req_id = g_obex_delete(session->obex, file, async_cb, p, err);
if (*err != NULL) {
--
1.7.7.6
From: Mikel Astiz <[email protected]>
The request confirmation from the agent is not really useful and the
rest of the reporting is already reported by the transfer's signal-
reporting.
The main benefit of this is that the API is simpler and the client apps
do not have to register the agent, and can just listen to the relevant
signals.
---
doc/client-api.txt | 52 ----------------------------------------------------
1 files changed, 0 insertions(+), 52 deletions(-)
diff --git a/doc/client-api.txt b/doc/client-api.txt
index 527df05..656c492 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -46,15 +46,6 @@ Methods dict GetProperties()
Returns all properties for the session.
- void AssignAgent(object agent)
-
- Assign an OBEX agent to this session. This allows
- detailed progress reports about the transactions.
-
- void ReleaseAgent(object agent)
-
- Release a previously assigned OBEX agent.
-
string GetCapabilities()
Get remote device capabilities.
@@ -330,46 +321,3 @@ Signals PropertyChanged(string name, variant value)
Informs that the transfer has been terminated because
of some error.
-
-Agent hierarchy
-===============
-
-Service unique name
-Interface org.openobex.Agent
-Object path freely definable
-
-Methods void Release()
-
- This method gets called when the service daemon
- unregisters the agent. An agent can use it to do
- cleanup tasks. There is no need to unregister the
- agent, because when this method gets called it has
- already been unregistered.
-
- string Request(object transfer)
-
- Accept or reject a new transfer (client and server)
- and provide the filename for it.
-
- In case of incoming transfers it is the filename
- where to store the file and for outgoing transfers
- it is the filename to show the remote device. If left
- empty it will be calculated automatically.
-
- Possible errors: org.openobex.Error.Rejected
- org.openobex.Error.Canceled
-
- void Progress(object transfer, uint64 transferred)
-
- Progress within the transfer has been made. The
- number of transferred bytes is given as second
- argument for convenience.
-
- void Complete(object transfer)
-
- Informs that the transfer has completed successfully.
-
- void Error(object transfer, string message)
-
- Informs that the transfer has been terminated because
- of some error.
--
1.7.7.6
From: Mikel Astiz <[email protected]>
After the removal of the agent these functions are not useful any more.
---
client/transfer.c | 23 -----------------------
client/transfer.h | 3 ---
2 files changed, 0 insertions(+), 26 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index ab9f84a..f631843 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -730,29 +730,6 @@ int obc_transfer_get_contents(struct obc_transfer *transfer, char **contents,
return 0;
}
-void obc_transfer_set_name(struct obc_transfer *transfer, const char *name)
-{
- g_free(transfer->name);
- transfer->name = g_strdup(name);
-}
-
-int obc_transfer_set_filename(struct obc_transfer *transfer,
- const char *filename)
-{
- int err;
-
- err = rename(transfer->filename, filename);
- if (err < 0) {
- error("rename(): %s (%d)", strerror(errno), errno);
- return -errno;
- }
-
- g_free(transfer->filename);
- transfer->filename = g_strdup(filename);
-
- return 0;
-}
-
const char *obc_transfer_get_path(struct obc_transfer *transfer)
{
return transfer->path;
diff --git a/client/transfer.h b/client/transfer.h
index a65a2ed..bfa166d 100644
--- a/client/transfer.h
+++ b/client/transfer.h
@@ -56,8 +56,5 @@ const void *obc_transfer_get_params(struct obc_transfer *transfer,
int obc_transfer_get_contents(struct obc_transfer *transfer, char **contents,
size_t *size);
-void obc_transfer_set_name(struct obc_transfer *transfer, const char *name);
-int obc_transfer_set_filename(struct obc_transfer *transfer,
- const char *filename);
const char *obc_transfer_get_path(struct obc_transfer *transfer);
gint64 obc_transfer_get_size(struct obc_transfer *transfer);
--
1.7.7.6
From: Mikel Astiz <[email protected]>
This property exposes the number of bytes transferred so far in a given
transfer.
---
doc/client-api.txt | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/doc/client-api.txt b/doc/client-api.txt
index cfb4ec9..cc25543 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -312,6 +312,16 @@ Properties string Name [readonly]
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.
+
+Signals PropertyChanged(string name, variant value)
+
+ This signal indicates a changed value of the given
+ property.
+
Agent hierarchy
===============
--
1.7.7.6
From: Mikel Astiz <[email protected]>
These signals replace the old agent-based notification mechanism.
---
doc/client-api.txt | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/doc/client-api.txt b/doc/client-api.txt
index cc25543..527df05 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -322,6 +322,15 @@ Signals PropertyChanged(string name, variant value)
This signal indicates a changed value of the given
property.
+ void Complete()
+
+ Informs that the transfer has completed successfully.
+
+ void Error(string message)
+
+ Informs that the transfer has been terminated because
+ of some error.
+
Agent hierarchy
===============
--
1.7.7.6
From: Mikel Astiz <[email protected]>
No functionality changes. This is just about avoiding duplicated code.
---
Makefile.am | 1 +
client/dbus.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++
client/dbus.h | 66 ++++++++++++++
client/ftp.c | 42 ++--------
client/session.c | 42 +--------
client/transfer.c | 42 +--------
6 files changed, 339 insertions(+), 110 deletions(-)
create mode 100644 client/dbus.c
create mode 100644 client/dbus.h
diff --git a/Makefile.am b/Makefile.am
index 3cde6c0..86f9ad1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -126,6 +126,7 @@ client_obex_client_SOURCES = $(gdbus_sources) $(gobex_sources) \
client/transfer.h client/transfer.c \
client/agent.h client/agent.c \
client/transport.h client/transport.c \
+ client/dbus.h client/dbus.c \
client/driver.h client/driver.c \
src/map_ap.h src/map_ap.c
diff --git a/client/dbus.c b/client/dbus.c
new file mode 100644
index 0000000..c8f86f8
--- /dev/null
+++ b/client/dbus.c
@@ -0,0 +1,256 @@
+/*
+ *
+ * OBEX Client
+ *
+ * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "log.h"
+#include "dbus.h"
+
+static void append_variant(DBusMessageIter *iter,
+ int type, void *value)
+{
+ char sig[2];
+ DBusMessageIter valueiter;
+
+ sig[0] = type;
+ sig[1] = 0;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+ sig, &valueiter);
+
+ dbus_message_iter_append_basic(&valueiter, type, value);
+
+ dbus_message_iter_close_container(iter, &valueiter);
+}
+
+void obex_dbus_dict_append(DBusMessageIter *dict,
+ const char *key, int type, void *value)
+{
+ DBusMessageIter keyiter;
+
+ if (type == DBUS_TYPE_STRING) {
+ const char *str = *((const char **) value);
+ if (str == NULL)
+ return;
+ }
+
+ dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+ NULL, &keyiter);
+
+ dbus_message_iter_append_basic(&keyiter, DBUS_TYPE_STRING, &key);
+
+ append_variant(&keyiter, type, value);
+
+ dbus_message_iter_close_container(dict, &keyiter);
+}
+
+static void append_array_variant(DBusMessageIter *iter, int type, void *val)
+{
+ DBusMessageIter variant, array;
+ char typesig[2];
+ char arraysig[3];
+ const char **str_array = *(const char ***) val;
+ int i;
+
+ arraysig[0] = DBUS_TYPE_ARRAY;
+ arraysig[1] = typesig[0] = type;
+ arraysig[2] = typesig[1] = '\0';
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+ arraysig, &variant);
+
+ dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+ typesig, &array);
+
+ for (i = 0; str_array[i]; i++)
+ dbus_message_iter_append_basic(&array, type,
+ &(str_array[i]));
+
+ dbus_message_iter_close_container(&variant, &array);
+
+ dbus_message_iter_close_container(iter, &variant);
+}
+
+void obex_dbus_dict_append_array(DBusMessageIter *dict, const char *key,
+ int type, void *val)
+{
+ DBusMessageIter entry;
+
+ dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+ append_array_variant(&entry, type, val);
+
+ dbus_message_iter_close_container(dict, &entry);
+}
+
+static void append_dict_variant(DBusMessageIter *iter, int type, void *val)
+{
+ DBusMessageIter variant, array, entry;
+ char typesig[5];
+ char arraysig[6];
+ const void **val_array = *(const void ***) val;
+ int i;
+
+ arraysig[0] = DBUS_TYPE_ARRAY;
+ arraysig[1] = typesig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR;
+ arraysig[2] = typesig[1] = DBUS_TYPE_STRING;
+ arraysig[3] = typesig[2] = type;
+ arraysig[4] = typesig[3] = DBUS_DICT_ENTRY_END_CHAR;
+ arraysig[5] = typesig[4] = '\0';
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+ arraysig, &variant);
+
+ dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+ typesig, &array);
+
+ for (i = 0; val_array[i]; i += 2) {
+ dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING,
+ &(val_array[i + 0]));
+
+ /*
+ * D-Bus expects a char** or uint8* depending on the type
+ * given. Since we are dealing with an array through a void**
+ * (and thus val_array[i] is a pointer) we need to
+ * differentiate DBUS_TYPE_STRING from the others. The other
+ * option would be the user to pass the exact type to this
+ * function, instead of a pointer to it. However in this case
+ * a cast from type to void* would be needed, which is not
+ * good.
+ */
+ if (type == DBUS_TYPE_STRING) {
+ dbus_message_iter_append_basic(&entry, type,
+ &(val_array[i + 1]));
+ } else {
+ dbus_message_iter_append_basic(&entry, type,
+ val_array[i + 1]);
+ }
+
+ dbus_message_iter_close_container(&array, &entry);
+ }
+
+ dbus_message_iter_close_container(&variant, &array);
+
+ dbus_message_iter_close_container(iter, &variant);
+}
+
+void obex_dbus_dict_append_dict(DBusMessageIter *dict, const char *key,
+ int type, void *val)
+{
+ DBusMessageIter entry;
+
+ dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+ append_dict_variant(&entry, type, val);
+
+ dbus_message_iter_close_container(dict, &entry);
+}
+
+int obex_dbus_signal_property_changed(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name,
+ int type, void *value)
+{
+ DBusMessage *signal;
+ DBusMessageIter iter;
+
+ signal = dbus_message_new_signal(path, interface, "PropertyChanged");
+ if (signal == NULL) {
+ error("Unable to allocate new %s.PropertyChanged signal",
+ interface);
+ return -1;
+ }
+
+ dbus_message_iter_init_append(signal, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+ append_variant(&iter, type, value);
+
+ return g_dbus_send_message(conn, signal);
+}
+
+int obex_dbus_signal_array_property_changed(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name,
+ int type, void *value)
+
+{
+ DBusMessage *signal;
+ DBusMessageIter iter;
+
+ signal = dbus_message_new_signal(path, interface, "PropertyChanged");
+ if (signal == NULL) {
+ error("Unable to allocate new %s.PropertyChanged signal",
+ interface);
+ return -1;
+ }
+
+ dbus_message_iter_init_append(signal, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+ append_array_variant(&iter, type, value);
+
+ return g_dbus_send_message(conn, signal);
+}
+
+int obex_dbus_signal_dict_property_changed(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name,
+ int type, void *value)
+
+{
+ DBusMessage *signal;
+ DBusMessageIter iter;
+
+ signal = dbus_message_new_signal(path, interface, "PropertyChanged");
+ if (signal == NULL) {
+ error("Unable to allocate new %s.PropertyChanged signal",
+ interface);
+ return -1;
+ }
+
+ dbus_message_iter_init_append(signal, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+ append_dict_variant(&iter, type, value);
+
+ return g_dbus_send_message(conn, signal);
+}
diff --git a/client/dbus.h b/client/dbus.h
new file mode 100644
index 0000000..d861c1a
--- /dev/null
+++ b/client/dbus.h
@@ -0,0 +1,66 @@
+/*
+ *
+ * OBEX Client
+ *
+ * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __OBEX_DBUS_H
+#define __OBEX_DBUS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <dbus/dbus.h>
+
+/* Essentially a{sv} */
+#define OBC_PROPERTIES_ARRAY_SIGNATURE DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING \
+ DBUS_TYPE_STRING_AS_STRING \
+ DBUS_TYPE_VARIANT_AS_STRING \
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+
+void obex_dbus_dict_append(DBusMessageIter *dict, const char *key, int type,
+ void *value);
+
+void obex_dbus_dict_append_array(DBusMessageIter *dict, const char *key,
+ int type, void *val);
+
+void obex_dbus_dict_append_dict(DBusMessageIter *dict, const char *key,
+ int type, void *val);
+
+int obex_dbus_signal_property_changed(DBusConnection *conn, const char *path,
+ const char *interface, const char *name,
+ int type, void *value);
+
+int obex_dbus_signal_array_property_changed(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name, int type,
+ void *value);
+
+int obex_dbus_signal_dict_property_changed(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name, int type,
+ void *value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OBEX_DBUS_H */
diff --git a/client/ftp.c b/client/ftp.c
index 8585566..9b2c51d 100644
--- a/client/ftp.c
+++ b/client/ftp.c
@@ -30,6 +30,7 @@
#include <gdbus.h>
+#include "dbus.h"
#include "log.h"
#include "transfer.h"
@@ -95,39 +96,6 @@ static DBusMessage *change_folder(DBusConnection *connection,
return NULL;
}
-static void append_variant(DBusMessageIter *iter, int type, void *val)
-{
- DBusMessageIter value;
- char sig[2] = { type, '\0' };
-
- dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &value);
-
- dbus_message_iter_append_basic(&value, type, val);
-
- dbus_message_iter_close_container(iter, &value);
-}
-
-static void dict_append_entry(DBusMessageIter *dict,
- const char *key, int type, void *val)
-{
- DBusMessageIter entry;
-
- if (type == DBUS_TYPE_STRING) {
- const char *str = *((const char **) val);
- if (str == NULL)
- return;
- }
-
- dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
- NULL, &entry);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
- append_variant(&entry, type, val);
-
- dbus_message_iter_close_container(dict, &entry);
-}
-
static void xml_element(GMarkupParseContext *ctxt,
const gchar *element,
const gchar **names,
@@ -147,7 +115,7 @@ static void xml_element(GMarkupParseContext *ctxt,
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
- dict_append_entry(&dict, "Type", DBUS_TYPE_STRING, &element);
+ obex_dbus_dict_append(&dict, "Type", DBUS_TYPE_STRING, &element);
/* FIXME: User, Group, Other permission must be reviewed */
@@ -157,9 +125,11 @@ static void xml_element(GMarkupParseContext *ctxt,
if (g_str_equal("Size", key) == TRUE) {
guint64 size;
size = g_ascii_strtoll(values[i], NULL, 10);
- dict_append_entry(&dict, key, DBUS_TYPE_UINT64, &size);
+ obex_dbus_dict_append(&dict, key, DBUS_TYPE_UINT64,
+ &size);
} else
- dict_append_entry(&dict, key, DBUS_TYPE_STRING, &values[i]);
+ obex_dbus_dict_append(&dict, key, DBUS_TYPE_STRING,
+ &values[i]);
}
dbus_message_iter_close_container(iter, &dict);
diff --git a/client/session.c b/client/session.c
index 1c5e452..94256b4 100644
--- a/client/session.c
+++ b/client/session.c
@@ -37,6 +37,7 @@
#include <gdbus.h>
#include <gobex.h>
+#include "dbus.h"
#include "log.h"
#include "transfer.h"
#include "session.h"
@@ -582,40 +583,6 @@ static DBusMessage *release_agent(DBusConnection *connection,
return dbus_message_new_method_return(message);
}
-static void append_entry(DBusMessageIter *dict,
- const char *key, int type, void *val)
-{
- DBusMessageIter entry, value;
- const char *signature;
-
- dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
- NULL, &entry);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
- switch (type) {
- case DBUS_TYPE_STRING:
- signature = DBUS_TYPE_STRING_AS_STRING;
- break;
- case DBUS_TYPE_BYTE:
- signature = DBUS_TYPE_BYTE_AS_STRING;
- break;
- case DBUS_TYPE_UINT64:
- signature = DBUS_TYPE_UINT64_AS_STRING;
- break;
- default:
- signature = DBUS_TYPE_VARIANT_AS_STRING;
- break;
- }
-
- dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
- signature, &value);
- dbus_message_iter_append_basic(&value, type, val);
- dbus_message_iter_close_container(&entry, &value);
-
- dbus_message_iter_close_container(dict, &entry);
-}
-
static DBusMessage *session_get_properties(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -635,13 +602,14 @@ static DBusMessage *session_get_properties(DBusConnection *connection,
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
if (session->source != NULL)
- append_entry(&dict, "Source", DBUS_TYPE_STRING,
+ obex_dbus_dict_append(&dict, "Source", DBUS_TYPE_STRING,
&session->source);
- append_entry(&dict, "Destination", DBUS_TYPE_STRING,
+ obex_dbus_dict_append(&dict, "Destination", DBUS_TYPE_STRING,
&session->destination);
- append_entry(&dict, "Channel", DBUS_TYPE_BYTE, &session->channel);
+ obex_dbus_dict_append(&dict, "Channel", DBUS_TYPE_BYTE,
+ &session->channel);
dbus_message_iter_close_container(&iter, &dict);
diff --git a/client/transfer.c b/client/transfer.c
index 3065c9c..8292265 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -38,6 +38,7 @@
#include <gdbus.h>
#include <gobex.h>
+#include "dbus.h"
#include "log.h"
#include "transfer.h"
@@ -81,40 +82,6 @@ static GQuark obc_transfer_error_quark(void)
return g_quark_from_static_string("obc-transfer-error-quark");
}
-static void append_entry(DBusMessageIter *dict,
- const char *key, int type, void *val)
-{
- DBusMessageIter entry, value;
- const char *signature;
-
- dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
- NULL, &entry);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
- switch (type) {
- case DBUS_TYPE_STRING:
- signature = DBUS_TYPE_STRING_AS_STRING;
- break;
- case DBUS_TYPE_BYTE:
- signature = DBUS_TYPE_BYTE_AS_STRING;
- break;
- case DBUS_TYPE_UINT64:
- signature = DBUS_TYPE_UINT64_AS_STRING;
- break;
- default:
- signature = DBUS_TYPE_VARIANT_AS_STRING;
- break;
- }
-
- dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
- signature, &value);
- dbus_message_iter_append_basic(&value, type, val);
- dbus_message_iter_close_container(&entry, &value);
-
- dbus_message_iter_close_container(dict, &entry);
-}
-
static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -133,9 +100,10 @@ static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
- append_entry(&dict, "Name", DBUS_TYPE_STRING, &transfer->name);
- append_entry(&dict, "Size", DBUS_TYPE_UINT64, &transfer->size);
- append_entry(&dict, "Filename", DBUS_TYPE_STRING, &transfer->filename);
+ obex_dbus_dict_append(&dict, "Name", DBUS_TYPE_STRING, &transfer->name);
+ obex_dbus_dict_append(&dict, "Size", DBUS_TYPE_UINT64, &transfer->size);
+ obex_dbus_dict_append(&dict, "Filename", DBUS_TYPE_STRING,
+ &transfer->filename);
dbus_message_iter_close_container(&iter, &dict);
--
1.7.7.6