mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 03:40:11 +01:00
shared: return deleted object from nm_dedup_multi_index_remove_obj()
For completeness of the API. remove_obj() is basically a shortcut of nm_dedup_multi_index_lookup_obj() combined with nm_dedup_multi_index_remove_entry(). As such, it is useful to return the actually deleted object. Note that the lookup needle @obj is not necessarily the same instance as the one that will be removed, it's only an instance that compares equal according to the index's equality operator.
This commit is contained in:
parent
3fc501e833
commit
2f693fb68c
4 changed files with 29 additions and 11 deletions
|
|
@ -626,13 +626,22 @@ nm_dedup_multi_index_remove_entry (NMDedupMultiIndex *self,
|
|||
guint
|
||||
nm_dedup_multi_index_remove_obj (NMDedupMultiIndex *self,
|
||||
NMDedupMultiIdxType *idx_type,
|
||||
/*const NMDedupMultiObj * */ gconstpointer obj)
|
||||
/*const NMDedupMultiObj * */ gconstpointer obj,
|
||||
/*const NMDedupMultiObj ** */ gconstpointer *out_obj)
|
||||
{
|
||||
const NMDedupMultiEntry *entry;
|
||||
|
||||
entry = nm_dedup_multi_index_lookup_obj (self, idx_type, obj);
|
||||
if (!entry)
|
||||
if (!entry) {
|
||||
NM_SET_OUT (out_obj, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* since we are about to remove the object, we obviously pass
|
||||
* a reference to @out_obj, the caller MUST unref the object,
|
||||
* if he chooses to provide @out_obj. */
|
||||
NM_SET_OUT (out_obj, nm_dedup_multi_obj_ref (entry->obj));
|
||||
|
||||
_remove_entry (self, (NMDedupMultiEntry *) entry, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,7 +291,8 @@ guint nm_dedup_multi_index_remove_entry (NMDedupMultiIndex *self,
|
|||
|
||||
guint nm_dedup_multi_index_remove_obj (NMDedupMultiIndex *self,
|
||||
NMDedupMultiIdxType *idx_type,
|
||||
/*const NMDedupMultiObj * */ gconstpointer obj);
|
||||
/*const NMDedupMultiObj * */ gconstpointer obj,
|
||||
/*const NMDedupMultiObj ** */ gconstpointer *out_obj);
|
||||
|
||||
guint nm_dedup_multi_index_remove_head (NMDedupMultiIndex *self,
|
||||
NMDedupMultiIdxType *idx_type,
|
||||
|
|
|
|||
|
|
@ -1228,7 +1228,8 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
|
|||
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, src, &a) {
|
||||
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
|
||||
&priv_dst->idx_ip4_addresses,
|
||||
NMP_OBJECT_UP_CAST (a)))
|
||||
NMP_OBJECT_UP_CAST (a),
|
||||
NULL))
|
||||
changed = TRUE;
|
||||
}
|
||||
if (changed)
|
||||
|
|
@ -1256,7 +1257,8 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
|
|||
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, src, &r) {
|
||||
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
|
||||
&priv_dst->idx_ip4_routes,
|
||||
NMP_OBJECT_UP_CAST (r)))
|
||||
NMP_OBJECT_UP_CAST (r),
|
||||
NULL))
|
||||
changed = TRUE;
|
||||
}
|
||||
if (changed)
|
||||
|
|
@ -1921,7 +1923,8 @@ _nmtst_nm_ip4_config_del_address (NMIP4Config *self, guint i)
|
|||
|
||||
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
|
||||
&priv->idx_ip4_addresses,
|
||||
NMP_OBJECT_UP_CAST (a)) != 1)
|
||||
NMP_OBJECT_UP_CAST (a),
|
||||
NULL) != 1)
|
||||
g_return_if_reached ();
|
||||
_notify_addresses (self);
|
||||
}
|
||||
|
|
@ -2040,7 +2043,8 @@ _nmtst_nm_ip4_config_del_route (NMIP4Config *self, guint i)
|
|||
|
||||
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
|
||||
&priv->idx_ip4_routes,
|
||||
NMP_OBJECT_UP_CAST (r)) != 1)
|
||||
NMP_OBJECT_UP_CAST (r),
|
||||
NULL) != 1)
|
||||
g_return_if_reached ();
|
||||
_notify_routes (self);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1025,7 +1025,8 @@ nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src)
|
|||
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, src, &a) {
|
||||
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
|
||||
&priv_dst->idx_ip6_addresses,
|
||||
NMP_OBJECT_UP_CAST (a)))
|
||||
NMP_OBJECT_UP_CAST (a),
|
||||
NULL))
|
||||
changed = TRUE;
|
||||
}
|
||||
if (changed)
|
||||
|
|
@ -1054,7 +1055,8 @@ nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src)
|
|||
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, src, &r) {
|
||||
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
|
||||
&priv_dst->idx_ip6_routes,
|
||||
NMP_OBJECT_UP_CAST (r)))
|
||||
NMP_OBJECT_UP_CAST (r),
|
||||
NULL))
|
||||
changed = TRUE;
|
||||
}
|
||||
if (changed)
|
||||
|
|
@ -1586,7 +1588,8 @@ _nmtst_nm_ip6_config_del_address (NMIP6Config *self, guint i)
|
|||
|
||||
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
|
||||
&priv->idx_ip6_addresses,
|
||||
NMP_OBJECT_UP_CAST (a)) != 1)
|
||||
NMP_OBJECT_UP_CAST (a),
|
||||
NULL) != 1)
|
||||
g_return_if_reached ();
|
||||
_notify_addresses (self);
|
||||
}
|
||||
|
|
@ -1763,7 +1766,8 @@ _nmtst_ip6_config_del_route (NMIP6Config *self, guint i)
|
|||
|
||||
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
|
||||
&priv->idx_ip6_routes,
|
||||
NMP_OBJECT_UP_CAST (r)) != 1)
|
||||
NMP_OBJECT_UP_CAST (r),
|
||||
NULL) != 1)
|
||||
g_return_if_reached ();
|
||||
_notify_routes (self);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue