Commit 0f8198f1 authored by Gerd Hoffmann's avatar Gerd Hoffmann
Browse files

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: default avatarGerd Hoffmann <kraxel@redhat.com>
Message-id: 20200624131045.14512-3-kraxel@redhat.com
parent 28457744
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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);
+14 −0
Original line number Diff line number Diff line
@@ -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);