On Tue, Mar 11, 2025 at 07:59:31PM +0400, marcandre.lur...@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lur...@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com>
> ---
>  ui/vdagent.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 139 insertions(+)
> 
> diff --git a/ui/vdagent.c b/ui/vdagent.c
> index 125c659af7..cc5738a6ea 100644
> --- a/ui/vdagent.c
> +++ b/ui/vdagent.c
> @@ -10,6 +10,7 @@
>  #include "ui/clipboard.h"
>  #include "ui/console.h"
>  #include "ui/input.h"
> +#include "migration/vmstate.h"
>  #include "trace.h"


> +static int put_cbinfo(QEMUFile *f, void *pv, size_t size,
> +                      const VMStateField *field, JSONWriter *vmdesc)
> +{
> +    VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(pv);
> +    struct CBInfoArray cbinfo = { 0, };

Just ' = {}' should be sufficient to initialize all fields.

> +    int i;
> +
> +    if (!have_clipboard(vd)) {
> +        return 0;
> +    }
> +
> +    for (i = 0; i < QEMU_CLIPBOARD_SELECTION__COUNT; i++) {
> +        if (qemu_clipboard_peer_owns(&vd->cbpeer, i)) {
> +             cbinfo.cbinfo[cbinfo.n++] = *qemu_clipboard_info(i);
> +        }
> +    }
> +
> +    return vmstate_save_state(f, &vmstate_cbinfo_array, &cbinfo, vmdesc);
> +}
> +
> +static int get_cbinfo(QEMUFile *f, void *pv, size_t size,
> +                      const VMStateField *field)
> +{
> +    VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(pv);
> +    struct CBInfoArray cbinfo = { 0, };

Likewise.

> +    int i, ret;
> +
> +    if (!have_clipboard(vd)) {
> +        return 0;
> +    }
> +
> +    vdagent_clipboard_peer_register(vd);
> +
> +    ret = vmstate_load_state(f, &vmstate_cbinfo_array, &cbinfo, 0);
> +    if (ret) {
> +        return ret;
> +    }
> +
> +    for (i = 0; i < cbinfo.n; i++) {
> +        g_autoptr(QemuClipboardInfo) info = 
> qemu_clipboard_info_new(&vd->cbpeer, cbinfo.cbinfo[i].selection);
> +        /* this will steal clipboard data pointer from cbinfo.types */
> +        memcpy(info->types, cbinfo.cbinfo[i].types, 
> sizeof(cbinfo.cbinfo[i].types));
> +        qemu_clipboard_update(info);
> +    }
> +
> +    return 0;
> +}


Reviewed-by: Daniel P. Berrangé <berra...@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Reply via email to