From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [PATCH obexd v1 03/16] client: Add progress property to transfer
Date: Fri, 25 May 2012 12:11:20 +0200 [thread overview]
Message-ID: <1337940693-3417-4-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1337940693-3417-1-git-send-email-mikel.astiz.oss@gmail.com>
From: Mikel Astiz <mikel.astiz@bmw-carit.de>
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
next prev parent reply other threads:[~2012-05-25 10:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-25 10:11 [PATCH obexd v1 00/16] client: Remove D-Bus agent Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 01/16] client: Add D-Bus helper library Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 02/16] client-doc: Add progress property to transfer Mikel Astiz
2012-05-25 10:11 ` Mikel Astiz [this message]
2012-05-25 10:15 ` [PATCH obexd v1 03/16] client: " Mikel Astiz
2012-05-25 10:35 ` Luiz Augusto von Dentz
2012-05-25 10:45 ` Mikel Astiz
2012-05-25 10:55 ` Luiz Augusto von Dentz
2012-05-25 11:02 ` Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 04/16] client-doc: Add transfer event-reporting signals Mikel Astiz
2012-05-25 10:50 ` Luiz Augusto von Dentz
2012-05-25 10:57 ` Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 05/16] client: " Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 06/16] client-doc: Remove D-Bus agent Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 07/16] client: Use transfer owner instead of agent Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 08/16] client: Remove D-Bus agent Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 09/16] client: Remove unused functions in transfer API Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 10/16] client: Remove internal transfer progress report Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 11/16] client: Remove obsolete authentication code Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 12/16] client: Make D-Bus exposure of transfers optional Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 13/16] client-doc: Add signal to report new transfers Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 14/16] client: Expose D-Bus data in internal transfer API Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 15/16] client: Add signal to report new transfers Mikel Astiz
2012-05-25 10:11 ` [PATCH obexd v1 16/16] client-test: Remove agent from ftp-client Mikel Astiz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1337940693-3417-4-git-send-email-mikel.astiz.oss@gmail.com \
--to=mikel.astiz.oss@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=mikel.astiz@bmw-carit.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox