diff mbox

[13/23] qdev: split out common init to instance_init

Message ID 1327957741-5842-13-git-send-email-aliguori@us.ibm.com
State New
Headers show

Commit Message

Anthony Liguori Jan. 30, 2012, 9:08 p.m. UTC
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 <aliguori@us.ibm.com>
---
 hw/qdev.c |   41 ++++++++++++++++++++++++++++-------------
 1 files changed, 28 insertions(+), 13 deletions(-)
diff mbox

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index a7980c5..491f45e 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -124,31 +124,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;
 }
@@ -1649,6 +1640,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);
@@ -1662,6 +1676,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),
 };