Skip to content

Commit 0f8198f

Browse files
committed
object: qom module support
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 <[email protected]> Message-id: [email protected]
1 parent 2845774 commit 0f8198f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/qom/object.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,18 @@ bool object_class_is_abstract(ObjectClass *klass);
994994
*/
995995
ObjectClass *object_class_by_name(const char *typename);
996996

997+
/**
998+
* module_object_class_by_name:
999+
* @typename: The QOM typename to obtain the class for.
1000+
*
1001+
* For objects which might be provided by a module. Behaves like
1002+
* object_class_by_name, but additionally tries to load the module
1003+
* needed in case the class is not available.
1004+
*
1005+
* Returns: The class for @typename or %NULL if not found.
1006+
*/
1007+
ObjectClass *module_object_class_by_name(const char *typename);
1008+
9971009
void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
9981010
const char *implements_type, bool include_abstract,
9991011
void *opaque);

qom/object.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,20 @@ ObjectClass *object_class_by_name(const char *typename)
985985
return type->class;
986986
}
987987

988+
ObjectClass *module_object_class_by_name(const char *typename)
989+
{
990+
ObjectClass *oc;
991+
992+
oc = object_class_by_name(typename);
993+
#ifdef CONFIG_MODULES
994+
if (!oc) {
995+
module_load_qom_one(typename);
996+
oc = object_class_by_name(typename);
997+
}
998+
#endif
999+
return oc;
1000+
}
1001+
9881002
ObjectClass *object_class_get_parent(ObjectClass *class)
9891003
{
9901004
TypeImpl *type = type_get_parent(class->type);

0 commit comments

Comments
 (0)