Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/8] obexd/transfer: Add Transfer.Suspend method
@ 2014-02-14 15:52 Luiz Augusto von Dentz
  2014-02-14 15:52 ` [PATCH BlueZ 2/8] obexd/transfer: Add Transfer.Resume method Luiz Augusto von Dentz
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-14 15:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: patrick.ohly

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This method can be used to suspend ongoing transfers.
---
 obexd/client/transfer.c | 60 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/obexd/client/transfer.c b/obexd/client/transfer.c
index 5a8d4f2..813d20b 100644
--- a/obexd/client/transfer.c
+++ b/obexd/client/transfer.c
@@ -60,6 +60,7 @@ struct transfer_callback {
 enum {
 	TRANSFER_STATUS_QUEUED = 0,
 	TRANSFER_STATUS_ACTIVE,
+	TRANSFER_STATUS_SUSPENDED,
 	TRANSFER_STATUS_COMPLETE,
 	TRANSFER_STATUS_ERROR
 };
@@ -187,6 +188,41 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
 	return NULL;
 }
 
+static void transfer_set_status(struct obc_transfer *transfer, uint8_t status)
+{
+	if (transfer->status == status)
+		return;
+
+	transfer->status = status;
+
+	g_dbus_emit_property_changed(transfer->conn, transfer->path,
+					TRANSFER_INTERFACE, "Status");
+}
+
+static DBusMessage *obc_transfer_suspend(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct obc_transfer *transfer = user_data;
+	const char *sender;
+
+	sender = dbus_message_get_sender(message);
+	if (g_strcmp0(transfer->owner, sender) != 0)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".NotAuthorized",
+				"Not Authorized");
+
+	if (transfer->xfer == 0)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".NotInProgress",
+				"Not in progress");
+
+	g_obex_suspend(transfer->obex);
+
+	transfer_set_status(transfer, TRANSFER_STATUS_SUSPENDED);
+
+	return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
+}
+
 static gboolean name_exists(const GDBusPropertyTable *property, void *data)
 {
 	struct obc_transfer *transfer = data;
@@ -269,6 +305,8 @@ static const char *status2str(uint8_t status)
 		return "queued";
 	case TRANSFER_STATUS_ACTIVE:
 		return "active";
+	case TRANSFER_STATUS_SUSPENDED:
+		return "suspended";
 	case TRANSFER_STATUS_COMPLETE:
 		return "complete";
 	case TRANSFER_STATUS_ERROR:
@@ -300,6 +338,7 @@ static gboolean get_session(const GDBusPropertyTable *property,
 }
 
 static const GDBusMethodTable obc_transfer_methods[] = {
+	{ GDBUS_METHOD("Suspend", NULL, NULL, obc_transfer_suspend) },
 	{ GDBUS_ASYNC_METHOD("Cancel", NULL, NULL,
 				obc_transfer_cancel) },
 	{ }
@@ -549,14 +588,6 @@ static gboolean get_xfer_progress(const void *buf, gsize len,
 	return TRUE;
 }
 
-static void transfer_set_status(struct obc_transfer *transfer, uint8_t status)
-{
-	transfer->status = status;
-
-	g_dbus_emit_property_changed(transfer->conn, transfer->path,
-					TRANSFER_INTERFACE, "Status");
-}
-
 static void xfer_complete(GObex *obex, GError *err, gpointer user_data)
 {
 	struct obc_transfer *transfer = user_data;
@@ -634,13 +665,15 @@ static void get_xfer_progress_first(GObex *obex, GError *err, GObexPacket *rsp,
 		return;
 	}
 
-	if (!g_obex_srm_active(obex)) {
-		req = g_obex_packet_new(G_OBEX_OP_GET, TRUE, G_OBEX_HDR_INVALID);
+	if (g_obex_srm_active(obex) ||
+				transfer->status == TRANSFER_STATUS_SUSPENDED)
+		return;
 
-		transfer->xfer = g_obex_get_req_pkt(obex, req, get_xfer_progress,
+	req = g_obex_packet_new(G_OBEX_OP_GET, TRUE, G_OBEX_HDR_INVALID);
+
+	transfer->xfer = g_obex_get_req_pkt(obex, req, get_xfer_progress,
 						xfer_complete, transfer,
 						&err);
-	}
 }
 
 static gssize put_xfer_progress(void *buf, gsize len, gpointer user_data)
@@ -689,7 +722,8 @@ static gboolean report_progress(gpointer data)
 		return FALSE;
 	}
 
-	if (transfer->status != TRANSFER_STATUS_ACTIVE)
+	if (transfer->status != TRANSFER_STATUS_ACTIVE &&
+				transfer->status != TRANSFER_STATUS_SUSPENDED)
 		transfer_set_status(transfer, TRANSFER_STATUS_ACTIVE);
 
 	g_dbus_emit_property_changed(transfer->conn, transfer->path,
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-02-20 12:09 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-14 15:52 [PATCH BlueZ 1/8] obexd/transfer: Add Transfer.Suspend method Luiz Augusto von Dentz
2014-02-14 15:52 ` [PATCH BlueZ 2/8] obexd/transfer: Add Transfer.Resume method Luiz Augusto von Dentz
2014-02-14 15:52 ` [PATCH BlueZ 3/8] tools/obexctl: Add suspend command Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 4/8] tools/obexctl: Add resume command Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 5/8] unit/test-gobex-transfer: Add /gobex/test_packet_get_req_suspend_resume Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 6/8] gobex: Fix not handling SRM properly Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 7/8] gobex: Handle suspending/resuming for GET when SRM is active Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 8/8] doc/obex-api: Update documentation Luiz Augusto von Dentz
2014-02-17  7:24   ` Andrei Emeltchenko
2014-02-18  9:09   ` Patrick Ohly
2014-02-18  9:30     ` Luiz Augusto von Dentz
2014-02-18 16:54       ` Patrick Ohly
2014-02-19 17:11         ` Luiz Augusto von Dentz
2014-02-20 10:52           ` Patrick Ohly
2014-02-20 12:09             ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox