Call connect function if service is present
[connman] / plugins / bluetooth.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2008  Intel Corporation. All rights reserved.
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 version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27
28 #include <gdbus.h>
29
30 #include <connman/plugin.h>
31 #include <connman/device.h>
32 #include <connman/log.h>
33
34 #define BLUEZ_SERVICE "org.bluez"
35
36 static int bluetooth_probe(struct connman_device *device)
37 {
38         DBG("device %p", device);
39
40         return 0;
41 }
42
43 static void bluetooth_remove(struct connman_device *device)
44 {
45         DBG("device %p", device);
46 }
47
48 static struct connman_device_driver bluetooth_driver = {
49         .name   = "bluetooth",
50         .type   = CONNMAN_DEVICE_TYPE_BLUETOOTH,
51         .probe  = bluetooth_probe,
52         .remove = bluetooth_remove,
53 };
54
55 static void bluetooth_connect(DBusConnection *connection, void *user_data)
56 {
57         DBG("connection %p", connection);
58 }
59
60 static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
61 {
62         DBG("connection %p", connection);
63 }
64
65 static DBusConnection *connection;
66 static guint watch;
67
68 static int bluetooth_init(void)
69 {
70         int err;
71
72         connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
73         if (connection == NULL)
74                 return -EIO;
75
76         err = connman_device_driver_register(&bluetooth_driver);
77         if (err < 0) {
78                 dbus_connection_unref(connection);
79                 return -EIO;
80         }
81
82         watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
83                         bluetooth_connect, bluetooth_disconnect, NULL, NULL);
84         if (watch == 0) {
85                 connman_device_driver_unregister(&bluetooth_driver);
86                 dbus_connection_unref(connection);
87                 return -EIO;
88         }
89
90         if (g_dbus_check_service(connection, BLUEZ_SERVICE) == TRUE)
91                 bluetooth_connect(connection, NULL);
92
93         return 0;
94 }
95
96 static void bluetooth_exit(void)
97 {
98         g_dbus_remove_watch(connection, watch);
99
100         connman_device_driver_unregister(&bluetooth_driver);
101
102         dbus_connection_unref(connection);
103 }
104
105 CONNMAN_PLUGIN_DEFINE("bluetooth", "Bluetooth technology plugin", VERSION,
106                                                 bluetooth_init, bluetooth_exit)