qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 17/41] char: get rid of CharDriver


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2 17/41] char: get rid of CharDriver
Date: Mon, 30 Jan 2017 13:50:28 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0

On 01/30/2017 07:39 AM, Marc-André Lureau wrote:
> qemu_chr_new_from_opts() is modified to not need CharDriver backend[]
> array, but uses instead objectified qmp_query_chardev_backends() and
> char_get_class(). The alias field is moved outside in a ChardevAlias[],
> similar to QDevAlias for devices.
> 
> "kind" and "parse" are moved to ChardevClass ("kind" is to be removed
> next)
> 
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
>  include/sysemu/char.h |  12 +-
>  backends/baum.c       |   6 +-
>  backends/msmouse.c    |   6 +-
>  backends/testdev.c    |   6 +-
>  qemu-char.c           | 315 
> +++++++++++++++++++++++---------------------------
>  spice-qemu-char.c     |  15 +--
>  ui/console.c          |  10 +-
>  ui/gtk.c              |  10 +-
>  8 files changed, 159 insertions(+), 221 deletions(-)
> 

> +static void
> +chardev_name_foreach(void (*fn)(const char *name, void *opaque), void 
> *opaque)
> +{
> +    ChadevClassFE fe = { .fn = fn, .opaque = opaque };
> +    int i;
> +
> +    object_class_foreach(chardev_class_foreach, TYPE_CHARDEV, false, &fe);
> +
> +    for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
> +        fn(chardev_alias_table[i].alias, opaque);
> +    }

This now visits all aliases last,...

> @@ -4182,15 +4237,8 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
>  
>      if (is_help_option(name)) {
>          GString *str = g_string_new("");
> -        for (i = 0; i < ARRAY_SIZE(backends); i++) {
> -            cd = backends[i];
> -            if (cd) {
> -                g_string_append_printf(str, "\n%s", 
> ChardevBackendKind_lookup[cd->kind]);
> -                if (cd->alias) {
> -                    g_string_append_printf(str, "\n%s", cd->alias);
> -                }
> -            }
> -        }

...while the old code visited them inline.  But that's cosmetic; I don't
think it hurts.

> +
> +        chardev_name_foreach(help_string_append, str);

>  
>  ChardevBackendInfoList *qmp_query_chardev_backends(Error **errp)
>  {
>      ChardevBackendInfoList *backend_list = NULL;
> -    const CharDriver *c;
> -    int i;
>  
> -    for (i = 0; i < ARRAY_SIZE(backends); i++) {
> -        c = backends[i];
> -        if (!c) {
> -            continue;
> -        }
> -
> -        backend_list = qmp_prepend_backend(backend_list,
> -                                           
> ChardevBackendKind_lookup[c->kind]);
> -        if (c->alias) {
> -            backend_list = qmp_prepend_backend(backend_list, c->alias);
> -        }
> -    }
> +    chardev_name_foreach(qmp_prepend_backend, &backend_list);

And the refactoring into visitor/callback made for some nice reuse.

Reviewed-by: Eric Blake <address@hidden>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]