ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) { Object *obj; bool ambiguous = false; ObjectPropertyInfoList *props = NULL; ObjectProperty *prop; ObjectPropertyIterator *iter; obj = object_resolve_path(path, &ambiguous); if (obj == NULL) { if (ambiguous) { error_setg(errp, "Path '%s' is ambiguous", path); } else { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", path); } return NULL; } iter = object_property_iter_init(obj); while ((prop = object_property_iter_next(iter))) { ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); entry->next = props; props = entry; entry->value->name = g_strdup(prop->name); entry->value->type = g_strdup(prop->type); } object_property_iter_free(iter); return props; }
static void test_dummy_prop_iterator(ObjectPropertyIterator *iter) { bool seenbv = false, seensv = false, seenav = false, seentype = false; ObjectProperty *prop; while ((prop = object_property_iter_next(iter))) { if (!seenbv && g_str_equal(prop->name, "bv")) { seenbv = true; } else if (!seensv && g_str_equal(prop->name, "sv")) { seensv = true; } else if (!seenav && g_str_equal(prop->name, "av")) { seenav = true; } else if (!seentype && g_str_equal(prop->name, "type")) { /* This prop comes from the base Object class */ seentype = true; } else { g_printerr("Found prop '%s'\n", prop->name); g_assert_not_reached(); } } g_assert(seenbv); g_assert(seenav); g_assert(seensv); g_assert(seentype); }
static void test_dummy_iterator(void) { Object *parent = object_get_objects_root(); DummyObject *dobj = DUMMY_OBJECT( object_new_with_props(TYPE_DUMMY, parent, "dummy0", &error_abort, "bv", "yes", "sv", "Hiss hiss hiss", "av", "platypus", NULL)); ObjectProperty *prop; ObjectPropertyIterator *iter; bool seenbv = false, seensv = false, seenav = false, seentype; iter = object_property_iter_init(OBJECT(dobj)); while ((prop = object_property_iter_next(iter))) { if (g_str_equal(prop->name, "bv")) { seenbv = true; } else if (g_str_equal(prop->name, "sv")) { seensv = true; } else if (g_str_equal(prop->name, "av")) { seenav = true; } else if (g_str_equal(prop->name, "type")) { /* This prop comes from the base Object class */ seentype = true; } else { g_printerr("Found prop '%s'\n", prop->name); g_assert_not_reached(); } } object_property_iter_free(iter); g_assert(seenbv); g_assert(seenav); g_assert(seensv); g_assert(seentype); object_unparent(OBJECT(dobj)); }
/** * spapr_drc_populate_dt * * @fdt: libfdt device tree * @path: path in the DT to generate properties * @owner: parent Object/DeviceState for which to generate DRC * descriptions for * @drc_type_mask: mask of sPAPRDRConnectorType values corresponding * to the types of DRCs to generate entries for * * generate OF properties to describe DRC topology/indices to guests * * as documented in PAPR+ v2.1, 13.5.2 */ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, uint32_t drc_type_mask) { Object *root_container; ObjectProperty *prop; ObjectPropertyIterator *iter; uint32_t drc_count = 0; GArray *drc_indexes, *drc_power_domains; GString *drc_names, *drc_types; int ret; /* the first entry of each properties is a 32-bit integer encoding * the number of elements in the array. we won't know this until * we complete the iteration through all the matching DRCs, but * reserve the space now and set the offsets accordingly so we * can fill them in later. */ drc_indexes = g_array_new(false, true, sizeof(uint32_t)); drc_indexes = g_array_set_size(drc_indexes, 1); drc_power_domains = g_array_new(false, true, sizeof(uint32_t)); drc_power_domains = g_array_set_size(drc_power_domains, 1); drc_names = g_string_set_size(g_string_new(NULL), sizeof(uint32_t)); drc_types = g_string_set_size(g_string_new(NULL), sizeof(uint32_t)); /* aliases for all DRConnector objects will be rooted in QOM * composition tree at DRC_CONTAINER_PATH */ root_container = container_get(object_get_root(), DRC_CONTAINER_PATH); iter = object_property_iter_init(root_container); while ((prop = object_property_iter_next(iter))) { Object *obj; sPAPRDRConnector *drc; sPAPRDRConnectorClass *drck; uint32_t drc_index, drc_power_domain; if (!strstart(prop->type, "link<", NULL)) { continue; } obj = object_property_get_link(root_container, prop->name, NULL); drc = SPAPR_DR_CONNECTOR(obj); drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); if (owner && (drc->owner != owner)) { continue; } if ((drc->type & drc_type_mask) == 0) { continue; } drc_count++; /* ibm,drc-indexes */ drc_index = cpu_to_be32(drck->get_index(drc)); g_array_append_val(drc_indexes, drc_index); /* ibm,drc-power-domains */ drc_power_domain = cpu_to_be32(-1); g_array_append_val(drc_power_domains, drc_power_domain); /* ibm,drc-names */ drc_names = g_string_append(drc_names, drck->get_name(drc)); drc_names = g_string_insert_len(drc_names, -1, "\0", 1); /* ibm,drc-types */ drc_types = g_string_append(drc_types, spapr_drc_get_type_str(drc->type)); drc_types = g_string_insert_len(drc_types, -1, "\0", 1); } object_property_iter_free(iter); /* now write the drc count into the space we reserved at the * beginning of the arrays previously */ *(uint32_t *)drc_indexes->data = cpu_to_be32(drc_count); *(uint32_t *)drc_power_domains->data = cpu_to_be32(drc_count); *(uint32_t *)drc_names->str = cpu_to_be32(drc_count); *(uint32_t *)drc_types->str = cpu_to_be32(drc_count); ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-indexes", drc_indexes->data, drc_indexes->len * sizeof(uint32_t)); if (ret) { fprintf(stderr, "Couldn't create ibm,drc-indexes property\n"); goto out; } ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-power-domains", drc_power_domains->data, drc_power_domains->len * sizeof(uint32_t)); if (ret) { fprintf(stderr, "Couldn't finalize ibm,drc-power-domains property\n"); goto out; } ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-names", drc_names->str, drc_names->len); if (ret) { fprintf(stderr, "Couldn't finalize ibm,drc-names property\n"); goto out; } ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-types", drc_types->str, drc_types->len); if (ret) { fprintf(stderr, "Couldn't finalize ibm,drc-types property\n"); goto out; } out: g_array_free(drc_indexes, true); g_array_free(drc_power_domains, true); g_string_free(drc_names, true); g_string_free(drc_types, true); return ret; }