[Top][All Lists]

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

Re: [Qemu-devel] [PATCH 14/18] rtc: add a dynamic property for retrievin

From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 14/18] rtc: add a dynamic property for retrieving the date
Date: Thu, 01 Dec 2011 19:19:21 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13

On 12/01/2011 09:46 AM, Gerd Hoffmann wrote:

+static void rtc_get_date(DeviceState *dev, Visitor *v, void *opaque,
+                         const char *name, Error **errp)
+    ISADevice *isa = DO_UPCAST(ISADevice, qdev, dev);
+    RTCState *s = DO_UPCAST(RTCState, dev, isa);
+    visit_start_struct(v, NULL, "struct tm", name, 0, errp);
+    visit_type_int32(v,&s->current_tm.tm_year, "tm_year", errp);
+    visit_type_int32(v,&s->current_tm.tm_mon, "tm_mon", errp);
+    visit_type_int32(v,&s->current_tm.tm_mday, "tm_mday", errp);
+    visit_type_int32(v,&s->current_tm.tm_hour, "tm_hour", errp);
+    visit_type_int32(v,&s->current_tm.tm_min, "tm_min", errp);
+    visit_type_int32(v,&s->current_tm.tm_sec, "tm_sec", errp);
+    visit_end_struct(v, errp);

Ok, what is the long term plan here?  I don't think we want open-code
everything here, do we?  Especially once visitors become more widespread
used.  And I can see that they are useful for a bunch of stuff beside
device properties and relationships.  vmstate for example.  Or to list
device state (say a register dump) for debugging purposes.

Today we have code to generate structs and visitors from scratch.
I think it would be useful to also generate visitors for existing
structs, with some kind of annotation, like this ...

struct SomeDev {
       DeviceState dev;
       Chardev     *chr;
       uint32_t    reg1   __v(vmstate);
       uint32_t    reg2   __v(vmstate);
       [ ... ]


In your example:

struct SomeDev {
       DeviceState _immutable dev;
       Chardev _immutable     *chr;
       uint32_t               reg1;
       uint32_t               reg2;
       [ ... ]

... instead of the vmstate structs we create manually today.  Likewise
for properties.  And probably we can even generate different visitors
for different "views" at the same struct.

qc generates a json description of the struct. You can then use a generate to take that json and generate code for VMState, QAPI, etc.

The readme has quite a lot of detail about the syntax. The parser is pretty complete already.


But I want to get us moving on QOM first before I go any further with this. We can always go back and remove the manually written visit functions.


Anthony Liguori


reply via email to

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