]> xenbits.xensource.com Git - qemu-xen-4.2-testing.git/commitdiff
qdev: add a qdev_get_type() function and expose as a 'type' property
authorAnthony Liguori <aliguori@us.ibm.com>
Mon, 12 Dec 2011 20:29:43 +0000 (14:29 -0600)
committerAnthony Liguori <aliguori@us.ibm.com>
Thu, 15 Dec 2011 15:20:49 +0000 (09:20 -0600)
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/qdev.c
hw/qdev.h

index 0fc20fc6a8e82e5a1b42f4309c35e5fe91071b26..83913c72f21198199316aa73af7441c1a3ee26eb 100644 (file)
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -110,6 +110,8 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
         qdev_property_add_legacy(dev, prop, NULL);
     }
 
+    qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
+
     return dev;
 }
 
@@ -1031,6 +1033,11 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
     return strdup(path);
 }
 
+char *qdev_get_type(DeviceState *dev, Error **errp)
+{
+    return g_strdup(dev->info->name);
+}
+
 void qdev_ref(DeviceState *dev)
 {
     dev->ref++;
index 9faf2ee18b5a2e2207fcd9327dc5588fa4acadaa..6e184278f4e993fae4cb36bc6bcbd90ff682d14d 100644 (file)
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -596,4 +596,18 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
                            void (*set)(DeviceState *, const char *, Error **),
                            Error **errp);
 
+/**
+ * @qdev_get_type
+ *
+ * Returns the string representation of the type of this object.
+ *
+ * @dev - the device
+ *
+ * @errp - if an error occurs, a pointer to an area to store the error
+ *
+ * Returns: a string representing the type.  This must be freed by the caller
+ *          with g_free().
+ */
+char *qdev_get_type(DeviceState *dev, Error **errp);
+
 #endif