api,modem: new 'SetPrimarySimSlot' method

This new method allows changing the SIM slot considered as primary,
when the modem supports multiple SIM slots.

The generic handling of this method will make sure that the modem
object and all its SIM objects are re-probed from scratch as soon as a
successful SIM slot switch happens.

Implementations may report MM_CORE_ERROR_EXISTS when the switch
doesn't need to happen (e.g. if the requested SIM slot is already the
active one).
This commit is contained in:
Aleksander Morgado
2020-08-01 09:59:37 +02:00
parent 5041b9c99b
commit 924cf1af3c
8 changed files with 303 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ static gchar *set_current_capabilities_str;
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 inhibit_flag;
static GOptionEntry entries[] = {
@@ -126,6 +127,10 @@ static GOptionEntry entries[] = {
"Set bands to be used by a given modem.",
"[BAND1|BAND2...]"
},
{ "set-primary-sim-slot", 0, 0, G_OPTION_ARG_INT, &set_primary_sim_slot_int,
"Switch to the selected SIM slot",
"[SLOT NUMBER]"
},
{ "inhibit", 0, 0, G_OPTION_ARG_NONE, &inhibit_flag,
"Inhibit the modem",
NULL
@@ -173,6 +178,7 @@ mmcli_modem_options_enabled (void)
!!set_allowed_modes_str +
!!set_preferred_mode_str +
!!set_current_bands_str +
(set_primary_sim_slot_int > 0) +
inhibit_flag);
if (n_actions == 0 && mmcli_get_common_modem_string ()) {
@@ -890,6 +896,32 @@ parse_current_bands (MMModemBand **bands,
}
}
static void
set_primary_sim_slot_process_reply (gboolean result,
const GError *error)
{
if (!result) {
g_printerr ("error: couldn't request primary SIM switch: '%s'\n",
error ? error->message : "unknown error");
exit (EXIT_FAILURE);
}
g_print ("successfully requested primary SIM switch in modem\n");
}
static void
set_primary_sim_slot_ready (MMModem *modem,
GAsyncResult *result)
{
gboolean operation_result;
g_autoptr(GError) error = NULL;
operation_result = mm_modem_set_primary_sim_slot_finish (modem, result, &error);
set_primary_sim_slot_process_reply (operation_result, error);
mmcli_async_operation_done ();
}
static void
state_changed (MMModem *modem,
MMModemState old_state,
@@ -1132,6 +1164,16 @@ get_modem_ready (GObject *source,
return;
}
/* Request to switch SIM? */
if (set_primary_sim_slot_int > 0) {
mm_modem_set_primary_sim_slot (ctx->modem,
set_primary_sim_slot_int,
ctx->cancellable,
(GAsyncReadyCallback)set_primary_sim_slot_ready,
NULL);
return;
}
/* Request to inhibit the modem? */
if (inhibit_flag) {
gchar *uid;
@@ -1391,5 +1433,14 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
return;
}
/* Request to switch current SIM? */
if (set_primary_sim_slot_int > 0) {
gboolean result;
result = mm_modem_set_primary_sim_slot_sync (ctx->modem, set_primary_sim_slot_int, NULL, &error);
set_primary_sim_slot_process_reply (result, error);
return;
}
g_warn_if_reached ();
}