From 13dd8c94b5d41951833900810e3509193fdda537 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 21 Dec 2012 17:01:55 +0200 Subject: [PATCH] media: Remove custom property when last endpoint is removed When the last endpoint for a given UUID is removed the code should also remove the custom property. --- profiles/audio/media.c | 57 +++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 37eb809c5..84f8aeb3d 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -153,6 +153,32 @@ static void media_endpoint_destroy(struct media_endpoint *endpoint) g_free(endpoint); } +static struct media_endpoint *media_adapter_find_endpoint( + struct media_adapter *adapter, + const char *sender, + const char *path, + const char *uuid) +{ + GSList *l; + + for (l = adapter->endpoints; l; l = l->next) { + struct media_endpoint *endpoint = l->data; + + if (sender && g_strcmp0(endpoint->sender, sender) != 0) + continue; + + if (path && g_strcmp0(endpoint->path, path) != 0) + continue; + + if (uuid && g_strcmp0(endpoint->uuid, uuid) != 0) + continue; + + return endpoint; + } + + return NULL; +} + static void media_endpoint_remove(struct media_endpoint *endpoint) { struct media_adapter *adapter = endpoint->adapter; @@ -167,6 +193,11 @@ static void media_endpoint_remove(struct media_endpoint *endpoint) adapter->endpoints = g_slist_remove(adapter->endpoints, endpoint); + if (media_adapter_find_endpoint(adapter, NULL, NULL, + endpoint->uuid) == NULL) + btd_profile_remove_custom_prop(endpoint->uuid, + "MediaEndpoints"); + media_endpoint_destroy(endpoint); } @@ -576,32 +607,6 @@ static gboolean endpoint_init_a2dp_sink(struct media_endpoint *endpoint, return TRUE; } -static struct media_endpoint *media_adapter_find_endpoint( - struct media_adapter *adapter, - const char *sender, - const char *path, - const char *uuid) -{ - GSList *l; - - for (l = adapter->endpoints; l; l = l->next) { - struct media_endpoint *endpoint = l->data; - - if (sender && g_strcmp0(endpoint->sender, sender) != 0) - continue; - - if (path && g_strcmp0(endpoint->path, path) != 0) - continue; - - if (uuid && g_strcmp0(endpoint->uuid, uuid) != 0) - continue; - - return endpoint; - } - - return NULL; -} - static bool endpoint_properties_exists(const char *uuid, struct btd_device *dev, void *user_data) -- 2.47.3