core: add nm_platform_dedup_multi_iter_next_*() helpers to "nmp-object.h"

This code is not specific to "nm-ip4-config.h"/"nm-ip6-config.h".
It applies to everybody who wants to iterate over a dedup-multi-index of
certain NMPObjects. Move it.
This commit is contained in:
Thomas Haller 2020-07-23 12:19:15 +02:00
parent 67bfcb49c9
commit b44f7dce40
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
5 changed files with 58 additions and 56 deletions

View file

@ -1657,8 +1657,8 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
const NMPlatformIP4Address *r_src = NULL;
const NMPlatformIP4Address *r_dst = NULL;
has = nm_ip_config_iter_ip4_address_next (&ipconf_iter_src, &r_src);
if (has != nm_ip_config_iter_ip4_address_next (&ipconf_iter_dst, &r_dst)) {
has = nm_platform_dedup_multi_iter_next_ip4_address (&ipconf_iter_src, &r_src);
if (has != nm_platform_dedup_multi_iter_next_ip4_address (&ipconf_iter_dst, &r_dst)) {
are_equal = FALSE;
has_relevant_changes = TRUE;
break;
@ -1704,8 +1704,8 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
const NMPlatformIP4Route *r_src = NULL;
const NMPlatformIP4Route *r_dst = NULL;
has = nm_ip_config_iter_ip4_route_next (&ipconf_iter_src, &r_src);
if (has != nm_ip_config_iter_ip4_route_next (&ipconf_iter_dst, &r_dst)) {
has = nm_platform_dedup_multi_iter_next_ip4_route (&ipconf_iter_src, &r_src);
if (has != nm_platform_dedup_multi_iter_next_ip4_route (&ipconf_iter_dst, &r_dst)) {
are_equal = FALSE;
has_relevant_changes = TRUE;
break;

View file

@ -35,36 +35,14 @@ void nm_ip_config_dedup_multi_idx_type_init (NMIPConfigDedupMultiIdxType *idx_ty
void nm_ip_config_iter_ip4_address_init (NMDedupMultiIter *iter, const NMIP4Config *self);
void nm_ip_config_iter_ip4_route_init (NMDedupMultiIter *iter, const NMIP4Config *self);
static inline gboolean
nm_ip_config_iter_ip4_address_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP4Address **out_address)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_address)
*out_address = has_next ? NMP_OBJECT_CAST_IP4_ADDRESS (ipconf_iter->current->obj) : NULL;
return has_next;
}
static inline gboolean
nm_ip_config_iter_ip4_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP4Route **out_route)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_route)
*out_route = has_next ? NMP_OBJECT_CAST_IP4_ROUTE (ipconf_iter->current->obj) : NULL;
return has_next;
}
#define nm_ip_config_iter_ip4_address_for_each(iter, self, address) \
for (nm_ip_config_iter_ip4_address_init ((iter), (self)); \
nm_ip_config_iter_ip4_address_next ((iter), (address)); \
nm_platform_dedup_multi_iter_next_ip4_address ((iter), (address)); \
)
#define nm_ip_config_iter_ip4_route_for_each(iter, self, route) \
for (nm_ip_config_iter_ip4_route_init ((iter), (self)); \
nm_ip_config_iter_ip4_route_next ((iter), (route)); \
nm_platform_dedup_multi_iter_next_ip4_route ((iter), (route)); \
)
/*****************************************************************************/

View file

@ -1296,8 +1296,8 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
const NMPlatformIP6Address *r_src = NULL;
const NMPlatformIP6Address *r_dst = NULL;
has = nm_ip_config_iter_ip6_address_next (&ipconf_iter_src, &r_src);
if (has != nm_ip_config_iter_ip6_address_next (&ipconf_iter_dst, &r_dst)) {
has = nm_platform_dedup_multi_iter_next_ip6_address (&ipconf_iter_src, &r_src);
if (has != nm_platform_dedup_multi_iter_next_ip6_address (&ipconf_iter_dst, &r_dst)) {
are_equal = FALSE;
has_relevant_changes = TRUE;
break;
@ -1344,8 +1344,8 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
const NMPlatformIP6Route *r_src = NULL;
const NMPlatformIP6Route *r_dst = NULL;
has = nm_ip_config_iter_ip6_route_next (&ipconf_iter_src, &r_src);
if (has != nm_ip_config_iter_ip6_route_next (&ipconf_iter_dst, &r_dst)) {
has = nm_platform_dedup_multi_iter_next_ip6_route (&ipconf_iter_src, &r_src);
if (has != nm_platform_dedup_multi_iter_next_ip6_route (&ipconf_iter_dst, &r_dst)) {
are_equal = FALSE;
has_relevant_changes = TRUE;
break;

View file

@ -18,36 +18,14 @@
void nm_ip_config_iter_ip6_address_init (NMDedupMultiIter *iter, const NMIP6Config *self);
void nm_ip_config_iter_ip6_route_init (NMDedupMultiIter *iter, const NMIP6Config *self);
static inline gboolean
nm_ip_config_iter_ip6_address_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP6Address **out_address)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_address)
*out_address = has_next ? NMP_OBJECT_CAST_IP6_ADDRESS (ipconf_iter->current->obj) : NULL;
return has_next;
}
static inline gboolean
nm_ip_config_iter_ip6_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP6Route **out_route)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_route)
*out_route = has_next ? NMP_OBJECT_CAST_IP6_ROUTE (ipconf_iter->current->obj) : NULL;
return has_next;
}
#define nm_ip_config_iter_ip6_address_for_each(iter, self, address) \
for (nm_ip_config_iter_ip6_address_init ((iter), (self)); \
nm_ip_config_iter_ip6_address_next ((iter), (address)); \
nm_platform_dedup_multi_iter_next_ip6_address ((iter), (address)); \
)
#define nm_ip_config_iter_ip6_route_for_each(iter, self, route) \
for (nm_ip_config_iter_ip6_route_init ((iter), (self)); \
nm_ip_config_iter_ip6_route_next ((iter), (route)); \
nm_platform_dedup_multi_iter_next_ip6_route ((iter), (route)); \
)
/*****************************************************************************/

View file

@ -1057,4 +1057,50 @@ nmp_object_ip_route_is_best_defaut_route (const NMPObject *obj)
&& r->type_coerced == nm_platform_route_type_coerce (1 /* RTN_UNICAST */);
}
/*****************************************************************************/
static inline gboolean
nm_platform_dedup_multi_iter_next_ip4_address (NMDedupMultiIter *ipconf_iter, const NMPlatformIP4Address **out_address)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_address)
*out_address = has_next ? NMP_OBJECT_CAST_IP4_ADDRESS (ipconf_iter->current->obj) : NULL;
return has_next;
}
static inline gboolean
nm_platform_dedup_multi_iter_next_ip4_route (NMDedupMultiIter *ipconf_iter, const NMPlatformIP4Route **out_route)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_route)
*out_route = has_next ? NMP_OBJECT_CAST_IP4_ROUTE (ipconf_iter->current->obj) : NULL;
return has_next;
}
static inline gboolean
nm_platform_dedup_multi_iter_next_ip6_address (NMDedupMultiIter *ipconf_iter, const NMPlatformIP6Address **out_address)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_address)
*out_address = has_next ? NMP_OBJECT_CAST_IP6_ADDRESS (ipconf_iter->current->obj) : NULL;
return has_next;
}
static inline gboolean
nm_platform_dedup_multi_iter_next_ip6_route (NMDedupMultiIter *ipconf_iter, const NMPlatformIP6Route **out_route)
{
gboolean has_next;
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (out_route)
*out_route = has_next ? NMP_OBJECT_CAST_IP6_ROUTE (ipconf_iter->current->obj) : NULL;
return has_next;
}
#endif /* __NMP_OBJECT_H__ */