Commit c1e0cb96 authored by Chris T's avatar Chris T

Better handle suspending.

parent 82d95bad
......@@ -76,7 +76,10 @@ struct modem_data {
//The Bus org.ofono.mms.ModemManager
GDBusConnection *master_connection;
guint owner_id;
guint registration_id;
guint registration_id;
// This is a way to track the state of the modem if it is disabled
MmGdbusModem *gdbus_modem;
gulong modem_state_watch_id;
//These are modem manager related settings
MMManager *mm;
guint mm_watch_id;
......@@ -500,8 +503,6 @@ pur_mm_get_modem_state (void)
}
state = mm_modem_get_state (modem->modem);
if (state < MM_MODEM_STATE_ENABLED) {
mms_error("ModemManagerPlugin(): Modem Initializing....");
while (state < MM_MODEM_STATE_DISABLED) {
mms_error("ModemManagerPlugin(): Something May be wrong with the modem, checking....");
switch (state) {
case MM_MODEM_STATE_FAILED:
......@@ -517,22 +518,16 @@ pur_mm_get_modem_state (void)
pur_mm_state (PUR_MM_STATE_MODEM_DISABLED);
return FALSE;
case MM_MODEM_STATE_INITIALIZING:
/* Give the modem a second to initialize*/
sleep(3);
state = mm_modem_get_state (modem->modem);
break;
mms_error("ModemManagerPlugin(): MM_MODEM_STATE_INITIALIZING");
pur_mm_state (PUR_MM_STATE_MODEM_DISABLED);
return FALSE;
case MM_MODEM_STATE_DISABLED:
mms_error("ModemManagerPlugin(): MM_MODEM_STATE_DISABLED");
mms_error("ModemManagerPlugin(): Turning on Modem....");
mm_modem_set_power_state_sync (modem->modem, MM_MODEM_POWER_STATE_ON, NULL, &error);
return FALSE;
default:
break;
}
}
if (state == MM_MODEM_STATE_DISABLED) {
mms_error("ModemManagerPlugin(): MM_MODEM_STATE_DISABLED");
mms_error("ModemManagerPlugin(): Turning on Modem....");
mm_modem_set_power_state_sync (modem->modem, MM_MODEM_POWER_STATE_ON, NULL, &error);
if (error != NULL) {
g_warning ("ModemManagerPlugin(): Error setting power state: %s\n", error->message);
}
sleep(1);
}
} else {
mms_error("ModemManagerPlugin(): MM_MODEM_STATE_ENABLED");
......@@ -541,6 +536,22 @@ pur_mm_get_modem_state (void)
return TRUE;
}
static void state_changed_cb(MMModem *cb_modem,
MMModemState old,
MMModemState new,
MMModemStateChangeReason reason)
{
mms_error("ModemManagerPlugin(): State Change: Old: %d New: %d, Reason: %d", old, new, reason);
if (new >= MM_MODEM_STATE_CONNECTING) {
mms_error("ModemManagerPlugin(): Modem is ready");
g_signal_handler_disconnect (modem->gdbus_modem,
modem->modem_state_watch_id);
pur_mm_state (PUR_MM_STATE_MODEM_FOUND);
}
}
static void
pur_mm_state (int state)
......@@ -550,15 +561,23 @@ pur_mm_state (int state)
case PUR_MM_STATE_MODEM_FOUND:
if (!modem->modem_available) {
if (modem->modem) {
mm_modem_get_sim (modem->modem,
NULL,
(GAsyncReadyCallback)cb_get_sim_ready,
NULL);
mms_error("ModemManagerPlugin(): SIM is Unlocked!");
if (!pur_mm_get_modem_state ()) {
mms_error("ModemManagerPlugin(): There's a problem with the modem!");
modem->gdbus_modem = MM_GDBUS_MODEM(modem->modem);
modem->modem_state_watch_id = g_signal_connect(modem->gdbus_modem,
"state-changed",
G_CALLBACK(state_changed_cb),
NULL);
mms_error("ModemManagerPlugin(): Monitoring the modem to see if it will recover....");
break;
} else {
pur_mm_state (PUR_MM_STATE_READY);
mm_modem_get_sim (modem->modem,
NULL,
(GAsyncReadyCallback)cb_get_sim_ready,
NULL);
}
}
modem->modem_available = TRUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment