[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/10] object: qom module support
From: |
Gerd Hoffmann |
Subject: |
[PULL 02/10] object: qom module support |
Date: |
Tue, 7 Jul 2020 15:42:21 +0200 |
Little helper function to load modules on demand. In most cases adding
module loading support for devices and other objects is just
s/object_class_by_name/module_object_class_by_name/ in the right spot.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 20200624131045.14512-3-kraxel@redhat.com
---
include/qom/object.h | 12 ++++++++++++
qom/object.c | 14 ++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index 94a61ccc3fe8..51f188137f1f 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -994,6 +994,18 @@ bool object_class_is_abstract(ObjectClass *klass);
*/
ObjectClass *object_class_by_name(const char *typename);
+/**
+ * module_object_class_by_name:
+ * @typename: The QOM typename to obtain the class for.
+ *
+ * For objects which might be provided by a module. Behaves like
+ * object_class_by_name, but additionally tries to load the module
+ * needed in case the class is not available.
+ *
+ * Returns: The class for @typename or %NULL if not found.
+ */
+ObjectClass *module_object_class_by_name(const char *typename);
+
void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
const char *implements_type, bool include_abstract,
void *opaque);
diff --git a/qom/object.c b/qom/object.c
index 6ece96bc2bfc..34daaf1280f5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -985,6 +985,20 @@ ObjectClass *object_class_by_name(const char *typename)
return type->class;
}
+ObjectClass *module_object_class_by_name(const char *typename)
+{
+ ObjectClass *oc;
+
+ oc = object_class_by_name(typename);
+#ifdef CONFIG_MODULES
+ if (!oc) {
+ module_load_qom_one(typename);
+ oc = object_class_by_name(typename);
+ }
+#endif
+ return oc;
+}
+
ObjectClass *object_class_get_parent(ObjectClass *class)
{
TypeImpl *type = type_get_parent(class->type);
--
2.18.4
- [PULL 00/10] Modules 20200707 patches, Gerd Hoffmann, 2020/07/07
- [PULL 03/10] qdev: device module support, Gerd Hoffmann, 2020/07/07
- [PULL 02/10] object: qom module support,
Gerd Hoffmann <=
- [PULL 10/10] chardev: enable modules, use for braille, Gerd Hoffmann, 2020/07/07
- [PULL 07/10] vga: build qxl as module, Gerd Hoffmann, 2020/07/07
- [PULL 09/10] vga: build virtio-gpu as module, Gerd Hoffmann, 2020/07/07
- [PULL 01/10] module: qom module support, Gerd Hoffmann, 2020/07/07
- [PULL 08/10] vga: build virtio-gpu only once, Gerd Hoffmann, 2020/07/07
- [PULL 05/10] ccid: build smartcard as module, Gerd Hoffmann, 2020/07/07
- [PULL 04/10] build: fix device module builds, Gerd Hoffmann, 2020/07/07
- [PULL 06/10] usb: build usb-redir as module, Gerd Hoffmann, 2020/07/07
- Re: [PULL 00/10] Modules 20200707 patches, Peter Maydell, 2020/07/09
- Re: [PULL 00/10] Modules 20200707 patches, Thomas Huth, 2020/07/10