tizen 2.3.1 release
[framework/connectivity/bluez.git] / profiles / proximity / main.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2011  Nokia Corporation
6  *  Copyright (C) 2011  Marcel Holtmann <marcel@holtmann.org>
7  *
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <errno.h>
30 #include <stdint.h>
31 #include <glib.h>
32
33 #include "gdbus/gdbus.h"
34
35 #include "src/log.h"
36 #include "src/plugin.h"
37 #include "manager.h"
38
39 static GKeyFile *config = NULL;
40
41 static GKeyFile *open_config_file(const char *file)
42 {
43         GError *gerr = NULL;
44         GKeyFile *keyfile;
45
46         keyfile = g_key_file_new();
47
48         g_key_file_set_list_separator(keyfile, ',');
49
50         if (!g_key_file_load_from_file(keyfile, file, 0, &gerr)) {
51                 if (!g_error_matches(gerr, G_FILE_ERROR, G_FILE_ERROR_NOENT))
52                         error("Parsing %s failed: %s", file, gerr->message);
53                 g_error_free(gerr);
54                 g_key_file_free(keyfile);
55                 return NULL;
56         }
57
58         return keyfile;
59 }
60
61 static int proximity_init(void)
62 {
63         config = open_config_file(CONFIGDIR "/proximity.conf");
64
65         if (proximity_manager_init(config) < 0)
66                 return -EIO;
67
68         return 0;
69 }
70
71 static void proximity_exit(void)
72 {
73         if (config)
74                 g_key_file_free(config);
75
76         proximity_manager_exit();
77 }
78
79 BLUETOOTH_PLUGIN_DEFINE(proximity, VERSION,
80                         BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
81                         proximity_init, proximity_exit)