From 0498e18e84cf56a28ed0ebc72ad0b42071fa8efa Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Wed, 15 Feb 2012 10:19:45 +0200 Subject: [PATCH] session: filtering session state update according to connection type --- src/session.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/session.c b/src/session.c index b846e2d..b67b2ea 100644 --- a/src/session.c +++ b/src/session.c @@ -547,6 +547,28 @@ static void append_notify(DBusMessageIter *dict, session->append_all = FALSE; } +static connman_bool_t is_type_matching_state(enum connman_session_state *state, + enum connman_session_type type) +{ + switch (type) { + case CONNMAN_SESSION_TYPE_ANY: + return TRUE; + case CONNMAN_SESSION_TYPE_LOCAL: + if (*state >= CONNMAN_SESSION_STATE_CONNECTED) { + *state = CONNMAN_SESSION_STATE_CONNECTED; + return TRUE; + } + + break; + case CONNMAN_SESSION_TYPE_INTERNET: + if (*state == CONNMAN_SESSION_STATE_ONLINE) + return TRUE; + break; + } + + return FALSE; +} + static connman_bool_t compute_notifiable_changes(struct connman_session *session) { struct session_info *info_last = session->info_last; @@ -1005,7 +1027,13 @@ static void deselect_and_disconnect(struct connman_session *session, static void select_connected_service(struct session_info *info, struct service_entry *entry) { - info->state = service_to_session_state(entry->state); + enum connman_session_state state; + + state = service_to_session_state(entry->state); + if (is_type_matching_state(&state, info->type) == FALSE) + return; + + info->state = state; info->entry = entry; info->entry->reason = info->reason; @@ -1165,8 +1193,14 @@ static void session_changed(struct connman_session *session, DBG("session %p trigger %s reason %s", session, trigger2string(trigger), reason2string(info->reason)); - if (info->entry != NULL) - info->state = service_to_session_state(info->entry->state); + if (info->entry != NULL) { + enum connman_session_state state; + + state = service_to_session_state(info->entry->state); + + if (is_type_matching_state(&state, info->type) == TRUE) + info->state = state; + } switch (trigger) { case CONNMAN_SESSION_TRIGGER_UNKNOWN: @@ -1201,6 +1235,13 @@ static void session_changed(struct connman_session *session, g_sequence_free(service_list_last); } + if (info->type != info_last->type) { + if (info->state >= CONNMAN_SESSION_STATE_CONNECTED && + is_type_matching_state(&info->state, + info->type) == FALSE) + deselect_and_disconnect(session, info->reason); + } + if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED) { select_and_connect(session, CONNMAN_SESSION_REASON_FREE_RIDE); -- 2.7.4