device: launch modem initialization after reprobe

The mm_device_create_modem() was updated so that it would not run the
modem initialization implicitly. Due to this change, we must ensure
the modem initialization is run after a modem reprobe operation,
e.g. when switching SIM slots.

The logic to run the modem initialization is moved to MMDevice for
simplicity and clarity.

Fixes: 04d826f563
This commit is contained in:
Aleksander Morgado
2024-04-29 09:45:06 +00:00
parent c66a6b89ec
commit 95099a3ef4
3 changed files with 52 additions and 50 deletions
+2 -44
View File
@@ -190,48 +190,6 @@ find_device_by_physdev_uid (MMBaseManager *self,
/*****************************************************************************/
static void
initialize_ready (MMBaseModem *modem,
GAsyncResult *res)
{
g_autoptr(GError) error = NULL;
if (!mm_base_modem_initialize_finish (modem, res, &error)) {
if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_ABORTED)) {
/* FATAL error, won't even be exported in DBus */
mm_obj_err (modem, "fatal error initializing: %s", error->message);
} else {
/* non-fatal error */
mm_obj_warn (modem, "error initializing: %s", error->message);
mm_base_modem_set_valid (modem, TRUE);
}
} else {
mm_obj_dbg (modem, "modem initialized");
mm_base_modem_set_valid (modem, TRUE);
}
}
static void
modem_initialize (MMBaseManager *self,
MMDevice *device)
{
MMBaseModem *modem;
modem = mm_device_peek_modem (device);
if (!modem) {
mm_obj_warn (self, "cannot initialize modem at device '%s': not found",
mm_device_get_uid (device));
return;
}
mm_obj_dbg (modem, "modem initializing...");
mm_base_modem_initialize (modem,
(GAsyncReadyCallback)initialize_ready,
NULL);
}
/*****************************************************************************/
typedef struct {
MMBaseManager *self;
MMDevice *device;
@@ -264,7 +222,7 @@ dispatcher_modem_setup_ready (MMDispatcherModemSetup *dispatcher,
mm_device_get_uid (ctx->device));
/* launch async modem initialization */
modem_initialize (ctx->self, ctx->device);
mm_device_initialize_modem (ctx->device);
find_device_support_context_free (ctx);
}
@@ -1741,7 +1699,7 @@ handle_set_profile (MmGdbusTest *skeleton,
mm_device_get_uid (device));
/* launch async modem initialization */
modem_initialize (self, device);
mm_device_initialize_modem (device);
out:
+46 -3
View File
@@ -401,6 +401,48 @@ export_modem (MMDevice *self)
/*****************************************************************************/
static void
initialize_ready (MMBaseModem *modem,
GAsyncResult *res,
MMDevice *_self) /* full reference */
{
g_autoptr(MMDevice) self = _self;
g_autoptr(GError) error = NULL;
if (!mm_base_modem_initialize_finish (modem, res, &error)) {
if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_ABORTED)) {
/* FATAL error, won't even be exported in DBus */
mm_obj_err (self, "fatal error initializing: %s", error->message);
} else {
/* non-fatal error */
mm_obj_warn (self, "error initializing: %s", error->message);
mm_base_modem_set_valid (modem, TRUE);
}
} else {
mm_obj_dbg (self, "modem initialized");
mm_base_modem_set_valid (modem, TRUE);
}
}
void
mm_device_initialize_modem (MMDevice *self)
{
MMBaseModem *modem;
modem = mm_device_peek_modem (self);
if (!modem) {
mm_obj_warn (self, "cannot initialize modem: not found");
return;
}
mm_obj_dbg (self, "modem initializing...");
mm_base_modem_initialize (modem,
(GAsyncReadyCallback)initialize_ready,
g_object_ref (self));
}
/*****************************************************************************/
static void
clear_modem (MMDevice *self)
{
@@ -434,16 +476,17 @@ mm_device_remove_modem (MMDevice *self)
static gboolean
reprobe (MMDevice *self)
{
GError *error = NULL;
g_autoptr (GError) error = NULL;
self->priv->reprobe_id = 0;
mm_obj_dbg (self, "Reprobing modem...");
if (!mm_device_create_modem (self, &error)) {
mm_obj_warn (self, "could not recreate modem: %s", error->message);
g_error_free (error);
} else
} else {
mm_obj_dbg (self, "modem recreated");
mm_device_initialize_modem (self);
}
return G_SOURCE_REMOVE;
}
+4 -3
View File
@@ -80,9 +80,10 @@ void mm_device_release_port_name (MMDevice *self,
const gchar *subsystem,
const gchar *name);
gboolean mm_device_create_modem (MMDevice *self,
GError **error);
void mm_device_remove_modem (MMDevice *self);
gboolean mm_device_create_modem (MMDevice *self,
GError **error);
void mm_device_remove_modem (MMDevice *self);
void mm_device_initialize_modem (MMDevice *self);
void mm_device_inhibit (MMDevice *self,
GAsyncReadyCallback callback,