[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date |
Date: |
Fri, 2 Dec 2011 14:20:53 -0600 |
This really shows the power of dynamic object properties compared to qdev
static properties.
This property represents a complex structure who's format is preserved over the
wire. This is enabled by visitors.
It also shows an entirely synthetic property that is not tied to device state.
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/mc146818rtc.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 2aaca2f..0c23cb0 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -614,6 +614,29 @@ static const MemoryRegionOps cmos_ops = {
.old_portio = cmos_portio
};
+// FIXME add int32 visitor
+static void visit_type_int32(Visitor *v, int *value, const char *name, Error
**errp)
+{
+ int64_t val = *value;
+ visit_type_int(v, &val, name, errp);
+}
+
+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);
+}
+
static int rtc_initfn(ISADevice *dev)
{
RTCState *s = DO_UPCAST(RTCState, dev, dev);
@@ -647,6 +670,10 @@ static int rtc_initfn(ISADevice *dev)
qdev_set_legacy_instance_id(&dev->qdev, base, 2);
qemu_register_reset(rtc_reset, s);
+
+ qdev_property_add(&s->dev.qdev, "date", "struct tm",
+ rtc_get_date, NULL, NULL, s, NULL);
+
return 0;
}
--
1.7.4.1
- [Qemu-devel] [PATCH v2 12/18] qdev: add explicitly named devices to the root complex, (continued)
- [Qemu-devel] [PATCH v2 12/18] qdev: add explicitly named devices to the root complex, Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 09/18] qapi: allow a 'gen' key to suppress code generation, Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 14/18] rtc: make piix3 set the rtc as a child (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 16/18] qom: optimize qdev_get_canonical_path using a parent link, Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 18/18] qom: add test tools (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 17/18] qmp: make qmp.py easier to use, Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date,
Anthony Liguori <=
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Kevin Wolf, 2011/12/09
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/12/09
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Kevin Wolf, 2011/12/09
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/12/09
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Kevin Wolf, 2011/12/13
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Gerd Hoffmann, 2011/12/13
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/12/13
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/12/13
- Re: [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date, Kevin Wolf, 2011/12/13
[Qemu-devel] [PATCH v2 11/18] qom: qom_{get, set} monitor commands (v2), Anthony Liguori, 2011/12/02