diff --git a/qemu/include/qom/object.h b/qemu/include/qom/object.h index bc48cce6..18074cfa 100644 --- a/qemu/include/qom/object.h +++ b/qemu/include/qom/object.h @@ -85,6 +85,28 @@ struct uc_struct; * #TypeInfo describes information about the type including what it inherits * from, the instance and class size, and constructor/destructor hooks. * + * Alternatively several static types could be registered using helper macro + * DEFINE_TYPES() + * + * + * + * static const TypeInfo device_types_info[] = { + * { + * .name = TYPE_MY_DEVICE_A, + * .parent = TYPE_DEVICE, + * .instance_size = sizeof(MyDeviceA), + * }, + * { + * .name = TYPE_MY_DEVICE_B, + * .parent = TYPE_DEVICE, + * .instance_size = sizeof(MyDeviceB), + * }, + * }; + * + * DEFINE_TYPES(device_types_info) + * + * + * * Every type has an #ObjectClass associated with it. #ObjectClass derivatives * are instantiated dynamically but there is only ever one instance for any * given type. The #ObjectClass typically holds a table of function pointers @@ -685,6 +707,20 @@ Type type_register(struct uc_struct *uc, const TypeInfo *info); */ void type_register_static_array(struct uc_struct *uc, const TypeInfo *infos, int nr_infos); +/** + * DEFINE_TYPES: + * @type_array: The array containing #TypeInfo structures to register + * + * @type_array should be static constant that exists for the life time + * that the type is registered. + */ +#define DEFINE_TYPES(type_array) \ +static void do_qemu_init_ ## type_array(struct uc_struct *uc) \ +{ \ + type_register_static_array(uc, type_array, ARRAY_SIZE(type_array)); \ +} \ +type_init(do_qemu_init_ ## type_array) + /** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast.