From de4a89520ffebfabdf7814ece05c845cf73c163a Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Wed, 30 Nov 2011 13:16:28 +0200 Subject: [PATCH] service: Recompute service state when moving it up It should be possible to move down an online service to ready and the one which goes up might come up online after recomputing its state. --- src/connection.c | 2 -- src/service.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/connection.c b/src/connection.c index 477cf84..54f2b74 100644 --- a/src/connection.c +++ b/src/connection.c @@ -766,8 +766,6 @@ gboolean __connman_connection_update_gateway(void) unset_default_gateway(active_gateway, CONNMAN_IPCONFIG_TYPE_IPV6); - __connman_service_downgrade_state(active_gateway->service); - if (default_gateway) { if (default_gateway->ipv4_gateway) set_default_gateway(default_gateway, diff --git a/src/service.c b/src/service.c index fa2a483..c663def 100644 --- a/src/service.c +++ b/src/service.c @@ -3285,6 +3285,19 @@ static gboolean check_suitable_state(enum connman_service_state a, return a == b; } +static void apply_relevant_default_downgrade(struct connman_service *service) +{ + struct connman_service *def_service; + + def_service = get_default(); + if (def_service == NULL) + return; + + if (def_service == service && + def_service->state == CONNMAN_SERVICE_STATE_ONLINE) + def_service->state = CONNMAN_SERVICE_STATE_READY; +} + static DBusMessage *move_service(DBusConnection *conn, DBusMessage *msg, void *user_data, gboolean before) @@ -3364,7 +3377,21 @@ static DBusMessage *move_service(DBusConnection *conn, src = g_hash_table_lookup(service_hash, service->identifier); dst = g_hash_table_lookup(service_hash, target->identifier); - before ? g_sequence_move(src, dst) : g_sequence_move(dst, src); + /* + * If the service which goes down is the default service and is + * online, we downgrade directly its state to ready so: + * the service which goes up, needs to recompute its state which + * is triggered via downgrading it - if relevant - to state ready. + */ + if (before == TRUE) { + apply_relevant_default_downgrade(target); + g_sequence_move(src, dst); + __connman_service_downgrade_state(service); + } else { + apply_relevant_default_downgrade(service); + g_sequence_move(dst, src); + __connman_service_downgrade_state(target); + } services_changed(FALSE); -- 2.7.4