[PATCH 3/3] main: enabling settings support from storage directly

Tomasz Bursztyka tomasz.bursztyka at linux.intel.com
Wed Feb 15 07:05:00 PST 2012


---
 src/device.c |    2 +-
 src/main.c   |   65 ++-------------------------------------------------------
 2 files changed, 4 insertions(+), 63 deletions(-)

diff --git a/src/device.c b/src/device.c
index e7568f6..f2205be 100644
--- a/src/device.c
+++ b/src/device.c
@@ -497,7 +497,7 @@ struct connman_device *connman_device_create(const char *node,
 
 	device->refcount = 1;
 
-	bg_scan = connman_setting_get_bool("BackgroundScanning");
+	bg_scan = connman_storage_get_bool_setting("BackgroundScanning", TRUE);
 
 	device->type = type;
 	device->name = g_strdup(type2description(device->type));
diff --git a/src/main.c b/src/main.c
index ded3bb1..359f99a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,53 +42,6 @@
 
 #include "connman.h"
 
-static struct {
-	connman_bool_t bg_scan;
-} connman_settings  = {
-	.bg_scan = TRUE,
-};
-
-static GKeyFile *load_config(const char *file)
-{
-	GError *err = NULL;
-	GKeyFile *keyfile;
-
-	keyfile = g_key_file_new();
-
-	g_key_file_set_list_separator(keyfile, ',');
-
-	if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
-		if (err->code != G_FILE_ERROR_NOENT) {
-			connman_error("Parsing %s failed: %s", file,
-								err->message);
-		}
-
-		g_error_free(err);
-		g_key_file_free(keyfile);
-		return NULL;
-	}
-
-	return keyfile;
-}
-
-static void parse_config(GKeyFile *config)
-{
-	GError *error = NULL;
-	gboolean boolean;
-
-	if (config == NULL)
-		return;
-
-	DBG("parsing main.conf");
-
-	boolean = g_key_file_get_boolean(config, "General",
-						"BackgroundScanning", &error);
-	if (error == NULL)
-		connman_settings.bg_scan = boolean;
-
-	g_clear_error(&error);
-}
-
 static GMainLoop *main_loop = NULL;
 
 static unsigned int __terminated = 0;
@@ -229,21 +182,12 @@ const char *connman_option_get_string(const char *key)
 	return NULL;
 }
 
-connman_bool_t connman_setting_get_bool(const char *key)
-{
-	if (g_str_equal(key, "BackgroundScanning") == TRUE)
-		return connman_settings.bg_scan;
-
-	return FALSE;
-}
-
 int main(int argc, char *argv[])
 {
 	GOptionContext *context;
 	GError *error = NULL;
 	DBusConnection *conn;
 	DBusError err;
-	GKeyFile *config;
 	guint signal;
 
 #ifdef HAVE_CAPNG
@@ -324,9 +268,7 @@ int main(int argc, char *argv[])
 
 	__connman_dbus_init(conn);
 
-	config = load_config(CONFIGDIR "/main.conf");
-
-	parse_config(config);
+	__connman_storage_load_settings(CONFIGDIR "/main.conf");
 
 	__connman_storage_migrate();
 	__connman_technology_init();
@@ -410,15 +352,14 @@ int main(int argc, char *argv[])
 
 	__connman_dbus_cleanup();
 
+	__connman_storage_close_settings();
+
 	__connman_log_cleanup();
 
 	dbus_connection_unref(conn);
 
 	g_main_loop_unref(main_loop);
 
-	if (config)
-		g_key_file_free(config);
-
 	g_free(option_debug);
 
 	return 0;
-- 
1.7.8.4




More information about the connman mailing list