public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
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 15/16] client: Add signal to report new transfers
Date: Fri, 25 May 2012 12:11:32 +0200	[thread overview]
Message-ID: <1337940693-3417-16-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>

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


  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 ` [PATCH obexd v1 03/16] client: " Mikel Astiz
2012-05-25 10:15   ` 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 ` Mikel Astiz [this message]
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-16-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