Commit dacd989d authored by Chris T's avatar Chris T

Add support for modem suspending.

parent eb57387e
......@@ -88,6 +88,7 @@ struct modem_data {
GPtrArray *device_arr;
gboolean modem_available;
gboolean manager_available;
gboolean plugin_registered;
};
typedef struct {
......@@ -479,6 +480,7 @@ static gboolean
pur_mm_get_modem_state (void)
{
MMModemState state;
g_autoptr(GError) error = NULL;
if (!modem->modem) {
pur_mm_state (PUR_MM_STATE_NO_MODEM);
......@@ -492,7 +494,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....");
sleep(3);
while (state < MM_MODEM_STATE_DISABLED) {
mms_error("ModemManagerPlugin(): Something May be wrong with the modem, checking....");
switch (state) {
......@@ -510,12 +511,21 @@ pur_mm_get_modem_state (void)
return FALSE;
case MM_MODEM_STATE_INITIALIZING:
/* Give the modem a second to initialize*/
sleep(3);
state = mm_modem_get_state (modem->modem);
break;
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 ("Error setting power state: %s\n", error->message);
}
}
mms_error("Modem is ready...");
} else {
mms_error("Done with While Loop: MM_MODEM_STATE_ENABLED");
......@@ -528,34 +538,20 @@ pur_mm_get_modem_state (void)
static void
pur_mm_state (int state)
{
MMModemState modem_state;
//const char *pin = NULL;
switch (state) {
case PUR_MM_STATE_MODEM_FOUND:
if (!modem->modem_available) {
if (modem->modem) {
modem_state = mm_modem_get_state (modem->modem);
mms_error("ModemManagerPlugin(): PUR_MM_STATE_MODEM_FOUND");
if (modem_state == MM_MODEM_STATE_LOCKED) {
/*
* While logic exists to unlock the SIM, I do not think
* mmsd should attempt to unlock the modem.
*
*/
mms_error("ModemManagerPlugin(): SIM is locked! Not attempting to unlock...");
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 ()) {
break;
} else {
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 ()) {
break;
} else {
pur_mm_state (PUR_MM_STATE_READY);
}
pur_mm_state (PUR_MM_STATE_READY);
}
}
modem->modem_available = TRUE;
......@@ -824,7 +820,11 @@ static void unset_context (void) {
}
static void mmsd_plugin_connect (void) {
mms_service_register(modem->service);
if (modem->plugin_registered == FALSE) {
mms_error("ModemManagerPlugin(): Registering Modem Manager MMS Service");
mms_service_register(modem->service);
modem-> plugin_registered = TRUE;
}
mms_error("ModemManagerPlugin(): Setting Bearer Handler");
mms_service_set_bearer_handler(modem->service, bearer_handler, modem);
......@@ -834,9 +834,9 @@ static void mmsd_plugin_connect (void) {
static void mmsd_plugin_disconnect (void) {
mms_error("ModemManagerPlugin(): Disconnecting ModemManager Plugin");
mms_error("ModemManagerPlugin(): Disabling Bearer Handler");
deactivate_bearer(modem->service);
mms_service_set_bearer_handler(modem->service, NULL, NULL);
g_free(modem->path);
mms_service_unregister(modem->service);
}
......@@ -898,6 +898,7 @@ static int modemmanager_init(void)
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
g_assert (introspection_data != NULL);
modem->plugin_registered = FALSE;
mm_get_modem_manager ();
return 0;
......@@ -905,6 +906,9 @@ static int modemmanager_init(void)
static void modemmanager_exit(void)
{
if (modem->plugin_registered == TRUE) {
mms_service_unregister(modem->service);
}
if (modem->manager_available) {
pur_mm_disconnect ();
g_clear_object (&modem->mm);
......
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