diff --git a/tools/btpclient.c b/tools/btpclient.c
index d0ec4de..e94fc18 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
uint8_t index;
uint32_t supported_settings;
uint32_t current_settings;
+ struct l_queue *devices;
};
struct btp_device {
};
static struct l_queue *adapters;
-static struct l_queue *devices;
static char *socket_path;
static struct btp *btp;
return NULL;
}
+static struct btp_adapter *find_adapter_by_path(const char *path)
+{
+ const struct l_queue_entry *entry;
+
+ for (entry = l_queue_get_entries(adapters); entry;
+ entry = entry->next) {
+ struct btp_adapter *adapter = entry->data;
+
+ if (!strcmp(l_dbus_proxy_get_path(adapter->proxy), path))
+ return adapter;
+ }
+
+ return NULL;
+}
+
static void btp_gap_read_commands(uint8_t index, const void *param,
uint16_t length, void *user_data)
{
}
}
-static void btp_adapter_free(struct btp_adapter *adapter)
+static void btp_device_free(struct btp_device *device)
{
- l_free(adapter);
+ l_free(device);
}
-static void btp_device_free(struct btp_device *device)
+static void btp_adapter_free(struct btp_adapter *adapter)
{
- l_free(device);
+ l_queue_destroy(adapter->devices,
+ (l_queue_destroy_func_t)btp_device_free);
+ l_free(adapter);
}
static void extract_settings(struct l_dbus_proxy *proxy, uint32_t *current,
adapter = l_new(struct btp_adapter, 1);
adapter->proxy = proxy;
adapter->index = l_queue_length(adapters);
+ adapter->devices = l_queue_new();
extract_settings(proxy, &adapter->current_settings,
&adapter->supported_settings);
}
if (!strcmp(interface, "org.bluez.Device1")) {
+ struct btp_adapter *adapter;
struct btp_device *device;
+ char *str;
+
+ if (!l_dbus_proxy_get_property(proxy, "Adapter", "o", &str))
+ return;
+
+ adapter = find_adapter_by_path(str);
+ if (!adapter)
+ return;
device = l_new(struct btp_device, 1);
device->proxy = proxy;
- l_queue_push_tail(devices, device);
+ l_queue_push_tail(adapter->devices, device);
return;
}
}
}
if (!strcmp(interface, "org.bluez.Device1")) {
- l_queue_remove_if(devices, device_match_by_proxy, proxy);
+ struct btp_adapter *adapter;
+ char *str;
+
+ if (!l_dbus_proxy_get_property(proxy, "Adapter", "o", &str))
+ return;
+
+ adapter = find_adapter_by_path(str);
+ if (!adapter)
+ return;
+
+ l_queue_remove_if(adapter->devices, device_match_by_proxy,
+ proxy);
return;
}
adapters = l_queue_new();
- devices = l_queue_new();
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
l_signal_remove(signal);
btp_cleanup(btp);
- l_queue_destroy(devices, (l_queue_destroy_func_t)btp_device_free);
l_queue_destroy(adapters, (l_queue_destroy_func_t)btp_adapter_free);
l_free(socket_path);