quectel: minor refactor in the sim hot swap setup logic
This commit is contained in:
@@ -134,31 +134,34 @@ static void
|
||||
quectel_qusim_check_for_sim_swap_ready (MMIfaceModem *self,
|
||||
GAsyncResult *res)
|
||||
{
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish (self, res, &error)) {
|
||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish (self, res, &error))
|
||||
mm_obj_warn (self, "couldn't check SIM swap: %s", error->message);
|
||||
g_error_free (error);
|
||||
} else
|
||||
else
|
||||
mm_obj_dbg (self, "check SIM swap completed");
|
||||
}
|
||||
|
||||
static void
|
||||
quectel_qusim_unsolicited_handler (MMPortSerialAt *port,
|
||||
GMatchInfo *match_info,
|
||||
MMIfaceModem* self)
|
||||
MMIfaceModem *self)
|
||||
{
|
||||
if (MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap &&
|
||||
MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish) {
|
||||
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap ||
|
||||
!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish)
|
||||
return;
|
||||
|
||||
mm_obj_dbg (self, "checking SIM swap");
|
||||
MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap (
|
||||
self,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)quectel_qusim_check_for_sim_swap_ready,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Setup SIM hot swap context (Modem interface) */
|
||||
|
||||
gboolean
|
||||
mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
@@ -172,34 +175,28 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMPortSerialAt *port_primary;
|
||||
MMPortSerialAt *port_secondary;
|
||||
MMPortSerialAt *ports[2];
|
||||
GTask *task;
|
||||
GRegex *pattern;
|
||||
guint i;
|
||||
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
|
||||
port_primary = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
|
||||
port_secondary = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
|
||||
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
|
||||
ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
|
||||
|
||||
pattern = g_regex_new ("\\+QUSIM:\\s*1\\r\\n", G_REGEX_RAW, 0, NULL);
|
||||
g_assert (pattern);
|
||||
|
||||
if (port_primary)
|
||||
for (i = 0; i < G_N_ELEMENTS (ports); i++) {
|
||||
if (ports[i])
|
||||
mm_port_serial_at_add_unsolicited_msg_handler (
|
||||
port_primary,
|
||||
pattern,
|
||||
(MMPortSerialAtUnsolicitedMsgFn)quectel_qusim_unsolicited_handler,
|
||||
self,
|
||||
NULL);
|
||||
|
||||
if (port_secondary)
|
||||
mm_port_serial_at_add_unsolicited_msg_handler (
|
||||
port_secondary,
|
||||
ports[i],
|
||||
pattern,
|
||||
(MMPortSerialAtUnsolicitedMsgFn)quectel_qusim_unsolicited_handler,
|
||||
self,
|
||||
NULL);
|
||||
}
|
||||
|
||||
g_regex_unref (pattern);
|
||||
mm_obj_dbg (self, "+QUSIM detection set up");
|
||||
|
Reference in New Issue
Block a user