qom: Allow class type name to be specified in OBJECT_DECLARE*

Many QOM types don't follow the Type/TypeClass pattern
on the instance/struct names.  Let the class struct name
be specified in the OBJECT_DECLARE* macros.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20200831210740.126168-4-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
Eduardo Habkost 2020-08-31 17:07:25 -04:00
parent f84203a8c2
commit 4a5f0545d2

View file

@ -555,7 +555,8 @@ struct Object
/** /**
* OBJECT_DECLARE_TYPE: * OBJECT_DECLARE_TYPE:
* @ModuleObjName: the object name with initial capitalization * @InstanceType: instance struct name
* @ClassType: class struct name
* @module_obj_name: the object name in lowercase with underscore separators * @module_obj_name: the object name in lowercase with underscore separators
* @MODULE_OBJ_NAME: the object name in uppercase with underscore separators * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
* *
@ -567,33 +568,33 @@ struct Object
* *
* The object struct and class struct need to be declared manually. * The object struct and class struct need to be declared manually.
*/ */
#define OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME) \ #define OBJECT_DECLARE_TYPE(InstanceType, ClassType, module_obj_name, MODULE_OBJ_NAME) \
typedef struct ModuleObjName ModuleObjName; \ typedef struct InstanceType InstanceType; \
typedef struct ModuleObjName##Class ModuleObjName##Class; \ typedef struct ClassType ClassType; \
\ \
G_DEFINE_AUTOPTR_CLEANUP_FUNC(ModuleObjName, object_unref) \ G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstanceType, object_unref) \
\ \
static inline G_GNUC_UNUSED ModuleObjName##Class * \ static inline G_GNUC_UNUSED ClassType * \
MODULE_OBJ_NAME##_GET_CLASS(void *obj) \ MODULE_OBJ_NAME##_GET_CLASS(void *obj) \
{ return OBJECT_GET_CLASS(ModuleObjName##Class, obj, \ { return OBJECT_GET_CLASS(ClassType, obj, \
TYPE_##MODULE_OBJ_NAME); } \ TYPE_##MODULE_OBJ_NAME); } \
\ \
static inline G_GNUC_UNUSED ModuleObjName##Class * \ static inline G_GNUC_UNUSED ClassType * \
MODULE_OBJ_NAME##_CLASS(void *klass) \ MODULE_OBJ_NAME##_CLASS(void *klass) \
{ return OBJECT_CLASS_CHECK(ModuleObjName##Class, klass, \ { return OBJECT_CLASS_CHECK(ClassType, klass, \
TYPE_##MODULE_OBJ_NAME); } \ TYPE_##MODULE_OBJ_NAME); } \
\ \
static inline G_GNUC_UNUSED ModuleObjName * \ static inline G_GNUC_UNUSED InstanceType * \
MODULE_OBJ_NAME(void *obj) \ MODULE_OBJ_NAME(void *obj) \
{ return OBJECT_CHECK(ModuleObjName, obj, \ { return OBJECT_CHECK(InstanceType, obj, \
TYPE_##MODULE_OBJ_NAME); } TYPE_##MODULE_OBJ_NAME); }
/** /**
* OBJECT_DECLARE_SIMPLE_TYPE: * OBJECT_DECLARE_SIMPLE_TYPE:
* @ModuleObjName: the object name with initial caps * @InstanceType: instance struct name
* @module_obj_name: the object name in lowercase with underscore separators * @module_obj_name: the object name in lowercase with underscore separators
* @MODULE_OBJ_NAME: the object name in uppercase with underscore separators * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
* @ParentModuleObjName: the parent object name with initial caps * @ParentClassType: class struct name of parent type
* *
* This does the same as OBJECT_DECLARE_TYPE(), but also declares * This does the same as OBJECT_DECLARE_TYPE(), but also declares
* the class struct, thus only the object struct needs to be declare * the class struct, thus only the object struct needs to be declare
@ -602,10 +603,10 @@ struct Object
* This macro should be used unless the class struct needs to have * This macro should be used unless the class struct needs to have
* virtual methods declared. * virtual methods declared.
*/ */
#define OBJECT_DECLARE_SIMPLE_TYPE(ModuleObjName, module_obj_name, \ #define OBJECT_DECLARE_SIMPLE_TYPE(InstanceType, module_obj_name, \
MODULE_OBJ_NAME, ParentModuleObjName) \ MODULE_OBJ_NAME, ParentClassType) \
OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME) \ OBJECT_DECLARE_TYPE(InstanceType, InstanceType##Class, module_obj_name, MODULE_OBJ_NAME) \
struct ModuleObjName##Class { ParentModuleObjName##Class parent_class; }; struct InstanceType##Class { ParentClassType parent_class; };
/** /**