OSDN Git Service

plugins/policy: Add support to retreive ReconnectUUIDs from main.conf
authorJohan Hedberg <johan.hedberg@intel.com>
Thu, 15 May 2014 07:57:22 +0000 (10:57 +0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 15 May 2014 08:19:32 +0000 (11:19 +0300)
plugins/policy.c
src/main.conf

index 7d65797..b72467e 100644 (file)
@@ -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
@@ -535,6 +536,13 @@ static void service_cb(struct btd_service *service,
                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;
 }
index a94274a..3ebadde 100644 (file)
 # 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=