From: Patrik Flykt Date: Thu, 5 Apr 2012 19:38:33 +0000 (+0300) Subject: main: Add 'DefaultAutoConnectTechnologies' configuration option X-Git-Tag: 0.80~60 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ac6fb6c041115c6226c1e527b7b8f8236ed44f2;p=platform%2Fupstream%2Fconnman.git main: Add 'DefaultAutoConnectTechnologies' configuration option 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(). If this option is not specified, the default technologies to autoconnect are wifi, ethernet and cellular just like before. --- diff --git a/include/setting.h b/include/setting.h index 3ea631a..2e81d6e 100644 --- a/include/setting.h +++ b/include/setting.h @@ -22,12 +22,15 @@ #ifndef __CONNMAN_SETTING_H #define __CONNMAN_SETTING_H +#include + #ifdef __cplusplus extern "C" { #endif connman_bool_t connman_setting_get_bool(const char *key); char **connman_setting_get_string_list(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 6e0d64d..e539e6d 100644 --- a/src/main.c +++ b/src/main.c @@ -45,9 +45,11 @@ static struct { connman_bool_t bg_scan; char **pref_timeservers; + unsigned int *auto_connect; } connman_settings = { .bg_scan = TRUE, .pref_timeservers = NULL, + .auto_connect = NULL, }; static GKeyFile *load_config(const char *file) @@ -73,11 +75,44 @@ 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 **timeservers; + char **str_list; + gsize len; + char *default_auto_connect[] = { + "wifi", + "ethernet", + "cellular", + }; if (config == NULL) return; @@ -97,6 +132,20 @@ static void parse_config(GKeyFile *config) connman_settings.pref_timeservers = timeservers; 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; @@ -255,6 +304,14 @@ char **connman_setting_get_string_list(const char *key) return NULL; } +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; @@ -440,6 +497,8 @@ int main(int argc, char *argv[]) if (connman_settings.pref_timeservers != NULL) g_strfreev(connman_settings.pref_timeservers); + g_free(connman_settings.auto_connect); + g_free(option_debug); return 0;