From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 1/2] Fix not fetching current usb mode when obexd starts
Date: Fri, 28 Jan 2011 15:17:38 +0200 [thread overview]
Message-ID: <1296220659-24165-1-git-send-email-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
Cable may be already plugged when obexd starts
---
plugins/usb.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/plugins/usb.c b/plugins/usb.c
index 949e94f..580e7b8 100644
--- a/plugins/usb.c
+++ b/plugins/usb.c
@@ -173,20 +173,27 @@ static void sig_usb(int sig)
{
}
+static void usb_set_mode(struct obex_server *server, const char *mode)
+{
+ DBG("%s", mode);
+
+ if (g_str_equal(mode, "ovi_suite") == TRUE)
+ usb_connect(server);
+ else if (g_str_equal(mode, "USB disconnected") == TRUE)
+ usb_disconnect(server);
+}
+
static gboolean handle_signal(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
struct obex_server *server = user_data;
- const char *state;
+ const char *mode;
dbus_message_get_args(message, NULL,
- DBUS_TYPE_STRING, &state,
+ DBUS_TYPE_STRING, &mode,
DBUS_TYPE_INVALID);
- if (g_str_equal(state, "ovi_suite") == TRUE)
- usb_connect(server);
- else if (g_str_equal(state, "USB disconnected") == TRUE)
- usb_disconnect(server);
+ usb_set_mode(server, mode);
return TRUE;
}
@@ -197,18 +204,64 @@ static void usb_stop(void *data)
g_source_remove(id);
}
+static void mode_request_reply(DBusPendingCall *call, void *user_data)
+{
+ struct obex_server *server = user_data;
+ DBusMessage *reply = dbus_pending_call_steal_reply(call);
+ DBusError derr;
+
+ dbus_error_init(&derr);
+ if (dbus_set_error_from_message(&derr, reply)) {
+ error("usb: Replied with an error: %s, %s",
+ derr.name, derr.message);
+ dbus_error_free(&derr);
+ } else {
+ const char *mode;
+ dbus_message_get_args(reply, NULL,
+ DBUS_TYPE_STRING, &mode,
+ DBUS_TYPE_INVALID);
+
+ usb_set_mode(server, mode);
+ }
+
+ dbus_message_unref(reply);
+}
+
static void *usb_start(struct obex_server *server, int *err)
{
guint id;
+ DBusMessage *msg;
+ DBusPendingCall *call;
+
+ msg = dbus_message_new_method_call("com.meego.usb_moded",
+ "/com/meego/usb_moded",
+ "com.meego.usb_moded",
+ "mode_request");
+
+ if (dbus_connection_send_with_reply(connection,
+ msg, &call, -1) == FALSE) {
+ error("usb: unable to send mode_request");
+ goto fail;
+ }
+
+ dbus_pending_call_set_notify(call, mode_request_reply, server, NULL);
+ dbus_pending_call_unref(call);
id = g_dbus_add_signal_watch(connection, NULL, NULL,
"com.meego.usb_moded",
"sig_usb_state_ind",
handle_signal, server, NULL);
+
if (err != NULL)
*err = 0;
return GUINT_TO_POINTER(id);
+
+fail:
+ if (err != NULL)
+ *err = -1;
+
+ return NULL;
}
static struct obex_transport_driver driver = {
--
1.7.1
next reply other threads:[~2011-01-28 13:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-28 13:17 Luiz Augusto von Dentz [this message]
2011-01-28 13:17 ` [PATCH 2/2] Fix using g_source_remove intead of g_dbus_remove_watch Luiz Augusto von Dentz
2011-01-28 13:29 ` 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=1296220659-24165-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox