diff --git a/src/manager.c b/src/manager.c index 3156652..fa75741 100644 --- a/src/manager.c +++ b/src/manager.c @@ -17,39 +17,29 @@ #include -static gboolean quit_timeout_cb(struct EG25Manager *manager) -{ - g_message("Modem down, quitting..."); - g_main_loop_quit(manager->loop); - - return FALSE; -} - -static gboolean gpio_poll_cb(struct EG25Manager *manager) -{ - if (gpio_check_poweroff(manager)) { - quit_timeout_cb(manager); - return FALSE; - } - - return TRUE; -} - static gboolean quit_app(struct EG25Manager *manager) { + int i; + g_message("Request to quit..."); + at_destroy(manager); + mm_iface_destroy(manager); + suspend_destroy(manager); + if (manager->modem_state >= EG25_STATE_STARTED) { g_message("Powering down the modem..."); gpio_sequence_shutdown(manager); manager->modem_state = EG25_STATE_FINISHING; - g_timeout_add(500, G_SOURCE_FUNC(gpio_poll_cb), manager); - g_timeout_add_seconds(30, G_SOURCE_FUNC(quit_timeout_cb), manager); + for (i = 0; i < 30; i++) { + if (gpio_check_poweroff(manager)) + break; + sleep(1); + } } + g_message("Modem down, quitting..."); - mm_iface_destroy(manager); - suspend_destroy(manager); - g_bus_unwatch_name(manager->mm_watch); + g_main_loop_quit(manager->loop); return FALSE; } @@ -160,7 +150,6 @@ int main(int argc, char *argv[]) g_main_loop_run(manager.loop); - at_destroy(&manager); gpio_destroy(&manager); return 0;