main.conf will be neard settings file.
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
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
plugindir = $(libdir)/near/plugins
+configdir = ${sysconfdir}/neard
+
if MAINTAINER_MODE
build_plugindir = $(abs_top_srcdir)/plugins/.libs
else
--- /dev/null
+/*
+ *
+ * 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 */
#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;
{ 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);
__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();
g_main_loop_unref(main_loop);
+ if (config)
+ g_key_file_free(config);
+
return 0;
}
int __near_netlink_init(void);
void __near_netlink_cleanup(void);
+#include <near/setting.h>
+
#include <near/plugin.h>
int __near_plugin_init(const char *pattern, const char *exclude);