This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 plugins/bluetooth.c |  133 +++++++++++++++++++++++++--------------------------
 1 files changed, 65 insertions(+), 68 deletions(-)

New commits:
commit 3740318614518a1af92f22b297eb4603c6ca20e8
Author: Marcel Holtmann <[email protected]>
Date:   Sat Dec 20 09:38:46 2008 +0100

    Iterate over the Bluetooth Devices property

commit c40b50857d39ce1ba3110dea0abaa8c838c8b7c4
Author: Marcel Holtmann <[email protected]>
Date:   Sat Dec 20 09:07:13 2008 +0100

    Use private adapter data structure


Diff in this email is a maximum of 400 lines.
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 9a26a94..9bb29d4 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -41,20 +41,47 @@
 #define ADAPTER_REMOVED                        "AdapterRemoved"
 
 #define PROPERTY_CHANGED               "PropertyChanged"
+#define GET_PROPERTIES                 "GetProperties"
 #define SET_PROPERTY                   "SetProperty"
 
 #define TIMEOUT 5000
 
-static int bluetooth_probe(struct connman_element *device)
+struct adapter_data {
+       DBusConnection *connection;
+};
+
+static int bluetooth_probe(struct connman_element *adapter)
 {
-       DBG("device %p name %s", device, device->name);
+       struct adapter_data *data;
+
+       DBG("adapter %p name %s", adapter, adapter->name);
+
+       data = g_try_new0(struct adapter_data, 1);
+       if (data == NULL)
+               return -ENOMEM;
+
+       data->connection = connman_dbus_get_connection();
+       if (data->connection == NULL) {
+               g_free(data);
+               return -EIO;
+       }
+
+       connman_element_set_data(adapter, data);
 
        return 0;
 }
 
-static void bluetooth_remove(struct connman_element *device)
+static void bluetooth_remove(struct connman_element *adapter)
 {
-       DBG("device %p name %s", device, device->name);
+       struct adapter_data *data = connman_element_get_data(adapter);
+
+       DBG("adapter %p name %s", adapter, adapter->name);
+
+       connman_element_set_data(adapter, NULL);
+
+       dbus_connection_unref(data->connection);
+
+       g_free(data);
 }
 
 static void powered_reply(DBusPendingCall *call, void *user_data)
@@ -100,22 +127,22 @@ static int change_powered(DBusConnection *connection, 
const char *path,
        return -EINPROGRESS;
 }
 
-static int bluetooth_enable(struct connman_element *device)
+static int bluetooth_enable(struct connman_element *adapter)
 {
-       DBusConnection *connection = connman_element_get_data(device);
+       struct adapter_data *data = connman_element_get_data(adapter);
 
-       DBG("device %p name %s", device, device->name);
+       DBG("adapter %p name %s", adapter, adapter->name);
 
-       return change_powered(connection, device->devpath, TRUE);
+       return change_powered(data->connection, adapter->devpath, TRUE);
 }
 
-static int bluetooth_disable(struct connman_element *device)
+static int bluetooth_disable(struct connman_element *adapter)
 {
-       DBusConnection *connection = connman_element_get_data(device);
+       struct adapter_data *data = connman_element_get_data(adapter);
 
-       DBG("device %p name %s", device, device->name);
+       DBG("adapter %p name %s", adapter, adapter->name);
 
-       return change_powered(connection, device->devpath, FALSE);
+       return change_powered(data->connection, adapter->devpath, FALSE);
 }
 
 static struct connman_driver bluetooth_driver = {
@@ -146,6 +173,29 @@ static struct connman_element *find_adapter(const char 
*path)
        return NULL;
 }
 
+static void check_devices(struct connman_element *adapter,
+                                               DBusMessageIter *array)
+{
+       DBusMessageIter value;
+
+       DBG("adapter %p name %s", adapter, adapter->name);
+
+       if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+               return;
+
+       dbus_message_iter_recurse(array, &value);
+
+       while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) 
{
+               const char *path;
+
+               dbus_message_iter_get_basic(&value, &path);
+
+               DBG("device %s", path);
+
+               dbus_message_iter_next(&value);
+       }
+}
+
 static void property_changed(DBusConnection *connection, DBusMessage *message)
 {
        const char *path = dbus_message_get_path(message);
@@ -226,6 +276,8 @@ static void properties_reply(DBusPendingCall *call, void 
*user_data)
 
                        dbus_message_iter_get_basic(&value, &val);
                        connman_element_set_scanning(device, val);
+               } else if (g_str_equal(key, "Devices") == TRUE) {
+                       check_devices(device, &value);
                }
 
                dbus_message_iter_next(&dict);
@@ -235,45 +287,6 @@ done:
        dbus_message_unref(reply);
 }
 
-static void devices_reply(DBusPendingCall *call, void *user_data)
-{
-       DBusMessage *message = user_data;
-       const char *path = dbus_message_get_path(message);
-       DBusMessage *reply;
-       DBusError error;
-       char **devices;
-       int i, num_devices;
-
-       DBG("path %s", path);
-
-       dbus_message_unref(message);
-
-       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,
-                                               &devices, &num_devices,
-                                               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 device list");
-               goto done;
-       }
-
-       for (i = 0; i < num_devices; i++) {
-               DBG("device %s", devices[i]);
-       }
-
-       g_strfreev(devices);
-
-done:
-       dbus_message_unref(reply);
-}
-
 static void add_adapter(DBusConnection *connection, const char *path)
 {
        struct connman_element *device;
@@ -294,8 +307,6 @@ static void add_adapter(DBusConnection *connection, const 
char *path)
        device->name = g_path_get_basename(path);
        device->devpath = g_strdup(path);
 
-       connman_element_set_data(device, connection);
-
        if (connman_element_register(device, NULL) < 0) {
                connman_element_unref(device);
                return;
@@ -304,7 +315,7 @@ static void add_adapter(DBusConnection *connection, const 
char *path)
        device_list = g_slist_append(device_list, device);
 
        message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
-                               BLUEZ_ADAPTER_INTERFACE, "GetProperties");
+                               BLUEZ_ADAPTER_INTERFACE, GET_PROPERTIES);
        if (message == NULL)
                return;
 
@@ -316,20 +327,6 @@ static void add_adapter(DBusConnection *connection, const 
char *path)
        }
 
        dbus_pending_call_set_notify(call, properties_reply, message, NULL);
-
-       message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
-                               BLUEZ_ADAPTER_INTERFACE, "ListDevices");
-       if (message == NULL)
-               return;
-
-       if (dbus_connection_send_with_reply(connection, message,
-                                               &call, TIMEOUT) == FALSE) {
-               connman_error("Failed to get Bluetooth devices");
-               dbus_message_unref(message);
-               return;
-       }
-
-       dbus_pending_call_set_notify(call, devices_reply, message, NULL);
 }
 
 static void remove_adapter(DBusConnection *connection, const char *path)
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to