Fix async handling of device powered property
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 1 Jul 2009 14:40:49 +0000 (07:40 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 1 Jul 2009 14:40:49 +0000 (07:40 -0700)
src/device.c
src/service.c

index 4afb2f4..a2507b5 100644 (file)
@@ -384,15 +384,17 @@ static DBusMessage *set_property(DBusConnection *conn,
                        return __connman_error_in_progress(msg);
 
                err = set_powered(device, powered);
-               if (err < 0 && err != -EINPROGRESS)
-                       return __connman_error_failed(msg, -err);
+               if (err < 0) {
+                       if (err != -EINPROGRESS)
+                               return __connman_error_failed(msg, -err);
 
-               device->pending = dbus_message_ref(msg);
+                       device->pending = dbus_message_ref(msg);
 
-               device->timeout = g_timeout_add_seconds(15,
+                       device->timeout = g_timeout_add_seconds(15,
                                                powered_timeout, device);
 
-               return NULL;
+                       return NULL;
+               }
        } else if (g_str_equal(name, "ScanInterval") == TRUE) {
                connman_uint16_t interval;
 
@@ -1199,6 +1201,7 @@ int connman_device_set_powered(struct connman_device *device,
                                                        DBUS_TYPE_INVALID);
 
                dbus_message_unref(device->pending);
+               device->pending = NULL;
        }
 
        if (device->powered == powered)
index fe4d956..6400d10 100644 (file)
@@ -464,15 +464,17 @@ static DBusMessage *connect_service(DBusConnection *conn,
                                "WiFi.Passphrase", service->passphrase);
 
                err = __connman_network_connect(service->network);
-               if (err < 0 && err != -EINPROGRESS)
-                       return __connman_error_failed(msg, -err);
+               if (err < 0) {
+                       if (err != -EINPROGRESS)
+                               return __connman_error_failed(msg, -err);
 
-               service->pending = dbus_message_ref(msg);
+                       service->pending = dbus_message_ref(msg);
 
-               service->timeout = g_timeout_add_seconds(45,
+                       service->timeout = g_timeout_add_seconds(45,
                                                connect_timeout, service);
 
-               return NULL;
+                       return NULL;
+               }
        } else if (service->device != NULL) {
                if (service->favorite == FALSE)
                        return __connman_error_no_carrier(msg);
@@ -485,9 +487,10 @@ static DBusMessage *connect_service(DBusConnection *conn,
                                                connect_timeout, service);
 
                return NULL;
-       }
+       } else
+               return __connman_error_not_supported(msg);
 
-       return __connman_error_not_supported(msg);
+       return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
 static DBusMessage *disconnect_service(DBusConnection *conn,
@@ -516,8 +519,6 @@ static DBusMessage *disconnect_service(DBusConnection *conn,
                err = __connman_network_disconnect(service->network);
                if (err < 0 && err != -EINPROGRESS)
                        return __connman_error_failed(msg, -err);
-
-               return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
        } else if (service->device != NULL) {
                int err;
 
@@ -527,11 +528,10 @@ static DBusMessage *disconnect_service(DBusConnection *conn,
                err = __connman_device_disconnect(service->device);
                if (err < 0)
                        return __connman_error_failed(msg, -err);
+       } else
+               return __connman_error_not_supported(msg);
 
-               return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-       }
-
-       return __connman_error_not_supported(msg);
+       return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
 static DBusMessage *remove_service(DBusConnection *conn,