[libvirt] [PATCH v3 6/9] util: virTypedParams{Filter, PickStrings}
Jiri Denemark
jdenemar at redhat.com
Wed Jun 3 08:15:41 UTC 2015
On Tue, May 26, 2015 at 15:01:48 +0200, Michal Privoznik wrote:
> From: Pavel Boldin <pboldin at mirantis.com>
>
> Add multikey API:
>
> * virTypedParamsFilter that returns all the parameters with specified name.
> * virTypedParamsPickStrings that returns a list with all the values for
> specified name and string type.
...
> diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
> index 716dd2f..845a0b8 100644
> --- a/src/libvirt_public.syms
> +++ b/src/libvirt_public.syms
> @@ -713,6 +713,8 @@ LIBVIRT_1.2.15 {
> LIBVIRT_1.2.16 {
> global:
> virDomainSetUserPassword;
> + virTypedParamsFilter;
> + virTypedParamsPickStrings;
> } LIBVIRT_1.2.15;
>
> # .... define new API here using predicted next version number ....
> diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
> index e91ca99..d88d4a7 100644
> --- a/src/util/virtypedparam.c
> +++ b/src/util/virtypedparam.c
> @@ -481,6 +481,57 @@ virTypedParamsGet(virTypedParameterPtr params,
> }
>
>
> +/**
> + * virTypedParamsFilter:
> + * @params: array of typed parameters
> + * @nparams: number of parameters in the @params array
> + * @name: name of the parameter to find
> + * @ret: pointer to the returned array
> + *
> + *
> + * Filters @params retaining only the parameters named @name in the
> + * resulting array @ret. Caller should free the @ret array but not
> + * the items since they are pointing to the @params elements.
> + *
> + * Returns amount of elements in @ret on success, -1 on error.
> + */
> +int
> +virTypedParamsFilter(virTypedParameterPtr params,
> + int nparams,
> + const char *name,
> + virTypedParameterPtr **ret)
I don't think we should make this API public. We can use it as an
internal helper for implementing the other public API(s) but I don't see
how this API could be any helpful to libvirt users.
...
> /**
> + * virTypedParamsPickStrings:
> + * @params: array of typed parameters
> + * @nparams: number of parameters in the @params array
> + * @name: name of the parameter to find
> + * @values: array of returned values
> + * @picked: pointer to the amount of picked strings.
> + *
> + * Finds all parameters with desired @name within @params and
> + * store their values into @values. The @values array is self
> + * allocated and its length is stored into @picked. When no
> + * longer needed, caller should free the returned array, but not
> + * the items since they are taken from @params array.
> + *
> + * Returns 0 on success, -1 otherwise.
> + */
> +int
> +virTypedParamsPickStrings(virTypedParameterPtr params,
> + int nparams,
> + const char *name,
> + const char ***values,
> + size_t *picked)
I don't really like the API name. We have several virTypedParamsGet*
APIs including virTypedParamsGetString and I think we should be
consistent when creating this new API and call it
virTypedParamsGetAllStrings or something similar. We could also directly
return the number of strings stored in @values, but having the extra
@picked parameter works too. Although, I'd suggest renaming it.
Jirka
More information about the libvir-list
mailing list