diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2022-01-07 12:53:30 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2022-01-18 09:00:10 +0000 |
commit | c4f59aebe00c0cd25c4d27ed9e58b690e6b4b878 (patch) | |
tree | 86046499b0c5d3c7139473073e1478153395515e /cli/mmcli-modem.c | |
parent | dbeeb987456150c8a49ba5f6062ad6b96887cd38 (diff) |
mmcli,modem: new '--get-cell-info' action
Diffstat (limited to 'cli/mmcli-modem.c')
-rw-r--r-- | cli/mmcli-modem.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 2ab6438a..f8fa6c1b 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -64,6 +64,7 @@ static gchar *set_allowed_modes_str; static gchar *set_preferred_mode_str; static gchar *set_current_bands_str; static gint set_primary_sim_slot_int; +static gboolean get_cell_info_flag; static gboolean inhibit_flag; static GOptionEntry entries[] = { @@ -131,6 +132,10 @@ static GOptionEntry entries[] = { "Switch to the selected SIM slot", "[SLOT NUMBER]" }, + { "get-cell-info", 0, 0, G_OPTION_ARG_NONE, &get_cell_info_flag, + "Get cell info", + NULL + }, { "inhibit", 0, 0, G_OPTION_ARG_NONE, &inhibit_flag, "Inhibit the modem", NULL @@ -179,6 +184,7 @@ mmcli_modem_options_enabled (void) !!set_preferred_mode_str + !!set_current_bands_str + (set_primary_sim_slot_int > 0) + + get_cell_info_flag + inhibit_flag); if (n_actions == 0 && mmcli_get_common_modem_string ()) { @@ -940,6 +946,35 @@ set_primary_sim_slot_ready (MMModem *modem, } static void +get_cell_info_process_reply (GList *list, + const GError *error) +{ + if (!list) { + g_printerr ("error: couldn't get cell info in the modem: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + mmcli_output_cell_info (list); + mmcli_output_dump (); + + g_list_free_full (list, (GDestroyNotify) g_object_unref); +} + +static void +get_cell_info_ready (MMModem *modem, + GAsyncResult *result) +{ + GList *list; + g_autoptr(GError) error = NULL; + + list = mm_modem_get_cell_info_finish (modem, result, &error); + get_cell_info_process_reply (list, error); + + mmcli_async_operation_done (); +} + +static void state_changed (MMModem *modem, MMModemState old_state, MMModemState new_state, @@ -1191,6 +1226,15 @@ get_modem_ready (GObject *source, return; } + /* Request to get cell info? */ + if (get_cell_info_flag) { + mm_modem_get_cell_info (ctx->modem, + ctx->cancellable, + (GAsyncReadyCallback)get_cell_info_ready, + NULL); + return; + } + /* Request to inhibit the modem? */ if (inhibit_flag) { gchar *uid; @@ -1459,5 +1503,14 @@ mmcli_modem_run_synchronous (GDBusConnection *connection) return; } + /* Request to get cell info? */ + if (get_cell_info_flag) { + GList *list; + + list = mm_modem_get_cell_info_sync (ctx->modem, NULL, &error); + get_cell_info_process_reply (list, error); + return; + } + g_warn_if_reached (); } |