option,hso: allow 'unmanaged' GPS setup
This commit is contained in:
@@ -448,7 +448,25 @@ location_load_capabilities (MMIfaceModemLocation *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Disable location gathering (Location interface) */
|
/* Enable/Disable location gathering (Location interface) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MMBroadbandModemHso *self;
|
||||||
|
GSimpleAsyncResult *result;
|
||||||
|
MMModemLocationSource source;
|
||||||
|
} LocationGatheringContext;
|
||||||
|
|
||||||
|
static void
|
||||||
|
location_gathering_context_complete_and_free (LocationGatheringContext *ctx)
|
||||||
|
{
|
||||||
|
g_simple_async_result_complete_in_idle (ctx->result);
|
||||||
|
g_object_unref (ctx->result);
|
||||||
|
g_object_unref (ctx->self);
|
||||||
|
g_slice_free (LocationGatheringContext, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************/
|
||||||
|
/* Disable location gathering */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
disable_location_gathering_finish (MMIfaceModemLocation *self,
|
disable_location_gathering_finish (MMIfaceModemLocation *self,
|
||||||
@@ -461,23 +479,26 @@ disable_location_gathering_finish (MMIfaceModemLocation *self,
|
|||||||
static void
|
static void
|
||||||
gps_disabled_ready (MMBaseModem *self,
|
gps_disabled_ready (MMBaseModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GSimpleAsyncResult *simple)
|
LocationGatheringContext *ctx)
|
||||||
{
|
{
|
||||||
MMPortSerialGps *gps_port;
|
MMPortSerialGps *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);
|
||||||
else
|
else
|
||||||
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
|
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
||||||
|
|
||||||
/* Even if we get an error here, we try to close the GPS port */
|
/* Only use the GPS port in NMEA/RAW setups */
|
||||||
gps_port = mm_base_modem_peek_port_gps (self);
|
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
if (gps_port)
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
|
||||||
mm_port_serial_close (MM_PORT_SERIAL (gps_port));
|
/* Even if we get an error here, we try to close the GPS port */
|
||||||
|
gps_port = mm_base_modem_peek_port_gps (self);
|
||||||
|
if (gps_port)
|
||||||
|
mm_port_serial_close (MM_PORT_SERIAL (gps_port));
|
||||||
|
}
|
||||||
|
|
||||||
g_simple_async_result_complete (simple);
|
location_gathering_context_complete_and_free (ctx);
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -487,21 +508,26 @@ disable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMBroadbandModemHso *hso = MM_BROADBAND_MODEM_HSO (self);
|
MMBroadbandModemHso *hso = MM_BROADBAND_MODEM_HSO (self);
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
gboolean stop_gps = FALSE;
|
gboolean stop_gps = FALSE;
|
||||||
|
LocationGatheringContext *ctx;
|
||||||
|
|
||||||
result = g_simple_async_result_new (G_OBJECT (self),
|
ctx = g_slice_new (LocationGatheringContext);
|
||||||
callback,
|
ctx->self = g_object_ref (self);
|
||||||
user_data,
|
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
disable_location_gathering);
|
callback,
|
||||||
|
user_data,
|
||||||
|
disable_location_gathering);
|
||||||
|
ctx->source = source;
|
||||||
|
|
||||||
/* Only stop GPS engine if no GPS-related sources enabled */
|
/* Only stop GPS engine if no GPS-related sources enabled */
|
||||||
if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
||||||
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
|
||||||
hso->priv->enabled_sources &= ~source;
|
hso->priv->enabled_sources &= ~source;
|
||||||
|
|
||||||
if (!(hso->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
if (!(hso->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_RAW)))
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
||||||
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)))
|
||||||
stop_gps = TRUE;
|
stop_gps = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,33 +541,17 @@ disable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
FALSE, /* raw */
|
FALSE, /* raw */
|
||||||
NULL, /* cancellable */
|
NULL, /* cancellable */
|
||||||
(GAsyncReadyCallback)gps_disabled_ready,
|
(GAsyncReadyCallback)gps_disabled_ready,
|
||||||
result);
|
ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For any other location (e.g. 3GPP), or if still some GPS needed, just return */
|
/* For any other location (e.g. 3GPP), or if still some GPS needed, 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);
|
location_gathering_context_complete_and_free (ctx);
|
||||||
g_object_unref (result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************/
|
||||||
/* Enable location gathering (Location interface) */
|
/* Enable location gathering */
|
||||||
|
|
||||||
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
|
static gboolean
|
||||||
enable_location_gathering_finish (MMIfaceModemLocation *self,
|
enable_location_gathering_finish (MMIfaceModemLocation *self,
|
||||||
@@ -554,55 +564,66 @@ enable_location_gathering_finish (MMIfaceModemLocation *self,
|
|||||||
static void
|
static void
|
||||||
gps_enabled_ready (MMBaseModem *self,
|
gps_enabled_ready (MMBaseModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
EnableLocationGatheringContext *ctx)
|
LocationGatheringContext *ctx)
|
||||||
{
|
{
|
||||||
MMPortSerialGps *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 (ctx->result, error);
|
g_simple_async_result_take_error (ctx->result, error);
|
||||||
enable_location_gathering_context_complete_and_free (ctx);
|
location_gathering_context_complete_and_free (ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gps_port = mm_base_modem_peek_port_gps (self);
|
/* Only use the GPS port in NMEA/RAW setups */
|
||||||
if (!gps_port ||
|
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
!mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) {
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
|
||||||
if (error)
|
MMPortSerialGps *gps_port;
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
|
||||||
else
|
gps_port = mm_base_modem_peek_port_gps (self);
|
||||||
g_simple_async_result_set_error (ctx->result,
|
if (!gps_port ||
|
||||||
MM_CORE_ERROR,
|
!mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) {
|
||||||
MM_CORE_ERROR_FAILED,
|
if (error)
|
||||||
"Couldn't open raw GPS serial port");
|
g_simple_async_result_take_error (ctx->result, error);
|
||||||
} else
|
else
|
||||||
|
g_simple_async_result_set_error (ctx->result,
|
||||||
|
MM_CORE_ERROR,
|
||||||
|
MM_CORE_ERROR_FAILED,
|
||||||
|
"Couldn't open raw GPS serial port");
|
||||||
|
} else
|
||||||
|
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
||||||
|
}
|
||||||
|
else
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
||||||
|
|
||||||
enable_location_gathering_context_complete_and_free (ctx);
|
location_gathering_context_complete_and_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
|
parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
EnableLocationGatheringContext *ctx)
|
LocationGatheringContext *ctx)
|
||||||
{
|
{
|
||||||
gboolean start_gps = FALSE;
|
gboolean start_gps = FALSE;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) {
|
if (!iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) {
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
g_simple_async_result_take_error (ctx->result, error);
|
||||||
enable_location_gathering_context_complete_and_free (ctx);
|
location_gathering_context_complete_and_free (ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now our own enabling */
|
/* Now our own enabling */
|
||||||
|
|
||||||
/* NMEA and RAW are both enabled in the same way */
|
/* NMEA, RAW and UNMANAGED are all enabled in the same way */
|
||||||
if (ctx->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 */
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
|
||||||
|
/* Only start GPS engine if not done already.
|
||||||
|
* NOTE: interface already takes care of making sure that raw/nmea and
|
||||||
|
* unmanaged are not enabled at the same time */
|
||||||
if (!(ctx->self->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 |
|
||||||
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)))
|
||||||
start_gps = TRUE;
|
start_gps = TRUE;
|
||||||
ctx->self->priv->enabled_sources |= ctx->source;
|
ctx->self->priv->enabled_sources |= ctx->source;
|
||||||
}
|
}
|
||||||
@@ -623,7 +644,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
|
|||||||
|
|
||||||
/* 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 (ctx->result, TRUE);
|
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
||||||
enable_location_gathering_context_complete_and_free (ctx);
|
location_gathering_context_complete_and_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -632,9 +653,9 @@ enable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
EnableLocationGatheringContext *ctx;
|
LocationGatheringContext *ctx;
|
||||||
|
|
||||||
ctx = g_new (EnableLocationGatheringContext, 1);
|
ctx = g_slice_new (LocationGatheringContext);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
callback,
|
callback,
|
||||||
|
Reference in New Issue
Block a user