summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-12-05 13:59:25 +0100
committerMarcel Holtmann <marcel@holtmann.org>2008-12-05 13:59:25 +0100
commitcf87ef5c131af32de16b51d47ecd55f26d2b991c (patch)
treeb7d01adf4be33c27e7432f10da837fb810c0927f /plugins
parent0f7286042151b6fa69570a0990dc5400ac8ca70c (diff)
downloadconnman-cf87ef5c131af32de16b51d47ecd55f26d2b991c.tar.gz
connman-cf87ef5c131af32de16b51d47ecd55f26d2b991c.tar.bz2
connman-cf87ef5c131af32de16b51d47ecd55f26d2b991c.zip
Fix detection of Bluetooth devices
Diffstat (limited to 'plugins')
-rw-r--r--plugins/bluetooth.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 6b0b69a0..978f2577 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -33,6 +33,8 @@
#define BLUEZ_SERVICE "org.bluez"
+#define TIMEOUT 5000
+
static int bluetooth_probe(struct connman_device *device)
{
DBG("device %p", device);
@@ -52,14 +54,91 @@ static struct connman_device_driver bluetooth_driver = {
.remove = bluetooth_remove,
};
+static GSList *device_list = NULL;
+
+static void adapters_reply(DBusPendingCall *call, void *user_data)
+{
+ DBusMessage *reply;
+ DBusError error;
+ char **adapters;
+ int i, num_adapters;
+
+ DBG("");
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&error);
+
+ if (dbus_message_get_args(reply, &error,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH,
+ &adapters, &num_adapters,
+ DBUS_TYPE_INVALID) == FALSE) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ } else
+ connman_error("Wrong arguments for adapter list");
+ goto done;
+ }
+
+ for (i = 0; i < num_adapters; i++) {
+ struct connman_element *device;
+
+ device = connman_element_create(NULL);
+ device->type = CONNMAN_ELEMENT_TYPE_DEVICE;
+ device->subtype = CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH;
+
+ device->name = g_path_get_basename(adapters[i]);
+
+ connman_element_register(device, NULL);
+ device_list = g_slist_append(device_list, device);
+ }
+
+ g_strfreev(adapters);
+
+done:
+ dbus_message_unref(reply);
+}
+
static void bluetooth_connect(DBusConnection *connection, void *user_data)
{
+ DBusMessage *message;
+ DBusPendingCall *call;
+
DBG("connection %p", connection);
+
+ message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
+ "org.bluez.Manager", "ListAdapters");
+ if (message == NULL)
+ return;
+
+ if (dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT) == FALSE) {
+ connman_error("Failed to get Bluetooth adapters");
+ dbus_message_unref(message);
+ return;
+ }
+
+ dbus_pending_call_set_notify(call, adapters_reply, NULL, NULL);
+
+ dbus_message_unref(message);
}
static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
{
+ GSList *list;
+
DBG("connection %p", connection);
+
+ for (list = device_list; list; list = list->next) {
+ struct connman_element *device = list->data;
+
+ connman_element_unregister(device);
+ connman_element_unref(device);
+ }
+
+ g_slist_free(device_list);
+ device_list = NULL;
}
static DBusConnection *connection;