From f8a0c50bc6632455d1533d322935e9ebff6f4432 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 15 May 2014 10:57:22 +0300 Subject: [PATCH] plugins/policy: Add support to retreive ReconnectUUIDs from main.conf --- plugins/policy.c | 34 +++++++++++++++++++++++++++++----- src/main.conf | 9 +++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/plugins/policy.c b/plugins/policy.c index 7d6579771..b72467e7d 100644 --- a/plugins/policy.c +++ b/plugins/policy.c @@ -40,6 +40,7 @@ #include "src/device.h" #include "src/service.h" #include "src/profile.h" +#include "src/hcid.h" #define CONTROL_CONNECT_TIMEOUT 2 #define SOURCE_RETRY_TIMEOUT 2 @@ -534,6 +535,13 @@ static void service_cb(struct btd_service *service, else if (g_str_equal(profile->remote_uuid, AVRCP_TARGET_UUID)) target_cb(service, old_state, new_state); + /* + * Return if the reconnection feature is not enabled (all + * subsequent code in this function is about that). + */ + if (!reconnect_uuids) + return; + /* * We're only interested in reconnecting profiles which have set * auto_connect to true. @@ -660,14 +668,30 @@ static void conn_fail_cb(struct btd_device *dev, uint8_t status) static int policy_init(void) { - service_id = btd_service_add_state_cb(service_cb, NULL); + GError *gerr = NULL; + GKeyFile *conf; - /* TODO: Add overriding default from config file */ - reconnect_uuids = g_strdupv((char **) default_reconnect); + service_id = btd_service_add_state_cb(service_cb, NULL); - btd_add_disconnect_cb(disconnect_cb); + conf = btd_get_main_conf(); + if (!conf) { + reconnect_uuids = g_strdupv((char **) default_reconnect); + goto add_cb; + } - btd_add_conn_fail_cb(conn_fail_cb); + reconnect_uuids = g_key_file_get_string_list(conf, "Policy", + "ReconnectUUIDs", + NULL, &gerr); + if (gerr) { + g_error_free(gerr); + reconnect_uuids = g_strdupv((char **) default_reconnect); + goto add_cb; + } +add_cb: + if (reconnect_uuids) { + btd_add_disconnect_cb(disconnect_cb); + btd_add_conn_fail_cb(conn_fail_cb); + } return 0; } diff --git a/src/main.conf b/src/main.conf index a94274aa3..3ebaddeb4 100644 --- a/src/main.conf +++ b/src/main.conf @@ -46,3 +46,12 @@ # makes debug link keys valid only for the duration of the connection # that they were created for. #DebugKeys = false + +#[Policy] +# +# The ReconnectUUIDs defines the set of remote services that should try +# to be reconnected to in case of a link loss (link supervision +# timeout). The policy plugin should contain a sane set of values by +# default, but this list can be overridden here. By setting the list to +# empty the reconnection feature gets disabled. +#ReconnectUUIDs= -- 2.47.3