diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-11-03 12:04:01 +0100 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-11-26 16:51:35 +0000 |
commit | cafc40245d2007ad3a9a33875fc6b71d25e6a254 (patch) | |
tree | af6b079289c7b61e470587c2bf5ad57c43263f0e /cli/mmcli-modem-location.c | |
parent | 613aceabda4bbcfd037be746567e568339a37ed0 (diff) |
cli,location: remove redundant --location-get-XXX actions
The --location-get action provides full location information from all
sources, which is better than per-source actions, as those were anyway
using the same API method to load location information as the global
one.
Diffstat (limited to 'cli/mmcli-modem-location.c')
-rw-r--r-- | cli/mmcli-modem-location.c | 221 |
1 files changed, 71 insertions, 150 deletions
diff --git a/cli/mmcli-modem-location.c b/cli/mmcli-modem-location.c index 276c607a..6dcfaf0b 100644 --- a/cli/mmcli-modem-location.c +++ b/cli/mmcli-modem-location.c @@ -48,23 +48,19 @@ static Context *ctx; static gboolean status_flag; static gboolean enable_3gpp_flag; static gboolean disable_3gpp_flag; -static gboolean get_3gpp_flag; static gboolean enable_agps_flag; static gboolean disable_agps_flag; static gboolean enable_gps_nmea_flag; static gboolean disable_gps_nmea_flag; -static gboolean get_gps_nmea_flag; static gboolean enable_gps_raw_flag; static gboolean disable_gps_raw_flag; -static gboolean get_gps_raw_flag; static gboolean enable_cdma_bs_flag; static gboolean disable_cdma_bs_flag; -static gboolean get_cdma_bs_flag; static gboolean enable_gps_unmanaged_flag; static gboolean disable_gps_unmanaged_flag; static gboolean set_enable_signal_flag; static gboolean set_disable_signal_flag; -static gboolean get_all_flag; +static gboolean get_flag; static gchar *set_supl_server_str; static gchar *inject_assistance_data_str; static gchar *set_gps_refresh_rate_str; @@ -74,7 +70,7 @@ static GOptionEntry entries[] = { "Show status of location gathering.", NULL }, - { "location-get", 0, 0, G_OPTION_ARG_NONE, &get_all_flag, + { "location-get", 0, 0, G_OPTION_ARG_NONE, &get_flag, "Get all available location information.", NULL }, @@ -86,10 +82,6 @@ static GOptionEntry entries[] = { "Disable 3GPP location gathering.", NULL }, - { "location-get-3gpp", 0, 0, G_OPTION_ARG_NONE, &get_3gpp_flag, - "Get 3GPP-based location.", - NULL - }, { "location-enable-agps", 0, 0, G_OPTION_ARG_NONE, &enable_agps_flag, "Enable A-GPS location gathering.", NULL @@ -106,10 +98,6 @@ static GOptionEntry entries[] = { "Disable NMEA-based GPS location gathering.", NULL }, - { "location-get-gps-nmea", 0, 0, G_OPTION_ARG_NONE, &get_gps_nmea_flag, - "Get NMEA GPS traces.", - NULL - }, { "location-enable-gps-raw", 0, 0, G_OPTION_ARG_NONE, &enable_gps_raw_flag, "Enable raw GPS location gathering.", NULL @@ -118,10 +106,6 @@ static GOptionEntry entries[] = { "Disable raw GPS location gathering.", NULL }, - { "location-get-gps-raw", 0, 0, G_OPTION_ARG_NONE, &get_gps_raw_flag, - "Get raw GPS location.", - NULL - }, { "location-enable-cdma-bs", 0, 0, G_OPTION_ARG_NONE, &enable_cdma_bs_flag, "Enable CDMA base station location gathering.", NULL @@ -130,10 +114,6 @@ static GOptionEntry entries[] = { "Disable CDMA base station location gathering.", NULL }, - { "location-get-cdma-bs", 0, 0, G_OPTION_ARG_NONE, &get_cdma_bs_flag, - "Get CDMA base station location.", - NULL - }, { "location-enable-gps-unmanaged", 0, 0, G_OPTION_ARG_NONE, &enable_gps_unmanaged_flag, "Enable unmanaged GPS location gathering.", NULL @@ -204,13 +184,6 @@ mmcli_modem_location_options_enabled (void) exit (EXIT_FAILURE); } - if (get_all_flag) { - get_3gpp_flag = TRUE; - get_gps_nmea_flag = TRUE; - get_gps_raw_flag = TRUE; - get_cdma_bs_flag = TRUE; - } - n_actions = (status_flag + !!(enable_3gpp_flag + disable_3gpp_flag + @@ -226,10 +199,7 @@ mmcli_modem_location_options_enabled (void) disable_gps_unmanaged_flag + set_enable_signal_flag + set_disable_signal_flag) + - !!(get_3gpp_flag + - get_gps_nmea_flag + - get_gps_raw_flag + - get_cdma_bs_flag) + + get_flag + !!set_supl_server_str + !!inject_assistance_data_str + !!set_gps_refresh_rate_str); @@ -553,37 +523,9 @@ get_location_process_reply (MMLocation3gpp *location_3gpp, MMLocationCdmaBs *location_cdma_bs, const GError *error) { - /* First, check for failures */ - if (!get_all_flag) { - gboolean exit_error = FALSE; - - if (get_3gpp_flag && !location_3gpp) { - g_printerr ("error: couldn't get 3GPP-based location from the modem: '%s'\n", - error ? error->message : "not available"); - exit_error = TRUE; - } - - if (get_gps_nmea_flag && !location_gps_nmea) { - g_printerr ("error: couldn't get NMEA GPS traces from the modem: '%s'\n", - error ? error->message : "not available"); - exit_error = TRUE; - } - - if (get_gps_raw_flag && !location_gps_raw) { - g_printerr ("error: couldn't get raw GPS location from the modem: '%s'\n", - error ? error->message : "not available"); - exit_error = TRUE; - } - - if (get_cdma_bs_flag && !location_cdma_bs) { - g_printerr ("error: couldn't get CDMA base station location from the modem: '%s'\n", - error ? error->message : "not available"); - exit_error = TRUE; - } + gchar *full = NULL; - if (exit_error) - exit (EXIT_FAILURE); - } else if (error) { + if (error) { g_printerr ("error: couldn't get location from the modem: '%s'\n", error ? error->message : "unknown error"); exit (EXIT_FAILURE); @@ -593,85 +535,71 @@ get_location_process_reply (MMLocation3gpp *location_3gpp, "%s\n", mm_modem_location_get_path (ctx->modem_location)); - if (get_3gpp_flag) { - if (location_3gpp) - g_print (" -------------------------\n" - " 3GPP location | Mobile country code: '%u'\n" - " | Mobile network code: '%u'\n" - " | Location area code: '%04lX'\n" - " | Tracking area code: '%04lX'\n" - " | Cell ID: '%08lX'\n", - mm_location_3gpp_get_mobile_country_code (location_3gpp), - mm_location_3gpp_get_mobile_network_code (location_3gpp), - mm_location_3gpp_get_location_area_code (location_3gpp), - mm_location_3gpp_get_tracking_area_code (location_3gpp), - mm_location_3gpp_get_cell_id (location_3gpp)); - else - g_print (" -------------------------\n" - " 3GPP location | Not available\n"); - } - - if (get_gps_nmea_flag) { - gchar *full = NULL; + if (location_3gpp) + g_print (" -------------------------\n" + " 3GPP location | Mobile country code: '%u'\n" + " | Mobile network code: '%u'\n" + " | Location area code: '%04lX'\n" + " | Tracking area code: '%04lX'\n" + " | Cell ID: '%08lX'\n", + mm_location_3gpp_get_mobile_country_code (location_3gpp), + mm_location_3gpp_get_mobile_network_code (location_3gpp), + mm_location_3gpp_get_location_area_code (location_3gpp), + mm_location_3gpp_get_tracking_area_code (location_3gpp), + mm_location_3gpp_get_cell_id (location_3gpp)); + else + g_print (" -------------------------\n" + " 3GPP location | Not available\n"); - if (location_gps_nmea) - full = mm_location_gps_nmea_build_full (location_gps_nmea); + if (location_gps_nmea) + full = mm_location_gps_nmea_build_full (location_gps_nmea); - if (full) { - gchar *prefixed; + if (full) { + gchar *prefixed; - prefixed = mmcli_prefix_newlines (" | ", full); - g_print (" -------------------------\n" - " GPS NMEA traces | %s\n", - prefixed); - g_free (prefixed); - g_free (full); - } else - g_print (" -------------------------\n" - " GPS NMEA traces | Not available\n"); - } + prefixed = mmcli_prefix_newlines (" | ", full); + g_print (" -------------------------\n" + " GPS NMEA traces | %s\n", + prefixed); + g_free (prefixed); + g_free (full); + } else + g_print (" -------------------------\n" + " GPS NMEA traces | Not available\n"); - if (get_gps_raw_flag) { - if (location_gps_raw) - g_print (" -------------------------\n" - " Raw GPS | UTC time: '%s'\n" - " | Longitude: '%lf'\n" - " | Latitude: '%lf'\n" - " | Altitude: '%lf'\n", - mm_location_gps_raw_get_utc_time (location_gps_raw), - mm_location_gps_raw_get_longitude (location_gps_raw), - mm_location_gps_raw_get_latitude (location_gps_raw), - mm_location_gps_raw_get_altitude (location_gps_raw)); - else - g_print (" -------------------------\n" - " Raw GPS | Not available\n"); - } - - if (get_cdma_bs_flag) { - if (location_cdma_bs) - g_print (" -------------------------\n" - " CDMA BS | Longitude: '%lf'\n" - " | Latitude: '%lf'\n", - mm_location_cdma_bs_get_longitude (location_cdma_bs), - mm_location_cdma_bs_get_latitude (location_cdma_bs)); - else - g_print (" -------------------------\n" - " CDMA BS | Not available\n"); - } - - if (location_3gpp) - g_object_unref (location_3gpp); - if (location_gps_nmea) - g_object_unref (location_gps_nmea); if (location_gps_raw) - g_object_unref (location_gps_raw); + g_print (" -------------------------\n" + " Raw GPS | UTC time: '%s'\n" + " | Longitude: '%lf'\n" + " | Latitude: '%lf'\n" + " | Altitude: '%lf'\n", + mm_location_gps_raw_get_utc_time (location_gps_raw), + mm_location_gps_raw_get_longitude (location_gps_raw), + mm_location_gps_raw_get_latitude (location_gps_raw), + mm_location_gps_raw_get_altitude (location_gps_raw)); + else + g_print (" -------------------------\n" + " Raw GPS | Not available\n"); + if (location_cdma_bs) - g_object_unref (location_cdma_bs); + g_print (" -------------------------\n" + " CDMA BS | Longitude: '%lf'\n" + " | Latitude: '%lf'\n", + mm_location_cdma_bs_get_longitude (location_cdma_bs), + mm_location_cdma_bs_get_latitude (location_cdma_bs)); + else + g_print (" -------------------------\n" + " CDMA BS | Not available\n"); + + g_clear_object (&location_3gpp); + g_clear_object (&location_gps_nmea); + g_clear_object (&location_gps_raw); + g_clear_object (&location_cdma_bs); } static void -get_location_ready (MMModemLocation *modem_location, - GAsyncResult *result) +get_location_ready (MMModemLocation *modem_location, + GAsyncResult *result) { MMLocation3gpp *location_3gpp = NULL; MMLocationGpsNmea *location_gps_nmea = NULL; @@ -681,13 +609,12 @@ get_location_ready (MMModemLocation *modem_location, mm_modem_location_get_full_finish (modem_location, result, - get_3gpp_flag ? &location_3gpp : NULL, - get_gps_nmea_flag ? &location_gps_nmea : NULL, - get_gps_raw_flag ? &location_gps_raw : NULL, - get_cdma_bs_flag ? &location_cdma_bs : NULL, + &location_3gpp, + &location_gps_nmea, + &location_gps_raw, + &location_cdma_bs, &error); get_location_process_reply (location_3gpp, location_gps_nmea, location_gps_raw, location_cdma_bs, error); - mmcli_async_operation_done (); } @@ -734,10 +661,7 @@ get_modem_ready (GObject *source, } /* Request to get location from the modem? */ - if (get_3gpp_flag || - get_gps_nmea_flag || - get_gps_raw_flag || - get_cdma_bs_flag) { + if (get_flag) { g_debug ("Asynchronously getting location from the modem..."); mm_modem_location_get_full (ctx->modem_location, ctx->cancellable, @@ -869,10 +793,7 @@ mmcli_modem_location_run_synchronous (GDBusConnection *connection) } /* Request to get location from the modem? */ - if (get_3gpp_flag || - get_gps_nmea_flag || - get_gps_raw_flag || - get_cdma_bs_flag) { + if (get_flag) { MMLocation3gpp *location_3gpp = NULL; MMLocationGpsNmea *location_gps_nmea = NULL; MMLocationGpsRaw *location_gps_raw = NULL; @@ -880,10 +801,10 @@ mmcli_modem_location_run_synchronous (GDBusConnection *connection) g_debug ("Synchronously getting location from the modem..."); mm_modem_location_get_full_sync (ctx->modem_location, - get_3gpp_flag ? &location_3gpp : NULL, - get_gps_nmea_flag ? &location_gps_nmea : NULL, - get_gps_raw_flag ? &location_gps_raw : NULL, - get_cdma_bs_flag ? &location_cdma_bs : NULL, + &location_3gpp, + &location_gps_nmea, + &location_gps_raw, + &location_cdma_bs, NULL, &error); get_location_process_reply (location_3gpp, location_gps_nmea, location_gps_raw, location_cdma_bs, error); |