[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/18] rtc: add a dynamic property for retrieving th
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 14/18] rtc: add a dynamic property for retrieving the date |
Date: |
Wed, 30 Nov 2011 15:03:44 -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 08/18] qapi: allow a 'gen' key to suppress code generation, (continued)
- [Qemu-devel] [PATCH 08/18] qapi: allow a 'gen' key to suppress code generation, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 10/18] qom: qom_{get,set} monitor commands, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 11/18] qdev: add explicitly named devices to the root complex, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 17/18] Add test tools, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 16/18] Make qmp.py easier to use, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 18/18] qdev: split out QOM functions to separate files, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 13/18] rtc: make piix3 set the rtc as a child, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 09/18] qmp: add qom-list command, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 15/18] qom: optimize qdev_get_canonical_path using a parent link, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 12/18] dev: add an anonymous peripheral container, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 14/18] rtc: add a dynamic property for retrieving the date,
Anthony Liguori <=
- Re: [Qemu-devel] [PATCH 00/18] qom: dynamic properties and composition tree, Anthony Liguori, 2011/11/30