All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, mreitz@redhat.com
Subject: Re: [PATCH v2 2/4] qom: Factor out helpers from user_creatable_print_help()
Date: Fri, 02 Oct 2020 14:13:59 +0200	[thread overview]
Message-ID: <87d020kepk.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20200930124557.51835-3-kwolf@redhat.com> (Kevin Wolf's message of "Wed, 30 Sep 2020 14:45:55 +0200")

Kevin Wolf <kwolf@redhat.com> writes:

> This creates separate helper functions for printing a list of user
> creatable object types and for printing a list of properties of a given
> type. This allows using these parts without having a QemuOpts.

Does the last sentence allude to a future patch?  If yes, I suggest to
phrase it as "This will allow ..."

> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  qom/object_interfaces.c | 90 ++++++++++++++++++++++++-----------------
>  1 file changed, 52 insertions(+), 38 deletions(-)
>
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index e8e1523960..3fd1da157e 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -214,54 +214,68 @@ char *object_property_help(const char *name, const char *type,
>      return g_string_free(str, false);
>  }
>  
> -bool user_creatable_print_help(const char *type, QemuOpts *opts)
> +static void user_creatable_print_types(void)
> +{
> +    GSList *l, *list;
> +
> +    printf("List of user creatable objects:\n");
> +    list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
> +    for (l = list; l != NULL; l = l->next) {
> +        ObjectClass *oc = OBJECT_CLASS(l->data);
> +        printf("  %s\n", object_class_get_name(oc));
> +    }
> +    g_slist_free(list);
> +}
> +
> +static bool user_creatable_print_type_properites(const char *type)
>  {
>      ObjectClass *klass;
> +    ObjectPropertyIterator iter;
> +    ObjectProperty *prop;
> +    GPtrArray *array;
> +    int i;
>  
> -    if (is_help_option(type)) {
> -        GSList *l, *list;
> +    klass = object_class_by_name(type);
> +    if (!klass) {
> +        return false;
> +    }
>  
> -        printf("List of user creatable objects:\n");
> -        list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
> -        for (l = list; l != NULL; l = l->next) {
> -            ObjectClass *oc = OBJECT_CLASS(l->data);
> -            printf("  %s\n", object_class_get_name(oc));
> +    array = g_ptr_array_new();
> +    object_class_property_iter_init(&iter, klass);
> +    while ((prop = object_property_iter_next(&iter))) {
> +        if (!prop->set) {
> +            continue;
>          }
> -        g_slist_free(list);
> -        return true;
> +
> +        g_ptr_array_add(array,
> +                        object_property_help(prop->name, prop->type,
> +                                             prop->defval, prop->description));
>      }
> +    g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
> +    if (array->len > 0) {
> +        printf("%s options:\n", type);
> +    } else {
> +        printf("There are no options for %s.\n", type);
> +    }
> +    for (i = 0; i < array->len; i++) {
> +        printf("%s\n", (char *)array->pdata[i]);
> +    }
> +    g_ptr_array_set_free_func(array, g_free);
> +    g_ptr_array_free(array, true);
> +    return true;
> +}
>  
> -    klass = object_class_by_name(type);
> -    if (klass && qemu_opt_has_help_opt(opts)) {
> -        ObjectPropertyIterator iter;
> -        ObjectProperty *prop;
> -        GPtrArray *array = g_ptr_array_new();
> -        int i;
> -
> -        object_class_property_iter_init(&iter, klass);
> -        while ((prop = object_property_iter_next(&iter))) {
> -            if (!prop->set) {
> -                continue;
> -            }
> -
> -            g_ptr_array_add(array,
> -                            object_property_help(prop->name, prop->type,
> -                                                 prop->defval, prop->description));
> -        }
> -        g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
> -        if (array->len > 0) {
> -            printf("%s options:\n", type);
> -        } else {
> -            printf("There are no options for %s.\n", type);
> -        }
> -        for (i = 0; i < array->len; i++) {
> -            printf("%s\n", (char *)array->pdata[i]);
> -        }
> -        g_ptr_array_set_free_func(array, g_free);
> -        g_ptr_array_free(array, true);
> +bool user_creatable_print_help(const char *type, QemuOpts *opts)
> +{
> +    if (is_help_option(type)) {
> +        user_creatable_print_types();
>          return true;
>      }
>  
> +    if (qemu_opt_has_help_opt(opts)) {
> +        return user_creatable_print_type_properites(type);
> +    }
> +
>      return false;
>  }

I'd make user_creatable_print_types() return true for summetry with
user_creatable_print_type_properites(), but that's a matter of taste.

Reviewed-by: Markus Armbruster <armbru@redhat.com>



  parent reply	other threads:[~2020-10-02 12:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30 12:45 [PATCH v2 0/4] qemu-storage-daemon: Remove QemuOpts from --object parser Kevin Wolf
2020-09-30 12:45 ` [PATCH v2 1/4] keyval: Parse help options Kevin Wolf
2020-09-30 13:35   ` Eric Blake
2020-09-30 15:10     ` Kevin Wolf
2020-10-01 10:34       ` Markus Armbruster
2020-10-01 11:33         ` Kevin Wolf
2020-10-01 15:46   ` Markus Armbruster
2020-10-05 12:08     ` Markus Armbruster
2020-09-30 12:45 ` [PATCH v2 2/4] qom: Factor out helpers from user_creatable_print_help() Kevin Wolf
2020-09-30 13:46   ` Eric Blake
2020-10-02 12:13   ` Markus Armbruster [this message]
2020-09-30 12:45 ` [PATCH v2 3/4] qom: Add user_creatable_print_help_from_qdict() Kevin Wolf
2020-09-30 13:48   ` Eric Blake
2020-10-02 12:25   ` Markus Armbruster
2020-10-02 12:36     ` Markus Armbruster
2020-09-30 12:45 ` [PATCH v2 4/4] qemu-storage-daemon: Remove QemuOpts from --object parser Kevin Wolf
2020-09-30 13:49   ` Eric Blake
2020-10-02 12:26   ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d020kepk.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.