From: Patrik Flykt <patrik.fl...@linux.intel.com> The main.conf 'DefaultAutoConnectTechnologies' is a list of service type strings. It is converted to a list of service type enums, and thus the configuration option is accessible via the function connman_setting_get_uint_list(). --- include/setting.h | 3 ++ src/main.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/include/setting.h b/include/setting.h index 78adad7..160336d 100644 --- a/include/setting.h +++ b/include/setting.h @@ -22,11 +22,14 @@ #ifndef __CONNMAN_SETTING_H #define __CONNMAN_SETTING_H +#include <connman/types.h> + #ifdef __cplusplus extern "C" { #endif connman_bool_t connman_setting_get_bool(const char *key); +unsigned int *connman_setting_get_uint_list(const char *key); #ifdef __cplusplus } diff --git a/src/main.c b/src/main.c index ded3bb1..33f6204 100644 --- a/src/main.c +++ b/src/main.c @@ -44,8 +44,10 @@ static struct { connman_bool_t bg_scan; + unsigned int *auto_connect; } connman_settings = { .bg_scan = TRUE, + .auto_connect = NULL, }; static GKeyFile *load_config(const char *file) @@ -71,10 +73,43 @@ static GKeyFile *load_config(const char *file) return keyfile; } +static uint *parse_service_types(char **str_list, gsize len) +{ + unsigned int *type_list; + int i, j; + enum connman_service_type type; + + type_list = g_try_new0(unsigned int, len + 1); + if (type_list == NULL) + return NULL; + + i = 0; + j = 0; + while (str_list[i] != NULL) + { + type = __connman_service_string2type(str_list[i]); + + if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) { + type_list[j] = type; + j += 1; + } + i += 1; + } + + return type_list; +} + static void parse_config(GKeyFile *config) { GError *error = NULL; gboolean boolean; + char **str_list; + gsize len; + char *default_auto_connect[] = { + "wifi", + "ethernet", + "cellular", + }; if (config == NULL) return; @@ -87,6 +122,19 @@ static void parse_config(GKeyFile *config) connman_settings.bg_scan = boolean; g_clear_error(&error); + + str_list = g_key_file_get_string_list(config, "General", + "DefaultAutoConnectTechnologies", &len, &error); + + if (error == NULL) + connman_settings.auto_connect = + parse_service_types(str_list, len); + else + connman_settings.auto_connect = + parse_service_types(default_auto_connect, 3); + + g_strfreev(str_list); + g_clear_error(&error); } static GMainLoop *main_loop = NULL; @@ -237,6 +285,14 @@ connman_bool_t connman_setting_get_bool(const char *key) return FALSE; } +unsigned int *connman_setting_get_uint_list(const char *key) +{ + if (g_str_equal(key, "DefaultAutoConnectTechnologies") == TRUE) + return connman_settings.auto_connect; + + return NULL; +} + int main(int argc, char *argv[]) { GOptionContext *context; @@ -419,6 +475,8 @@ int main(int argc, char *argv[]) if (config) g_key_file_free(config); + g_free(connman_settings.auto_connect); + g_free(option_debug); return 0; -- 1.7.9.1 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman