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,
|
quectel_qusim_check_for_sim_swap_ready (MMIfaceModem *self,
|
||||||
GAsyncResult *res)
|
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);
|
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");
|
mm_obj_dbg (self, "check SIM swap completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
quectel_qusim_unsolicited_handler (MMPortSerialAt *port,
|
quectel_qusim_unsolicited_handler (MMPortSerialAt *port,
|
||||||
GMatchInfo *match_info,
|
GMatchInfo *match_info,
|
||||||
MMIfaceModem* self)
|
MMIfaceModem *self)
|
||||||
{
|
{
|
||||||
if (MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap &&
|
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap ||
|
||||||
MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish) {
|
!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish)
|
||||||
|
return;
|
||||||
|
|
||||||
mm_obj_dbg (self, "checking SIM swap");
|
mm_obj_dbg (self, "checking SIM swap");
|
||||||
MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap (
|
MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap (
|
||||||
self,
|
self,
|
||||||
NULL,
|
NULL,
|
||||||
(GAsyncReadyCallback)quectel_qusim_check_for_sim_swap_ready,
|
(GAsyncReadyCallback)quectel_qusim_check_for_sim_swap_ready,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Setup SIM hot swap context (Modem interface) */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self,
|
mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -172,34 +175,28 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMPortSerialAt *port_primary;
|
MMPortSerialAt *ports[2];
|
||||||
MMPortSerialAt *port_secondary;
|
|
||||||
GTask *task;
|
GTask *task;
|
||||||
GRegex *pattern;
|
GRegex *pattern;
|
||||||
|
guint i;
|
||||||
|
|
||||||
task = g_task_new (self, NULL, callback, user_data);
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
|
|
||||||
port_primary = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
|
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
|
||||||
port_secondary = mm_base_modem_peek_port_secondary (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);
|
pattern = g_regex_new ("\\+QUSIM:\\s*1\\r\\n", G_REGEX_RAW, 0, NULL);
|
||||||
g_assert (pattern);
|
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 (
|
mm_port_serial_at_add_unsolicited_msg_handler (
|
||||||
port_primary,
|
ports[i],
|
||||||
pattern,
|
|
||||||
(MMPortSerialAtUnsolicitedMsgFn)quectel_qusim_unsolicited_handler,
|
|
||||||
self,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (port_secondary)
|
|
||||||
mm_port_serial_at_add_unsolicited_msg_handler (
|
|
||||||
port_secondary,
|
|
||||||
pattern,
|
pattern,
|
||||||
(MMPortSerialAtUnsolicitedMsgFn)quectel_qusim_unsolicited_handler,
|
(MMPortSerialAtUnsolicitedMsgFn)quectel_qusim_unsolicited_handler,
|
||||||
self,
|
self,
|
||||||
NULL);
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
g_regex_unref (pattern);
|
g_regex_unref (pattern);
|
||||||
mm_obj_dbg (self, "+QUSIM detection set up");
|
mm_obj_dbg (self, "+QUSIM detection set up");
|
||||||
|
Reference in New Issue
Block a user