Tizen 2.0 Release
[framework/connectivity/bluez.git] / thermometer / main.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2011 GSyC/LibreSoft, Universidad Rey Juan Carlos.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdint.h>
28 #include <glib.h>
29 #include <errno.h>
30 #include <gdbus.h>
31
32 #include "plugin.h"
33 #include "manager.h"
34 #include "hcid.h"
35 #include "log.h"
36
37 static DBusConnection *connection = NULL;
38
39 static int thermometer_init(void)
40 {
41         if (!main_opts.gatt_enabled) {
42                 DBG("GATT is disabled");
43                 return -ENOTSUP;
44         }
45
46         connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
47         if (connection == NULL)
48                 return -EIO;
49
50         if (thermometer_manager_init(connection) < 0) {
51                 dbus_connection_unref(connection);
52                 return -EIO;
53         }
54
55         return 0;
56 }
57
58 static void thermometer_exit(void)
59 {
60         if (!main_opts.gatt_enabled)
61                 return;
62
63         thermometer_manager_exit();
64
65         dbus_connection_unref(connection);
66         connection = NULL;
67 }
68
69 BLUETOOTH_PLUGIN_DEFINE(thermometer, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
70                                         thermometer_init, thermometer_exit)