Jelajahi Sumber

qmp: Convert QMP code to use object property iterators

Stop directly accessing the Object::properties field data
structure and instead use the formal object property iterator
APIs. This insulates the code from future data structure
changes in the Object struct.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Tested-by: Pavel Fedin <p.fedin@samsung.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Daniel P. Berrange 10 tahun lalu
induk
melakukan
1b30c094dc
1 mengubah file dengan 8 tambahan dan 2 penghapusan
  1. 8 2
      qmp.c

+ 8 - 2
qmp.c

@@ -210,6 +210,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
     bool ambiguous = false;
     bool ambiguous = false;
     ObjectPropertyInfoList *props = NULL;
     ObjectPropertyInfoList *props = NULL;
     ObjectProperty *prop;
     ObjectProperty *prop;
+    ObjectPropertyIterator *iter;
 
 
     obj = object_resolve_path(path, &ambiguous);
     obj = object_resolve_path(path, &ambiguous);
     if (obj == NULL) {
     if (obj == NULL) {
@@ -222,7 +223,8 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
         return NULL;
         return NULL;
     }
     }
 
 
-    QTAILQ_FOREACH(prop, &obj->properties, node) {
+    iter = object_property_iter_init(obj);
+    while ((prop = object_property_iter_next(iter))) {
         ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
         ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
 
 
         entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
         entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
@@ -232,6 +234,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
         entry->value->name = g_strdup(prop->name);
         entry->value->name = g_strdup(prop->name);
         entry->value->type = g_strdup(prop->type);
         entry->value->type = g_strdup(prop->type);
     }
     }
+    object_property_iter_free(iter);
 
 
     return props;
     return props;
 }
 }
@@ -503,6 +506,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
     ObjectClass *klass;
     ObjectClass *klass;
     Object *obj;
     Object *obj;
     ObjectProperty *prop;
     ObjectProperty *prop;
+    ObjectPropertyIterator *iter;
     DevicePropertyInfoList *prop_list = NULL;
     DevicePropertyInfoList *prop_list = NULL;
 
 
     klass = object_class_by_name(typename);
     klass = object_class_by_name(typename);
@@ -531,7 +535,8 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
 
 
     obj = object_new(typename);
     obj = object_new(typename);
 
 
-    QTAILQ_FOREACH(prop, &obj->properties, node) {
+    iter = object_property_iter_init(obj);
+    while ((prop = object_property_iter_next(iter))) {
         DevicePropertyInfo *info;
         DevicePropertyInfo *info;
         DevicePropertyInfoList *entry;
         DevicePropertyInfoList *entry;
 
 
@@ -562,6 +567,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
         entry->next = prop_list;
         entry->next = prop_list;
         prop_list = entry;
         prop_list = entry;
     }
     }
+    object_property_iter_free(iter);
 
 
     object_unref(obj);
     object_unref(obj);