Diff between fd9d6c2bbd3517bcf338dad339285672f8332105 and a4bb1b593901878f8ab6d551c41772bcaa1b1357

Changed Files

File Additions Deletions Status
src/adapter.c +16 -0 modified
src/adapter.h +1 -0 modified
src/device.c +13 -0 modified
src/device.h +1 -0 modified
src/profile.c +2 -0 modified

Full Patch

diff --git a/src/adapter.c b/src/adapter.c
index 48d6294..421cd43 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 9f840e8..f34763f 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 cb25606..efa3dbe 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 02c1782..eb45244 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 ad2ad4a..24f7b28 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);