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.
This commit is contained in:
Aleksander Morgado
2018-11-03 12:04:01 +01:00
committed by Dan Williams
parent 613aceabda
commit cafc40245d

View File

@@ -48,23 +48,19 @@ static Context *ctx;
static gboolean status_flag; static gboolean status_flag;
static gboolean enable_3gpp_flag; static gboolean enable_3gpp_flag;
static gboolean disable_3gpp_flag; static gboolean disable_3gpp_flag;
static gboolean get_3gpp_flag;
static gboolean enable_agps_flag; static gboolean enable_agps_flag;
static gboolean disable_agps_flag; static gboolean disable_agps_flag;
static gboolean enable_gps_nmea_flag; static gboolean enable_gps_nmea_flag;
static gboolean disable_gps_nmea_flag; static gboolean disable_gps_nmea_flag;
static gboolean get_gps_nmea_flag;
static gboolean enable_gps_raw_flag; static gboolean enable_gps_raw_flag;
static gboolean disable_gps_raw_flag; static gboolean disable_gps_raw_flag;
static gboolean get_gps_raw_flag;
static gboolean enable_cdma_bs_flag; static gboolean enable_cdma_bs_flag;
static gboolean disable_cdma_bs_flag; static gboolean disable_cdma_bs_flag;
static gboolean get_cdma_bs_flag;
static gboolean enable_gps_unmanaged_flag; static gboolean enable_gps_unmanaged_flag;
static gboolean disable_gps_unmanaged_flag; static gboolean disable_gps_unmanaged_flag;
static gboolean set_enable_signal_flag; static gboolean set_enable_signal_flag;
static gboolean set_disable_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 *set_supl_server_str;
static gchar *inject_assistance_data_str; static gchar *inject_assistance_data_str;
static gchar *set_gps_refresh_rate_str; static gchar *set_gps_refresh_rate_str;
@@ -74,7 +70,7 @@ static GOptionEntry entries[] = {
"Show status of location gathering.", "Show status of location gathering.",
NULL 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.", "Get all available location information.",
NULL NULL
}, },
@@ -86,10 +82,6 @@ static GOptionEntry entries[] = {
"Disable 3GPP location gathering.", "Disable 3GPP location gathering.",
NULL 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, { "location-enable-agps", 0, 0, G_OPTION_ARG_NONE, &enable_agps_flag,
"Enable A-GPS location gathering.", "Enable A-GPS location gathering.",
NULL NULL
@@ -106,10 +98,6 @@ static GOptionEntry entries[] = {
"Disable NMEA-based GPS location gathering.", "Disable NMEA-based GPS location gathering.",
NULL 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, { "location-enable-gps-raw", 0, 0, G_OPTION_ARG_NONE, &enable_gps_raw_flag,
"Enable raw GPS location gathering.", "Enable raw GPS location gathering.",
NULL NULL
@@ -118,10 +106,6 @@ static GOptionEntry entries[] = {
"Disable raw GPS location gathering.", "Disable raw GPS location gathering.",
NULL 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, { "location-enable-cdma-bs", 0, 0, G_OPTION_ARG_NONE, &enable_cdma_bs_flag,
"Enable CDMA base station location gathering.", "Enable CDMA base station location gathering.",
NULL NULL
@@ -130,10 +114,6 @@ static GOptionEntry entries[] = {
"Disable CDMA base station location gathering.", "Disable CDMA base station location gathering.",
NULL 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, { "location-enable-gps-unmanaged", 0, 0, G_OPTION_ARG_NONE, &enable_gps_unmanaged_flag,
"Enable unmanaged GPS location gathering.", "Enable unmanaged GPS location gathering.",
NULL NULL
@@ -204,13 +184,6 @@ mmcli_modem_location_options_enabled (void)
exit (EXIT_FAILURE); 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 + n_actions = (status_flag +
!!(enable_3gpp_flag + !!(enable_3gpp_flag +
disable_3gpp_flag + disable_3gpp_flag +
@@ -226,10 +199,7 @@ mmcli_modem_location_options_enabled (void)
disable_gps_unmanaged_flag + disable_gps_unmanaged_flag +
set_enable_signal_flag + set_enable_signal_flag +
set_disable_signal_flag) + set_disable_signal_flag) +
!!(get_3gpp_flag + get_flag +
get_gps_nmea_flag +
get_gps_raw_flag +
get_cdma_bs_flag) +
!!set_supl_server_str + !!set_supl_server_str +
!!inject_assistance_data_str + !!inject_assistance_data_str +
!!set_gps_refresh_rate_str); !!set_gps_refresh_rate_str);
@@ -553,37 +523,9 @@ get_location_process_reply (MMLocation3gpp *location_3gpp,
MMLocationCdmaBs *location_cdma_bs, MMLocationCdmaBs *location_cdma_bs,
const GError *error) const GError *error)
{ {
/* First, check for failures */ gchar *full = NULL;
if (!get_all_flag) {
gboolean exit_error = FALSE;
if (get_3gpp_flag && !location_3gpp) { if (error) {
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;
}
if (exit_error)
exit (EXIT_FAILURE);
} else if (error) {
g_printerr ("error: couldn't get location from the modem: '%s'\n", g_printerr ("error: couldn't get location from the modem: '%s'\n",
error ? error->message : "unknown error"); error ? error->message : "unknown error");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@@ -593,85 +535,71 @@ get_location_process_reply (MMLocation3gpp *location_3gpp,
"%s\n", "%s\n",
mm_modem_location_get_path (ctx->modem_location)); 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_gps_nmea)
full = mm_location_gps_nmea_build_full (location_gps_nmea);
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");
}
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) if (location_3gpp)
g_object_unref (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) if (location_gps_nmea)
g_object_unref (location_gps_nmea); full = mm_location_gps_nmea_build_full (location_gps_nmea);
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");
if (location_gps_raw) 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) 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 static void
get_location_ready (MMModemLocation *modem_location, get_location_ready (MMModemLocation *modem_location,
GAsyncResult *result) GAsyncResult *result)
{ {
MMLocation3gpp *location_3gpp = NULL; MMLocation3gpp *location_3gpp = NULL;
MMLocationGpsNmea *location_gps_nmea = NULL; MMLocationGpsNmea *location_gps_nmea = NULL;
@@ -681,13 +609,12 @@ get_location_ready (MMModemLocation *modem_location,
mm_modem_location_get_full_finish (modem_location, mm_modem_location_get_full_finish (modem_location,
result, result,
get_3gpp_flag ? &location_3gpp : NULL, &location_3gpp,
get_gps_nmea_flag ? &location_gps_nmea : NULL, &location_gps_nmea,
get_gps_raw_flag ? &location_gps_raw : NULL, &location_gps_raw,
get_cdma_bs_flag ? &location_cdma_bs : NULL, &location_cdma_bs,
&error); &error);
get_location_process_reply (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 (); mmcli_async_operation_done ();
} }
@@ -734,10 +661,7 @@ get_modem_ready (GObject *source,
} }
/* Request to get location from the modem? */ /* Request to get location from the modem? */
if (get_3gpp_flag || if (get_flag) {
get_gps_nmea_flag ||
get_gps_raw_flag ||
get_cdma_bs_flag) {
g_debug ("Asynchronously getting location from the modem..."); g_debug ("Asynchronously getting location from the modem...");
mm_modem_location_get_full (ctx->modem_location, mm_modem_location_get_full (ctx->modem_location,
ctx->cancellable, ctx->cancellable,
@@ -869,10 +793,7 @@ mmcli_modem_location_run_synchronous (GDBusConnection *connection)
} }
/* Request to get location from the modem? */ /* Request to get location from the modem? */
if (get_3gpp_flag || if (get_flag) {
get_gps_nmea_flag ||
get_gps_raw_flag ||
get_cdma_bs_flag) {
MMLocation3gpp *location_3gpp = NULL; MMLocation3gpp *location_3gpp = NULL;
MMLocationGpsNmea *location_gps_nmea = NULL; MMLocationGpsNmea *location_gps_nmea = NULL;
MMLocationGpsRaw *location_gps_raw = 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..."); g_debug ("Synchronously getting location from the modem...");
mm_modem_location_get_full_sync (ctx->modem_location, mm_modem_location_get_full_sync (ctx->modem_location,
get_3gpp_flag ? &location_3gpp : NULL, &location_3gpp,
get_gps_nmea_flag ? &location_gps_nmea : NULL, &location_gps_nmea,
get_gps_raw_flag ? &location_gps_raw : NULL, &location_gps_raw,
get_cdma_bs_flag ? &location_cdma_bs : NULL, &location_cdma_bs,
NULL, NULL,
&error); &error);
get_location_process_reply (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);