[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 33/37] qdev: QDEV_PROP_FOREACH and QDEV_CLASS_FOREAC
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 33/37] qdev: QDEV_PROP_FOREACH and QDEV_CLASS_FOREACH |
Date: |
Mon, 22 Oct 2012 17:03:19 +0200 |
helpers to iterate over device static properties to allow to simplify
code a little.
Signed-off-by: Igor Mammedov <address@hidden>
---
hw/qdev-properties.h | 9 +++++++++
qom/qdev-core.c | 10 ++++------
qom/qdev-properties.c | 29 +++++++----------------------
3 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/hw/qdev-properties.h b/hw/qdev-properties.h
index 41358fa..19b55c0 100644
--- a/hw/qdev-properties.h
+++ b/hw/qdev-properties.h
@@ -135,4 +135,13 @@ void qdev_property_add_static(DeviceState *dev, Property
*prop, Error **errp);
const Property *qdev_prop_find(const DeviceClass *dc, const char *name);
+#define QDEV_PROP_FOREACH(_var, _class) \
+ for ((_var) = DEVICE_CLASS((_class))->props; \
+ (_var) && (_var)->name; \
+ (_var)++)
+
+#define QDEV_CLASS_FOREACH(_var, _class) \
+ for ((_var) = (_class); \
+ (_var) != DEVICE_CLASS(object_class_by_name(TYPE_DEVICE)); \
+ (_var) = DEVICE_CLASS(object_class_get_parent(OBJECT_CLASS((_var)))))
#endif
diff --git a/qom/qdev-core.c b/qom/qdev-core.c
index fbb7cb5..a062dbb 100644
--- a/qom/qdev-core.c
+++ b/qom/qdev-core.c
@@ -592,7 +592,7 @@ void qdev_property_add_static(DeviceState *dev, Property
*prop,
static void device_initfn(Object *obj)
{
DeviceState *dev = DEVICE(obj);
- ObjectClass *class;
+ DeviceClass *dc = DEVICE_CLASS(object_get_class(OBJECT(dev)));
Property *prop;
if (qdev_hotplug) {
@@ -603,14 +603,12 @@ static void device_initfn(Object *obj)
dev->instance_id_alias = -1;
dev->state = DEV_STATE_CREATED;
- class = object_get_class(OBJECT(dev));
- do {
- for (prop = DEVICE_CLASS(class)->props; prop && prop->name; prop++) {
+ QDEV_CLASS_FOREACH(dc, dc) {
+ QDEV_PROP_FOREACH(prop, dc) {
qdev_property_add_legacy(dev, prop, NULL);
qdev_property_add_static(dev, prop, NULL);
}
- class = object_class_get_parent(class);
- } while (class != object_class_by_name(TYPE_DEVICE));
+ }
qdev_prop_set_globals(dev);
object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS,
diff --git a/qom/qdev-properties.c b/qom/qdev-properties.c
index cc37479..3d3eefa 100644
--- a/qom/qdev-properties.c
+++ b/qom/qdev-properties.c
@@ -772,33 +772,18 @@ PropertyInfo qdev_prop_pci_host_devaddr = {
/* --- public helpers --- */
-static Property *qdev_prop_walk(Property *props, const char *name)
-{
- if (!props)
- return NULL;
- while (props->name) {
- if (strcmp(props->name, name) == 0)
- return props;
- props++;
- }
- return NULL;
-}
-
const Property *qdev_prop_find(const DeviceClass *dc, const char *name)
{
- ObjectClass *class;
- Property *prop;
+ const Property *prop;
/* device properties */
- class = OBJECT_CLASS(dc);
- do {
- prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name);
- if (prop) {
- return prop;
+ QDEV_CLASS_FOREACH(dc, dc) {
+ QDEV_PROP_FOREACH(prop, dc) {
+ if (strcmp(prop->name, name) == 0) {
+ return prop;
+ }
}
- class = object_class_get_parent(class);
- } while (class != object_class_by_name(TYPE_DEVICE));
-
+ }
return NULL;
}
--
1.7.11.7
- [Qemu-devel] [PATCH 29/37] target-i386: convert "stepping" to static property, (continued)
- [Qemu-devel] [PATCH 29/37] target-i386: convert "stepping" to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 12/37] target-i386: convert "xlevel" to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 17/37] target-i386: make 'f-kvmclock' compatible with legacy behaviour, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 31/37] target-i386: convert "family" to static property, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 18/37] target-i386: add stubs for hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)(), Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 35/37] target-i386: use static properties in check_features_against_host() to print CPUID feature names, Igor Mammedov, 2012/10/22
- [Qemu-devel] [PATCH 33/37] qdev: QDEV_PROP_FOREACH and QDEV_CLASS_FOREACH,
Igor Mammedov <=
- [Qemu-devel] [PATCH 16/37] target-i386: set kvm CPUID default feature values using static properties, Igor Mammedov, 2012/10/22
Re: [Qemu-devel] [PATCH 00/37 v5] target-i386: convert CPU features into properties, Don Slutz, 2012/10/23