[PATCH v2 4/9] obexd: Queue setpath command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Christian Fetzer <christian.fetzer@xxxxxxxxxxxx>

diff --git a/obexd/client/session.c b/obexd/client/session.c
index 6c2ecb7..36ed541 100644
--- a/obexd/client/session.c
+++ b/obexd/client/session.c
@@ -182,6 +182,14 @@ static void pending_request_free(struct pending_request *p)
 	g_free(p);
 }
 
+static void setpath_data_free(void *process_data)
+{
+	struct setpath_data *data = process_data;
+
+	g_strfreev(data->remaining);
+	g_free(data);
+}
+
 static void session_free(struct obc_session *session)
 {
 	DBG("%p", session);
@@ -888,9 +896,6 @@ static void setpath_complete(struct obc_session *session,
 	if (data->func)
 		data->func(session, NULL, err, data->user_data);
 
-	g_strfreev(data->remaining);
-	g_free(data);
-
 	if (session->p == p)
 		session->p = NULL;
 
@@ -942,13 +947,35 @@ static void setpath_cb(GObex *obex, GError *err, GObexPacket *rsp,
 	}
 }
 
+static int session_process_setpath(struct pending_request *p, GError **err)
+{
+	struct setpath_data *req = p->data;
+	const char *first = "";
+
+	/* Relative path */
+	if (req->remaining[0][0] != '/')
+		first = req->remaining[req->index];
+	req->index++;
+
+	p->req_id = g_obex_setpath(p->session->obex, first, setpath_cb, p, err);
+	if (*err != NULL)
+		goto fail;
+
+	p->session->p = p;
+
+	return 0;
+
+fail:
+	pending_request_free(p);
+	return (*err)->code;
+}
+
 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,
@@ -956,39 +983,15 @@ guint obc_session_setpath(struct obc_session *session, const char *path,
 		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(strlen(path) ? path : "/", "/", 0);
 
-	p = pending_request_new(session, NULL, 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;
-
+	p = pending_request_new(session, session_process_setpath,
+			setpath_data_free, NULL, setpath_complete, data);
+	session_queue_add(p);
 	return p->id;
-
-fail:
-	g_strfreev(data->remaining);
-	g_free(data);
-	pending_request_free(p);
-	return 0;
 }
 
 static void async_cb(GObex *obex, GError *err, GObexPacket *rsp,
-- 
1.8.2.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux