diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-07-06 23:41:48 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-07-06 23:41:48 -0700 |
commit | 9344d99693c02b44732883ee1e4451552f6ab4b9 (patch) | |
tree | 00ae1233fae68ed45401dbc01a9c7d1a8204b613 | |
parent | 4ce670e249666dc5fb92357a157cf84071617f42 (diff) | |
download | connman-9344d99693c02b44732883ee1e4451552f6ab4b9.tar.gz connman-9344d99693c02b44732883ee1e4451552f6ab4b9.tar.bz2 connman-9344d99693c02b44732883ee1e4451552f6ab4b9.zip |
Split service connect/disconnect from D-Bus message handling
-rw-r--r-- | src/connman.h | 3 | ||||
-rw-r--r-- | src/service.c | 131 |
2 files changed, 85 insertions, 49 deletions
diff --git a/src/connman.h b/src/connman.h index 380bfe37..03eb80fb 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 <connman/notifier.h> int __connman_notifier_init(void); diff --git a/src/service.c b/src/service.c index 0b435a3b..a7087be4 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 |