iface-modem: refactor new SIM slots array creation
This commit is contained in:
@@ -146,7 +146,7 @@ mm_iface_modem_modify_sim (MMIfaceModem *self,
|
|||||||
guint slot_index,
|
guint slot_index,
|
||||||
MMBaseSim *new_sim)
|
MMBaseSim *new_sim)
|
||||||
{
|
{
|
||||||
MmGdbusModem *skeleton;
|
g_autoptr(MmGdbusModemSkeleton) skeleton = NULL;
|
||||||
g_autoptr(GPtrArray) sim_slots_old = NULL;
|
g_autoptr(GPtrArray) sim_slots_old = NULL;
|
||||||
g_autoptr(GPtrArray) sim_slots_new = NULL;
|
g_autoptr(GPtrArray) sim_slots_new = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
@@ -154,56 +154,50 @@ mm_iface_modem_modify_sim (MMIfaceModem *self,
|
|||||||
g_auto(GStrv) sim_slot_paths = NULL;
|
g_auto(GStrv) sim_slot_paths = NULL;
|
||||||
|
|
||||||
g_object_get (self,
|
g_object_get (self,
|
||||||
MM_IFACE_MODEM_SIM_SLOTS,
|
MM_IFACE_MODEM_SIM_SLOTS, &sim_slots_old,
|
||||||
&sim_slots_old,
|
MM_IFACE_MODEM_DBUS_SKELETON, &skeleton,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!sim_slots_old) {
|
if (!sim_slots_old) {
|
||||||
mm_obj_warn (self, "Failed to process SIM hot swap: couldn't load current list of SIM slots");
|
mm_obj_warn (self, "Failed to process SIM hot swap: couldn't load current list of SIM slots");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!skeleton) {
|
||||||
|
mm_obj_warn (self, "Failed to process SIM hot swap: interface skeleton not available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sim_slot_paths_array = g_ptr_array_new ();
|
sim_slot_paths_array = g_ptr_array_new ();
|
||||||
sim_slots_new = g_ptr_array_new_with_free_func ((GDestroyNotify) sim_slot_free);
|
sim_slots_new = g_ptr_array_new_with_free_func ((GDestroyNotify) sim_slot_free);
|
||||||
for (i = 0; i < sim_slots_old->len; i++) {
|
for (i = 0; i < sim_slots_old->len; i++) {
|
||||||
MMBaseSim *sim;
|
MMBaseSim *sim;
|
||||||
const gchar *sim_path;
|
const gchar *sim_path = NULL;
|
||||||
|
|
||||||
sim = MM_BASE_SIM (g_ptr_array_index (sim_slots_old, i));
|
if (i == slot_index)
|
||||||
if (i == slot_index) {
|
|
||||||
mm_obj_dbg (self, "Updating sim at slot %d", i + 1);
|
|
||||||
g_ptr_array_add (sim_slots_new, new_sim ? g_object_ref (new_sim) : NULL);
|
|
||||||
sim = new_sim;
|
sim = new_sim;
|
||||||
} else {
|
else
|
||||||
|
sim = MM_BASE_SIM (g_ptr_array_index (sim_slots_old, i));
|
||||||
|
|
||||||
|
if (sim) {
|
||||||
g_ptr_array_add (sim_slots_new, g_object_ref (sim));
|
g_ptr_array_add (sim_slots_new, g_object_ref (sim));
|
||||||
}
|
|
||||||
|
|
||||||
if (!sim) {
|
|
||||||
g_ptr_array_add (sim_slot_paths_array, g_strdup ("/"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sim_path = mm_base_sim_get_path (sim);
|
sim_path = mm_base_sim_get_path (sim);
|
||||||
|
} else
|
||||||
|
g_ptr_array_add (sim_slots_new, NULL);
|
||||||
|
|
||||||
|
if (sim_path)
|
||||||
g_ptr_array_add (sim_slot_paths_array, g_strdup (sim_path));
|
g_ptr_array_add (sim_slot_paths_array, g_strdup (sim_path));
|
||||||
|
else
|
||||||
|
g_ptr_array_add (sim_slot_paths_array, g_strdup ("/"));
|
||||||
}
|
}
|
||||||
|
g_ptr_array_add (sim_slot_paths_array, NULL);
|
||||||
|
sim_slot_paths = (GStrv) g_ptr_array_free (sim_slot_paths_array, FALSE);
|
||||||
|
|
||||||
g_object_set (self,
|
g_object_set (self,
|
||||||
MM_IFACE_MODEM_SIM_SLOTS,
|
MM_IFACE_MODEM_SIM_SLOTS,
|
||||||
sim_slots_new,
|
sim_slots_new,
|
||||||
NULL);
|
NULL);
|
||||||
|
mm_gdbus_modem_set_sim_slots (MM_GDBUS_MODEM (skeleton), (const gchar *const *) sim_slot_paths);
|
||||||
g_ptr_array_add (sim_slot_paths_array, NULL);
|
|
||||||
sim_slot_paths = (GStrv) g_ptr_array_free (sim_slot_paths_array, FALSE);
|
|
||||||
|
|
||||||
g_object_get (self,
|
|
||||||
MM_IFACE_MODEM_DBUS_SKELETON,
|
|
||||||
&skeleton,
|
|
||||||
NULL);
|
|
||||||
if (!skeleton) {
|
|
||||||
mm_obj_warn (self, "Failed to get dbus skeleton in mm_iface_modem_modify_sim, will not update sim_slots");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mm_gdbus_modem_set_sim_slots (skeleton, (const gchar *const *) sim_slot_paths);
|
|
||||||
g_object_unref (skeleton);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Reference in New Issue
Block a user