From: Samuel Ortiz Date: Fri, 1 Apr 2011 23:35:28 +0000 (+0200) Subject: main: Initial configuration file support X-Git-Tag: 2.0_alpha~1603 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d6a8190836330d68f64b78c95303133b36d8b26b;p=framework%2Fconnectivity%2Fconnman.git main: Initial configuration file support --- diff --git a/Makefile.am b/Makefile.am index 95aefc7..2e29353 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,8 @@ noinst_HEADERS = include/driver.h include/element.h include/property.h \ include/dbus.h include/rfkill.h include/option.h \ include/profile.h include/provider.h \ include/utsname.h include/timeserver.h include/proxy.h \ - include/location.h include/technology.h + include/location.h include/technology.h \ + include/configuration.h local_headers = $(foreach file,$(include_HEADERS) $(nodist_include_HEADERS) \ $(noinst_HEADERS), include/connman/$(notdir $(file))) @@ -95,6 +96,8 @@ scriptdir = $(libdir)/connman/scripts storagedir = $(localstatedir)/lib/connman +configdir = ${sysconfdir}/connman + if MAINTAINER_MODE build_plugindir = $(abs_top_srcdir)/plugins/.libs build_scriptdir = $(abs_top_srcdir)/scripts @@ -110,7 +113,8 @@ AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @CAPNG_CFLAGS@ @XTABLES_CFLAGS@ \ -DSTATEDIR=\""$(statedir)"\" \ -DPLUGINDIR=\""$(build_plugindir)"\" \ -DSCRIPTDIR=\""$(build_scriptdir)"\" \ - -DSTORAGEDIR=\""$(storagedir)\"" + -DSTORAGEDIR=\""$(storagedir)\"" \ + -DCONFIGDIR=\""$(configdir)\"" INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/gdbus diff --git a/include/configuration.h b/include/configuration.h new file mode 100644 index 0000000..836fea9 --- /dev/null +++ b/include/configuration.h @@ -0,0 +1,35 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2011 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __CONNMAN_CONFIGURATION_H +#define __CONNMAN_CONFIGURATION_H + +#ifdef __cplusplus +extern "C" { +#endif + +connman_bool_t connman_configuration_get_bool(const char *key); + +#ifdef __cplusplus +} +#endif + +#endif /* __CONNMAN_CONFIGURATION_H */ diff --git a/src/connman.h b/src/connman.h index 2d152a4..379eec0 100644 --- a/src/connman.h +++ b/src/connman.h @@ -93,6 +93,8 @@ void __connman_debug_list_enabled(DBusMessageIter *iter, void *user_data); #include +#include + #include int __connman_plugin_init(const char *pattern, const char *exclude); diff --git a/src/main.c b/src/main.c index ac90b5e..9f7c7d2 100644 --- a/src/main.c +++ b/src/main.c @@ -40,6 +40,51 @@ #include "connman.h" +struct connman_conf { + connman_bool_t bg_scan; +}; + +static struct connman_conf main_conf = { + .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)) { + 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) + main_conf.bg_scan = boolean; + + g_clear_error(&error); +} + static GMainLoop *main_loop = NULL; static void sig_term(int sig) @@ -117,6 +162,14 @@ const char *connman_option_get_string(const char *key) return NULL; } +connman_bool_t connman_configuration_get_bool(const char *key) +{ + if (g_str_equal(key, "BackgroundScanning") == TRUE) + return main_conf.bg_scan; + + return FALSE; +} + int main(int argc, char *argv[]) { GOptionContext *context; @@ -125,6 +178,7 @@ int main(int argc, char *argv[]) DBusError err; struct sigaction sa; mode_t old_umask; + GKeyFile *config; #ifdef HAVE_CAPNG /* Drop capabilities */ @@ -208,6 +262,10 @@ int main(int argc, char *argv[]) __connman_dbus_init(conn); + config = load_config(CONFIGDIR "/main.conf"); + + parse_config(config); + __connman_storage_init(); __connman_element_init(option_device, option_nodevice); @@ -280,5 +338,8 @@ int main(int argc, char *argv[]) g_main_loop_unref(main_loop); + if (config) + g_key_file_free(config); + return 0; }