From dd2006797565dce831d5e9fd891ac1bd75fa0a75 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 20 Dec 2011 10:34:36 +0100 Subject: iface-modem: while connected, ignore registration state changes --- src/mm-iface-modem-3gpp.c | 4 ---- src/mm-iface-modem.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index d2777421..2dde1efb 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -440,10 +440,6 @@ mm_iface_modem_3gpp_update_registration_state (MMIfaceModem3gpp *self, NULL); /* TODO: - * While connected we don't want registration status changes to change - * the modem's state away from CONNECTED. - * - * TODO: * If we're connected and we're not supposed to roam, but the device * just roamed, disconnect the connection to avoid charging the user * loads of money. diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index fd820e2c..f6d7d17a 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -177,6 +177,14 @@ handle_list_bearers (MmGdbusModem *skeleton, /*****************************************************************************/ +static void +bearer_list_count_connected (MMBearer *bearer, + guint *count) +{ + if (mm_bearer_get_status (bearer) == MM_BEARER_STATUS_CONNECTED) + *count++; +} + void mm_iface_modem_update_state (MMIfaceModem *self, MMModemState new_state, @@ -184,13 +192,31 @@ mm_iface_modem_update_state (MMIfaceModem *self, { MMModemState old_state = MM_MODEM_STATE_UNKNOWN; MmGdbusModem *skeleton = NULL; + MMBearerList *bearer_list = NULL; - /* Did we already create it? */ g_object_get (self, MM_IFACE_MODEM_STATE, &old_state, MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, + MM_IFACE_MODEM_BEARER_LIST, &bearer_list, NULL); + /* While connected we don't want registration status changes to change + * the modem's state away from CONNECTED. */ + if ((new_state == MM_MODEM_STATE_SEARCHING || + new_state == MM_MODEM_STATE_REGISTERED) && + bearer_list && + old_state > MM_MODEM_STATE_REGISTERED) { + guint connected = 0; + + mm_bearer_list_foreach (bearer_list, + (MMBearerListForeachFunc)bearer_list_count_connected, + &connected); + if (connected > 0) + /* Don't update state */ + new_state = old_state; + } + + /* Update state only if different */ if (new_state != old_state) { GEnumClass *enum_class; GEnumValue *new_value; @@ -224,6 +250,11 @@ mm_iface_modem_update_state (MMIfaceModem *self, new_state, reason); } + + if (skeleton) + g_object_unref (skeleton); + if (bearer_list) + g_object_unref (bearer_list); } /*****************************************************************************/ -- cgit v1.2.3-70-g09d2