All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH obexd 04/13 v3] client: introduce obc_session_setpath
Date: Wed,  8 Feb 2012 11:44:00 +0200	[thread overview]
Message-ID: <1328694249-22225-4-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1328694249-22225-1-git-send-email-luiz.dentz@gmail.com>

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

---
Fix using strerror(-errno)

 client/session.c |  150 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 client/session.h |    4 ++
 2 files changed, 148 insertions(+), 6 deletions(-)

diff --git a/client/session.c b/client/session.c
index 482ee20..e946cfd 100644
--- a/client/session.c
+++ b/client/session.c
@@ -46,6 +46,12 @@
 #define SESSION_BASEPATH   "/org/openobex"
 
 #define OBEX_IO_ERROR obex_io_error_quark()
+#define OBEX_IO_ERROR_FIRST (0xff + 1)
+
+enum {
+	OBEX_IO_DISCONNECTED = OBEX_IO_ERROR_FIRST,
+	OBEX_IO_BUSY,
+};
 
 static guint64 counter = 0;
 
@@ -61,6 +67,8 @@ struct session_callback {
 };
 
 struct pending_request {
+	guint id;
+	guint req_id;
 	struct obc_session *session;
 	struct obc_transfer *transfer;
 	GFunc auth_complete;
@@ -68,6 +76,13 @@ struct pending_request {
 	void *data;
 };
 
+struct setpath_data {
+	char **remaining;
+	int index;
+	session_callback_t func;
+	void *user_data;
+};
+
 struct obc_session {
 	guint id;
 	gint refcount;
@@ -124,6 +139,26 @@ static void session_unregistered(struct obc_session *session)
 	g_free(path);
 }
 
+static struct pending_request *pending_request_new(struct obc_session *session,
+						struct obc_transfer *transfer,
+						GFunc auth_complete,
+						session_callback_t func,
+						void *data)
+{
+	struct pending_request *p;
+	static guint id = 0;
+
+	p = g_new0(struct pending_request, 1);
+	p->id = ++id;
+	p->session = obc_session_ref(session);
+	p->transfer = transfer;
+	p->auth_complete = auth_complete;
+	p->func = func;
+	p->data = data;
+
+	return p;
+}
+
 static void pending_request_free(struct pending_request *p)
 {
 	if (p->transfer)
@@ -665,12 +700,7 @@ static int session_request(struct obc_session *session,
 	struct pending_request *p;
 	int err;
 
-	p = g_new0(struct pending_request, 1);
-	p->session = obc_session_ref(session);
-	p->transfer = transfer;
-	p->auth_complete = auth_complete;
-	p->func = func;
-	p->data = data;
+	p = pending_request_new(session, transfer, auth_complete, func, data);
 
 	if (session->p) {
 		g_queue_push_tail(session->queue, p);
@@ -1103,3 +1133,111 @@ void *obc_session_get_params(struct obc_session *session, size_t *size)
 
 	return params.data;
 }
+
+static void setpath_complete(struct obc_session *session, GError *err,
+							void *user_data)
+{
+	struct pending_request *p = user_data;
+	struct setpath_data *data = p->data;
+
+	if (data->func)
+		data->func(session, err, data->user_data);
+
+	g_strfreev(data->remaining);
+	g_free(data);
+
+	if (session->p == p)
+		session->p = NULL;
+
+	pending_request_free(p);
+
+	session_process_queue(session);
+}
+
+static void setpath_cb(GObex *obex, GError *err, GObexPacket *rsp,
+							gpointer user_data)
+{
+	struct pending_request *p = user_data;
+	struct setpath_data *data = p->data;
+	char *next;
+	guint8 code;
+
+	p->req_id = 0;
+
+	if (err != NULL) {
+		setpath_complete(p->session, err, user_data);
+		return;
+	}
+
+	code = g_obex_packet_get_operation(rsp, NULL);
+	if (code != G_OBEX_RSP_SUCCESS) {
+		GError *gerr = NULL;
+		g_set_error(&gerr, OBEX_IO_ERROR, code, "%s",
+							g_obex_strerror(code));
+		setpath_complete(p->session, err, user_data);
+		g_clear_error(&gerr);
+		return;
+	}
+
+	next = data->remaining[data->index];
+	if (next == NULL) {
+		setpath_complete(p->session, NULL, user_data);
+		return;
+	}
+
+	data->index++;
+
+	p->req_id = g_obex_setpath(obex, next, setpath_cb, p, &err);
+	if (err != NULL) {
+		setpath_complete(p->session, err, data);
+		g_error_free(err);
+	}
+}
+
+guint obc_session_setpath(struct obc_session *session, const char *path,
+				session_callback_t func, void *user_data,
+				GError **err)
+{
+	struct setpath_data *data;
+	struct pending_request *p;
+	const char *first = "";
+
+	if (session->obex == NULL) {
+		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_DISCONNECTED,
+						"Session disconnected");
+		return 0;
+	}
+
+	if (session->p != NULL) {
+		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_BUSY,
+							"Session busy");
+		return 0;
+	}
+
+	data = g_new0(struct setpath_data, 1);
+	data->func = func;
+	data->user_data = user_data;
+	data->remaining = g_strsplit(path, "/", 3);
+
+	p = pending_request_new(session, NULL, NULL, setpath_complete, data);
+
+	/* Relative path */
+	if (path[0] != '/') {
+		first = data->remaining[data->index];
+		data->index++;
+	}
+
+	p->req_id = g_obex_setpath(session->obex, first, setpath_cb, p, err);
+	if (*err != NULL)
+		goto fail;
+
+	session->p = p;
+
+	return p->id;
+
+fail:
+	g_strfreev(data->remaining);
+	g_free(data);
+	pending_request_free(p);
+	return 0;
+}
diff --git a/client/session.h b/client/session.h
index 511f084..65cf4bd 100644
--- a/client/session.h
+++ b/client/session.h
@@ -73,3 +73,7 @@ const char *obc_session_register(struct obc_session *session,
 						GDBusDestroyFunction destroy);
 int obc_session_put(struct obc_session *session, char *buf,
 				const char *targetname);
+
+guint obc_session_setpath(struct obc_session *session, const char *path,
+				session_callback_t func, void *user_data,
+				GError **err);
-- 
1.7.7.6


  parent reply	other threads:[~2012-02-08  9:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-08  9:43 [PATCH obexd 01/13 v3] client: fix not checking session_request return Luiz Augusto von Dentz
2012-02-08  9:43 ` [PATCH obexd 02/13 v3] client: remove unused field from obc_session Luiz Augusto von Dentz
2012-02-08  9:43 ` [PATCH obexd 03/13 v3] client: fix not queuing requests properly Luiz Augusto von Dentz
2012-02-08  9:44 ` Luiz Augusto von Dentz [this message]
2012-02-08  9:44 ` [PATCH obexd 05/13 v3] client: introduce obc_session_mkdir Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 06/13 v3] client: introduce obc_session_copy Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 07/13 v3] client: introduce obc_session_move Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 08/13 v3] client: introduce obc_session_delete Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 09/13 v3] client: introduce obc_session_cancel Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 10/13 v3] client: remove use of gobex in pbap module Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 11/13 v3] client: remove use of gobex in map module Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 12/13 v3] client: remove use of gobex in ftp module Luiz Augusto von Dentz
2012-02-08  9:44 ` [PATCH obexd 13/13 v3] client: remove gobex dependency of session Luiz Augusto von Dentz
2012-02-08 10:42 ` [PATCH obexd 01/13 v3] client: fix not checking session_request return Johan Hedberg

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=1328694249-22225-4-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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 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.