From a4bb1b593901878f8ab6d551c41772bcaa1b1357 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 28 Sep 2012 16:22:50 +0300 Subject: [PATCH] core: Add proper support for run-time removal of profiles --- src/adapter.c | 16 ++++++++++++++++ src/adapter.h | 1 + src/device.c | 13 +++++++++++++ src/device.h | 1 + src/profile.c | 2 ++ 5 files changed, 33 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index 48d6294a6..421cd436c 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2060,6 +2060,22 @@ void adapter_add_profile(struct btd_adapter *adapter, gpointer p) g_slist_foreach(adapter->devices, device_probe_profile, profile); } +void adapter_remove_profile(struct btd_adapter *adapter, gpointer p) +{ + struct btd_profile *profile = p; + + if (!adapter->initialized) + return; + + if (profile->device_remove) + g_slist_foreach(adapter->devices, device_remove_profile, p); + + adapter->profiles = g_slist_remove(adapter->profiles, profile); + + if (profile->adapter_remove) + profile->adapter_remove(profile, adapter); +} + static void load_connections(struct btd_adapter *adapter) { GSList *l, *conns; diff --git a/src/adapter.h b/src/adapter.h index 9f840e88a..f34763f04 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -146,6 +146,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); +void adapter_remove_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 cb256060f..efa3dbeb1 100644 --- a/src/device.c +++ b/src/device.c @@ -1398,6 +1398,19 @@ void device_probe_profile(gpointer a, gpointer b) g_slist_free(probe_uuids); } +void device_remove_profile(gpointer a, gpointer b) +{ + struct btd_device *device = a; + struct btd_profile *profile = b; + + if (!g_slist_find(device->profiles, profile)) + return; + + device->profiles = g_slist_remove(device->profiles, profile); + + profile->device_remove(profile, device); +} + 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 02c1782e7..eb4524424 100644 --- a/src/device.h +++ b/src/device.h @@ -62,6 +62,7 @@ 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); +void device_remove_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); diff --git a/src/profile.c b/src/profile.c index ad2ad4abe..24f7b28aa 100644 --- a/src/profile.c +++ b/src/profile.c @@ -620,6 +620,8 @@ static struct ext_profile *create_ext(const char *owner, const char *path, static void remove_ext(struct ext_profile *ext) { + manager_foreach_adapter(adapter_remove_profile, &ext->p); + ext_profiles = g_slist_remove(ext_profiles, ext); DBG("Removed \"%s\"", ext->name); -- 2.47.3