[Qemu-devel] [PATCH RFC 3/3] qdev: Hook up DeviceClass::init to ObjectClass::realize
On realize, call the qdev init function. If that returns an error, raise QERR_DEVICE_INIT_FAILED. Signed-off-by: Andreas Färber afaer...@suse.de Cc: Anthony Liguori anth...@codemonkey.ws Cc: Paolo Bonzini pbonz...@redhat.com --- hw/qdev.c | 13 + 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index ee21d90..c84b656 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -649,6 +649,13 @@ static void device_finalize(Object *obj) QTAILQ_REMOVE(dev-parent_bus-children, dev, sibling); } +static int device_realize(Object *obj) +{ +DeviceState *dev = DEVICE(obj); + +return qdev_init(dev); +} + void device_reset(DeviceState *dev) { DeviceClass *klass = DEVICE_GET_CLASS(dev); @@ -658,6 +665,11 @@ void device_reset(DeviceState *dev) } } +static void device_class_init(ObjectClass *class, void *data) +{ +class-realize = device_realize; +} + static TypeInfo device_type_info = { .name = TYPE_DEVICE, .parent = TYPE_OBJECT, @@ -666,6 +678,7 @@ static TypeInfo device_type_info = { .instance_finalize = device_finalize, .abstract = true, .class_size = sizeof(DeviceClass), +.class_init = device_class_init, }; static void qdev_register_types(void) -- 1.7.7
Re: [Qemu-devel] [PATCH RFC 3/3] qdev: Hook up DeviceClass::init to ObjectClass::realize
Am 26.03.2012 15:46, schrieb Andreas Färber: On realize, call the qdev init function. If that returns an error, raise QERR_DEVICE_INIT_FAILED. Sorry, that sentence is outdated - the error is set in qom/object.c (patch 1/3) for non-zero return values. It is merely being passed through here. Andreas Signed-off-by: Andreas Färber afaer...@suse.de Cc: Anthony Liguori anth...@codemonkey.ws Cc: Paolo Bonzini pbonz...@redhat.com --- hw/qdev.c | 13 + 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index ee21d90..c84b656 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -649,6 +649,13 @@ static void device_finalize(Object *obj) QTAILQ_REMOVE(dev-parent_bus-children, dev, sibling); } +static int device_realize(Object *obj) +{ +DeviceState *dev = DEVICE(obj); + +return qdev_init(dev); +} + void device_reset(DeviceState *dev) { DeviceClass *klass = DEVICE_GET_CLASS(dev); [snip] -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg