main.conf: Add DefaultPowered configuration
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 10 Apr 2013 10:14:33 +0000 (12:14 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 11 Apr 2013 11:52:48 +0000 (13:52 +0200)
DefaultPowered is a boolean and will force neard into turning any detected
adapter on when set to TRUE.

doc/neard.conf.5
src/adapter.c
src/main.c
src/main.conf

index e883b8b..3f19cf3 100644 (file)
@@ -35,5 +35,9 @@ This section is the only mandatory section of the configuration file.
 .B ConstantPoll=\fPtrue|false\fP
 Enable constant polling. Default is false. Constant polling will force neard
 into starting a new polling cycle whenever a target or a device are lost.
+.TP
+.B DefaultPowered=\fPtrue|false\fP
+Automatically turn an adapter on when being discovered.
+Default value is false.
 .SH "SEE ALSO"
 .BR neard (8)
index 91a4bec..c3785c6 100644 (file)
@@ -597,6 +597,7 @@ struct near_adapter *__near_adapter_create(uint32_t idx,
                const char *name, uint32_t protocols, near_bool_t powered)
 {
        struct near_adapter *adapter;
+       near_bool_t powered_setting;
 
        adapter = g_try_malloc0(sizeof(struct near_adapter));
        if (adapter == NULL)
@@ -607,6 +608,14 @@ struct near_adapter *__near_adapter_create(uint32_t idx,
                g_free(adapter);
                return NULL;
        }
+
+       powered_setting = near_setting_get_bool("DefaultPowered");
+       if (powered_setting == TRUE && powered == FALSE &&
+           !__near_netlink_adapter_enable(adapter->idx, powered_setting))
+                       powered = TRUE;
+
+       DBG("Powered %d", powered);
+
        adapter->idx = idx;
        adapter->protocols = protocols;
        adapter->powered = powered;
index b9f94c5..1a0f297 100644 (file)
 
 static struct {
        near_bool_t constant_poll;
+       near_bool_t default_powered;
 } near_settings  = {
        .constant_poll = FALSE,
+       .default_powered = FALSE,
 };
 
 static GKeyFile *load_config(const char *file)
@@ -77,6 +79,11 @@ static void parse_config(GKeyFile *config)
        if (error == NULL)
                near_settings.constant_poll = boolean;
 
+       boolean = g_key_file_get_boolean(config, "General",
+                                               "DefaultPowered", &error);
+       if (error == NULL)
+               near_settings.default_powered = boolean;
+
        g_clear_error(&error);
 }
 
@@ -141,6 +148,9 @@ near_bool_t near_setting_get_bool(const char *key)
        if (g_str_equal(key, "ConstantPoll") == TRUE)
                return near_settings.constant_poll;
 
+       if (g_str_equal(key, "DefaultPowered") == TRUE)
+               return near_settings.default_powered;
+
        return FALSE;
 }
 
index 65b6ac3..ccaa871 100644 (file)
@@ -5,3 +5,7 @@
 # polling loop whenever a tag or a device is no longer
 # in the RF field.
 ConstantPoll = true
+
+# Automatically turn an adapter on when being discovered.
+# Default value is false.
+DefaultPowered = true