diff options
author | Gustavo F. Padovan <padovan@profusion.mobi> | 2010-12-07 16:31:34 -0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-12-17 19:12:32 -0600 |
commit | 8bdbdc2c7d113865e980c6cbd71317c8717a69b5 (patch) | |
tree | 64d1e0fddb0bfa73b92339c426387f7b6046d405 /src/modem.c | |
parent | 79b29d2802fcd57eb47e5f41d4f7cd6cf0528f87 (diff) | |
download | ofono-8bdbdc2c7d113865e980c6cbd71317c8717a69b5.tar.bz2 |
modem: restore state when resetting the modem
Diffstat (limited to 'src/modem.c')
-rw-r--r-- | src/modem.c | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/src/modem.c b/src/modem.c index 2f9387c1..816443eb 100644 --- a/src/modem.c +++ b/src/modem.c @@ -70,6 +70,7 @@ struct ofono_modem { guint interface_update; ofono_bool_t powered; ofono_bool_t powered_pending; + ofono_bool_t get_online; guint timeout; ofono_bool_t online; struct ofono_watchlist *online_watches; @@ -434,30 +435,6 @@ static void modem_change_state(struct ofono_modem *modem, } } -static void sim_state_watch(enum ofono_sim_state new_state, void *user) -{ - struct ofono_modem *modem = user; - - switch (new_state) { - case OFONO_SIM_STATE_NOT_PRESENT: - modem_change_state(modem, MODEM_STATE_PRE_SIM); - break; - case OFONO_SIM_STATE_INSERTED: - break; - case OFONO_SIM_STATE_READY: - modem_change_state(modem, MODEM_STATE_OFFLINE); - - /* - * If we don't have the set_online method, also proceed - * straight to the online state - */ - if (modem->driver->set_online == NULL) - modem_change_state(modem, MODEM_STATE_ONLINE); - - break; - } -} - unsigned int __ofono_modem_add_online_watch(struct ofono_modem *modem, ofono_modem_online_notify_func notify, void *data, ofono_destroy_func destroy) @@ -487,6 +464,9 @@ static void online_cb(const struct ofono_error *error, void *data) struct ofono_modem *modem = data; DBusMessage *reply; + if (!modem->pending) + goto out; + if (error->type == OFONO_ERROR_TYPE_NO_ERROR && modem->modem_state == MODEM_STATE_OFFLINE) reply = dbus_message_new_method_return(modem->pending); @@ -495,6 +475,7 @@ static void online_cb(const struct ofono_error *error, void *data) __ofono_dbus_pending_reply(&modem->pending, reply); +out: if (error->type == OFONO_ERROR_TYPE_NO_ERROR && modem->modem_state == MODEM_STATE_OFFLINE) modem_change_state(modem, MODEM_STATE_ONLINE); @@ -517,6 +498,34 @@ static void offline_cb(const struct ofono_error *error, void *data) modem_change_state(modem, MODEM_STATE_OFFLINE); } +static void sim_state_watch(enum ofono_sim_state new_state, void *user) +{ + struct ofono_modem *modem = user; + + switch (new_state) { + case OFONO_SIM_STATE_NOT_PRESENT: + modem_change_state(modem, MODEM_STATE_PRE_SIM); + break; + case OFONO_SIM_STATE_INSERTED: + break; + case OFONO_SIM_STATE_READY: + modem_change_state(modem, MODEM_STATE_OFFLINE); + + /* + * If we don't have the set_online method, also proceed + * straight to the online state + */ + if (modem->driver->set_online == NULL) + modem_change_state(modem, MODEM_STATE_ONLINE); + else if (modem->get_online) + modem->driver->set_online(modem, 1, online_cb, modem); + + modem->get_online = FALSE; + + break; + } +} + static DBusMessage *set_property_online(struct ofono_modem *modem, DBusMessage *msg, DBusMessageIter *var) @@ -1627,6 +1636,9 @@ void ofono_modem_reset(struct ofono_modem *modem) __ofono_dbus_pending_reply(&modem->pending, reply); } + if (modem->modem_state == MODEM_STATE_ONLINE) + modem->get_online = TRUE; + ofono_modem_set_powered(modem, FALSE); err = set_powered(modem, TRUE); |