5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
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.
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.
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
30 #include <connman/plugin.h>
31 #include <connman/device.h>
32 #include <connman/log.h>
34 #define BLUEZ_SERVICE "org.bluez"
36 static int bluetooth_probe(struct connman_device *device)
38 DBG("device %p", device);
43 static void bluetooth_remove(struct connman_device *device)
45 DBG("device %p", device);
48 static struct connman_device_driver bluetooth_driver = {
50 .type = CONNMAN_DEVICE_TYPE_BLUETOOTH,
51 .probe = bluetooth_probe,
52 .remove = bluetooth_remove,
55 static void bluetooth_connect(DBusConnection *connection, void *user_data)
57 DBG("connection %p", connection);
60 static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
62 DBG("connection %p", connection);
65 static DBusConnection *connection;
68 static int bluetooth_init(void)
72 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
73 if (connection == NULL)
76 err = connman_device_driver_register(&bluetooth_driver);
78 dbus_connection_unref(connection);
82 watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
83 bluetooth_connect, bluetooth_disconnect, NULL, NULL);
85 connman_device_driver_unregister(&bluetooth_driver);
86 dbus_connection_unref(connection);
90 if (g_dbus_check_service(connection, BLUEZ_SERVICE) == TRUE)
91 bluetooth_connect(connection, NULL);
96 static void bluetooth_exit(void)
98 g_dbus_remove_watch(connection, watch);
100 connman_device_driver_unregister(&bluetooth_driver);
102 dbus_connection_unref(connection);
105 CONNMAN_PLUGIN_DEFINE("bluetooth", "Bluetooth technology plugin", VERSION,
106 bluetooth_init, bluetooth_exit)