[Libosinfo] [libosinfo PATCH v2 13/15] os: Add add_entity_to_list_check()
Cole Robinson
crobinso at redhat.com
Fri Nov 16 18:51:13 UTC 2018
On 11/12/2018 05:31 AM, Fabiano Fidêncio wrote:
> The addition of this new function is basically preparing the ground for
> the changes that are coming in the next commits where we'll need to do
> the very same check in both _get_device_links_internal() and
> _get_devices_internal(). With that in mind, let's avoid code
> duplication and have a single function that can be used in both methods.
>
> https://gitlab.com/libosinfo/osinfo-db/issues/13
>
> Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
> ---
> osinfo/osinfo_os.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
> index cbc4459..b00d773 100644
> --- a/osinfo/osinfo_os.c
> +++ b/osinfo/osinfo_os.c
> @@ -204,6 +204,21 @@ OsinfoOs *osinfo_os_new(const gchar *id)
> }
>
>
> +static gboolean
> +add_entity_to_list_check(OsinfoEntity *ent1, /* OsinfoDeviceLink */
> + OsinfoEntity *ent2, /* OsinfoDevice or OsinfoDevice Link */
> + OsinfoFilter *filter,
> + gboolean include_removed)
> +{
> + gboolean ret = FALSE;
> +
> + if (filter == NULL || osinfo_filter_matches(filter, ent2))
> + ret = TRUE;
> +
> + return ret;
> +}
> +
> +
> static OsinfoDeviceList *
> osinfo_os_get_devices_internal(OsinfoOs *os,
> OsinfoFilter *filter,
> @@ -220,7 +235,9 @@ osinfo_os_get_devices_internal(OsinfoOs *os,
> while (tmp) {
> OsinfoDeviceLink *devlink = OSINFO_DEVICELINK(tmp->data);
> OsinfoDevice *dev = osinfo_devicelink_get_target(devlink);
> - if (!filter || osinfo_filter_matches(filter, OSINFO_ENTITY(dev)))
> +
> + if (add_entity_to_list_check
> + (OSINFO_ENTITY(devlink), OSINFO_ENTITY(dev), filter, include_removed))
Odd formatting here to have the starting function paren on the second
line... is that used elsewhere in libosinfo? I'm surprised syntax-check
doesn't warn about it, but maybe it's not as advanced as libvirt's
syntax-check
- Cole
More information about the Libosinfo
mailing list