aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-06-28 10:53:33 +0200
committerAleksander Morgado <aleksander@aleksander.es>2020-06-29 08:53:00 +0000
commit234ba4544b324765a3ba9f7d468715378c585106 (patch)
tree8b0a15ee5d061bed99ce4f0f7d5a0535d0f44b37
parent5a9d321346df5e964780def158072df794c604dd (diff)
quectel: coding style fixes in the QGPS logic
-rw-r--r--plugins/quectel/mm-broadband-modem-quectel.c38
-rw-r--r--plugins/quectel/mm-shared-quectel.c203
-rw-r--r--plugins/quectel/mm-shared-quectel.h50
3 files changed, 149 insertions, 142 deletions
diff --git a/plugins/quectel/mm-broadband-modem-quectel.c b/plugins/quectel/mm-broadband-modem-quectel.c
index b9fdaeb3..4fdfdfcf 100644
--- a/plugins/quectel/mm-broadband-modem-quectel.c
+++ b/plugins/quectel/mm-broadband-modem-quectel.c
@@ -21,17 +21,17 @@
#include "mm-iface-modem-location.h"
static void iface_modem_init (MMIfaceModem *iface);
-static void shared_quectel_init (MMSharedQuectel *iface);
static void iface_modem_firmware_init (MMIfaceModemFirmware *iface);
static void iface_modem_location_init (MMIfaceModemLocation *iface);
+static void shared_quectel_init (MMSharedQuectel *iface);
static MMIfaceModemLocation *iface_modem_location_parent;
G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQuectel, mm_broadband_modem_quectel, MM_TYPE_BROADBAND_MODEM, 0,
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init)
- G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)
- G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init))
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init))
/*****************************************************************************/
@@ -52,13 +52,6 @@ mm_broadband_modem_quectel_new (const gchar *device,
}
static void
-iface_modem_firmware_init (MMIfaceModemFirmware *iface)
-{
- iface->load_update_settings = mm_shared_quectel_firmware_load_update_settings;
- iface->load_update_settings_finish = mm_shared_quectel_firmware_load_update_settings_finish;
-}
-
-static void
mm_broadband_modem_quectel_init (MMBroadbandModemQuectel *self)
{
}
@@ -70,20 +63,15 @@ iface_modem_init (MMIfaceModem *iface)
iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish;
}
-static MMIfaceModemLocation *
-peek_parent_location_interface (MMSharedQuectel *self)
-{
- return iface_modem_location_parent;
-}
-
static void
-shared_quectel_init (MMSharedQuectel *iface)
+iface_modem_firmware_init (MMIfaceModemFirmware *iface)
{
- iface->peek_parent_location_interface = peek_parent_location_interface;
+ iface->load_update_settings = mm_shared_quectel_firmware_load_update_settings;
+ iface->load_update_settings_finish = mm_shared_quectel_firmware_load_update_settings_finish;
}
static void
-iface_modem_location_init(MMIfaceModemLocation *iface)
+iface_modem_location_init (MMIfaceModemLocation *iface)
{
iface_modem_location_parent = g_type_interface_peek_parent (iface);
@@ -95,6 +83,18 @@ iface_modem_location_init(MMIfaceModemLocation *iface)
iface->disable_location_gathering_finish = mm_shared_quectel_disable_location_gathering_finish;
}
+static MMIfaceModemLocation *
+peek_parent_location_interface (MMSharedQuectel *self)
+{
+ return iface_modem_location_parent;
+}
+
+static void
+shared_quectel_init (MMSharedQuectel *iface)
+{
+ iface->peek_parent_location_interface = peek_parent_location_interface;
+}
+
static void
mm_broadband_modem_quectel_class_init (MMBroadbandModemQuectelClass *klass)
{
diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c
index c53b4660..fae9805e 100644
--- a/plugins/quectel/mm-shared-quectel.c
+++ b/plugins/quectel/mm-shared-quectel.c
@@ -169,15 +169,12 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
static GQuark private_quark;
static const gchar *gps_startup[] = {
+ /* NOTES:
+ * 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data
+ * without the nmea port.
+ * 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\".
+ */
"+QGPSCFG=\"outport\",\"usbnmea\"",
- // TODO: "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data without the nmea port
-
- // perhaps these should be the highest value of everything that has nmea in it?
- // TODO: it may be necessary to set "+QGPSCFG=\"gpsnmeatype\", however
- // the correct value will very based on the modem, it may be enough to
-
- // TODO: is it possible to report a gps interval,
- // or even better, allow users to set one?
"+QGPS=1",
};
@@ -203,14 +200,20 @@ typedef struct {
FeatureSupport qgps_supported;
} Private;
+static void
+location_gathering_context_free (LocationGatheringContext *ctx)
+{
+ g_clear_error (&ctx->command_error);
+ g_slice_free (LocationGatheringContext, ctx);
+}
+
static LocationGatheringContext *
location_gathering_context_new (MMModemLocationSource source)
{
- LocationGatheringContext *ctx = g_new (LocationGatheringContext, 1);
- ctx->source = source;
- ctx->idx = 0;
- ctx->command_error = NULL;
+ LocationGatheringContext *ctx;
+ ctx = g_slice_new0 (LocationGatheringContext);
+ ctx->source = source;
return ctx;
}
@@ -239,15 +242,15 @@ get_private (MMSharedQuectel *self)
}
/*****************************************************************************/
-/* Functions used to probe & report Location Support */
+/* Location capabilities loading (Location interface) */
MMModemLocationSource
-mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GError **error)
+mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self,
+ GAsyncResult *res,
+ GError **error)
{
GError *inner_error = NULL;
- gssize value;
+ gssize value;
value = g_task_propagate_int (G_TASK (res), &inner_error);
if (inner_error) {
@@ -260,9 +263,9 @@ mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self,
static void
build_provided_location_sources (GTask *task)
{
- MMModemLocationSource parent_sources;
- MMSharedQuectel *self;
- Private *priv;
+ MMModemLocationSource parent_sources;
+ MMSharedQuectel *self;
+ Private *priv;
parent_sources = GPOINTER_TO_UINT (g_task_get_task_data (task));
self = MM_SHARED_QUECTEL (g_task_get_source_object (task));
@@ -286,13 +289,13 @@ build_provided_location_sources (GTask *task)
}
static void
-probe_qgps_ready (MMBaseModem *_self,
+probe_qgps_ready (MMBaseModem *_self,
GAsyncResult *res,
- GTask *task)
+ GTask *task)
{
MMSharedQuectel *self;
- Private *priv;
- GError *error = NULL;
+ Private *priv;
+ GError *error = NULL;
self = MM_SHARED_QUECTEL (g_task_get_source_object (task));
priv = get_private (self);
@@ -320,12 +323,12 @@ probe_qgps (GTask *task)
static void
parent_load_capabilities_ready (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GTask *task)
+ GAsyncResult *res,
+ GTask *task)
{
- Private *priv;
- MMModemLocationSource sources;
- GError *error = NULL;
+ Private *priv;
+ MMModemLocationSource sources;
+ GError *error = NULL;
priv = get_private (MM_SHARED_QUECTEL (self));
sources = priv->iface_modem_location_parent->load_capabilities_finish (self, res, &error);
@@ -337,18 +340,20 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self,
g_task_set_task_data (task, GUINT_TO_POINTER (sources), NULL);
- if (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN)
+ if (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN) {
probe_qgps (task);
- else
- build_provided_location_sources (task);
+ return;
+ }
+
+ build_provided_location_sources (task);
}
void
mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GTask *task;
+ GTask *task;
Private *priv;
task = g_task_new (_self, NULL, callback, user_data);
@@ -356,29 +361,34 @@ mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self,
/* Chain up parent's setup */
priv->iface_modem_location_parent->load_capabilities (_self,
- (GAsyncReadyCallback)parent_load_capabilities_ready,
- task);
+ (GAsyncReadyCallback)parent_load_capabilities_ready,
+ task);
}
/*****************************************************************************/
/* Functions used to Enable Location */
-static void qgps_enable_loop (MMBaseModem *self, GTask *task);
+static void qgps_enable_loop (MMBaseModem *self,
+ GTask *task);
gboolean
-mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GError **error)
+mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self,
+ GAsyncResult *res,
+ GError **error)
{
return g_task_propagate_boolean (G_TASK (res), error);
}
static void
-qgps_check_enabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
+qgps_check_enabled_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GTask *task)
{
- const gchar *response;
- GError *error = NULL;
- LocationGatheringContext *ctx = g_task_get_task_data (task);
+ const gchar *response;
+ GError *error = NULL;
+ LocationGatheringContext *ctx;
+
+ ctx = g_task_get_task_data (task);
response = mm_base_modem_at_command_finish (self, res, &error);
@@ -387,8 +397,6 @@ qgps_check_enabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "1"))
g_task_return_error (task, ctx->command_error);
else {
- // TODO: Do I need to free ctx->command_error?
- ctx->command_error = NULL;
qgps_enable_loop (self, task);
return;
}
@@ -396,25 +404,31 @@ qgps_check_enabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
}
static void
-qgps_enable_command_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
+qgps_enable_command_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GTask *task)
{
- LocationGatheringContext *ctx = g_task_get_task_data (task);
- GError *error = NULL;
+ LocationGatheringContext *ctx;
+ GError *error = NULL;
- if (!mm_base_modem_at_command_full_finish (self, res, &error)) {
+ ctx = g_task_get_task_data (task);
+
+ if (!mm_base_modem_at_command_full_finish (self, res, &error))
ctx->command_error = error;
- }
qgps_enable_loop (self, task);
}
static void
-qgps_enable_loop (MMBaseModem *self, GTask *task)
+qgps_enable_loop (MMBaseModem *self,
+ GTask *task)
{
- MMPortSerialGps *gps_port;
- LocationGatheringContext *ctx = g_task_get_task_data (task);
- GError *error = NULL;
-
+ MMPortSerialGps *gps_port;
+ LocationGatheringContext *ctx;
+ GError *error = NULL;
+
+ ctx = g_task_get_task_data (task);
+
/* If there are more commands run them, then return */
if (ctx->idx < G_N_ELEMENTS (gps_startup)) {
mm_base_modem_at_command_full (MM_BASE_MODEM (self),
@@ -433,21 +447,19 @@ qgps_enable_loop (MMBaseModem *self, GTask *task)
if (ctx->command_error != NULL) {
mm_base_modem_at_command (self,
"+QGPS?",
- 3, // timeout
- FALSE, // not cached
+ 3,
+ FALSE,
(GAsyncReadyCallback)qgps_check_enabled_ready,
task);
return;
}
- // TODO: The NMEA port isn't necessary to get NMEA data, use +QGPSNMEA to retrive data
/* Last run Only: Check if the nmea/raw gps port
* exists and is available Otherwise throw an error */
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
gps_port = mm_base_modem_peek_port_gps (self);
- if (!gps_port ||
- !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) {
+ if (!gps_port || !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) {
if (error)
g_task_return_error (task, error);
else
@@ -465,8 +477,8 @@ qgps_enable_loop (MMBaseModem *self, GTask *task)
static void
parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GTask *task)
+ GAsyncResult *res,
+ GTask *task)
{
GError *error;
Private *priv;
@@ -474,8 +486,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
priv = get_private (MM_SHARED_QUECTEL (self));
g_assert (priv->iface_modem_location_parent);
- if (!priv->iface_modem_location_parent->
- enable_location_gathering_finish (self, res, &error))
+ if (!priv->iface_modem_location_parent->enable_location_gathering_finish (self, res, &error))
g_task_return_error (task, error);
else
g_task_return_boolean (task, TRUE);
@@ -483,15 +494,15 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
}
void
-mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
- MMModemLocationSource source,
- GAsyncReadyCallback callback,
- gpointer user_data)
+mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
+ MMModemLocationSource source,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
LocationGatheringContext *ctx;
- GTask *task;
- Private *priv;
- gboolean start_gps = FALSE;
+ GTask *task;
+ Private *priv;
+ gboolean start_gps = FALSE;
priv = get_private (MM_SHARED_QUECTEL (self));
task = g_task_new (self, NULL, callback, user_data);
@@ -515,9 +526,9 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
}
ctx = location_gathering_context_new (source);
- g_task_set_task_data (task, ctx, g_free);
+ g_task_set_task_data (task, ctx, (GDestroyNotify) location_gathering_context_free);
- // NMEA and UNMANAGED are both enabled in the same way
+ /* NMEA and UNMANAGED are both enabled in the same way */
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
@@ -541,15 +552,17 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
/* Functions used to Disable Location */
gboolean
-mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GError **error)
+mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self,
+ GAsyncResult *res,
+ GError **error)
{
return g_task_propagate_boolean (G_TASK (res), error);
}
static void
-qgps_check_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
+qgps_check_disabled_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GTask *task)
{
const gchar *response;
GError *error = NULL;
@@ -575,15 +588,17 @@ qgps_check_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
}
static void
-qgps_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
+qgps_end_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GTask *task)
{
GError *error = NULL;
if (!mm_base_modem_at_command_full_finish (self, res, &error)) {
mm_base_modem_at_command (self,
"+QGPS?",
- 3, // timeout
- FALSE, // not cached
+ 3,
+ FALSE,
(GAsyncReadyCallback)qgps_check_disabled_ready,
task);
return;
@@ -595,15 +610,16 @@ qgps_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task)
static void
disable_location_gathering_parent_ready (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GTask *task)
+ GAsyncResult *res,
+ GTask *task)
{
GError *error;
- Private *priv = get_private (MM_SHARED_QUECTEL (self));
+ Private *priv;
+
+ priv = get_private (MM_SHARED_QUECTEL (self));
g_assert (priv->iface_modem_location_parent);
- if (!priv->iface_modem_location_parent->
- disable_location_gathering_finish (self, res, &error))
+ if (!priv->iface_modem_location_parent->disable_location_gathering_finish (self, res, &error))
g_task_return_error (task, error);
else
g_task_return_boolean (task, TRUE);
@@ -611,15 +627,16 @@ disable_location_gathering_parent_ready (MMIfaceModemLocation *self,
}
void
-mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self,
- MMModemLocationSource source,
- GAsyncReadyCallback callback,
- gpointer user_data)
+mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self,
+ MMModemLocationSource source,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GTask *task;
MMPortSerialGps *gps_port;
- Private *priv = get_private (MM_SHARED_QUECTEL (self));
+ Private *priv;
+ priv = get_private (MM_SHARED_QUECTEL (self));
task = g_task_new (self, NULL, callback, user_data);
priv->enabled_sources &= ~source;
@@ -655,7 +672,7 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self,
FALSE,
FALSE, /* raw */
NULL, /* cancellable */
- (GAsyncReadyCallback)qgps_disabled_ready,
+ (GAsyncReadyCallback)qgps_end_ready,
task);
return;
}
diff --git a/plugins/quectel/mm-shared-quectel.h b/plugins/quectel/mm-shared-quectel.h
index a019bdf7..e628b22c 100644
--- a/plugins/quectel/mm-shared-quectel.h
+++ b/plugins/quectel/mm-shared-quectel.h
@@ -57,35 +57,25 @@ gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceMo
GAsyncResult *res,
GError **error);
-void
-mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self,
- GAsyncReadyCallback callback,
- gpointer user_data);
+void mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMModemLocationSource mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self,
+ GAsyncResult *res,
+ GError **error);
+void mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
+ MMModemLocationSource source,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self,
+ GAsyncResult *res,
+ GError **error);
+void mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self,
+ MMModemLocationSource source,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self,
+ GAsyncResult *res,
+ GError **error);
-MMModemLocationSource
-mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GError **error);
-
-void
-mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
- MMModemLocationSource source,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean
-mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GError **error);
-
-void
-mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *_self,
- MMModemLocationSource source,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean
-mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self,
- GAsyncResult *res,
- GError **error);
#endif /* MM_SHARED_QUECTEL_H */