From: "Michał Poczwardowski" <dmp0x7c5@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: "Michał Poczwardowski" <dmp0x7c5@gmail.com>
Subject: [RFC v3 obexd 04/10] fuse: Add request helpers and setpath operation
Date: Sun, 2 Dec 2012 00:14:49 +0100 [thread overview]
Message-ID: <1354403695-18985-4-git-send-email-dmp0x7c5@gmail.com> (raw)
In-Reply-To: <1354403695-18985-1-git-send-email-dmp0x7c5@gmail.com>
---
fuse/helpers.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 108 insertions(+), 0 deletions(-)
diff --git a/fuse/helpers.c b/fuse/helpers.c
index 82797d9..d3e70ff 100644
--- a/fuse/helpers.c
+++ b/fuse/helpers.c
@@ -320,3 +320,111 @@ void obexhlp_disconnect(struct obexhlp_session* session)
g_free(session);
}
+
+void request_new(struct obexhlp_session *session,
+ gchar *name)
+{
+ g_print("REQUEST %s\n", name);
+
+ if (session->request != NULL)
+ g_error("Another request (%s) active!\n",
+ session->request->name);
+
+ session->status = 0;
+ session->request = g_malloc0(sizeof(struct obexhlp_request));
+ session->request->name = name;
+
+ /*
+ * suspend/resume operations recreates g_io_add_watch(),
+ * it fixes obex->io freeze during transfer
+ */
+ g_obex_suspend(session->obex);
+ g_obex_resume(session->obex);
+}
+
+void request_wait_free(struct obexhlp_session *session)
+{
+ g_print("WAIT for %s\n", session->request->name);
+
+ g_obex_suspend(session->obex);
+ g_obex_resume(session->obex);
+
+ if (session->err != NULL) {
+ g_print("ERROR: %s (%d)\n", session->err->message,
+ session->err->code);
+ g_error_free(session->err);
+ raise(SIGTERM);
+ return;
+ }
+
+ g_mutex_lock(obexhlp_mutex);
+
+ while (session->request->complete != TRUE)
+ g_cond_wait(obexhlp_cond, obexhlp_mutex);
+
+ g_mutex_unlock(obexhlp_mutex);
+
+ g_free(session->request->name);
+ g_free(session->request);
+ session->request = NULL;
+}
+
+static void complete_func(GObex *obex, GError *err,
+ gpointer user_data)
+{
+ struct obexhlp_session *session = user_data;
+
+ if (err != NULL) {
+ g_print("ERROR: %s\n", err->message);
+ session->status = -ECANCELED;
+ g_error_free(err);
+ } else {
+ g_print("COMPLETE %s\n", session->request->name);
+ }
+
+ g_mutex_lock(obexhlp_mutex);
+ session->request->complete = TRUE;
+ g_cond_signal(obexhlp_cond);
+ g_mutex_unlock(obexhlp_mutex);
+}
+
+static void response_func(GObex *obex, GError *err, GObexPacket *rsp,
+ gpointer user_data)
+{
+ complete_func(obex, err, user_data);
+}
+
+void obexhlp_setpath(struct obexhlp_session *session, const char *path)
+{
+ guint i = 0, split = 0;
+ gchar **path_v;
+ gsize len;
+
+ g_print("obexhlp_setpath(%s)\n", path);
+
+ if (g_str_has_prefix(path, session->setpath)) {
+ split = strlen(session->setpath);
+ } else {
+ request_new(session, g_strdup_printf("setpath root"));
+ g_obex_setpath(session->obex, "", response_func,
+ session, &session->err);
+ request_wait_free(session);
+ }
+
+ path_v = g_strsplit(path+split, "/", -1);
+ len = g_strv_length(path_v);
+
+ for (i = 0; i < len; i++)
+ if (path_v[i][0] != '\0') {
+ request_new(session,
+ g_strdup_printf("setpath %s", path_v[i]));
+ g_obex_setpath(session->obex, path_v[i],
+ response_func, session, &session->err);
+ request_wait_free(session);
+ }
+
+ g_free(session->setpath);
+ session->setpath = g_strdup(path);
+
+ g_strfreev(path_v);
+}
--
1.7.8.6
next prev parent reply other threads:[~2012-12-01 23:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-01 23:14 [RFC v3 obexd 01/10] fuse: Add initial obexfuse files, fuse main and options parse Michał Poczwardowski
2012-12-01 23:14 ` [RFC v3 obexd 02/10] build: Add --enable-fuse for obexfuse Michał Poczwardowski
2012-12-01 23:14 ` [RFC v3 obexd 03/10] fuse: Add obexhlp_connect/disconnect functions with helpers Michał Poczwardowski
2012-12-01 23:14 ` Michał Poczwardowski [this message]
2012-12-01 23:14 ` [RFC v3 obexd 05/10] fuse: Add readdir operation Michał Poczwardowski
2012-12-01 23:14 ` [RFC v3 obexd 06/10] fuse: Add getattr operation Michał Poczwardowski
2012-12-01 23:14 ` [RFC v3 obexd 07/10] fuse: Add open and read operations plus location helpers Michał Poczwardowski
2012-12-01 23:14 ` [RFC v3 obexd 08/10] fuse: Add write and touch operations Michał Poczwardowski
2012-12-01 23:14 ` [RFC v3 obexd 09/10] fuse: Add unlink/rmdir operation Michał Poczwardowski
2012-12-01 23:14 ` [RFC v3 obexd 10/10] fuse: Add rename operation Michał Poczwardowski
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=1354403695-18985-4-git-send-email-dmp0x7c5@gmail.com \
--to=dmp0x7c5@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox