[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 23/24] qdev: implement qdev_init on top of realiz
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v2 23/24] qdev: implement qdev_init on top of realize |
Date: |
Wed, 11 Apr 2012 23:30:41 +0200 |
Finally, switch the qdev_init function to simply set the "realized"
property to true. The old contents of qdev_init become the
realize and realize_children methods.
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/qdev.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 38e3831..8641d29 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -119,17 +119,17 @@ DeviceState *qdev_try_create(BusState *bus, const char
*type)
calling this function.
On failure, destroy the device and return negative value.
Return 0 on success. */
-int qdev_init(DeviceState *dev)
+static void device_realize(Object *obj, Error **errp)
{
+ DeviceState *dev = DEVICE(obj);
DeviceClass *dc = DEVICE_GET_CLASS(dev);
int rc;
- assert(!object_is_realized(OBJECT(dev)));
-
rc = dc->init(dev);
if (rc < 0) {
qdev_free(dev);
- return rc;
+ error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
+ return;
}
if (!OBJECT(dev)->parent) {
@@ -146,11 +146,28 @@ int qdev_init(DeviceState *dev)
dev->instance_id_alias,
dev->alias_required_for_version);
}
- OBJECT(dev)->state = OBJECT_STATE_REALIZED;
+}
+
+static void device_realize_children(Object *obj, Error **errp)
+{
+ DeviceState *dev = DEVICE(obj);
+ Error *err = NULL;
+
+ object_realize_children(OBJECT(dev), &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
if (dev->hotplugged) {
device_reset(dev);
}
- return 0;
+}
+
+int qdev_init(DeviceState *dev)
+{
+ Error *err = NULL;
+ object_property_set_bool(OBJECT(dev), true, "realized", &err);
+ return err ? -EINVAL : 0;
}
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
@@ -628,6 +645,12 @@ Object *qdev_get_machine(void)
return dev;
}
+static void device_class_init(ObjectClass *klass, void *data)
+{
+ klass->realize = device_realize;
+ klass->realize_children = device_realize_children;
+}
+
static TypeInfo device_type_info = {
.name = TYPE_DEVICE,
.parent = TYPE_OBJECT,
@@ -636,6 +659,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.9.3
- [Qemu-devel] [PATCH v2 11/24] qdev: clean up global properties, (continued)
- [Qemu-devel] [PATCH v2 11/24] qdev: clean up global properties, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 10/24] qdev: move bus properties to abstract superclasses, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 12/24] qdev: remove qdev_prop_set_defaults, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 13/24] qapi: add Visitor interfaces for uint*_t and int*_t, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 14/24] qdev: use int32_t container for devfn property, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 15/24] qdev: switch property accessors to fixed-width visitor interfaces, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 17/24] qdev: remove qdev_prop_exists, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 16/24] qdev: remove PropertyInfo range checking, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 18/24] qdev: push state up to Object, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 23/24] qdev: implement qdev_init on top of realize,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v2 24/24] qdev: split part of device_finalize to device_unrealize, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 21/24] qom: push static properties to Object, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 20/24] qdev: move bulk of qdev-properties.c to qom/object.c, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 22/24] qom: add realized property, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 19/24] qdev: generalize properties to Objects, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2] qom: Introduce object_realize_nofail(), Andreas Färber, 2012/04/12