diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index f59a2f3..19aeb24 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
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 48970d2..3ca265e 100644
--- a/src/device.c
+++ b/src/device.c
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)
{
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 aed36fc..abb5a53 100644
--- a/src/profile.c
+++ b/src/profile.c
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)
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 d7b1ba1..6991041 100644
--- a/src/profile.h
+++ b/src/profile.h
#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,
struct btd_profile {
const char *name;
+ int priority;
const char *local_uuid;
const char **remote_uuids;