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.
This commit is contained in:
Aleksander Morgado
2012-03-29 17:20:37 +02:00
parent 3cea187a94
commit 0d8cf160e5
2 changed files with 125 additions and 38 deletions

View File

@@ -348,12 +348,12 @@ location_load_capabilities (MMIfaceModemLocation *self,
} }
/*****************************************************************************/ /*****************************************************************************/
/* Enable/Disable location gathering (Location interface) */ /* Disable location gathering (Location interface) */
static gboolean static gboolean
enable_disable_location_gathering_finish (MMIfaceModemLocation *self, disable_location_gathering_finish (MMIfaceModemLocation *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), 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); 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 static void
gps_enabled_ready (MMBaseModem *self, gps_enabled_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GSimpleAsyncResult *simple) EnableLocationGatheringContext *ctx)
{ {
MMGpsSerialPort *gps_port; MMGpsSerialPort *gps_port;
GError *error = NULL; GError *error = NULL;
if (!mm_base_modem_at_command_full_finish (self, res, &error)) { if (!mm_base_modem_at_command_full_finish (self, res, &error)) {
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (ctx->result, error);
g_simple_async_result_complete (simple); enable_location_gathering_context_complete_and_free (ctx);
g_object_unref (simple);
return; return;
} }
@@ -443,45 +468,42 @@ gps_enabled_ready (MMBaseModem *self,
if (!gps_port || if (!gps_port ||
!mm_serial_port_open (MM_SERIAL_PORT (gps_port), &error)) { !mm_serial_port_open (MM_SERIAL_PORT (gps_port), &error)) {
if (error) if (error)
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (ctx->result, error);
else else
g_simple_async_result_set_error (simple, g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't open raw GPS serial port"); "Couldn't open raw GPS serial port");
g_simple_async_result_complete (simple); } else
g_object_unref (simple); g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
return;
}
g_simple_async_result_set_op_res_gboolean (simple, TRUE); enable_location_gathering_context_complete_and_free (ctx);
g_simple_async_result_complete (simple);
g_object_unref (simple);
} }
static void static void
enable_location_gathering (MMIfaceModemLocation *self, parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
MMModemLocationSource source, GAsyncResult *res,
GAsyncReadyCallback callback, EnableLocationGatheringContext *ctx)
gpointer user_data)
{ {
MMBroadbandModemHso *hso = MM_BROADBAND_MODEM_HSO (self);
GSimpleAsyncResult *result;
gboolean start_gps = FALSE; gboolean start_gps = FALSE;
GError *error = NULL;
result = g_simple_async_result_new (G_OBJECT (self), if (!iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) {
callback, g_simple_async_result_take_error (ctx->result, error);
user_data, enable_location_gathering_context_complete_and_free (ctx);
enable_location_gathering); return;
}
/* Now our own enabling */
/* NMEA and RAW are both enabled in the same way */ /* NMEA and RAW are both enabled in the same way */
if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
/* Only start GPS engine if not done already */ /* Only start GPS engine if not done already */
if (!(hso->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | if (!(ctx->self->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
MM_MODEM_LOCATION_SOURCE_GPS_RAW))) MM_MODEM_LOCATION_SOURCE_GPS_RAW)))
start_gps = TRUE; start_gps = TRUE;
hso->priv->enabled_sources |= source; ctx->self->priv->enabled_sources |= ctx->source;
} }
if (start_gps) { if (start_gps) {
@@ -493,14 +515,37 @@ enable_location_gathering (MMIfaceModemLocation *self,
FALSE, FALSE,
NULL, /* cancellable */ NULL, /* cancellable */
(GAsyncReadyCallback)gps_enabled_ready, (GAsyncReadyCallback)gps_enabled_ready,
result); ctx);
return; return;
} }
/* For any other location (e.g. 3GPP), or if GPS already running just 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_set_op_res_gboolean (ctx->result, TRUE);
g_simple_async_result_complete_in_idle (result); enable_location_gathering_context_complete_and_free (ctx);
g_object_unref (result); }
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 = location_load_capabilities;
iface->load_capabilities_finish = location_load_capabilities_finish; iface->load_capabilities_finish = location_load_capabilities_finish;
iface->enable_location_gathering = enable_location_gathering; 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 = disable_location_gathering;
iface->disable_location_gathering_finish = enable_disable_location_gathering_finish; iface->disable_location_gathering_finish = disable_location_gathering_finish;
} }
static void static void

View File

@@ -5703,6 +5703,46 @@ modem_location_load_capabilities (MMIfaceModemLocation *self,
g_object_unref (result); g_object_unref (result);
} }
/*****************************************************************************/
/* 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 static void
@@ -7215,6 +7255,8 @@ iface_modem_location_init (MMIfaceModemLocation *iface)
{ {
iface->load_capabilities = modem_location_load_capabilities; iface->load_capabilities = modem_location_load_capabilities;
iface->load_capabilities_finish = modem_location_load_capabilities_finish; 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 static void