[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 13/22] qdev: split out common init to instance_init
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 13/22] qdev: split out common init to instance_init |
Date: |
Wed, 1 Feb 2012 13:50:54 -0600 |
This gets us closer to being able to object_new() a qdev type and have a
functioning object verses having to call qdev_create().
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/qdev.c | 41 ++++++++++++++++++++++++++++-------------
1 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 5830bef..9933ea2 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -130,31 +130,22 @@ static DeviceState *qdev_create_from_info(BusState *bus,
const char *typename)
Property *prop;
dev = DEVICE(object_new(typename));
+
dev->parent_bus = bus;
- qdev_prop_set_defaults(dev, qdev_get_props(dev));
qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
- qdev_prop_set_globals(dev);
- QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
+
if (qdev_hotplug) {
assert(bus->allow_hotplug);
- dev->hotplugged = 1;
- qdev_hot_added = true;
}
- dev->instance_id_alias = -1;
- QTAILQ_INIT(&dev->properties);
- dev->state = DEV_STATE_CREATED;
- for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
- qdev_property_add_legacy(dev, prop, NULL);
- qdev_property_add_static(dev, prop, NULL);
- }
+ QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
qdev_property_add_legacy(dev, prop, NULL);
qdev_property_add_static(dev, prop, NULL);
}
- qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
+ qdev_prop_set_globals(dev);
return dev;
}
@@ -1647,6 +1638,29 @@ void qdev_machine_init(void)
qdev_get_peripheral();
}
+static void device_initfn(Object *obj)
+{
+ DeviceState *dev = DEVICE(obj);
+ Property *prop;
+
+ if (qdev_hotplug) {
+ dev->hotplugged = 1;
+ qdev_hot_added = true;
+ }
+
+ dev->instance_id_alias = -1;
+ QTAILQ_INIT(&dev->properties);
+ dev->state = DEV_STATE_CREATED;
+
+ qdev_prop_set_defaults(dev, qdev_get_props(dev));
+ for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
+ qdev_property_add_legacy(dev, prop, NULL);
+ qdev_property_add_static(dev, prop, NULL);
+ }
+
+ qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
+}
+
void device_reset(DeviceState *dev)
{
DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -1660,6 +1674,7 @@ static TypeInfo device_type_info = {
.name = TYPE_DEVICE,
.parent = TYPE_OBJECT,
.instance_size = sizeof(DeviceState),
+ .instance_init = device_initfn,
.abstract = true,
.class_size = sizeof(DeviceClass),
};
--
1.7.4.1
- [Qemu-devel] [PATCH 17/22] qom: move properties from qdev to object, (continued)
- [Qemu-devel] [PATCH 17/22] qom: move properties from qdev to object, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 20/22] info qdm: do not require a parent_bus to be set, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 21/22] object: sure up reference counting, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 09/22] qdev: register all types natively through QEMU Object Model, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 22/22] container: make a decendent of Object, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 19/22] qdev: implement cleanup logic in finalize, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 07/22] qom: allow object_class_foreach to take additional parameters to refine search, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 14/22] qdev: refactor away qdev_create_from_info, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 13/22] qdev: split out common init to instance_init,
Anthony Liguori <=
- [Qemu-devel] [PATCH 18/22] qom: accept any compatible type when setting a link property, Anthony Liguori, 2012/02/01
- Re: [Qemu-devel] [PATCH 00/22] qom: use Type system to register all devices (v2), Anthony Liguori, 2012/02/03