* [PATCH 1/2] Fix not fetching current usb mode when obexd starts
@ 2011-01-28 13:17 Luiz Augusto von Dentz
2011-01-28 13:17 ` [PATCH 2/2] Fix using g_source_remove intead of g_dbus_remove_watch Luiz Augusto von Dentz
0 siblings, 1 reply; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2011-01-28 13:17 UTC (permalink / raw)
To: linux-bluetooth
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] Fix using g_source_remove intead of g_dbus_remove_watch
2011-01-28 13:17 [PATCH 1/2] Fix not fetching current usb mode when obexd starts Luiz Augusto von Dentz
@ 2011-01-28 13:17 ` Luiz Augusto von Dentz
2011-01-28 13:29 ` Johan Hedberg
0 siblings, 1 reply; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2011-01-28 13:17 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
Watches created with g_dbus_add_signal_watch cannot be removed with
g_source_remove.
---
plugins/usb.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/plugins/usb.c b/plugins/usb.c
index 580e7b8..466dc99 100644
--- a/plugins/usb.c
+++ b/plugins/usb.c
@@ -201,7 +201,7 @@ static gboolean handle_signal(DBusConnection *connection,
static void usb_stop(void *data)
{
guint id = GPOINTER_TO_UINT(data);
- g_source_remove(id);
+ g_dbus_remove_watch(connection, id);
}
static void mode_request_reply(DBusPendingCall *call, void *user_data)
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] Fix using g_source_remove intead of g_dbus_remove_watch
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
0 siblings, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2011-01-28 13:29 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
On Fri, Jan 28, 2011, Luiz Augusto von Dentz wrote:
> Watches created with g_dbus_add_signal_watch cannot be removed with
> g_source_remove.
> ---
> plugins/usb.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
Both patches have been pushed upstream. Thanks.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-01-28 13:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-28 13:17 [PATCH 1/2] Fix not fetching current usb mode when obexd starts Luiz Augusto von Dentz
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox