qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 04/16] qom: add QObject-based property get/set w


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 04/16] qom: add QObject-based property get/set wrappers
Date: Thu, 02 Feb 2012 13:36:14 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15

On 02/02/2012 01:24 PM, Paolo Bonzini wrote:
On 02/02/2012 08:06 PM, Anthony Liguori wrote:
I don't want object.h to have a dependency on QObject. We need to phase
out QObject.

The header doesn't.

Couple things:

1) We shouldn't use generic interfaces to read/write properties from
objects. We should use type-safe accessors provided by the types
themselves.

2) If we want to get fancy, we can add property_set_int, etc. and then
implement (1) via header files that just call these functions.

That's what patch 5 does. But writing visitors in C is a royal PITA. The only
sane way to do so is via QObject.

You just need a variant visitor.  It's pretty simple to do, essentially:

typedef struct VariantVisitor
{
    Visitor parent;
    enum { VV_INT, VV_STR } kind;
    union { int64_t v_int; char *v_str };
} VariantVisitor;

/* input */
static void visit_int(...)
{
   v->kind = TYPE_INT;
   v->v_int = *value;
}

/* output */
static void visit_int(...)
{
   assert(v->kind == TYPE_INT);
   *value = v->v_int;
}

void variant_visitor_set_int(VariantVisitor *v, int64_t value)
{
   v->kind = TYPE_INT;
   v->v_int = value;
}

The only types that matter are int and string so the variant visitor is pretty simple.

Regards,

Anthony Liguori


Paolo






reply via email to

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