From: Samuel Ortiz Date: Fri, 24 Feb 2012 16:38:24 +0000 (+0100) Subject: main: Support for general settings X-Git-Tag: 0.2~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff57b87cacfe0962d7c92c9b3478cfdab8b3f331;p=platform%2Fupstream%2Fneard.git main: Support for general settings main.conf will be neard settings file. --- diff --git a/Makefile.am b/Makefile.am index d64112e..3f01b2f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,7 @@ includedir = @includedir@/near include_HEADERS = include/types.h include/log.h include/plugin.h \ include/tag.h include/adapter.h include/ndef.h \ - include/target.h include/tlv.h + include/target.h include/tlv.h include/setting.h nodist_include_HEADERS = include/version.h @@ -42,7 +42,8 @@ nodist_src_neard_SOURCES = src/builtin.h AM_CFLAGS = @GLIB_CFLAGS@ @DBUS_CFLAGS@ @NETLINK_CFLAGS@ $(builtin_cflags) \ -DNEAR_PLUGIN_BUILTIN \ - -DPLUGINDIR=\""$(plugindir)"\" + -DPLUGINDIR=\""$(plugindir)"\" \ + -DCONFIGDIR=\""$(configdir)\"" INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/gdbus @@ -50,6 +51,8 @@ CLEANFILES = src/builtin.h $(local_headers) plugindir = $(libdir)/near/plugins +configdir = ${sysconfdir}/neard + if MAINTAINER_MODE build_plugindir = $(abs_top_srcdir)/plugins/.libs else diff --git a/include/setting.h b/include/setting.h new file mode 100644 index 0000000..8f7a26a --- /dev/null +++ b/include/setting.h @@ -0,0 +1,35 @@ +/* + * + * neard - Near Field Communication manager + * + * Copyright (C) 2012 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 __NEAR_SETTING_H +#define __NEAR_SETTING_H + +#ifdef __cplusplus +extern "C" { +#endif + +near_bool_t near_setting_get_bool(const char *key); + +#ifdef __cplusplus +} +#endif + +#endif /* __NEAR_SETTING_H */ diff --git a/src/main.c b/src/main.c index 7fe6388..f59fda4 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,53 @@ #include "near.h" +static struct { + near_bool_t constant_poll; +} near_settings = { + .constant_poll = FALSE, +}; + +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) { + near_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", + "ConstantPoll", &error); + if (error == NULL) + near_settings.constant_poll = boolean; + + g_clear_error(&error); +} + static GMainLoop *main_loop = NULL; static volatile sig_atomic_t __terminated = 0; @@ -89,12 +136,21 @@ static GOptionEntry options[] = { { NULL }, }; +near_bool_t near_setting_get_bool(const char *key) +{ + if (g_str_equal(key, "ConstantPoll") == TRUE) + return near_settings.constant_poll; + + return FALSE; +} + int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; DBusConnection *conn; DBusError err; + GKeyFile *config; struct sigaction sa; context = g_option_context_new(NULL); @@ -142,6 +198,10 @@ int main(int argc, char *argv[]) __near_log_init(option_debug, option_detach); __near_dbus_init(conn); + config = load_config(CONFIGDIR "/main.conf"); + + parse_config(config); + __near_netlink_init(); __near_target_init(); __near_adapter_init(); @@ -174,5 +234,8 @@ int main(int argc, char *argv[]) g_main_loop_unref(main_loop); + if (config) + g_key_file_free(config); + return 0; } diff --git a/src/near.h b/src/near.h index 9758038..15f362c 100644 --- a/src/near.h +++ b/src/near.h @@ -147,6 +147,8 @@ int __near_netlink_deactivate_target(uint32_t adapter_idx, int __near_netlink_init(void); void __near_netlink_cleanup(void); +#include + #include int __near_plugin_init(const char *pattern, const char *exclude);