[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/33] qom: Allow class type name to be specified in OBJECT_DECLAR
From: |
Eduardo Habkost |
Subject: |
[PULL 04/33] qom: Allow class type name to be specified in OBJECT_DECLARE* |
Date: |
Thu, 10 Sep 2020 14:20:43 -0400 |
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>
---
include/qom/object.h | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index f515230f61..500e7dfa99 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -555,7 +555,8 @@ struct Object
/**
* 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 uppercase with underscore separators
*
@@ -567,33 +568,33 @@ struct Object
*
* The object struct and class struct need to be declared manually.
*/
-#define OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME) \
- typedef struct ModuleObjName ModuleObjName; \
- typedef struct ModuleObjName##Class ModuleObjName##Class; \
+#define OBJECT_DECLARE_TYPE(InstanceType, ClassType, module_obj_name,
MODULE_OBJ_NAME) \
+ typedef struct InstanceType InstanceType; \
+ 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) \
- { return OBJECT_GET_CLASS(ModuleObjName##Class, obj, \
+ { return OBJECT_GET_CLASS(ClassType, obj, \
TYPE_##MODULE_OBJ_NAME); } \
\
- static inline G_GNUC_UNUSED ModuleObjName##Class * \
+ static inline G_GNUC_UNUSED ClassType * \
MODULE_OBJ_NAME##_CLASS(void *klass) \
- { return OBJECT_CLASS_CHECK(ModuleObjName##Class, klass, \
+ { return OBJECT_CLASS_CHECK(ClassType, klass, \
TYPE_##MODULE_OBJ_NAME); } \
\
- static inline G_GNUC_UNUSED ModuleObjName * \
+ static inline G_GNUC_UNUSED InstanceType * \
MODULE_OBJ_NAME(void *obj) \
- { return OBJECT_CHECK(ModuleObjName, obj, \
+ { return OBJECT_CHECK(InstanceType, obj, \
TYPE_##MODULE_OBJ_NAME); }
/**
* 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 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
* 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
* virtual methods declared.
*/
-#define OBJECT_DECLARE_SIMPLE_TYPE(ModuleObjName, module_obj_name, \
- MODULE_OBJ_NAME, ParentModuleObjName) \
- OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME) \
- struct ModuleObjName##Class { ParentModuleObjName##Class parent_class; };
+#define OBJECT_DECLARE_SIMPLE_TYPE(InstanceType, module_obj_name, \
+ MODULE_OBJ_NAME, ParentClassType) \
+ OBJECT_DECLARE_TYPE(InstanceType, InstanceType##Class, module_obj_name,
MODULE_OBJ_NAME) \
+ struct InstanceType##Class { ParentClassType parent_class; };
/**
--
2.26.2
- [PULL 00/33] QOM boilerplate cleanup (v4), Eduardo Habkost, 2020/09/10
- [PULL 02/33] qom: make object_ref/unref use a void * instead of Object *., Eduardo Habkost, 2020/09/10
- [PULL 03/33] qom: provide convenient macros for declaring and defining types, Eduardo Habkost, 2020/09/10
- [PULL 05/33] qom: DECLARE_*_CHECKERS macros, Eduardo Habkost, 2020/09/10
- [PULL 06/33] qom: Make type checker functions accept const pointers, Eduardo Habkost, 2020/09/10
- [PULL 01/33] memory: Remove kernel-doc comment marker, Eduardo Habkost, 2020/09/10
- [PULL 04/33] qom: Allow class type name to be specified in OBJECT_DECLARE*,
Eduardo Habkost <=
- [PULL 08/33] Delete duplicate QOM typedefs, Eduardo Habkost, 2020/09/10
- [PULL 12/33] Use OBJECT_DECLARE_TYPE where possible, Eduardo Habkost, 2020/09/10
- [PULL 11/33] Use DECLARE_*CHECKER* when possible (--force mode), Eduardo Habkost, 2020/09/10
- [PULL 14/33] gpex: Fix type checking function name, Eduardo Habkost, 2020/09/10
- [PULL 13/33] Use OBJECT_DECLARE_SIMPLE_TYPE when possible, Eduardo Habkost, 2020/09/10
- [PULL 07/33] codeconverter: script for automating QOM code cleanups, Eduardo Habkost, 2020/09/10
- [PULL 15/33] ap-device: Rename AP_DEVICE_TYPE to TYPE_AP_DEVICE, Eduardo Habkost, 2020/09/10
- [PULL 17/33] vfio: Rename VFIO_AP_DEVICE_TYPE to TYPE_VFIO_AP_DEVICE, Eduardo Habkost, 2020/09/10
- [PULL 16/33] dev-smartcard-reader: Rename CCID_DEV_NAME to TYPE_USB_CCID_DEV, Eduardo Habkost, 2020/09/10
- [PULL 19/33] ahci: Rename ICH_AHCI to ICH9_AHCI, Eduardo Habkost, 2020/09/10