diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-29 17:20:37 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-29 17:20:37 +0200 |
commit | 0d8cf160e5083b9f1433534b218490b7a1b5ce55 (patch) | |
tree | 6a35fb89aa53777b96cf063a0c2249ae0e0b285b | |
parent | 3cea187a9449c3aefe0a1a381a9477c6aff83745 (diff) |
broadband: ensure 3GPP location info gets updated when enabling the source
Whenever 3GPP location source gets enabled, we'll launch new registration status
checks (to get updated LAC/CI) and new operator code/name checks (to get updated
MCC/MNC).
Additional changes were needed in the HSO plugin, so that the specific location
gathering enabling implemented by the HSO modem chains up parent's one first.
-rw-r--r-- | plugins/option/mm-broadband-modem-hso.c | 121 | ||||
-rw-r--r-- | src/mm-broadband-modem.c | 42 |
2 files changed, 125 insertions, 38 deletions
diff --git a/plugins/option/mm-broadband-modem-hso.c b/plugins/option/mm-broadband-modem-hso.c index 80821371..fa40eea6 100644 --- a/plugins/option/mm-broadband-modem-hso.c +++ b/plugins/option/mm-broadband-modem-hso.c @@ -348,12 +348,12 @@ location_load_capabilities (MMIfaceModemLocation *self, } /*****************************************************************************/ -/* Enable/Disable location gathering (Location interface) */ +/* Disable location gathering (Location interface) */ static gboolean -enable_disable_location_gathering_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error) +disable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) { return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); } @@ -424,18 +424,43 @@ disable_location_gathering (MMIfaceModemLocation *self, g_object_unref (result); } +/*****************************************************************************/ +/* Enable location gathering (Location interface) */ + +typedef struct { + MMBroadbandModemHso *self; + GSimpleAsyncResult *result; + MMModemLocationSource source; +} EnableLocationGatheringContext; + +static void +enable_location_gathering_context_complete_and_free (EnableLocationGatheringContext *ctx) +{ + g_simple_async_result_complete (ctx->result); + g_object_unref (ctx->result); + g_object_unref (ctx->self); + g_free (ctx); +} + +static gboolean +enable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} + static void gps_enabled_ready (MMBaseModem *self, GAsyncResult *res, - GSimpleAsyncResult *simple) + EnableLocationGatheringContext *ctx) { MMGpsSerialPort *gps_port; GError *error = NULL; if (!mm_base_modem_at_command_full_finish (self, res, &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete (simple); - g_object_unref (simple); + g_simple_async_result_take_error (ctx->result, error); + enable_location_gathering_context_complete_and_free (ctx); return; } @@ -443,45 +468,42 @@ gps_enabled_ready (MMBaseModem *self, if (!gps_port || !mm_serial_port_open (MM_SERIAL_PORT (gps_port), &error)) { if (error) - g_simple_async_result_take_error (simple, error); + g_simple_async_result_take_error (ctx->result, error); else - g_simple_async_result_set_error (simple, + g_simple_async_result_set_error (ctx->result, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't open raw GPS serial port"); - g_simple_async_result_complete (simple); - g_object_unref (simple); - return; - } + } else + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - g_simple_async_result_complete (simple); - g_object_unref (simple); + enable_location_gathering_context_complete_and_free (ctx); } static void -enable_location_gathering (MMIfaceModemLocation *self, - MMModemLocationSource source, - GAsyncReadyCallback callback, - gpointer user_data) +parent_enable_location_gathering_ready (MMIfaceModemLocation *self, + GAsyncResult *res, + EnableLocationGatheringContext *ctx) { - MMBroadbandModemHso *hso = MM_BROADBAND_MODEM_HSO (self); - GSimpleAsyncResult *result; gboolean start_gps = FALSE; + GError *error = NULL; - result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - enable_location_gathering); + if (!iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) { + g_simple_async_result_take_error (ctx->result, error); + enable_location_gathering_context_complete_and_free (ctx); + return; + } + + /* Now our own enabling */ /* NMEA and RAW are both enabled in the same way */ - if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { + if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { /* Only start GPS engine if not done already */ - if (!(hso->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW))) + if (!(ctx->self->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW))) start_gps = TRUE; - hso->priv->enabled_sources |= source; + ctx->self->priv->enabled_sources |= ctx->source; } if (start_gps) { @@ -493,14 +515,37 @@ enable_location_gathering (MMIfaceModemLocation *self, FALSE, NULL, /* cancellable */ (GAsyncReadyCallback)gps_enabled_ready, - result); + ctx); return; } /* For any other location (e.g. 3GPP), or if GPS already running just return */ - g_simple_async_result_set_op_res_gboolean (result, TRUE); - g_simple_async_result_complete_in_idle (result); - g_object_unref (result); + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + enable_location_gathering_context_complete_and_free (ctx); +} + +static void +enable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) +{ + EnableLocationGatheringContext *ctx; + + ctx = g_new (EnableLocationGatheringContext, 1); + ctx->self = g_object_ref (self); + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + enable_location_gathering); + ctx->source = source; + + /* Chain up parent's gathering enable */ + iface_modem_location_parent->enable_location_gathering ( + self, + source, + (GAsyncReadyCallback)parent_enable_location_gathering_ready, + ctx); } /*****************************************************************************/ @@ -626,9 +671,9 @@ iface_modem_location_init (MMIfaceModemLocation *iface) iface->load_capabilities = location_load_capabilities; iface->load_capabilities_finish = location_load_capabilities_finish; iface->enable_location_gathering = enable_location_gathering; - iface->enable_location_gathering_finish = enable_disable_location_gathering_finish; + iface->enable_location_gathering_finish = enable_location_gathering_finish; iface->disable_location_gathering = disable_location_gathering; - iface->disable_location_gathering_finish = enable_disable_location_gathering_finish; + iface->disable_location_gathering_finish = disable_location_gathering_finish; } static void diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 06533f8a..cdaf83f9 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -5704,6 +5704,46 @@ modem_location_load_capabilities (MMIfaceModemLocation *self, } /*****************************************************************************/ +/* Enable location gathering (Location interface) */ + +static gboolean +enable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} + +static void +enable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + + result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + enable_location_gathering); + + /* 3GPP modems need to re-run registration checks, so that we get up to date + * LAC/CI location information. Note that we don't care for when the + * registration checks get finished. */ + if (mm_iface_modem_is_3gpp (MM_IFACE_MODEM (self))) { + /* Re-run registration to get update LAC/CI */ + mm_iface_modem_3gpp_run_all_registration_checks (MM_IFACE_MODEM_3GPP (self), NULL, NULL); + /* Reload operator, to get MCC/MNC */ + mm_iface_modem_3gpp_reload_current_operator (MM_IFACE_MODEM_3GPP (self)); + } + + /* Done we are */ + g_simple_async_result_set_op_res_gboolean (result, TRUE); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); +} + +/*****************************************************************************/ static void setup_ports (MMBroadbandModem *self) @@ -7215,6 +7255,8 @@ iface_modem_location_init (MMIfaceModemLocation *iface) { iface->load_capabilities = modem_location_load_capabilities; iface->load_capabilities_finish = modem_location_load_capabilities_finish; + iface->enable_location_gathering = enable_location_gathering; + iface->enable_location_gathering_finish = enable_location_gathering_finish; } static void |