core: use nm_dbus_manager_lookup_object_with_type()

I think this makes it clearer that we should always look for a certain
type, because NMDBusManager tracks all D-Bus objects.
This commit is contained in:
Thomas Haller 2022-02-22 21:19:18 +01:00
parent de61722efe
commit 6f948fcd2e
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
5 changed files with 27 additions and 17 deletions

View file

@ -1037,9 +1037,10 @@ nm_wifi_ap_lookup_for_device(NMDevice *device, const char *exported_path)
g_return_val_if_fail(NM_IS_DEVICE(device), NULL);
ap = nm_dbus_manager_lookup_object(nm_dbus_object_get_manager(NM_DBUS_OBJECT(device)),
exported_path);
if (!ap || !NM_IS_WIFI_AP(ap) || ap->wifi_device != device)
ap = nm_dbus_manager_lookup_object_with_type(nm_dbus_object_get_manager(NM_DBUS_OBJECT(device)),
NM_TYPE_WIFI_AP,
exported_path);
if (!ap || ap->wifi_device != device)
return NULL;
return ap;

View file

@ -139,10 +139,11 @@ nm_wifi_p2p_peer_lookup_for_device(NMDevice *device, const char *exported_path)
g_return_val_if_fail(NM_IS_DEVICE(device), NULL);
peer = (NMWifiP2PPeer *) nm_dbus_manager_lookup_object(
nm_dbus_object_get_manager(NM_DBUS_OBJECT(device)),
exported_path);
if (!peer || !NM_IS_WIFI_P2P_PEER(peer) || peer->wifi_device != device)
peer =
nm_dbus_manager_lookup_object_with_type(nm_dbus_object_get_manager(NM_DBUS_OBJECT(device)),
NM_TYPE_WIFI_P2P_PEER,
exported_path);
if (!peer || peer->wifi_device != device)
return NULL;
return peer;

View file

@ -259,10 +259,11 @@ nm_checkpoint_manager_lookup_by_path(NMCheckpointManager *self, const char *path
g_return_val_if_fail(self, NULL);
checkpoint =
nm_dbus_manager_lookup_object(nm_dbus_object_get_manager(NM_DBUS_OBJECT(GET_MANAGER(self))),
path);
if (!checkpoint || !NM_IS_CHECKPOINT(checkpoint)) {
checkpoint = nm_dbus_manager_lookup_object_with_type(
nm_dbus_object_get_manager(NM_DBUS_OBJECT(GET_MANAGER(self))),
NM_TYPE_CHECKPOINT,
path);
if (!checkpoint) {
g_set_error(error,
NM_MANAGER_ERROR,
NM_MANAGER_ERROR_INVALID_ARGUMENTS,

View file

@ -1159,8 +1159,10 @@ active_connection_get_by_path(NMManager *self, const char *path)
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self);
NMActiveConnection *ac;
ac = nm_dbus_manager_lookup_object(nm_dbus_object_get_manager(NM_DBUS_OBJECT(self)), path);
if (!ac || !NM_IS_ACTIVE_CONNECTION(ac) || c_list_is_empty(&ac->active_connections_lst))
ac = nm_dbus_manager_lookup_object_with_type(nm_dbus_object_get_manager(NM_DBUS_OBJECT(self)),
NM_TYPE_ACTIVE_CONNECTION,
path);
if (!ac || c_list_is_empty(&ac->active_connections_lst))
return NULL;
nm_assert(c_list_contains(&priv->active_connections_lst_head, &ac->active_connections_lst));
@ -1292,8 +1294,11 @@ nm_manager_get_device_by_path(NMManager *self, const char *path)
g_return_val_if_fail(path, NULL);
device = nm_dbus_manager_lookup_object(nm_dbus_object_get_manager(NM_DBUS_OBJECT(self)), path);
if (!device || !NM_IS_DEVICE(device) || c_list_is_empty(&device->devices_lst))
device =
nm_dbus_manager_lookup_object_with_type(nm_dbus_object_get_manager(NM_DBUS_OBJECT(self)),
NM_TYPE_DEVICE,
path);
if (!device || c_list_is_empty(&device->devices_lst))
return NULL;
nm_assert(c_list_contains(&priv->devices_lst_head, &device->devices_lst));

View file

@ -3201,8 +3201,10 @@ nm_settings_get_connection_by_path(NMSettings *self, const char *path)
priv = NM_SETTINGS_GET_PRIVATE(self);
connection =
nm_dbus_manager_lookup_object(nm_dbus_object_get_manager(NM_DBUS_OBJECT(self)), path);
if (!connection || !NM_IS_SETTINGS_CONNECTION(connection))
nm_dbus_manager_lookup_object_with_type(nm_dbus_object_get_manager(NM_DBUS_OBJECT(self)),
NM_TYPE_SETTINGS_CONNECTION,
path);
if (!connection)
return NULL;
nm_assert(c_list_contains(&priv->connections_lst_head, &connection->_connections_lst));