From: "Frédéric Dalleau" <frederic.dalleau@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: "Frédéric Dalleau" <frederic.dalleau@linux.intel.com>
Subject: [PATCH v2] core: Fix allow registering same custom property
Date: Wed, 16 Jan 2013 18:07:14 +0100 [thread overview]
Message-ID: <1358356034-2622-1-git-send-email-frederic.dalleau@linux.intel.com> (raw)
With several adapters, MediaEndpoint custom property is only created for the
first adapter. When a new connection happens on another adapter
btd_profile_custom_property_exists fails because the custom property doesn't
exist for this last adapter. In case of HFP ofono fails with error: "Media
Endpoint missing error".
This patch allows the creation of several custom property with same name that
can be distinguished based on a 'key'. When querying the property, additional
checking must happen. For example endpoint_properties_exists, compares
btd_adapter.
'NULL' key maintains existing behavior.
---
profiles/audio/media.c | 5 +++--
src/profile.c | 22 ++++++++++++++++------
src/profile.h | 6 ++++--
3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index 4b91656..60a5da5 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -195,7 +195,7 @@ static void media_endpoint_remove(struct media_endpoint *endpoint)
if (media_adapter_find_endpoint(adapter, NULL, NULL,
endpoint->uuid) == NULL)
- btd_profile_remove_custom_prop(endpoint->uuid,
+ btd_profile_remove_custom_prop(adapter, endpoint->uuid,
"MediaEndpoints");
media_endpoint_destroy(endpoint);
@@ -740,7 +740,8 @@ static struct media_endpoint *media_endpoint_create(struct media_adapter *adapte
endpoint, NULL);
if (media_adapter_find_endpoint(adapter, NULL, NULL, uuid) == NULL) {
- btd_profile_add_custom_prop(uuid, "a{sv}", "MediaEndpoints",
+ btd_profile_add_custom_prop(adapter, uuid, "a{sv}",
+ "MediaEndpoints",
endpoint_properties_exists,
endpoint_properties_get,
adapter);
diff --git a/src/profile.c b/src/profile.c
index b0c8500..7d48cfc 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -572,6 +572,7 @@ struct ext_record {
};
struct btd_profile_custom_property {
+ const void *key;
char *uuid;
char *type;
char *name;
@@ -2208,7 +2209,8 @@ static const GDBusMethodTable methods[] = {
{ }
};
-static struct btd_profile_custom_property *find_custom_prop(const char *uuid,
+static struct btd_profile_custom_property *find_custom_prop(const char *key,
+ const char *uuid,
const char *name)
{
GSList *l;
@@ -2216,6 +2218,9 @@ static struct btd_profile_custom_property *find_custom_prop(const char *uuid,
for (l = custom_props; l; l = l->next) {
struct btd_profile_custom_property *prop = l->data;
+ if (prop->key != key)
+ continue;
+
if (strcasecmp(prop->uuid, uuid) != 0)
continue;
@@ -2226,7 +2231,8 @@ static struct btd_profile_custom_property *find_custom_prop(const char *uuid,
return NULL;
}
-bool btd_profile_add_custom_prop(const char *uuid, const char *type,
+bool btd_profile_add_custom_prop(const void *key, const char *uuid,
+ const char *type,
const char *name,
btd_profile_prop_exists exists,
btd_profile_prop_get get,
@@ -2234,12 +2240,15 @@ bool btd_profile_add_custom_prop(const char *uuid, const char *type,
{
struct btd_profile_custom_property *prop;
- prop = find_custom_prop(uuid, name);
- if (prop != NULL)
+ prop = find_custom_prop(key, uuid, name);
+ if (prop != NULL) {
+ DBG("Custom property %s already exists", name);
return false;
+ }
prop = g_new0(struct btd_profile_custom_property, 1);
+ prop->key = key;
prop->uuid = g_strdup(uuid);
prop->type = g_strdup(type);
prop->name = g_strdup(name);
@@ -2263,11 +2272,12 @@ static void free_property(gpointer data)
g_free(p);
}
-bool btd_profile_remove_custom_prop(const char *uuid, const char *name)
+bool btd_profile_remove_custom_prop(const void *key, const char *uuid,
+ const char *name)
{
struct btd_profile_custom_property *prop;
- prop = find_custom_prop(uuid, name);
+ prop = find_custom_prop(key, uuid, name);
if (prop == NULL)
return false;
diff --git a/src/profile.h b/src/profile.h
index d858925..0764f6f 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -67,12 +67,14 @@ typedef bool (*btd_profile_prop_get)(const char *uuid,
DBusMessageIter *iter,
void *user_data);
-bool btd_profile_add_custom_prop(const char *uuid, const char *type,
+bool btd_profile_add_custom_prop(const void *key, const char *uuid,
+ const char *type,
const char *name,
btd_profile_prop_exists exists,
btd_profile_prop_get get,
void *user_data);
-bool btd_profile_remove_custom_prop(const char *uuid, const char *name);
+bool btd_profile_remove_custom_prop(const void *key, const char *uuid,
+ const char *name);
void btd_profile_init(void);
void btd_profile_cleanup(void);
--
1.7.9.5
next reply other threads:[~2013-01-16 17:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 17:07 Frédéric Dalleau [this message]
2013-01-18 9:08 ` [PATCH v2] core: Fix allow registering same custom property Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1358356034-2622-1-git-send-email-frederic.dalleau@linux.intel.com \
--to=frederic.dalleau@linux.intel.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox