summaryrefslogtreecommitdiff
path: root/plugins/bluetooth.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/bluetooth.c')
-rw-r--r--plugins/bluetooth.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 2bc32c3e..f52477cb 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -48,6 +48,7 @@
#define LIST_ADAPTERS "ListAdapters"
#define ADAPTER_ADDED "AdapterAdded"
#define ADAPTER_REMOVED "AdapterRemoved"
+#define DEVICE_REMOVED "DeviceRemoved"
#define PROPERTY_CHANGED "PropertyChanged"
#define GET_PROPERTIES "GetProperties"
@@ -534,6 +535,24 @@ static gboolean adapter_changed(DBusConnection *connection,
return TRUE;
}
+static gboolean device_removed(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ const char *network_path;
+ DBusMessageIter iter;
+
+ DBG("");
+
+ if (dbus_message_iter_init(message, &iter) == FALSE)
+ return TRUE;
+
+ dbus_message_iter_get_basic(&iter, &network_path);
+
+ g_hash_table_remove(bluetooth_networks, network_path);
+
+ return TRUE;
+}
+
static gboolean device_changed(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -744,6 +763,21 @@ static void unregister_device(gpointer data)
connman_device_unref(device);
}
+static void unregister_network(gpointer data)
+{
+ struct connman_network *network = data;
+ struct connman_device *device;
+ const char *identifier;
+
+ device = connman_network_get_device(network);
+ if (device == NULL)
+ return;
+
+ identifier = connman_network_get_identifier(network);
+
+ connman_device_remove_network(device, identifier);
+}
+
static void bluetooth_connect(DBusConnection *connection, void *user_data)
{
DBusMessage *message;
@@ -755,7 +789,7 @@ static void bluetooth_connect(DBusConnection *connection, void *user_data)
g_free, unregister_device);
bluetooth_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, NULL);
+ g_free, unregister_network);
message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
@@ -929,6 +963,7 @@ static guint added_watch;
static guint removed_watch;
static guint adapter_watch;
static guint device_watch;
+static guint device_removed_watch;
static guint network_watch;
static int bluetooth_init(void)
@@ -957,6 +992,11 @@ static int bluetooth_init(void)
PROPERTY_CHANGED, adapter_changed,
NULL, NULL);
+ device_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ BLUEZ_ADAPTER_INTERFACE,
+ DEVICE_REMOVED, device_removed,
+ NULL, NULL);
+
device_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
BLUEZ_DEVICE_INTERFACE,
PROPERTY_CHANGED, device_changed,
@@ -969,7 +1009,8 @@ static int bluetooth_init(void)
if (watch == 0 || added_watch == 0 || removed_watch == 0
|| adapter_watch == 0 || network_watch == 0
- || device_watch == 0) {
+ || device_watch == 0
+ || device_removed_watch == 0) {
err = -EIO;
goto remove;
}
@@ -998,6 +1039,7 @@ remove:
g_dbus_remove_watch(connection, added_watch);
g_dbus_remove_watch(connection, removed_watch);
g_dbus_remove_watch(connection, adapter_watch);
+ g_dbus_remove_watch(connection, device_removed_watch);
g_dbus_remove_watch(connection, device_watch);
g_dbus_remove_watch(connection, network_watch);
@@ -1012,6 +1054,7 @@ static void bluetooth_exit(void)
g_dbus_remove_watch(connection, added_watch);
g_dbus_remove_watch(connection, removed_watch);
g_dbus_remove_watch(connection, adapter_watch);
+ g_dbus_remove_watch(connection, device_removed_watch);
g_dbus_remove_watch(connection, device_watch);
g_dbus_remove_watch(connection, network_watch);