dbus_pending_call_unref(call);
- connman_network_unregister(network);
connman_network_unref(network);
}
if (network == NULL)
goto done;
- connman_network_register(network);
-
connman_network_set_string(network, "Path", path);
connman_network_set_name(network, name);
connman_network_set_group(network, ident);
- g_hash_table_insert(bluetooth_networks, g_strdup(path), network);
+ g_hash_table_replace(bluetooth_networks, g_strdup(path), network);
done:
dbus_message_unref(reply);
static gboolean device_removed(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
- const char *network_path, *identifier;
+ const char *network_path;
struct connman_network *network;
struct connman_device *device;
DBusMessageIter iter;
if (device == NULL)
return TRUE;
- identifier = connman_network_get_identifier(network);
-
g_hash_table_remove(bluetooth_networks, network_path);
- connman_device_remove_network(device, identifier);
-
return TRUE;
}
return TRUE;
}
+static void remove_device_networks(struct connman_device *device)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+ GSList *key_list = NULL;
+ GSList *list;
+
+ if (bluetooth_networks == NULL)
+ return;
+
+ g_hash_table_iter_init(&iter, bluetooth_networks);
+
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ struct connman_network *network = value;
+
+ if (connman_network_get_device(network) != device)
+ continue;
+
+ key_list = g_slist_append(key_list, key);
+ }
+
+ for (list = key_list; list != NULL; list = list->next) {
+ const char *network_path = list->data;
+
+ g_hash_table_remove(bluetooth_networks, network_path);
+ }
+
+ g_slist_free(key_list);
+}
+
static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
{
char *path = user_data;
if (powered == TRUE)
check_networks(device, &networks);
+ else
+ remove_device_networks(device);
done:
dbus_message_unref(reply);
DBG("");
+ remove_device_networks(device);
+
connman_device_unregister(device);
connman_device_unref(device);
}
+static void remove_network(gpointer data)
+{
+ struct connman_network *network = data;
+ struct connman_device *device;
+
+ DBG("network %p", network);
+
+ device = connman_network_get_device(network);
+ if (device != NULL)
+ connman_device_remove_network(device, network);
+
+ connman_network_unref(network);
+}
+
static void bluetooth_connect(DBusConnection *connection, void *user_data)
{
DBusMessage *message;
g_free, unregister_device);
bluetooth_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, NULL);
+ g_free, remove_network);
message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
return;
g_hash_table_destroy(bluetooth_networks);
+ bluetooth_networks = NULL;
g_hash_table_destroy(bluetooth_devices);
bluetooth_devices = NULL;
}
if (err < 0) {
connman_device_driver_unregister(&bluetooth_driver);
connman_network_driver_unregister(&pan_driver);
- return err;
+ goto remove;
}
return 0;