From 5ca45764738fde7f4efb8c20e154f7c2b8f42a5e Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 25 Sep 2012 18:42:05 +0300 Subject: [PATCH] core: Add dynamic adapter and device probe support Particularly With the introduction of external profiles the probe functions must be possible to be triggered at any point during runtime. --- src/adapter.c | 12 ++++++++++++ src/adapter.h | 1 + src/device.c | 26 ++++++++++++++++++++++++++ src/device.h | 1 + 4 files changed, 40 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index e154c6955..6731444a4 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2051,6 +2051,18 @@ static void probe_profile(struct btd_profile *profile, void *data) adapter->profiles = g_slist_prepend(adapter->profiles, profile); } +void adapter_add_profile(struct btd_adapter *adapter, gpointer p) +{ + struct btd_profile *profile = p; + + if (!adapter->initialized) + return; + + probe_profile(profile, adapter); + + g_slist_foreach(adapter->devices, device_probe_profile, profile); +} + static void load_connections(struct btd_adapter *adapter) { GSList *l, *conns; diff --git a/src/adapter.h b/src/adapter.h index eece6f5dd..9f840e88a 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -145,6 +145,7 @@ struct btd_adapter_driver { typedef void (*service_auth_cb) (DBusError *derr, void *user_data); +void adapter_add_profile(struct btd_adapter *adapter, gpointer p); int btd_register_adapter_driver(struct btd_adapter_driver *driver); void btd_unregister_adapter_driver(struct btd_adapter_driver *driver); int btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst, diff --git a/src/device.c b/src/device.c index 57fdf0052..cb256060f 100644 --- a/src/device.c +++ b/src/device.c @@ -1372,6 +1372,32 @@ static void dev_probe(struct btd_profile *p, void *user_data) g_slist_free(probe_uuids); } +void device_probe_profile(gpointer a, gpointer b) +{ + struct btd_device *device = a; + struct btd_profile *profile = b; + GSList *probe_uuids; + char addr[18]; + int err; + + if (profile->device_probe == NULL) + return; + + probe_uuids = device_match_profile(device, profile, device->uuids); + if (!probe_uuids) + return; + + ba2str(&device->bdaddr, addr); + + err = profile->device_probe(profile, device, probe_uuids); + if (err < 0) + error("%s profile probe failed for %s", profile->name, addr); + else + device->profiles = g_slist_append(device->profiles, profile); + + g_slist_free(probe_uuids); +} + void device_probe_profiles(struct btd_device *device, GSList *uuids) { struct probe_data d = { device, uuids }; diff --git a/src/device.h b/src/device.h index aee6d131e..02c1782e7 100644 --- a/src/device.h +++ b/src/device.h @@ -61,6 +61,7 @@ void device_register_services(struct btd_device *device, GSList *device_services_from_record(struct btd_device *device, GSList *profiles); void btd_device_add_uuid(struct btd_device *device, const char *uuid); +void device_probe_profile(gpointer a, gpointer b); struct btd_adapter *device_get_adapter(struct btd_device *device); void device_get_address(struct btd_device *device, bdaddr_t *bdaddr, uint8_t *bdaddr_type); -- 2.47.3