All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH obexd v2 0/4] Add adapter session request/release to obex-client
@ 2011-06-28 21:40 Dmitriy Paliy
  2011-06-28 21:40 ` [PATCH obexd v2 1/4] Add system bus connection in obex-client Dmitriy Paliy
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Dmitriy Paliy @ 2011-06-28 21:40 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

Hi,

Luiz, thanks for the detailed review. However, I'm not sure that
fully understood you. Whole idea was to request session before
transfer and release it afterwards. Therefore, still I would like
to have adapter ReleaseSession.

Please, see subsequent patches if those reflect your comments.

BR,
Dmitriy


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

* [PATCH obexd v2 1/4] Add system bus connection in obex-client
  2011-06-28 21:40 [PATCH obexd v2 0/4] Add adapter session request/release to obex-client Dmitriy Paliy
@ 2011-06-28 21:40 ` Dmitriy Paliy
  2011-06-28 21:40 ` [PATCH obexd v2 2/4] Split up session_create in separate functions Dmitriy Paliy
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Dmitriy Paliy @ 2011-06-28 21:40 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy

Connection to system bus is added in obex-client. Purpose is to carry
out OBEX transfers within a single adapter's session.
---
 client/session.c |    9 +++++++++
 client/session.h |    1 +
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/client/session.c b/client/session.c
index 825bee7..c894526 100644
--- a/client/session.c
+++ b/client/session.c
@@ -200,6 +200,9 @@ static void session_free(struct session_data *session)
 	if (session->conn)
 		dbus_connection_unref(session->conn);
 
+	if (session->conn_system)
+		dbus_connection_unref(session->conn_system);
+
 	sessions = g_slist_remove(sessions, session);
 
 	g_free(session->callback);
@@ -564,6 +567,12 @@ struct session_data *session_create(const char *source,
 		return NULL;
 	}
 
+	session->conn_system = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
+	if (session->conn_system == NULL) {
+		session_free(session);
+		return NULL;
+	}
+
 	if (source == NULL)
 		bacpy(&session->src, BDADDR_ANY);
 	else
diff --git a/client/session.h b/client/session.h
index 6f8a434..554b494 100644
--- a/client/session.h
+++ b/client/session.h
@@ -42,6 +42,7 @@ struct session_data {
 	uuid_t uuid;		/* Bluetooth Service Class */
 	gchar *path;		/* Session path */
 	DBusConnection *conn;
+	DBusConnection *conn_system; /* system bus connection */
 	DBusMessage *msg;
 	GwObex *obex;
 	GIOChannel *io;
-- 
1.7.4.1


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

* [PATCH obexd v2 2/4] Split up session_create in separate functions
  2011-06-28 21:40 [PATCH obexd v2 0/4] Add adapter session request/release to obex-client Dmitriy Paliy
  2011-06-28 21:40 ` [PATCH obexd v2 1/4] Add system bus connection in obex-client Dmitriy Paliy
@ 2011-06-28 21:40 ` Dmitriy Paliy
  2011-06-28 21:40 ` [PATCH obexd v2 3/4] Add handling of system D-Bus method calls Dmitriy Paliy
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Dmitriy Paliy @ 2011-06-28 21:40 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy

Connection of RFCOMM and SDP are extracted from session_create function
into session_connect. Such allows making asynchronous calls before
creating connections.
---
 client/session.c |   41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/client/session.c b/client/session.c
index c894526..e6b95de 100644
--- a/client/session.c
+++ b/client/session.c
@@ -533,6 +533,29 @@ static struct session_data *session_find(const char *source,
 	return NULL;
 }
 
+static int session_connect(struct session_data *session,
+						struct callback_data *callback)
+{
+	int err;
+
+	if (session->obex) {
+		g_idle_add(connection_complete, callback);
+		err = 0;
+	} else if (session->channel > 0) {
+		session->io = rfcomm_connect(&session->src, &session->dst,
+							session->channel,
+							rfcomm_callback,
+							callback);
+		err = (session->io == NULL) ? -EINVAL : 0;
+	} else {
+		callback->sdp = service_connect(&session->src, &session->dst,
+						service_callback, callback);
+		err = (callback->sdp == NULL) ? -ENOMEM : 0;
+	}
+
+	return err;
+}
+
 struct session_data *session_create(const char *source,
 						const char *destination,
 						const char *service,
@@ -543,7 +566,6 @@ struct session_data *session_create(const char *source,
 {
 	struct session_data *session;
 	struct callback_data *callback;
-	int err;
 
 	if (destination == NULL)
 		return NULL;
@@ -612,22 +634,7 @@ proceed:
 	callback->func = function;
 	callback->data = user_data;
 
-	if (session->obex) {
-		g_idle_add(connection_complete, callback);
-		err = 0;
-	} else if (session->channel > 0) {
-		session->io = rfcomm_connect(&session->src, &session->dst,
-							session->channel,
-							rfcomm_callback,
-							callback);
-		err = (session->io == NULL) ? -EINVAL : 0;
-	} else {
-		callback->sdp = service_connect(&session->src, &session->dst,
-						service_callback, callback);
-		err = (callback->sdp == NULL) ? -ENOMEM : 0;
-	}
-
-	if (err < 0) {
+	if (session_connect(session, callback) < 0) {
 		session_unref(session);
 		g_free(callback);
 		return NULL;
-- 
1.7.4.1


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

* [PATCH obexd v2 3/4] Add handling of system D-Bus method calls
  2011-06-28 21:40 [PATCH obexd v2 0/4] Add adapter session request/release to obex-client Dmitriy Paliy
  2011-06-28 21:40 ` [PATCH obexd v2 1/4] Add system bus connection in obex-client Dmitriy Paliy
  2011-06-28 21:40 ` [PATCH obexd v2 2/4] Split up session_create in separate functions Dmitriy Paliy
@ 2011-06-28 21:40 ` Dmitriy Paliy
  2011-07-13  8:31   ` Johan Hedberg
  2011-06-28 21:40 ` [PATCH obexd v2 4/4] Add adapter ReleaseSession to obex-client Dmitriy Paliy
  2011-06-29  6:32 ` [PATCH obexd v2 0/4] Add adapter session request/release " Luiz Augusto von Dentz
  4 siblings, 1 reply; 7+ messages in thread
From: Dmitriy Paliy @ 2011-06-28 21:40 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy

Sending system D-Bus method calls (DefaultAdapter, FindAdapter
and RequestSession) and handling of pending D-Bus calls is added
to obex-client.
---
 client/session.c |  196 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 client/session.h |    2 +
 2 files changed, 197 insertions(+), 1 deletions(-)

diff --git a/client/session.c b/client/session.c
index e6b95de..4b8cf09 100644
--- a/client/session.c
+++ b/client/session.c
@@ -56,6 +56,11 @@
 
 #define OBEX_IO_ERROR obex_io_error_quark()
 
+#define BT_BUS_NAME		"org.bluez"
+#define BT_PATH			"/"
+#define BT_ADAPTER_IFACE	"org.bluez.Adapter"
+#define BT_MANAGER_IFACE	"org.bluez.Manager"
+
 static guint64 counter = 0;
 
 static unsigned char pcsuite_uuid[] = { 0x00, 0x00, 0x50, 0x05, 0x00, 0x00,
@@ -87,6 +92,11 @@ struct agent_data {
 	struct pending_data *pending;
 };
 
+struct pending_req {
+	DBusPendingCall *call;
+	void *user_data;
+};
+
 static GSList *sessions = NULL;
 
 static void session_prepare_put(struct session_data *session, GError *err,
@@ -176,10 +186,44 @@ static void session_unregistered(struct session_data *session)
 	session->path = NULL;
 }
 
+struct pending_req *find_session_request(const struct session_data *session,
+				const DBusPendingCall *call)
+{
+	GSList *l;
+
+	for (l = session->pending_calls; l; l = l->next) {
+		struct pending_req *req = l->data;
+
+		if (req->call == call)
+			return req;
+	}
+
+	return NULL;
+}
+
+static void pending_req_finalize(struct pending_req *req)
+{
+	if (!dbus_pending_call_get_completed(req->call))
+		dbus_pending_call_cancel(req->call);
+
+	dbus_pending_call_unref(req->call);
+	g_free(req);
+}
+
 static void session_free(struct session_data *session)
 {
+	GSList *l = session->pending_calls;
+
 	DBG("%p", session);
 
+	while (l) {
+		struct pending_req *req = l->data;
+		l = l->next;
+
+		session->pending_calls = g_slist_remove(session->pending_calls, req);
+		pending_req_finalize(req);
+	}
+
 	if (session->agent)
 		agent_release(session);
 
@@ -205,6 +249,7 @@ static void session_free(struct session_data *session)
 
 	sessions = g_slist_remove(sessions, session);
 
+	g_free(session->adapter);
 	g_free(session->callback);
 	g_free(session->path);
 	g_free(session->service);
@@ -212,6 +257,50 @@ static void session_free(struct session_data *session)
 	g_free(session);
 }
 
+static struct pending_req *send_method_call(DBusConnection *connection,
+				const char *dest, const char *path,
+				const char *interface, const char *method,
+				DBusPendingCallNotifyFunction cb,
+				void *user_data, int type, ...)
+{
+	DBusMessage *msg;
+	DBusPendingCall *call;
+	va_list args;
+	struct pending_req *req;
+
+	msg = dbus_message_new_method_call(dest, path, interface, method);
+	if (!msg) {
+		error("Unable to allocate new D-Bus %s message", method);
+		return NULL;
+	}
+
+	va_start(args, type);
+
+	if (!dbus_message_append_args_valist(msg, type, args)) {
+		dbus_message_unref(msg);
+		va_end(args);
+		return NULL;
+	}
+
+	va_end(args);
+
+	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+		error("Sending %s failed", method);
+		dbus_message_unref(msg);
+		return NULL;
+	}
+
+	dbus_pending_call_set_notify(call, cb, user_data, NULL);
+
+	req = g_new0(struct pending_req, 1);
+	req->call = call;
+	req->user_data = user_data;
+
+	dbus_message_unref(msg);
+
+	return req;
+}
+
 void session_unref(struct session_data *session)
 {
 	gboolean ret;
@@ -556,6 +645,93 @@ static int session_connect(struct session_data *session,
 	return err;
 }
 
+static void adapter_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusError err;
+	DBusMessage *reply;
+	struct callback_data *callback = user_data;
+	struct session_data *session = callback->session;
+	struct pending_req *req = find_session_request(session, call);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	session->pending_calls = g_slist_remove(session->pending_calls, req);
+	pending_req_finalize(req);
+
+	dbus_error_init(&err);
+	if (dbus_set_error_from_message(&err, reply)) {
+		error("manager replied with an error: %s, %s",
+				err.name, err.message);
+		dbus_error_free(&err);
+
+		goto failed;
+	}
+
+	if (session_connect(session, callback) < 0)
+		goto failed;
+
+	goto proceed;
+
+failed:
+	session_unref(session);
+	g_free(callback);
+
+proceed:
+	dbus_message_unref(reply);
+}
+
+static void manager_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusError err;
+	DBusMessage *reply;
+	char *adapter;
+	struct callback_data *callback = user_data;
+	struct session_data *session = callback->session;
+	struct pending_req *req = find_session_request(session, call);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	session->pending_calls = g_slist_remove(session->pending_calls, req);
+	pending_req_finalize(req);
+
+	dbus_error_init(&err);
+	if (dbus_set_error_from_message(&err, reply)) {
+		error("manager replied with an error: %s, %s",
+				err.name, err.message);
+		dbus_error_free(&err);
+
+		goto failed;
+	}
+
+	if (dbus_message_get_args(reply, NULL,
+				DBUS_TYPE_OBJECT_PATH, &adapter,
+				DBUS_TYPE_INVALID)) {
+		DBG("adapter path %s", adapter);
+
+		session->adapter = g_strdup(adapter);
+		req = send_method_call(session->conn_system,
+					BT_BUS_NAME, adapter,
+					BT_ADAPTER_IFACE, "RequestSession",
+					adapter_reply, callback,
+					DBUS_TYPE_INVALID);
+		if (!req)
+			goto failed;
+
+		session->pending_calls = g_slist_prepend(session->pending_calls,
+									req);
+	} else
+		goto failed;
+
+	goto proceed;
+
+failed:
+	session_unref(session);
+	g_free(callback);
+
+proceed:
+	dbus_message_unref(reply);
+}
+
 struct session_data *session_create(const char *source,
 						const char *destination,
 						const char *service,
@@ -566,6 +742,7 @@ struct session_data *session_create(const char *source,
 {
 	struct session_data *session;
 	struct callback_data *callback;
+	struct pending_req *req;
 
 	if (destination == NULL)
 		return NULL;
@@ -634,12 +811,29 @@ proceed:
 	callback->func = function;
 	callback->data = user_data;
 
-	if (session_connect(session, callback) < 0) {
+	if (source) {
+		req = send_method_call(session->conn_system,
+				BT_BUS_NAME, BT_PATH,
+				BT_MANAGER_IFACE, "FindAdapter",
+				manager_reply, callback,
+				DBUS_TYPE_STRING, &source,
+				DBUS_TYPE_INVALID);
+	} else {
+		req = send_method_call(session->conn_system,
+				BT_BUS_NAME, BT_PATH,
+				BT_MANAGER_IFACE, "DefaultAdapter",
+				manager_reply, callback,
+				DBUS_TYPE_INVALID);
+	}
+
+	if (!req) {
 		session_unref(session);
 		g_free(callback);
 		return NULL;
 	}
 
+	session->pending_calls = g_slist_prepend(session->pending_calls, req);
+
 	if (owner)
 		session_set_owner(session, owner, owner_disconnected);
 
diff --git a/client/session.h b/client/session.h
index 554b494..39f5742 100644
--- a/client/session.h
+++ b/client/session.h
@@ -51,7 +51,9 @@ struct session_data {
 	gchar *owner;		/* Session owner */
 	guint watch;
 	GSList *pending;
+	GSList *pending_calls;
 	void *priv;
+	char *adapter;
 };
 
 typedef void (*session_callback_t) (struct session_data *session,
-- 
1.7.4.1


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

* [PATCH obexd v2 4/4] Add adapter ReleaseSession to obex-client
  2011-06-28 21:40 [PATCH obexd v2 0/4] Add adapter session request/release to obex-client Dmitriy Paliy
                   ` (2 preceding siblings ...)
  2011-06-28 21:40 ` [PATCH obexd v2 3/4] Add handling of system D-Bus method calls Dmitriy Paliy
@ 2011-06-28 21:40 ` Dmitriy Paliy
  2011-06-29  6:32 ` [PATCH obexd v2 0/4] Add adapter session request/release " Luiz Augusto von Dentz
  4 siblings, 0 replies; 7+ messages in thread
From: Dmitriy Paliy @ 2011-06-28 21:40 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy

Release of adapter session is added to obex-client when closing OBEX
transfer.
---
 client/session.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/client/session.c b/client/session.c
index 4b8cf09..a2a3b2d 100644
--- a/client/session.c
+++ b/client/session.c
@@ -284,6 +284,11 @@ static struct pending_req *send_method_call(DBusConnection *connection,
 
 	va_end(args);
 
+	if (!cb) {
+		g_dbus_send_message(connection, msg);
+		return 0;
+	}
+
 	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
 		error("Sending %s failed", method);
 		dbus_message_unref(msg);
@@ -312,6 +317,11 @@ void session_unref(struct session_data *session)
 	if (ret == FALSE)
 		return;
 
+	send_method_call(session->conn_system,
+				BT_BUS_NAME, session->adapter,
+				BT_ADAPTER_IFACE, "ReleaseSession",
+				NULL, NULL,
+				DBUS_TYPE_INVALID);
 	session_free(session);
 }
 
-- 
1.7.4.1


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

* Re: [PATCH obexd v2 0/4] Add adapter session request/release to obex-client
  2011-06-28 21:40 [PATCH obexd v2 0/4] Add adapter session request/release to obex-client Dmitriy Paliy
                   ` (3 preceding siblings ...)
  2011-06-28 21:40 ` [PATCH obexd v2 4/4] Add adapter ReleaseSession to obex-client Dmitriy Paliy
@ 2011-06-29  6:32 ` Luiz Augusto von Dentz
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-06-29  6:32 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth

Hi Dmitriy,

On Wed, Jun 29, 2011 at 12:40 AM, Dmitriy Paliy <dmitriy.paliy@gmail.com> wrote:
> Hi,
>
> Luiz, thanks for the detailed review. However, I'm not sure that
> fully understood you. Whole idea was to request session before
> transfer and release it afterwards. Therefore, still I would like
> to have adapter ReleaseSession.
>
> Please, see subsequent patches if those reflect your comments.

Looks good.

-- 
Luiz Augusto von Dentz

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

* Re: [PATCH obexd v2 3/4] Add handling of system D-Bus method calls
  2011-06-28 21:40 ` [PATCH obexd v2 3/4] Add handling of system D-Bus method calls Dmitriy Paliy
@ 2011-07-13  8:31   ` Johan Hedberg
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2011-07-13  8:31 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth, luiz.dentz, Dmitriy Paliy

Hi Dmitriy,

On Wed, Jun 29, 2011, Dmitriy Paliy wrote:
> Sending system D-Bus method calls (DefaultAdapter, FindAdapter
> and RequestSession) and handling of pending D-Bus calls is added
> to obex-client.
> ---
>  client/session.c |  196 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  client/session.h |    2 +
>  2 files changed, 197 insertions(+), 1 deletions(-)

I've applied the first two patches but this third one doesn't compile:

client/session.c:189:21: error: no previous declaration for ‘find_session_request’ [-Werror=missing-declarations]

Please fix and resend.

Johan

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

end of thread, other threads:[~2011-07-13  8:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-28 21:40 [PATCH obexd v2 0/4] Add adapter session request/release to obex-client Dmitriy Paliy
2011-06-28 21:40 ` [PATCH obexd v2 1/4] Add system bus connection in obex-client Dmitriy Paliy
2011-06-28 21:40 ` [PATCH obexd v2 2/4] Split up session_create in separate functions Dmitriy Paliy
2011-06-28 21:40 ` [PATCH obexd v2 3/4] Add handling of system D-Bus method calls Dmitriy Paliy
2011-07-13  8:31   ` Johan Hedberg
2011-06-28 21:40 ` [PATCH obexd v2 4/4] Add adapter ReleaseSession to obex-client Dmitriy Paliy
2011-06-29  6:32 ` [PATCH obexd v2 0/4] Add adapter session request/release " Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.