[gnome-bluetooth] lib: Fix agent registration when bluetoothd comes and goes
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth] lib: Fix agent registration when bluetoothd comes and goes
- Date: Sun, 26 Nov 2017 16:15:57 +0000 (UTC)
commit 491f454e714f163923990b0d4277217c746c9fe0
Author: Bastien Nocera <hadess hadess net>
Date: Fri Nov 24 18:09:20 2017 +0100
lib: Fix agent registration when bluetoothd comes and goes
Use our watch for org.bluez appearing and vanishing to register our
agent. There's no need to try and call out to org.bluez if the daemon
isn't around. We'll register when both org.bluez is set, and _register()
has been called.
https://bugzilla.gnome.org/show_bug.cgi?id=790797
lib/bluetooth-agent.c | 61 ++++++++++++++++++++++++++++++------------------
1 files changed, 38 insertions(+), 23 deletions(-)
---
diff --git a/lib/bluetooth-agent.c b/lib/bluetooth-agent.c
index f93a86a..58bf57e 100644
--- a/lib/bluetooth-agent.c
+++ b/lib/bluetooth-agent.c
@@ -295,6 +295,31 @@ static gboolean bluetooth_agent_cancel(BluetoothAgent *agent,
}
static void
+register_agent (BluetoothAgentPrivate *priv)
+{
+ GError *error = NULL;
+ gboolean ret;
+
+ ret = agent_manager1_call_register_agent_sync (priv->agent_manager,
+ priv->path,
+ "DisplayYesNo",
+ NULL, &error);
+ if (ret == FALSE) {
+ g_printerr ("Agent registration failed: %s\n", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ ret = agent_manager1_call_request_default_agent_sync (priv->agent_manager,
+ priv->path,
+ NULL, &error);
+ if (ret == FALSE) {
+ g_printerr ("Agent registration as default failed: %s\n", error->message);
+ g_error_free (error);
+ }
+}
+
+static void
name_appeared_cb (GDBusConnection *connection,
const gchar *name,
const gchar *name_owner,
@@ -304,6 +329,16 @@ name_appeared_cb (GDBusConnection *connection,
g_free (priv->busname);
priv->busname = g_strdup (name_owner);
+
+ priv->agent_manager = agent_manager1_proxy_new_sync (priv->conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+ BLUEZ_SERVICE,
+ "/org/bluez",
+ NULL,
+ NULL);
+
+ if (priv->reg_id > 0)
+ register_agent (priv);
}
static void
@@ -315,6 +350,7 @@ name_vanished_cb (GDBusConnection *connection,
g_free (priv->busname);
priv->busname = NULL;
+ g_clear_object (&priv->agent_manager);
}
static void
@@ -496,16 +532,11 @@ gboolean bluetooth_agent_register(BluetoothAgent *agent)
{
BluetoothAgentPrivate *priv;
GError *error = NULL;
- gboolean ret;
g_return_val_if_fail (BLUETOOTH_IS_AGENT (agent), FALSE);
priv = BLUETOOTH_AGENT_GET_PRIVATE (agent);
- priv->agent_manager = agent_manager1_proxy_new_sync(priv->conn,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
- BLUEZ_SERVICE, "/org/bluez", NULL, NULL);
-
priv->reg_id = g_dbus_connection_register_object (priv->conn,
priv->path,
priv->introspection_data->interfaces[0],
@@ -520,24 +551,8 @@ gboolean bluetooth_agent_register(BluetoothAgent *agent)
return FALSE;
}
- ret = agent_manager1_call_register_agent_sync (priv->agent_manager,
- priv->path,
- "DisplayYesNo",
- NULL, &error);
- if (ret == FALSE) {
- g_printerr ("Agent registration failed: %s\n", error->message);
- g_error_free (error);
- return FALSE;
- }
-
- ret = agent_manager1_call_request_default_agent_sync (priv->agent_manager,
- priv->path,
- NULL, &error);
- if (ret == FALSE) {
- g_printerr ("Agent registration as default failed: %s\n", error->message);
- g_error_free (error);
- return FALSE;
- }
+ if (priv->agent_manager != NULL)
+ register_agent (priv);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]