Set device powered when bluetooth adapters are powered
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 10 Feb 2010 19:44:37 +0000 (20:44 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 11 Feb 2010 04:34:15 +0000 (05:34 +0100)
When a bluetooth adapters are added, we go through adapter_properties_reply(),
but we dont call connman_device_set_powered() or check_networks() because the
powered variable is false.

We should get the adapter properties upon getting the powered D-Bus reply
message and that will end up calling the right functions.

plugins/bluetooth.c

index ef852dd..9a43059 100644 (file)
@@ -246,101 +246,6 @@ static struct connman_network_driver pan_driver = {
        .disconnect     = pan_disconnect,
 };
 
-static int bluetooth_probe(struct connman_device *device)
-{
-       DBG("device %p", device);
-
-       return 0;
-}
-
-static void bluetooth_remove(struct connman_device *device)
-{
-       DBG("device %p", device);
-}
-
-static void powered_reply(DBusPendingCall *call, void *user_data)
-{
-       DBusMessage *reply;
-
-       DBG("");
-
-       reply = dbus_pending_call_steal_reply(call);
-
-       dbus_message_unref(reply);
-
-       dbus_pending_call_unref(call);
-}
-
-static int change_powered(DBusConnection *connection, const char *path,
-                                                       dbus_bool_t powered)
-{
-       DBusMessage *message;
-       DBusMessageIter iter;
-       DBusPendingCall *call;
-
-       DBG("");
-
-       if (path == NULL)
-               return -EINVAL;
-
-       message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
-                                       BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
-       if (message == NULL)
-               return -ENOMEM;
-
-       dbus_message_set_auto_start(message, FALSE);
-
-       dbus_message_iter_init_append(message, &iter);
-       connman_dbus_property_append_basic(&iter, "Powered",
-                                               DBUS_TYPE_BOOLEAN, &powered);
-
-       if (dbus_connection_send_with_reply(connection, message,
-                                               &call, TIMEOUT) == FALSE) {
-               connman_error("Failed to change Powered property");
-               dbus_message_unref(message);
-               return -EINVAL;
-       }
-
-       if (call == NULL) {
-               connman_error("D-Bus connection not available");
-               dbus_message_unref(message);
-               return -EINVAL;
-       }
-
-       dbus_pending_call_set_notify(call, powered_reply, NULL, NULL);
-
-       dbus_message_unref(message);
-
-       return -EINPROGRESS;
-}
-
-static int bluetooth_enable(struct connman_device *device)
-{
-       const char *path = connman_device_get_string(device, "Path");
-
-       DBG("device %p", device);
-
-       return change_powered(connection, path, TRUE);
-}
-
-static int bluetooth_disable(struct connman_device *device)
-{
-       const char *path = connman_device_get_string(device, "Path");
-
-       DBG("device %p", device);
-
-       return change_powered(connection, path, FALSE);
-}
-
-static struct connman_device_driver bluetooth_driver = {
-       .name           = "bluetooth",
-       .type           = CONNMAN_DEVICE_TYPE_BLUETOOTH,
-       .probe          = bluetooth_probe,
-       .remove         = bluetooth_remove,
-       .enable         = bluetooth_enable,
-       .disable        = bluetooth_disable,
-};
-
 static void extract_properties(DBusMessage *reply, const char **parent,
                                                const char **address,
                                                const char **name,
@@ -803,6 +708,104 @@ static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
        bluetooth_devices = NULL;
 }
 
+static int bluetooth_probe(struct connman_device *device)
+{
+       DBG("device %p", device);
+
+       return 0;
+}
+
+static void bluetooth_remove(struct connman_device *device)
+{
+       DBG("device %p", device);
+}
+
+static void powered_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply;
+
+       DBG("");
+
+       reply = dbus_pending_call_steal_reply(call);
+
+       dbus_message_unref(reply);
+
+       dbus_pending_call_unref(call);
+
+       add_adapter(connection, user_data);
+}
+
+static int change_powered(DBusConnection *connection, const char *path,
+                                                       dbus_bool_t powered)
+{
+       DBusMessage *message;
+       DBusMessageIter iter;
+       DBusPendingCall *call;
+
+       DBG("");
+
+       if (path == NULL)
+               return -EINVAL;
+
+       message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+                                       BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
+       if (message == NULL)
+               return -ENOMEM;
+
+       dbus_message_set_auto_start(message, FALSE);
+
+       dbus_message_iter_init_append(message, &iter);
+       connman_dbus_property_append_basic(&iter, "Powered",
+                                               DBUS_TYPE_BOOLEAN, &powered);
+
+       if (dbus_connection_send_with_reply(connection, message,
+                                               &call, TIMEOUT) == FALSE) {
+               connman_error("Failed to change Powered property");
+               dbus_message_unref(message);
+               return -EINVAL;
+       }
+
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return -EINVAL;
+       }
+
+       dbus_pending_call_set_notify(call, powered_reply,
+                                       g_strdup(path), g_free);
+
+       dbus_message_unref(message);
+
+       return -EINPROGRESS;
+}
+
+static int bluetooth_enable(struct connman_device *device)
+{
+       const char *path = connman_device_get_string(device, "Path");
+
+       DBG("device %p", device);
+
+       return change_powered(connection, path, TRUE);
+}
+
+static int bluetooth_disable(struct connman_device *device)
+{
+       const char *path = connman_device_get_string(device, "Path");
+
+       DBG("device %p", device);
+
+       return change_powered(connection, path, FALSE);
+}
+
+static struct connman_device_driver bluetooth_driver = {
+       .name           = "bluetooth",
+       .type           = CONNMAN_DEVICE_TYPE_BLUETOOTH,
+       .probe          = bluetooth_probe,
+       .remove         = bluetooth_remove,
+       .enable         = bluetooth_enable,
+       .disable        = bluetooth_disable,
+};
+
 static guint watch;
 static guint added_watch;
 static guint removed_watch;