From 54c07e307016863a6d9c7b5a330cda78d108b32c Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 14 Nov 2012 12:34:26 +0200 Subject: [PATCH] core: Add connection priority to btd_profile --- profiles/audio/manager.c | 1 + src/device.c | 14 ++++++++++++-- src/profile.c | 21 +++++++++++++++++++++ src/profile.h | 5 +++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c index f59a2f30f..19aeb24b1 100644 --- a/profiles/audio/manager.c +++ b/profiles/audio/manager.c @@ -327,6 +327,7 @@ static void media_server_remove(struct btd_adapter *adapter) static struct btd_profile a2dp_profile = { .name = "audio-a2dp", + .priority = BTD_PROFILE_PRIORITY_MEDIUM, .remote_uuids = BTD_UUIDS(A2DP_SOURCE_UUID, A2DP_SINK_UUID, ADVANCED_AUDIO_UUID), diff --git a/src/device.c b/src/device.c index 48970d23e..3ca265eb6 100644 --- a/src/device.c +++ b/src/device.c @@ -1313,6 +1313,13 @@ static struct btd_profile *find_connectable_profile(struct btd_device *dev, return NULL; } +static gint profile_prio_cmp(gconstpointer a, gconstpointer b) +{ + const struct btd_profile *p1 = a, *p2 = b; + + return p1->priority - p2->priority; +} + static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg, const char *uuid) { @@ -1351,8 +1358,11 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg, for (l = dev->profiles; l != NULL; l = g_slist_next(l)) { p = l->data; - if (p->auto_connect) - dev->pending = g_slist_append(dev->pending, p); + if (!p->auto_connect) + continue; + + dev->pending = g_slist_insert_sorted(dev->pending, p, + profile_prio_cmp); } if (!dev->pending) diff --git a/src/profile.c b/src/profile.c index aed36fcf5..abb5a53d9 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1074,6 +1074,26 @@ static int parse_ext_opt(struct ext_profile *ext, const char *key, return 0; } +static gint get_priority(const struct btd_profile *p) +{ + if (strcasecmp(p->local_uuid, HFP_HS_UUID) == 0) + return BTD_PROFILE_PRIORITY_HIGH; + + if (strcasecmp(p->local_uuid, HFP_AG_UUID) == 0) + return BTD_PROFILE_PRIORITY_HIGH; + + if (strcasecmp(p->local_uuid, A2DP_SOURCE_UUID) == 0) + return BTD_PROFILE_PRIORITY_MEDIUM; + + if (strcasecmp(p->local_uuid, A2DP_SINK_UUID) == 0) + return BTD_PROFILE_PRIORITY_MEDIUM; + + if (strcasecmp(p->local_uuid, ADVANCED_AUDIO_UUID) == 0) + return BTD_PROFILE_PRIORITY_MEDIUM; + + return BTD_PROFILE_PRIORITY_LOW; +} + static struct ext_profile *create_ext(const char *owner, const char *path, const char *uuid, DBusMessageIter *opts) @@ -1118,6 +1138,7 @@ static struct ext_profile *create_ext(const char *owner, const char *path, p = &ext->p; p->name = ext->name; + p->priority = get_priority(p); p->local_uuid = ext->uuid; /* Typecast can't really be avoided here: diff --git a/src/profile.h b/src/profile.h index d7b1ba14a..6991041d3 100644 --- a/src/profile.h +++ b/src/profile.h @@ -23,6 +23,10 @@ #define BTD_UUIDS(args...) ((const char *[]) { args, NULL } ) +#define BTD_PROFILE_PRIORITY_LOW 0 +#define BTD_PROFILE_PRIORITY_MEDIUM 1 +#define BTD_PROFILE_PRIORITY_HIGH 2 + struct btd_profile; typedef void (*btd_profile_cb)(struct btd_profile *profile, @@ -30,6 +34,7 @@ typedef void (*btd_profile_cb)(struct btd_profile *profile, struct btd_profile { const char *name; + int priority; const char *local_uuid; const char **remote_uuids; -- 2.47.3