From b983deaa40b9b68c1a6684df416e38fff2328e28 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 12 Jul 2021 15:41:21 +0200 Subject: iface-modem: refactor new SIM slots array creation --- src/mm-iface-modem.c | 64 ++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index b3a301f7..92bf23e5 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -146,64 +146,58 @@ mm_iface_modem_modify_sim (MMIfaceModem *self, guint slot_index, MMBaseSim *new_sim) { - MmGdbusModem *skeleton; - g_autoptr (GPtrArray) sim_slots_old = NULL; - g_autoptr (GPtrArray) sim_slots_new = NULL; - guint i; - GPtrArray *sim_slot_paths_array; - g_auto (GStrv) sim_slot_paths = NULL; + g_autoptr(MmGdbusModemSkeleton) skeleton = NULL; + g_autoptr(GPtrArray) sim_slots_old = NULL; + g_autoptr(GPtrArray) sim_slots_new = NULL; + guint i; + GPtrArray *sim_slot_paths_array; + g_auto(GStrv) sim_slot_paths = NULL; g_object_get (self, - MM_IFACE_MODEM_SIM_SLOTS, - &sim_slots_old, + MM_IFACE_MODEM_SIM_SLOTS, &sim_slots_old, + MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, NULL); + if (!sim_slots_old) { mm_obj_warn (self, "Failed to process SIM hot swap: couldn't load current list of SIM slots"); 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_slots_new = g_ptr_array_new_with_free_func ((GDestroyNotify) sim_slot_free); for (i = 0; i < sim_slots_old->len; i++) { 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) { - 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); + if (i == slot_index) 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)); - } + sim_path = mm_base_sim_get_path (sim); + } else + g_ptr_array_add (sim_slots_new, NULL); - if (!sim) { + if (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 ("/")); - continue; - } - - sim_path = mm_base_sim_get_path (sim); - g_ptr_array_add (sim_slot_paths_array, g_strdup (sim_path)); } + 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, MM_IFACE_MODEM_SIM_SLOTS, sim_slots_new, NULL); - - 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); + mm_gdbus_modem_set_sim_slots (MM_GDBUS_MODEM (skeleton), (const gchar *const *) sim_slot_paths); } /*****************************************************************************/ -- cgit v1.2.3-70-g09d2