diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2010-02-10 20:44:37 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-02-11 05:34:15 +0100 |
commit | b66394fcbc820c4047753904bc4096c09b37ed7f (patch) | |
tree | 0f1360e7c9ca0169ad69a06703fe5367fecd328b /plugins/bluetooth.c | |
parent | b7d93813b4f141ff26356f305f2c0881f7d20cf0 (diff) | |
download | connman-b66394fcbc820c4047753904bc4096c09b37ed7f.tar.gz connman-b66394fcbc820c4047753904bc4096c09b37ed7f.tar.bz2 connman-b66394fcbc820c4047753904bc4096c09b37ed7f.zip |
Set device powered when bluetooth adapters are powered
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.
Diffstat (limited to 'plugins/bluetooth.c')
-rw-r--r-- | plugins/bluetooth.c | 193 |
1 files changed, 98 insertions, 95 deletions
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index ef852dd4..9a43059d 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -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; |