From f796be3d7dcda422fd56fddf5d721f99e7e7a871 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 23 Aug 2019 17:23:09 +0200 Subject: [PATCH] wwan: add nm_modem_manager_get_modems() to iterate over modems Currently, we cannot ask which modems exist. NMDeviceBt may claim it via nm_device_factory_emit_component_added(), and NMWWanFactory may take it by listening to NM_MODEM_MANAGER_MODEM_ADDED. But that's it. We will drop nm_device_factory_emit_component_added() because it's only used for passing modems to NMDeviceBt. Instead, NMDeviceBt can directly subscribe to NM_MODEM_MANAGER_MODEM_ADDED. It already has a reference to NMModemManager. Anyway, the NM_MODEM_MANAGER_MODEM_ADDED signal is no enough, because sometimes when the mode appears, NMDeviceBt might not yet know whether it should take it (because the DUN connect call is not yet complete). Currently that never happens because dun_connect() blocks waiting for the device. That must be fixed, by not waiting. But this opens up a race, and NMDeviceBt might after NM_MODEM_MANAGER_MODEM_ADDED need to search for the suitable modem: by iterating the list of all modems. --- src/devices/wwan/libnm-wwan.ver | 1 + src/devices/wwan/nm-modem-manager.c | 14 ++++++++++++++ src/devices/wwan/nm-modem-manager.h | 3 +++ 3 files changed, 18 insertions(+) diff --git a/src/devices/wwan/libnm-wwan.ver b/src/devices/wwan/libnm-wwan.ver index b63a5066bc..c368a5907d 100644 --- a/src/devices/wwan/libnm-wwan.ver +++ b/src/devices/wwan/libnm-wwan.ver @@ -25,6 +25,7 @@ global: nm_modem_ip4_pre_commit; nm_modem_is_claimed; nm_modem_manager_get; + nm_modem_manager_get_modems; nm_modem_manager_get_type; nm_modem_manager_name_owner_get; nm_modem_manager_name_owner_ref; diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 463e042ff9..63470148d4 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -136,6 +136,20 @@ remove_one_modem (gpointer key, gpointer value, gpointer user_data) /*****************************************************************************/ +NMModem ** +nm_modem_manager_get_modems (NMModemManager *self, + guint *out_len) +{ + g_return_val_if_fail (NM_IS_MODEM_MANAGER (self), NULL); + + return (NMModem **) nm_utils_hash_values_to_array (NM_MODEM_MANAGER_GET_PRIVATE (self)->modems, + NULL, + NULL, + out_len); +} + +/*****************************************************************************/ + static void modm_clear_manager (NMModemManager *self) { diff --git a/src/devices/wwan/nm-modem-manager.h b/src/devices/wwan/nm-modem-manager.h index 503afc8edb..3dd3024e11 100644 --- a/src/devices/wwan/nm-modem-manager.h +++ b/src/devices/wwan/nm-modem-manager.h @@ -38,4 +38,7 @@ void nm_modem_manager_name_owner_unref (NMModemManager *self); const char *nm_modem_manager_name_owner_get (NMModemManager *self); +NMModem **nm_modem_manager_get_modems (NMModemManager *self, + guint *out_len); + #endif /* __NETWORKMANAGER_MODEM_MANAGER_H__ */