4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
17 #include "qapi/qapi-builtin-types.h"
18 #include "qemu/module.h"
21 typedef struct TypeImpl
*Type
;
23 typedef struct Object Object
;
25 typedef struct TypeInfo TypeInfo
;
27 typedef struct InterfaceClass InterfaceClass
;
28 typedef struct InterfaceInfo InterfaceInfo
;
30 #define TYPE_OBJECT "object"
34 * @title:Base Object Type System
35 * @short_description: interfaces for creating new types and objects
37 * The QEMU Object Model provides a framework for registering user creatable
38 * types and instantiating objects from those types. QOM provides the following
41 * - System for dynamically registering types
42 * - Support for single-inheritance of types
43 * - Multiple inheritance of stateless interfaces
46 * <title>Creating a minimal type</title>
50 * #define TYPE_MY_DEVICE "my-device"
52 * // No new virtual functions: we can reuse the typedef for the
54 * typedef DeviceClass MyDeviceClass;
55 * typedef struct MyDevice
59 * int reg0, reg1, reg2;
62 * static const TypeInfo my_device_info = {
63 * .name = TYPE_MY_DEVICE,
64 * .parent = TYPE_DEVICE,
65 * .instance_size = sizeof(MyDevice),
68 * static void my_device_register_types(void)
70 * type_register_static(&my_device_info);
73 * type_init(my_device_register_types)
77 * In the above example, we create a simple type that is described by #TypeInfo.
78 * #TypeInfo describes information about the type including what it inherits
79 * from, the instance and class size, and constructor/destructor hooks.
81 * Alternatively several static types could be registered using helper macro
86 * static const TypeInfo device_types_info[] = {
88 * .name = TYPE_MY_DEVICE_A,
89 * .parent = TYPE_DEVICE,
90 * .instance_size = sizeof(MyDeviceA),
93 * .name = TYPE_MY_DEVICE_B,
94 * .parent = TYPE_DEVICE,
95 * .instance_size = sizeof(MyDeviceB),
99 * DEFINE_TYPES(device_types_info)
103 * Every type has an #ObjectClass associated with it. #ObjectClass derivatives
104 * are instantiated dynamically but there is only ever one instance for any
105 * given type. The #ObjectClass typically holds a table of function pointers
106 * for the virtual methods implemented by this type.
108 * Using object_new(), a new #Object derivative will be instantiated. You can
109 * cast an #Object to a subclass (or base-class) type using
110 * object_dynamic_cast(). You typically want to define macro wrappers around
111 * OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a
115 * <title>Typecasting macros</title>
117 * #define MY_DEVICE_GET_CLASS(obj) \
118 * OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE)
119 * #define MY_DEVICE_CLASS(klass) \
120 * OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE)
121 * #define MY_DEVICE(obj) \
122 * OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
126 * # Class Initialization #
128 * Before an object is initialized, the class for the object must be
129 * initialized. There is only one class object for all instance objects
130 * that is created lazily.
132 * Classes are initialized by first initializing any parent classes (if
133 * necessary). After the parent class object has initialized, it will be
134 * copied into the current class object and any additional storage in the
135 * class object is zero filled.
137 * The effect of this is that classes automatically inherit any virtual
138 * function pointers that the parent class has already initialized. All
139 * other fields will be zero filled.
141 * Once all of the parent classes have been initialized, #TypeInfo::class_init
142 * is called to let the class being instantiated provide default initialize for
143 * its virtual functions. Here is how the above example might be modified
144 * to introduce an overridden virtual function:
147 * <title>Overriding a virtual function</title>
151 * void my_device_class_init(ObjectClass *klass, void *class_data)
153 * DeviceClass *dc = DEVICE_CLASS(klass);
154 * dc->reset = my_device_reset;
157 * static const TypeInfo my_device_info = {
158 * .name = TYPE_MY_DEVICE,
159 * .parent = TYPE_DEVICE,
160 * .instance_size = sizeof(MyDevice),
161 * .class_init = my_device_class_init,
166 * Introducing new virtual methods requires a class to define its own
167 * struct and to add a .class_size member to the #TypeInfo. Each method
168 * will also have a wrapper function to call it easily:
171 * <title>Defining an abstract class</title>
175 * typedef struct MyDeviceClass
177 * DeviceClass parent;
179 * void (*frobnicate) (MyDevice *obj);
182 * static const TypeInfo my_device_info = {
183 * .name = TYPE_MY_DEVICE,
184 * .parent = TYPE_DEVICE,
185 * .instance_size = sizeof(MyDevice),
186 * .abstract = true, // or set a default in my_device_class_init
187 * .class_size = sizeof(MyDeviceClass),
190 * void my_device_frobnicate(MyDevice *obj)
192 * MyDeviceClass *klass = MY_DEVICE_GET_CLASS(obj);
194 * klass->frobnicate(obj);
201 * Interfaces allow a limited form of multiple inheritance. Instances are
202 * similar to normal types except for the fact that are only defined by
203 * their classes and never carry any state. As a consequence, a pointer to
204 * an interface instance should always be of incomplete type in order to be
205 * sure it cannot be dereferenced. That is, you should define the
206 * 'typedef struct SomethingIf SomethingIf' so that you can pass around
207 * 'SomethingIf *si' arguments, but not define a 'struct SomethingIf { ... }'.
208 * The only things you can validly do with a 'SomethingIf *' are to pass it as
209 * an argument to a method on its corresponding SomethingIfClass, or to
210 * dynamically cast it to an object that implements the interface.
214 * A <emphasis>method</emphasis> is a function within the namespace scope of
215 * a class. It usually operates on the object instance by passing it as a
216 * strongly-typed first argument.
217 * If it does not operate on an object instance, it is dubbed
218 * <emphasis>class method</emphasis>.
220 * Methods cannot be overloaded. That is, the #ObjectClass and method name
221 * uniquely identity the function to be called; the signature does not vary
222 * except for trailing varargs.
224 * Methods are always <emphasis>virtual</emphasis>. Overriding a method in
225 * #TypeInfo.class_init of a subclass leads to any user of the class obtained
226 * via OBJECT_GET_CLASS() accessing the overridden function.
227 * The original function is not automatically invoked. It is the responsibility
228 * of the overriding class to determine whether and when to invoke the method
231 * To invoke the method being overridden, the preferred solution is to store
232 * the original value in the overriding class before overriding the method.
233 * This corresponds to |[ {super,base}.method(...) ]| in Java and C#
234 * respectively; this frees the overriding class from hardcoding its parent
235 * class, which someone might choose to change at some point.
238 * <title>Overriding a virtual method</title>
240 * typedef struct MyState MyState;
242 * typedef void (*MyDoSomething)(MyState *obj);
244 * typedef struct MyClass {
245 * ObjectClass parent_class;
247 * MyDoSomething do_something;
250 * static void my_do_something(MyState *obj)
255 * static void my_class_init(ObjectClass *oc, void *data)
257 * MyClass *mc = MY_CLASS(oc);
259 * mc->do_something = my_do_something;
262 * static const TypeInfo my_type_info = {
264 * .parent = TYPE_OBJECT,
265 * .instance_size = sizeof(MyState),
266 * .class_size = sizeof(MyClass),
267 * .class_init = my_class_init,
270 * typedef struct DerivedClass {
271 * MyClass parent_class;
273 * MyDoSomething parent_do_something;
276 * static void derived_do_something(MyState *obj)
278 * DerivedClass *dc = DERIVED_GET_CLASS(obj);
280 * // do something here
281 * dc->parent_do_something(obj);
282 * // do something else here
285 * static void derived_class_init(ObjectClass *oc, void *data)
287 * MyClass *mc = MY_CLASS(oc);
288 * DerivedClass *dc = DERIVED_CLASS(oc);
290 * dc->parent_do_something = mc->do_something;
291 * mc->do_something = derived_do_something;
294 * static const TypeInfo derived_type_info = {
295 * .name = TYPE_DERIVED,
297 * .class_size = sizeof(DerivedClass),
298 * .class_init = derived_class_init,
303 * Alternatively, object_class_by_name() can be used to obtain the class and
304 * its non-overridden methods for a specific type. This would correspond to
305 * |[ MyClass::method(...) ]| in C++.
307 * The first example of such a QOM method was #CPUClass.reset,
308 * another example is #DeviceClass.realize.
313 * ObjectPropertyAccessor:
314 * @obj: the object that owns the property
315 * @v: the visitor that contains the property data
316 * @name: the name of the property
317 * @opaque: the object property opaque
318 * @errp: a pointer to an Error that is filled if getting/setting fails.
320 * Called when trying to get/set a property.
322 typedef void (ObjectPropertyAccessor
)(Object
*obj
,
329 * ObjectPropertyResolve:
330 * @obj: the object that owns the property
331 * @opaque: the opaque registered with the property
332 * @part: the name of the property
334 * Resolves the #Object corresponding to property @part.
336 * The returned object can also be used as a starting point
337 * to resolve a relative path starting with "@part".
339 * Returns: If @path is the path that led to @obj, the function
340 * returns the #Object corresponding to "@path/@part".
341 * If "@path/@part" is not a valid object path, it returns #NULL.
343 typedef Object
*(ObjectPropertyResolve
)(Object
*obj
,
348 * ObjectPropertyRelease:
349 * @obj: the object that owns the property
350 * @name: the name of the property
351 * @opaque: the opaque registered with the property
353 * Called when a property is removed from a object.
355 typedef void (ObjectPropertyRelease
)(Object
*obj
,
359 typedef struct ObjectProperty
364 ObjectPropertyAccessor
*get
;
365 ObjectPropertyAccessor
*set
;
366 ObjectPropertyResolve
*resolve
;
367 ObjectPropertyRelease
*release
;
373 * @obj: the object that is being removed from the composition tree
375 * Called when an object is being removed from the QOM composition tree.
376 * The function should remove any backlinks from children objects to @obj.
378 typedef void (ObjectUnparent
)(Object
*obj
);
382 * @obj: the object being freed
384 * Called when an object's last reference is removed.
386 typedef void (ObjectFree
)(void *obj
);
388 #define OBJECT_CLASS_CAST_CACHE 4
393 * The base for all classes. The only thing that #ObjectClass contains is an
394 * integer type handle.
402 const char *object_cast_cache
[OBJECT_CLASS_CAST_CACHE
];
403 const char *class_cast_cache
[OBJECT_CLASS_CAST_CACHE
];
405 ObjectUnparent
*unparent
;
407 GHashTable
*properties
;
413 * The base for all objects. The first member of this object is a pointer to
414 * a #ObjectClass. Since C guarantees that the first member of a structure
415 * always begins at byte 0 of that structure, as long as any sub-object places
416 * its parent as the first member, we can cast directly to a #Object.
418 * As a result, #Object contains a reference to the objects type as its
419 * first member. This allows identification of the real type of the object at
427 GHashTable
*properties
;
434 * @name: The name of the type.
435 * @parent: The name of the parent type.
436 * @instance_size: The size of the object (derivative of #Object). If
437 * @instance_size is 0, then the size of the object will be the size of the
439 * @instance_init: This function is called to initialize an object. The parent
440 * class will have already been initialized so the type is only responsible
441 * for initializing its own members.
442 * @instance_post_init: This function is called to finish initialization of
443 * an object, after all @instance_init functions were called.
444 * @instance_finalize: This function is called during object destruction. This
445 * is called before the parent @instance_finalize function has been called.
446 * An object should only free the members that are unique to its type in this
448 * @abstract: If this field is true, then the class is considered abstract and
449 * cannot be directly instantiated.
450 * @class_size: The size of the class object (derivative of #ObjectClass)
451 * for this object. If @class_size is 0, then the size of the class will be
452 * assumed to be the size of the parent class. This allows a type to avoid
453 * implementing an explicit class type if they are not adding additional
455 * @class_init: This function is called after all parent class initialization
456 * has occurred to allow a class to set its default virtual method pointers.
457 * This is also the function to use to override virtual methods from a parent
459 * @class_base_init: This function is called for all base classes after all
460 * parent class initialization has occurred, but before the class itself
461 * is initialized. This is the function to use to undo the effects of
462 * memcpy from the parent class to the descendants.
463 * @class_data: Data to pass to the @class_init,
464 * @class_base_init. This can be useful when building dynamic
466 * @interfaces: The list of interfaces associated with this type. This
467 * should point to a static array that's terminated with a zero filled
475 size_t instance_size
;
476 void (*instance_init
)(Object
*obj
);
477 void (*instance_post_init
)(Object
*obj
);
478 void (*instance_finalize
)(Object
*obj
);
483 void (*class_init
)(ObjectClass
*klass
, void *data
);
484 void (*class_base_init
)(ObjectClass
*klass
, void *data
);
487 InterfaceInfo
*interfaces
;
492 * @obj: A derivative of #Object
494 * Converts an object to a #Object. Since all objects are #Objects,
495 * this function will always succeed.
497 #define OBJECT(obj) \
502 * @class: A derivative of #ObjectClass.
504 * Converts a class to an #ObjectClass. Since all objects are #Objects,
505 * this function will always succeed.
507 #define OBJECT_CLASS(class) \
508 ((ObjectClass *)(class))
512 * @type: The C type to use for the return value.
513 * @obj: A derivative of @type to cast.
514 * @name: The QOM typename of @type
516 * A type safe version of @object_dynamic_cast_assert. Typically each class
517 * will define a macro based on this type to perform type safe dynamic_casts to
520 * If an invalid object is passed to this function, a run time assert will be
523 #define OBJECT_CHECK(type, obj, name) \
524 ((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \
525 __FILE__, __LINE__, __func__))
528 * OBJECT_CLASS_CHECK:
529 * @class_type: The C type to use for the return value.
530 * @class: A derivative class of @class_type to cast.
531 * @name: the QOM typename of @class_type.
533 * A type safe version of @object_class_dynamic_cast_assert. This macro is
534 * typically wrapped by each type to perform type safe casts of a class to a
535 * specific class type.
537 #define OBJECT_CLASS_CHECK(class_type, class, name) \
538 ((class_type *)object_class_dynamic_cast_assert(OBJECT_CLASS(class), (name), \
539 __FILE__, __LINE__, __func__))
543 * @class: The C type to use for the return value.
544 * @obj: The object to obtain the class for.
545 * @name: The QOM typename of @obj.
547 * This function will return a specific class for a given object. Its generally
548 * used by each type to provide a type safe macro to get a specific class type
551 #define OBJECT_GET_CLASS(class, obj, name) \
552 OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
556 * @type: The name of the interface.
558 * The information associated with an interface.
560 struct InterfaceInfo
{
566 * @parent_class: the base class
568 * The class for all interfaces. Subclasses of this class should only add
571 struct InterfaceClass
573 ObjectClass parent_class
;
575 ObjectClass
*concrete_class
;
579 #define TYPE_INTERFACE "interface"
583 * @klass: class to cast from
584 * Returns: An #InterfaceClass or raise an error if cast is invalid
586 #define INTERFACE_CLASS(klass) \
587 OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE)
591 * @interface: the type to return
592 * @obj: the object to convert to an interface
593 * @name: the interface type name
595 * Returns: @obj casted to @interface if cast is valid, otherwise raise error.
597 #define INTERFACE_CHECK(interface, obj, name) \
598 ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \
599 __FILE__, __LINE__, __func__))
602 * object_new_with_class:
603 * @klass: The class to instantiate.
605 * This function will initialize a new object using heap allocated memory.
606 * The returned object has a reference count of 1, and will be freed when
607 * the last reference is dropped.
609 * Returns: The newly allocated and instantiated object.
611 Object
*object_new_with_class(ObjectClass
*klass
);
615 * @typename: The name of the type of the object to instantiate.
617 * This function will initialize a new object using heap allocated memory.
618 * The returned object has a reference count of 1, and will be freed when
619 * the last reference is dropped.
621 * Returns: The newly allocated and instantiated object.
623 Object
*object_new(const char *typename
);
626 * object_new_with_props:
627 * @typename: The name of the type of the object to instantiate.
628 * @parent: the parent object
629 * @id: The unique ID of the object
630 * @errp: pointer to error object
631 * @...: list of property names and values
633 * This function will initialize a new object using heap allocated memory.
634 * The returned object has a reference count of 1, and will be freed when
635 * the last reference is dropped.
637 * The @id parameter will be used when registering the object as a
638 * child of @parent in the composition tree.
640 * The variadic parameters are a list of pairs of (propname, propvalue)
641 * strings. The propname of %NULL indicates the end of the property
642 * list. If the object implements the user creatable interface, the
643 * object will be marked complete once all the properties have been
647 * <title>Creating an object with properties</title>
652 * obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE,
653 * object_get_objects_root(),
657 * "mem-path", "/dev/shm/somefile",
663 * g_printerr("Cannot create memory backend: %s\n",
664 * error_get_pretty(err));
669 * The returned object will have one stable reference maintained
670 * for as long as it is present in the object hierarchy.
672 * Returns: The newly allocated, instantiated & initialized object.
674 Object
*object_new_with_props(const char *typename
,
681 * object_new_with_propv:
682 * @typename: The name of the type of the object to instantiate.
683 * @parent: the parent object
684 * @id: The unique ID of the object
685 * @errp: pointer to error object
686 * @vargs: list of property names and values
688 * See object_new_with_props() for documentation.
690 Object
*object_new_with_propv(const char *typename
,
696 void object_apply_global_props(Object
*obj
, const GPtrArray
*props
,
698 void object_set_machine_compat_props(GPtrArray
*compat_props
);
699 void object_set_accelerator_compat_props(GPtrArray
*compat_props
);
700 void object_register_sugar_prop(const char *driver
, const char *prop
, const char *value
);
701 void object_apply_compat_props(Object
*obj
);
705 * @obj: the object instance to set properties on
706 * @errp: pointer to error object
707 * @...: list of property names and values
709 * This function will set a list of properties on an existing object
712 * The variadic parameters are a list of pairs of (propname, propvalue)
713 * strings. The propname of %NULL indicates the end of the property
717 * <title>Update an object's properties</title>
720 * Object *obj = ...get / create object...;
722 * obj = object_set_props(obj,
725 * "mem-path", "/dev/shm/somefile",
731 * g_printerr("Cannot set properties: %s\n",
732 * error_get_pretty(err));
737 * The returned object will have one stable reference maintained
738 * for as long as it is present in the object hierarchy.
740 * Returns: -1 on error, 0 on success
742 int object_set_props(Object
*obj
,
748 * @obj: the object instance to set properties on
749 * @errp: pointer to error object
750 * @vargs: list of property names and values
752 * See object_set_props() for documentation.
754 * Returns: -1 on error, 0 on success
756 int object_set_propv(Object
*obj
,
762 * @obj: A pointer to the memory to be used for the object.
763 * @size: The maximum size available at @obj for the object.
764 * @typename: The name of the type of the object to instantiate.
766 * This function will initialize an object. The memory for the object should
767 * have already been allocated. The returned object has a reference count of 1,
768 * and will be finalized when the last reference is dropped.
770 void object_initialize(void *obj
, size_t size
, const char *typename
);
773 * object_initialize_child:
774 * @parentobj: The parent object to add a property to
775 * @propname: The name of the property
776 * @childobj: A pointer to the memory to be used for the object.
777 * @size: The maximum size available at @childobj for the object.
778 * @type: The name of the type of the object to instantiate.
779 * @errp: If an error occurs, a pointer to an area to store the error
780 * @...: list of property names and values
782 * This function will initialize an object. The memory for the object should
783 * have already been allocated. The object will then be added as child property
784 * to a parent with object_property_add_child() function. The returned object
785 * has a reference count of 1 (for the "child<...>" property from the parent),
786 * so the object will be finalized automatically when the parent gets removed.
788 * The variadic parameters are a list of pairs of (propname, propvalue)
789 * strings. The propname of %NULL indicates the end of the property list.
790 * If the object implements the user creatable interface, the object will
791 * be marked complete once all the properties have been processed.
793 void object_initialize_child(Object
*parentobj
, const char *propname
,
794 void *childobj
, size_t size
, const char *type
,
795 Error
**errp
, ...) QEMU_SENTINEL
;
798 * object_initialize_childv:
799 * @parentobj: The parent object to add a property to
800 * @propname: The name of the property
801 * @childobj: A pointer to the memory to be used for the object.
802 * @size: The maximum size available at @childobj for the object.
803 * @type: The name of the type of the object to instantiate.
804 * @errp: If an error occurs, a pointer to an area to store the error
805 * @vargs: list of property names and values
807 * See object_initialize_child() for documentation.
809 void object_initialize_childv(Object
*parentobj
, const char *propname
,
810 void *childobj
, size_t size
, const char *type
,
811 Error
**errp
, va_list vargs
);
814 * object_dynamic_cast:
815 * @obj: The object to cast.
816 * @typename: The @typename to cast to.
818 * This function will determine if @obj is-a @typename. @obj can refer to an
819 * object or an interface associated with an object.
821 * Returns: This function returns @obj on success or #NULL on failure.
823 Object
*object_dynamic_cast(Object
*obj
, const char *typename
);
826 * object_dynamic_cast_assert:
828 * See object_dynamic_cast() for a description of the parameters of this
829 * function. The only difference in behavior is that this function asserts
830 * instead of returning #NULL on failure if QOM cast debugging is enabled.
831 * This function is not meant to be called directly, but only through
832 * the wrapper macro OBJECT_CHECK.
834 Object
*object_dynamic_cast_assert(Object
*obj
, const char *typename
,
835 const char *file
, int line
, const char *func
);
839 * @obj: A derivative of #Object
841 * Returns: The #ObjectClass of the type associated with @obj.
843 ObjectClass
*object_get_class(Object
*obj
);
846 * object_get_typename:
847 * @obj: A derivative of #Object.
849 * Returns: The QOM typename of @obj.
851 const char *object_get_typename(const Object
*obj
);
854 * type_register_static:
855 * @info: The #TypeInfo of the new type.
857 * @info and all of the strings it points to should exist for the life time
858 * that the type is registered.
860 * Returns: the new #Type.
862 Type
type_register_static(const TypeInfo
*info
);
866 * @info: The #TypeInfo of the new type
868 * Unlike type_register_static(), this call does not require @info or its
869 * string members to continue to exist after the call returns.
871 * Returns: the new #Type.
873 Type
type_register(const TypeInfo
*info
);
876 * type_register_static_array:
877 * @infos: The array of the new type #TypeInfo structures.
878 * @nr_infos: number of entries in @infos
880 * @infos and all of the strings it points to should exist for the life time
881 * that the type is registered.
883 void type_register_static_array(const TypeInfo
*infos
, int nr_infos
);
887 * @type_array: The array containing #TypeInfo structures to register
889 * @type_array should be static constant that exists for the life time
890 * that the type is registered.
892 #define DEFINE_TYPES(type_array) \
893 static void do_qemu_init_ ## type_array(void) \
895 type_register_static_array(type_array, ARRAY_SIZE(type_array)); \
897 type_init(do_qemu_init_ ## type_array)
900 * object_class_dynamic_cast_assert:
901 * @klass: The #ObjectClass to attempt to cast.
902 * @typename: The QOM typename of the class to cast to.
904 * See object_class_dynamic_cast() for a description of the parameters
905 * of this function. The only difference in behavior is that this function
906 * asserts instead of returning #NULL on failure if QOM cast debugging is
907 * enabled. This function is not meant to be called directly, but only through
908 * the wrapper macros OBJECT_CLASS_CHECK and INTERFACE_CHECK.
910 ObjectClass
*object_class_dynamic_cast_assert(ObjectClass
*klass
,
911 const char *typename
,
912 const char *file
, int line
,
916 * object_class_dynamic_cast:
917 * @klass: The #ObjectClass to attempt to cast.
918 * @typename: The QOM typename of the class to cast to.
920 * Returns: If @typename is a class, this function returns @klass if
921 * @typename is a subtype of @klass, else returns #NULL.
923 * If @typename is an interface, this function returns the interface
924 * definition for @klass if @klass implements it unambiguously; #NULL
925 * is returned if @klass does not implement the interface or if multiple
926 * classes or interfaces on the hierarchy leading to @klass implement
927 * it. (FIXME: perhaps this can be detected at type definition time?)
929 ObjectClass
*object_class_dynamic_cast(ObjectClass
*klass
,
930 const char *typename
);
933 * object_class_get_parent:
934 * @klass: The class to obtain the parent for.
936 * Returns: The parent for @klass or %NULL if none.
938 ObjectClass
*object_class_get_parent(ObjectClass
*klass
);
941 * object_class_get_name:
942 * @klass: The class to obtain the QOM typename for.
944 * Returns: The QOM typename for @klass.
946 const char *object_class_get_name(ObjectClass
*klass
);
949 * object_class_is_abstract:
950 * @klass: The class to obtain the abstractness for.
952 * Returns: %true if @klass is abstract, %false otherwise.
954 bool object_class_is_abstract(ObjectClass
*klass
);
957 * object_class_by_name:
958 * @typename: The QOM typename to obtain the class for.
960 * Returns: The class for @typename or %NULL if not found.
962 ObjectClass
*object_class_by_name(const char *typename
);
964 void object_class_foreach(void (*fn
)(ObjectClass
*klass
, void *opaque
),
965 const char *implements_type
, bool include_abstract
,
969 * object_class_get_list:
970 * @implements_type: The type to filter for, including its derivatives.
971 * @include_abstract: Whether to include abstract classes.
973 * Returns: A singly-linked list of the classes in reverse hashtable order.
975 GSList
*object_class_get_list(const char *implements_type
,
976 bool include_abstract
);
979 * object_class_get_list_sorted:
980 * @implements_type: The type to filter for, including its derivatives.
981 * @include_abstract: Whether to include abstract classes.
983 * Returns: A singly-linked list of the classes in alphabetical
984 * case-insensitive order.
986 GSList
*object_class_get_list_sorted(const char *implements_type
,
987 bool include_abstract
);
993 * Increase the reference count of a object. A object cannot be freed as long
994 * as its reference count is greater than zero.
996 void object_ref(Object
*obj
);
1002 * Decrease the reference count of a object. A object cannot be freed as long
1003 * as its reference count is greater than zero.
1005 void object_unref(Object
*obj
);
1008 * object_property_add:
1009 * @obj: the object to add a property to
1010 * @name: the name of the property. This can contain any character except for
1011 * a forward slash. In general, you should use hyphens '-' instead of
1012 * underscores '_' when naming properties.
1013 * @type: the type name of the property. This namespace is pretty loosely
1014 * defined. Sub namespaces are constructed by using a prefix and then
1015 * to angle brackets. For instance, the type 'virtio-net-pci' in the
1016 * 'link' namespace would be 'link<virtio-net-pci>'.
1017 * @get: The getter to be called to read a property. If this is NULL, then
1018 * the property cannot be read.
1019 * @set: the setter to be called to write a property. If this is NULL,
1020 * then the property cannot be written.
1021 * @release: called when the property is removed from the object. This is
1022 * meant to allow a property to free its opaque upon object
1023 * destruction. This may be NULL.
1024 * @opaque: an opaque pointer to pass to the callbacks for the property
1025 * @errp: returns an error if this function fails
1027 * Returns: The #ObjectProperty; this can be used to set the @resolve
1028 * callback for child and link properties.
1030 ObjectProperty
*object_property_add(Object
*obj
, const char *name
,
1032 ObjectPropertyAccessor
*get
,
1033 ObjectPropertyAccessor
*set
,
1034 ObjectPropertyRelease
*release
,
1035 void *opaque
, Error
**errp
);
1037 void object_property_del(Object
*obj
, const char *name
, Error
**errp
);
1039 ObjectProperty
*object_class_property_add(ObjectClass
*klass
, const char *name
,
1041 ObjectPropertyAccessor
*get
,
1042 ObjectPropertyAccessor
*set
,
1043 ObjectPropertyRelease
*release
,
1044 void *opaque
, Error
**errp
);
1047 * object_property_find:
1049 * @name: the name of the property
1050 * @errp: returns an error if this function fails
1052 * Look up a property for an object and return its #ObjectProperty if found.
1054 ObjectProperty
*object_property_find(Object
*obj
, const char *name
,
1056 ObjectProperty
*object_class_property_find(ObjectClass
*klass
, const char *name
,
1059 typedef struct ObjectPropertyIterator
{
1060 ObjectClass
*nextclass
;
1061 GHashTableIter iter
;
1062 } ObjectPropertyIterator
;
1065 * object_property_iter_init:
1068 * Initializes an iterator for traversing all properties
1069 * registered against an object instance, its class and all parent classes.
1071 * It is forbidden to modify the property list while iterating,
1072 * whether removing or adding properties.
1074 * Typical usage pattern would be
1077 * <title>Using object property iterators</title>
1079 * ObjectProperty *prop;
1080 * ObjectPropertyIterator iter;
1082 * object_property_iter_init(&iter, obj);
1083 * while ((prop = object_property_iter_next(&iter))) {
1084 * ... do something with prop ...
1089 void object_property_iter_init(ObjectPropertyIterator
*iter
,
1093 * object_class_property_iter_init:
1096 * Initializes an iterator for traversing all properties
1097 * registered against an object class and all parent classes.
1099 * It is forbidden to modify the property list while iterating,
1100 * whether removing or adding properties.
1102 * This can be used on abstract classes as it does not create a temporary
1105 void object_class_property_iter_init(ObjectPropertyIterator
*iter
,
1106 ObjectClass
*klass
);
1109 * object_property_iter_next:
1110 * @iter: the iterator instance
1112 * Return the next available property. If no further properties
1113 * are available, a %NULL value will be returned and the @iter
1114 * pointer should not be used again after this point without
1115 * re-initializing it.
1117 * Returns: the next property, or %NULL when all properties
1118 * have been traversed.
1120 ObjectProperty
*object_property_iter_next(ObjectPropertyIterator
*iter
);
1122 void object_unparent(Object
*obj
);
1125 * object_property_get:
1127 * @v: the visitor that will receive the property value. This should be an
1128 * Output visitor and the data will be written with @name as the name.
1129 * @name: the name of the property
1130 * @errp: returns an error if this function fails
1132 * Reads a property from a object.
1134 void object_property_get(Object
*obj
, Visitor
*v
, const char *name
,
1138 * object_property_set_str:
1139 * @value: the value to be written to the property
1140 * @name: the name of the property
1141 * @errp: returns an error if this function fails
1143 * Writes a string value to a property.
1145 void object_property_set_str(Object
*obj
, const char *value
,
1146 const char *name
, Error
**errp
);
1149 * object_property_get_str:
1151 * @name: the name of the property
1152 * @errp: returns an error if this function fails
1154 * Returns: the value of the property, converted to a C string, or NULL if
1155 * an error occurs (including when the property value is not a string).
1156 * The caller should free the string.
1158 char *object_property_get_str(Object
*obj
, const char *name
,
1162 * object_property_set_link:
1163 * @value: the value to be written to the property
1164 * @name: the name of the property
1165 * @errp: returns an error if this function fails
1167 * Writes an object's canonical path to a property.
1169 * If the link property was created with
1170 * <code>OBJ_PROP_LINK_STRONG</code> bit, the old target object is
1171 * unreferenced, and a reference is added to the new target object.
1174 void object_property_set_link(Object
*obj
, Object
*value
,
1175 const char *name
, Error
**errp
);
1178 * object_property_get_link:
1180 * @name: the name of the property
1181 * @errp: returns an error if this function fails
1183 * Returns: the value of the property, resolved from a path to an Object,
1184 * or NULL if an error occurs (including when the property value is not a
1185 * string or not a valid object path).
1187 Object
*object_property_get_link(Object
*obj
, const char *name
,
1191 * object_property_set_bool:
1192 * @value: the value to be written to the property
1193 * @name: the name of the property
1194 * @errp: returns an error if this function fails
1196 * Writes a bool value to a property.
1198 void object_property_set_bool(Object
*obj
, bool value
,
1199 const char *name
, Error
**errp
);
1202 * object_property_get_bool:
1204 * @name: the name of the property
1205 * @errp: returns an error if this function fails
1207 * Returns: the value of the property, converted to a boolean, or NULL if
1208 * an error occurs (including when the property value is not a bool).
1210 bool object_property_get_bool(Object
*obj
, const char *name
,
1214 * object_property_set_int:
1215 * @value: the value to be written to the property
1216 * @name: the name of the property
1217 * @errp: returns an error if this function fails
1219 * Writes an integer value to a property.
1221 void object_property_set_int(Object
*obj
, int64_t value
,
1222 const char *name
, Error
**errp
);
1225 * object_property_get_int:
1227 * @name: the name of the property
1228 * @errp: returns an error if this function fails
1230 * Returns: the value of the property, converted to an integer, or negative if
1231 * an error occurs (including when the property value is not an integer).
1233 int64_t object_property_get_int(Object
*obj
, const char *name
,
1237 * object_property_set_uint:
1238 * @value: the value to be written to the property
1239 * @name: the name of the property
1240 * @errp: returns an error if this function fails
1242 * Writes an unsigned integer value to a property.
1244 void object_property_set_uint(Object
*obj
, uint64_t value
,
1245 const char *name
, Error
**errp
);
1248 * object_property_get_uint:
1250 * @name: the name of the property
1251 * @errp: returns an error if this function fails
1253 * Returns: the value of the property, converted to an unsigned integer, or 0
1254 * an error occurs (including when the property value is not an integer).
1256 uint64_t object_property_get_uint(Object
*obj
, const char *name
,
1260 * object_property_get_enum:
1262 * @name: the name of the property
1263 * @typename: the name of the enum data type
1264 * @errp: returns an error if this function fails
1266 * Returns: the value of the property, converted to an integer, or
1267 * undefined if an error occurs (including when the property value is not
1270 int object_property_get_enum(Object
*obj
, const char *name
,
1271 const char *typename
, Error
**errp
);
1274 * object_property_get_uint16List:
1276 * @name: the name of the property
1277 * @list: the returned int list
1278 * @errp: returns an error if this function fails
1280 * Returns: the value of the property, converted to integers, or
1281 * undefined if an error occurs (including when the property value is not
1282 * an list of integers).
1284 void object_property_get_uint16List(Object
*obj
, const char *name
,
1285 uint16List
**list
, Error
**errp
);
1288 * object_property_set:
1290 * @v: the visitor that will be used to write the property value. This should
1291 * be an Input visitor and the data will be first read with @name as the
1292 * name and then written as the property value.
1293 * @name: the name of the property
1294 * @errp: returns an error if this function fails
1296 * Writes a property to a object.
1298 void object_property_set(Object
*obj
, Visitor
*v
, const char *name
,
1302 * object_property_parse:
1304 * @string: the string that will be used to parse the property value.
1305 * @name: the name of the property
1306 * @errp: returns an error if this function fails
1308 * Parses a string and writes the result into a property of an object.
1310 void object_property_parse(Object
*obj
, const char *string
,
1311 const char *name
, Error
**errp
);
1314 * object_property_print:
1316 * @name: the name of the property
1317 * @human: if true, print for human consumption
1318 * @errp: returns an error if this function fails
1320 * Returns a string representation of the value of the property. The
1321 * caller shall free the string.
1323 char *object_property_print(Object
*obj
, const char *name
, bool human
,
1327 * object_property_get_type:
1329 * @name: the name of the property
1330 * @errp: returns an error if this function fails
1332 * Returns: The type name of the property.
1334 const char *object_property_get_type(Object
*obj
, const char *name
,
1340 * Returns: the root object of the composition tree
1342 Object
*object_get_root(void);
1346 * object_get_objects_root:
1348 * Get the container object that holds user created
1349 * object instances. This is the object at path
1352 * Returns: the user object container
1354 Object
*object_get_objects_root(void);
1357 * object_get_internal_root:
1359 * Get the container object that holds internally used object
1360 * instances. Any object which is put into this container must not be
1361 * user visible, and it will not be exposed in the QOM tree.
1363 * Returns: the internal object container
1365 Object
*object_get_internal_root(void);
1368 * object_get_canonical_path_component:
1370 * Returns: The final component in the object's canonical path. The canonical
1371 * path is the path within the composition tree starting from the root.
1372 * %NULL if the object doesn't have a parent (and thus a canonical path).
1374 gchar
*object_get_canonical_path_component(Object
*obj
);
1377 * object_get_canonical_path:
1379 * Returns: The canonical path for a object. This is the path within the
1380 * composition tree starting from the root.
1382 gchar
*object_get_canonical_path(Object
*obj
);
1385 * object_resolve_path:
1386 * @path: the path to resolve
1387 * @ambiguous: returns true if the path resolution failed because of an
1390 * There are two types of supported paths--absolute paths and partial paths.
1392 * Absolute paths are derived from the root object and can follow child<> or
1393 * link<> properties. Since they can follow link<> properties, they can be
1394 * arbitrarily long. Absolute paths look like absolute filenames and are
1395 * prefixed with a leading slash.
1397 * Partial paths look like relative filenames. They do not begin with a
1398 * prefix. The matching rules for partial paths are subtle but designed to make
1399 * specifying objects easy. At each level of the composition tree, the partial
1400 * path is matched as an absolute path. The first match is not returned. At
1401 * least two matches are searched for. A successful result is only returned if
1402 * only one match is found. If more than one match is found, a flag is
1403 * returned to indicate that the match was ambiguous.
1405 * Returns: The matched object or NULL on path lookup failure.
1407 Object
*object_resolve_path(const char *path
, bool *ambiguous
);
1410 * object_resolve_path_type:
1411 * @path: the path to resolve
1412 * @typename: the type to look for.
1413 * @ambiguous: returns true if the path resolution failed because of an
1416 * This is similar to object_resolve_path. However, when looking for a
1417 * partial path only matches that implement the given type are considered.
1418 * This restricts the search and avoids spuriously flagging matches as
1421 * For both partial and absolute paths, the return value goes through
1422 * a dynamic cast to @typename. This is important if either the link,
1423 * or the typename itself are of interface types.
1425 * Returns: The matched object or NULL on path lookup failure.
1427 Object
*object_resolve_path_type(const char *path
, const char *typename
,
1431 * object_resolve_path_component:
1432 * @parent: the object in which to resolve the path
1433 * @part: the component to resolve.
1435 * This is similar to object_resolve_path with an absolute path, but it
1436 * only resolves one element (@part) and takes the others from @parent.
1438 * Returns: The resolved object or NULL on path lookup failure.
1440 Object
*object_resolve_path_component(Object
*parent
, const gchar
*part
);
1443 * object_property_add_child:
1444 * @obj: the object to add a property to
1445 * @name: the name of the property
1446 * @child: the child object
1447 * @errp: if an error occurs, a pointer to an area to store the error
1449 * Child properties form the composition tree. All objects need to be a child
1450 * of another object. Objects can only be a child of one object.
1452 * There is no way for a child to determine what its parent is. It is not
1453 * a bidirectional relationship. This is by design.
1455 * The value of a child property as a C string will be the child object's
1456 * canonical path. It can be retrieved using object_property_get_str().
1457 * The child object itself can be retrieved using object_property_get_link().
1459 void object_property_add_child(Object
*obj
, const char *name
,
1460 Object
*child
, Error
**errp
);
1463 /* Unref the link pointer when the property is deleted */
1464 OBJ_PROP_LINK_STRONG
= 0x1,
1465 } ObjectPropertyLinkFlags
;
1468 * object_property_allow_set_link:
1470 * The default implementation of the object_property_add_link() check()
1471 * callback function. It allows the link property to be set and never returns
1474 void object_property_allow_set_link(const Object
*, const char *,
1475 Object
*, Error
**);
1478 * object_property_add_link:
1479 * @obj: the object to add a property to
1480 * @name: the name of the property
1481 * @type: the qobj type of the link
1482 * @child: a pointer to where the link object reference is stored
1483 * @check: callback to veto setting or NULL if the property is read-only
1484 * @flags: additional options for the link
1485 * @errp: if an error occurs, a pointer to an area to store the error
1487 * Links establish relationships between objects. Links are unidirectional
1488 * although two links can be combined to form a bidirectional relationship
1491 * Links form the graph in the object model.
1493 * The <code>@check()</code> callback is invoked when
1494 * object_property_set_link() is called and can raise an error to prevent the
1495 * link being set. If <code>@check</code> is NULL, the property is read-only
1496 * and cannot be set.
1498 * Ownership of the pointer that @child points to is transferred to the
1499 * link property. The reference count for <code>*@child</code> is
1500 * managed by the property from after the function returns till the
1501 * property is deleted with object_property_del(). If the
1502 * <code>@flags</code> <code>OBJ_PROP_LINK_STRONG</code> bit is set,
1503 * the reference count is decremented when the property is deleted or
1506 void object_property_add_link(Object
*obj
, const char *name
,
1507 const char *type
, Object
**child
,
1508 void (*check
)(const Object
*obj
, const char *name
,
1509 Object
*val
, Error
**errp
),
1510 ObjectPropertyLinkFlags flags
,
1514 * object_property_add_str:
1515 * @obj: the object to add a property to
1516 * @name: the name of the property
1517 * @get: the getter or NULL if the property is write-only. This function must
1518 * return a string to be freed by g_free().
1519 * @set: the setter or NULL if the property is read-only
1520 * @errp: if an error occurs, a pointer to an area to store the error
1522 * Add a string property using getters/setters. This function will add a
1523 * property of type 'string'.
1525 void object_property_add_str(Object
*obj
, const char *name
,
1526 char *(*get
)(Object
*, Error
**),
1527 void (*set
)(Object
*, const char *, Error
**),
1530 void object_class_property_add_str(ObjectClass
*klass
, const char *name
,
1531 char *(*get
)(Object
*, Error
**),
1532 void (*set
)(Object
*, const char *,
1537 * object_property_add_bool:
1538 * @obj: the object to add a property to
1539 * @name: the name of the property
1540 * @get: the getter or NULL if the property is write-only.
1541 * @set: the setter or NULL if the property is read-only
1542 * @errp: if an error occurs, a pointer to an area to store the error
1544 * Add a bool property using getters/setters. This function will add a
1545 * property of type 'bool'.
1547 void object_property_add_bool(Object
*obj
, const char *name
,
1548 bool (*get
)(Object
*, Error
**),
1549 void (*set
)(Object
*, bool, Error
**),
1552 void object_class_property_add_bool(ObjectClass
*klass
, const char *name
,
1553 bool (*get
)(Object
*, Error
**),
1554 void (*set
)(Object
*, bool, Error
**),
1558 * object_property_add_enum:
1559 * @obj: the object to add a property to
1560 * @name: the name of the property
1561 * @typename: the name of the enum data type
1562 * @get: the getter or %NULL if the property is write-only.
1563 * @set: the setter or %NULL if the property is read-only
1564 * @errp: if an error occurs, a pointer to an area to store the error
1566 * Add an enum property using getters/setters. This function will add a
1567 * property of type '@typename'.
1569 void object_property_add_enum(Object
*obj
, const char *name
,
1570 const char *typename
,
1571 const QEnumLookup
*lookup
,
1572 int (*get
)(Object
*, Error
**),
1573 void (*set
)(Object
*, int, Error
**),
1576 void object_class_property_add_enum(ObjectClass
*klass
, const char *name
,
1577 const char *typename
,
1578 const QEnumLookup
*lookup
,
1579 int (*get
)(Object
*, Error
**),
1580 void (*set
)(Object
*, int, Error
**),
1584 * object_property_add_tm:
1585 * @obj: the object to add a property to
1586 * @name: the name of the property
1587 * @get: the getter or NULL if the property is write-only.
1588 * @errp: if an error occurs, a pointer to an area to store the error
1590 * Add a read-only struct tm valued property using a getter function.
1591 * This function will add a property of type 'struct tm'.
1593 void object_property_add_tm(Object
*obj
, const char *name
,
1594 void (*get
)(Object
*, struct tm
*, Error
**),
1597 void object_class_property_add_tm(ObjectClass
*klass
, const char *name
,
1598 void (*get
)(Object
*, struct tm
*, Error
**),
1602 * object_property_add_uint8_ptr:
1603 * @obj: the object to add a property to
1604 * @name: the name of the property
1605 * @v: pointer to value
1606 * @errp: if an error occurs, a pointer to an area to store the error
1608 * Add an integer property in memory. This function will add a
1609 * property of type 'uint8'.
1611 void object_property_add_uint8_ptr(Object
*obj
, const char *name
,
1612 const uint8_t *v
, Error
**errp
);
1613 void object_class_property_add_uint8_ptr(ObjectClass
*klass
, const char *name
,
1614 const uint8_t *v
, Error
**errp
);
1617 * object_property_add_uint16_ptr:
1618 * @obj: the object to add a property to
1619 * @name: the name of the property
1620 * @v: pointer to value
1621 * @errp: if an error occurs, a pointer to an area to store the error
1623 * Add an integer property in memory. This function will add a
1624 * property of type 'uint16'.
1626 void object_property_add_uint16_ptr(Object
*obj
, const char *name
,
1627 const uint16_t *v
, Error
**errp
);
1628 void object_class_property_add_uint16_ptr(ObjectClass
*klass
, const char *name
,
1629 const uint16_t *v
, Error
**errp
);
1632 * object_property_add_uint32_ptr:
1633 * @obj: the object to add a property to
1634 * @name: the name of the property
1635 * @v: pointer to value
1636 * @errp: if an error occurs, a pointer to an area to store the error
1638 * Add an integer property in memory. This function will add a
1639 * property of type 'uint32'.
1641 void object_property_add_uint32_ptr(Object
*obj
, const char *name
,
1642 const uint32_t *v
, Error
**errp
);
1643 void object_class_property_add_uint32_ptr(ObjectClass
*klass
, const char *name
,
1644 const uint32_t *v
, Error
**errp
);
1647 * object_property_add_uint64_ptr:
1648 * @obj: the object to add a property to
1649 * @name: the name of the property
1650 * @v: pointer to value
1651 * @errp: if an error occurs, a pointer to an area to store the error
1653 * Add an integer property in memory. This function will add a
1654 * property of type 'uint64'.
1656 void object_property_add_uint64_ptr(Object
*obj
, const char *name
,
1657 const uint64_t *v
, Error
**Errp
);
1658 void object_class_property_add_uint64_ptr(ObjectClass
*klass
, const char *name
,
1659 const uint64_t *v
, Error
**Errp
);
1662 * object_property_add_alias:
1663 * @obj: the object to add a property to
1664 * @name: the name of the property
1665 * @target_obj: the object to forward property access to
1666 * @target_name: the name of the property on the forwarded object
1667 * @errp: if an error occurs, a pointer to an area to store the error
1669 * Add an alias for a property on an object. This function will add a property
1670 * of the same type as the forwarded property.
1672 * The caller must ensure that <code>@target_obj</code> stays alive as long as
1673 * this property exists. In the case of a child object or an alias on the same
1674 * object this will be the case. For aliases to other objects the caller is
1675 * responsible for taking a reference.
1677 void object_property_add_alias(Object
*obj
, const char *name
,
1678 Object
*target_obj
, const char *target_name
,
1682 * object_property_add_const_link:
1683 * @obj: the object to add a property to
1684 * @name: the name of the property
1685 * @target: the object to be referred by the link
1686 * @errp: if an error occurs, a pointer to an area to store the error
1688 * Add an unmodifiable link for a property on an object. This function will
1689 * add a property of type link<TYPE> where TYPE is the type of @target.
1691 * The caller must ensure that @target stays alive as long as
1692 * this property exists. In the case @target is a child of @obj,
1693 * this will be the case. Otherwise, the caller is responsible for
1694 * taking a reference.
1696 void object_property_add_const_link(Object
*obj
, const char *name
,
1697 Object
*target
, Error
**errp
);
1700 * object_property_set_description:
1701 * @obj: the object owning the property
1702 * @name: the name of the property
1703 * @description: the description of the property on the object
1704 * @errp: if an error occurs, a pointer to an area to store the error
1706 * Set an object property's description.
1709 void object_property_set_description(Object
*obj
, const char *name
,
1710 const char *description
, Error
**errp
);
1711 void object_class_property_set_description(ObjectClass
*klass
, const char *name
,
1712 const char *description
,
1716 * object_child_foreach:
1717 * @obj: the object whose children will be navigated
1718 * @fn: the iterator function to be called
1719 * @opaque: an opaque value that will be passed to the iterator
1721 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1724 * It is forbidden to add or remove children from @obj from the @fn
1727 * Returns: The last value returned by @fn, or 0 if there is no child.
1729 int object_child_foreach(Object
*obj
, int (*fn
)(Object
*child
, void *opaque
),
1733 * object_child_foreach_recursive:
1734 * @obj: the object whose children will be navigated
1735 * @fn: the iterator function to be called
1736 * @opaque: an opaque value that will be passed to the iterator
1738 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1739 * non-zero. Calls recursively, all child nodes of @obj will also be passed
1740 * all the way down to the leaf nodes of the tree. Depth first ordering.
1742 * It is forbidden to add or remove children from @obj (or its
1743 * child nodes) from the @fn callback.
1745 * Returns: The last value returned by @fn, or 0 if there is no child.
1747 int object_child_foreach_recursive(Object
*obj
,
1748 int (*fn
)(Object
*child
, void *opaque
),
1752 * @root: root of the #path, e.g., object_get_root()
1753 * @path: path to the container
1755 * Return a container object whose path is @path. Create more containers
1756 * along the path if necessary.
1758 * Returns: the container object.
1760 Object
*container_get(Object
*root
, const char *path
);
1763 * object_type_get_instance_size:
1764 * @typename: Name of the Type whose instance_size is required
1766 * Returns the instance_size of the given @typename.
1768 size_t object_type_get_instance_size(const char *typename
);