qemu/include/qapi/forward-visitor.h
Paolo Bonzini 18fa3ebc45 qapi: introduce forwarding visitor
This new adaptor visitor takes a single field of the adaptee, and exposes it
with a different name.

This will be used for QOM alias properties.  Alias targets can of course
have a different name than the alias property itself (e.g. a machine's
pflash0 might be an alias of a property named 'drive').  When the target's
getter or setter invokes the visitor, it will use a different name than
what the caller expects, and the visitor will not be able to find it
(or will consume erroneously).

The solution is for alias getters and setters to wrap the incoming
visitor, and forward the sole field that the target is expecting while
renaming it appropriately.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-07-23 18:17:17 +02:00

28 lines
718 B
C

/*
* Forwarding visitor
*
* Copyright Red Hat, Inc. 2021
*
* Author: Paolo Bonzini <pbonzini@redhat.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
#ifndef FORWARD_VISITOR_H
#define FORWARD_VISITOR_H
#include "qapi/visitor.h"
typedef struct ForwardFieldVisitor ForwardFieldVisitor;
/*
* The forwarding visitor only expects a single name, @from, to be passed for
* toplevel fields. It is converted to @to and forwarded to the @target visitor.
* Calls within a struct are forwarded without changing the name.
*/
Visitor *visitor_forward_field(Visitor *target, const char *from, const char *to);
#endif