From: Marcel Holtmann Date: Tue, 7 Jul 2009 06:41:48 +0000 (-0700) Subject: Split service connect/disconnect from D-Bus message handling X-Git-Tag: 2.0_alpha~3604 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9344d99693c02b44732883ee1e4451552f6ab4b9;p=framework%2Fconnectivity%2Fconnman.git Split service connect/disconnect from D-Bus message handling --- diff --git a/src/connman.h b/src/connman.h index 380bfe3..03eb80f 100644 --- a/src/connman.h +++ b/src/connman.h @@ -259,6 +259,9 @@ int __connman_service_indicate_error(struct connman_service *service, enum connman_service_error error); int __connman_service_indicate_default(struct connman_service *service); +int __connman_service_connect(struct connman_service *service); +int __connman_service_disconnect(struct connman_service *service); + #include int __connman_notifier_init(void); diff --git a/src/service.c b/src/service.c index 0b435a3..a7087be 100644 --- a/src/service.c +++ b/src/service.c @@ -449,50 +449,29 @@ static DBusMessage *connect_service(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct connman_service *service = user_data; + int err; DBG("service %p", service); if (service->pending != NULL) return __connman_error_in_progress(msg); - if (service->state == CONNMAN_SERVICE_STATE_READY) - return __connman_error_already_connected(msg); - - if (service->network != NULL) { - int err; - - if (service->hidden == TRUE) - return __connman_error_invalid_service(msg); - - connman_network_set_string(service->network, - "WiFi.Passphrase", service->passphrase); - - err = __connman_network_connect(service->network); - 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, - connect_timeout, service); + err = __connman_service_connect(service); + if (err < 0) { + if (err != -EINPROGRESS) { + dbus_message_unref(service->pending); + service->pending = NULL; - return NULL; + return __connman_error_failed(msg, -err); } - } else if (service->device != NULL) { - if (service->favorite == FALSE) - return __connman_error_no_carrier(msg); - - if (__connman_device_connect(service->device) < 0) - return __connman_error_failed(msg, EINVAL); - - service->pending = dbus_message_ref(msg); - service->timeout = g_timeout_add_seconds(15, - connect_timeout, service); return NULL; - } else - return __connman_error_not_supported(msg); + } + + dbus_message_unref(service->pending); + service->pending = NULL; return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } @@ -501,6 +480,7 @@ static DBusMessage *disconnect_service(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct connman_service *service = user_data; + int err; DBG("service %p", service); @@ -517,23 +497,13 @@ static DBusMessage *disconnect_service(DBusConnection *conn, return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } - if (service->network != NULL) { - int err; - - err = __connman_network_disconnect(service->network); - if (err < 0 && err != -EINPROGRESS) + err = __connman_service_disconnect(service); + if (err < 0) { + if (err != -EINPROGRESS) return __connman_error_failed(msg, -err); - } else if (service->device != NULL) { - int err; - if (service->favorite == FALSE) - return __connman_error_no_carrier(msg); - - err = __connman_device_disconnect(service->device); - if (err < 0) - return __connman_error_failed(msg, -err); - } else - return __connman_error_not_supported(msg); + return NULL; + } return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } @@ -554,7 +524,7 @@ static DBusMessage *remove_service(DBusConnection *conn, if (service->network != NULL) __connman_network_disconnect(service->network); - g_free (service->passphrase); + g_free(service->passphrase); service->passphrase = NULL; connman_service_set_favorite(service, FALSE); @@ -970,6 +940,69 @@ int __connman_service_indicate_default(struct connman_service *service) return 0; } +int __connman_service_connect(struct connman_service *service) +{ + int err; + + DBG("service %p", service); + + if (service->state == CONNMAN_SERVICE_STATE_READY) + return -EISCONN; + + if (service->network != NULL) { + if (service->hidden == TRUE) + return -EINVAL; + + connman_network_set_string(service->network, + "WiFi.Passphrase", service->passphrase); + + err = __connman_network_connect(service->network); + } else if (service->device != NULL) { + if (service->favorite == FALSE) + return -ENOLINK; + + err = __connman_device_connect(service->device); + } else + return -EOPNOTSUPP; + + if (err < 0) { + if (err != -EINPROGRESS) + return err; + + service->timeout = g_timeout_add_seconds(45, + connect_timeout, service); + + return -EINPROGRESS; + } + + return 0; +} + +int __connman_service_disconnect(struct connman_service *service) +{ + int err; + + DBG("service %p", service); + + if (service->network != NULL) { + err = __connman_network_disconnect(service->network); + } else if (service->device != NULL) { + if (service->favorite == FALSE) + return -ENOLINK; + err = __connman_device_disconnect(service->device); + } else + return -EOPNOTSUPP; + + if (err < 0) { + if (err != -EINPROGRESS) + return err; + + return -EINPROGRESS; + } + + return 0; +} + /** * __connman_service_lookup: * @identifier: service identifier