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.
20 #include "qemu-queue.h"
26 typedef struct TypeImpl
*Type
;
28 typedef struct ObjectClass ObjectClass
;
29 typedef struct Object Object
;
31 typedef struct TypeInfo TypeInfo
;
33 typedef struct InterfaceClass InterfaceClass
;
34 typedef struct InterfaceInfo InterfaceInfo
;
36 #define TYPE_OBJECT "object"
40 * @title:Base Object Type System
41 * @short_description: interfaces for creating new types and objects
43 * The QEMU Object Model provides a framework for registering user creatable
44 * types and instantiating objects from those types. QOM provides the following
47 * - System for dynamically registering types
48 * - Support for single-inheritance of types
49 * - Multiple inheritance of stateless interfaces
52 * <title>Creating a minimal type</title>
56 * #define TYPE_MY_DEVICE "my-device"
58 * // No new virtual functions: we can reuse the typedef for the
60 * typedef DeviceClass MyDeviceClass;
61 * typedef struct MyDevice
65 * int reg0, reg1, reg2;
68 * static TypeInfo my_device_info = {
69 * .name = TYPE_MY_DEVICE,
70 * .parent = TYPE_DEVICE,
71 * .instance_size = sizeof(MyDevice),
74 * static void my_device_register_types(void)
76 * type_register_static(&my_device_info);
79 * type_init(my_device_register_types)
83 * In the above example, we create a simple type that is described by #TypeInfo.
84 * #TypeInfo describes information about the type including what it inherits
85 * from, the instance and class size, and constructor/destructor hooks.
87 * Every type has an #ObjectClass associated with it. #ObjectClass derivatives
88 * are instantiated dynamically but there is only ever one instance for any
89 * given type. The #ObjectClass typically holds a table of function pointers
90 * for the virtual methods implemented by this type.
92 * Using object_new(), a new #Object derivative will be instantiated. You can
93 * cast an #Object to a subclass (or base-class) type using
94 * object_dynamic_cast(). You typically want to define macro wrappers around
95 * OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a
99 * <title>Typecasting macros</title>
101 * #define MY_DEVICE_GET_CLASS(obj) \
102 * OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE)
103 * #define MY_DEVICE_CLASS(klass) \
104 * OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE)
105 * #define MY_DEVICE(obj) \
106 * OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
110 * # Class Initialization #
112 * Before an object is initialized, the class for the object must be
113 * initialized. There is only one class object for all instance objects
114 * that is created lazily.
116 * Classes are initialized by first initializing any parent classes (if
117 * necessary). After the parent class object has initialized, it will be
118 * copied into the current class object and any additional storage in the
119 * class object is zero filled.
121 * The effect of this is that classes automatically inherit any virtual
122 * function pointers that the parent class has already initialized. All
123 * other fields will be zero filled.
125 * Once all of the parent classes have been initialized, #TypeInfo::class_init
126 * is called to let the class being instantiated provide default initialize for
127 * its virtual functions. Here is how the above example might be modified
128 * to introduce an overridden virtual function:
131 * <title>Overriding a virtual function</title>
135 * void my_device_class_init(ObjectClass *klass, void *class_data)
137 * DeviceClass *dc = DEVICE_CLASS(klass);
138 * dc->reset = my_device_reset;
141 * static TypeInfo my_device_info = {
142 * .name = TYPE_MY_DEVICE,
143 * .parent = TYPE_DEVICE,
144 * .instance_size = sizeof(MyDevice),
145 * .class_init = my_device_class_init,
150 * Introducing new virtual functions requires a class to define its own
151 * struct and to add a .class_size member to the TypeInfo. Each function
152 * will also have a wrapper to call it easily:
155 * <title>Defining an abstract class</title>
159 * typedef struct MyDeviceClass
161 * DeviceClass parent;
163 * void (*frobnicate) (MyDevice *obj);
166 * static TypeInfo my_device_info = {
167 * .name = TYPE_MY_DEVICE,
168 * .parent = TYPE_DEVICE,
169 * .instance_size = sizeof(MyDevice),
170 * .abstract = true, // or set a default in my_device_class_init
171 * .class_size = sizeof(MyDeviceClass),
174 * void my_device_frobnicate(MyDevice *obj)
176 * MyDeviceClass *klass = MY_DEVICE_GET_CLASS(obj);
178 * klass->frobnicate(obj);
185 * Interfaces allow a limited form of multiple inheritance. Instances are
186 * similar to normal types except for the fact that are only defined by
187 * their classes and never carry any state. You can dynamically cast an object
188 * to one of its #Interface types and vice versa.
193 * ObjectPropertyAccessor:
194 * @obj: the object that owns the property
195 * @v: the visitor that contains the property data
196 * @opaque: the object property opaque
197 * @name: the name of the property
198 * @errp: a pointer to an Error that is filled if getting/setting fails.
200 * Called when trying to get/set a property.
202 typedef void (ObjectPropertyAccessor
)(Object
*obj
,
206 struct Error
**errp
);
209 * ObjectPropertyRelease:
210 * @obj: the object that owns the property
211 * @name: the name of the property
212 * @opaque: the opaque registered with the property
214 * Called when a property is removed from a object.
216 typedef void (ObjectPropertyRelease
)(Object
*obj
,
220 typedef struct ObjectProperty
224 ObjectPropertyAccessor
*get
;
225 ObjectPropertyAccessor
*set
;
226 ObjectPropertyRelease
*release
;
229 QTAILQ_ENTRY(ObjectProperty
) node
;
235 * The base for all classes. The only thing that #ObjectClass contains is an
236 * integer type handle.
247 * The base for all objects. The first member of this object is a pointer to
248 * a #ObjectClass. Since C guarantees that the first member of a structure
249 * always begins at byte 0 of that structure, as long as any sub-object places
250 * its parent as the first member, we can cast directly to a #Object.
252 * As a result, #Object contains a reference to the objects type as its
253 * first member. This allows identification of the real type of the object at
256 * #Object also contains a list of #Interfaces that this object
264 QTAILQ_HEAD(, ObjectProperty
) properties
;
271 * @name: The name of the type.
272 * @parent: The name of the parent type.
273 * @instance_size: The size of the object (derivative of #Object). If
274 * @instance_size is 0, then the size of the object will be the size of the
276 * @instance_init: This function is called to initialize an object. The parent
277 * class will have already been initialized so the type is only responsible
278 * for initializing its own members.
279 * @instance_finalize: This function is called during object destruction. This
280 * is called before the parent @instance_finalize function has been called.
281 * An object should only free the members that are unique to its type in this
283 * @abstract: If this field is true, then the class is considered abstract and
284 * cannot be directly instantiated.
285 * @class_size: The size of the class object (derivative of #ObjectClass)
286 * for this object. If @class_size is 0, then the size of the class will be
287 * assumed to be the size of the parent class. This allows a type to avoid
288 * implementing an explicit class type if they are not adding additional
290 * @class_init: This function is called after all parent class initialization
291 * has occurred to allow a class to set its default virtual method pointers.
292 * This is also the function to use to override virtual methods from a parent
294 * @class_base_init: This function is called for all base classes after all
295 * parent class initialization has occurred, but before the class itself
296 * is initialized. This is the function to use to undo the effects of
297 * memcpy from the parent class to the descendents.
298 * @class_finalize: This function is called during class destruction and is
299 * meant to release and dynamic parameters allocated by @class_init.
300 * @class_data: Data to pass to the @class_init, @class_base_init and
301 * @class_finalize functions. This can be useful when building dynamic
303 * @interfaces: The list of interfaces associated with this type. This
304 * should point to a static array that's terminated with a zero filled
312 size_t instance_size
;
313 void (*instance_init
)(Object
*obj
);
314 void (*instance_finalize
)(Object
*obj
);
319 void (*class_init
)(ObjectClass
*klass
, void *data
);
320 void (*class_base_init
)(ObjectClass
*klass
, void *data
);
321 void (*class_finalize
)(ObjectClass
*klass
, void *data
);
324 InterfaceInfo
*interfaces
;
329 * @obj: A derivative of #Object
331 * Converts an object to a #Object. Since all objects are #Objects,
332 * this function will always succeed.
334 #define OBJECT(obj) \
339 * @class: A derivative of #ObjectClass.
341 * Converts a class to an #ObjectClass. Since all objects are #Objects,
342 * this function will always succeed.
344 #define OBJECT_CLASS(class) \
345 ((ObjectClass *)(class))
349 * @type: The C type to use for the return value.
350 * @obj: A derivative of @type to cast.
351 * @name: The QOM typename of @type
353 * A type safe version of @object_dynamic_cast_assert. Typically each class
354 * will define a macro based on this type to perform type safe dynamic_casts to
357 * If an invalid object is passed to this function, a run time assert will be
360 #define OBJECT_CHECK(type, obj, name) \
361 ((type *)object_dynamic_cast_assert(OBJECT(obj), (name)))
364 * OBJECT_CLASS_CHECK:
365 * @class: The C type to use for the return value.
366 * @obj: A derivative of @type to cast.
367 * @name: the QOM typename of @class.
369 * A type safe version of @object_class_dynamic_cast_assert. This macro is
370 * typically wrapped by each type to perform type safe casts of a class to a
371 * specific class type.
373 #define OBJECT_CLASS_CHECK(class, obj, name) \
374 ((class *)object_class_dynamic_cast_assert(OBJECT_CLASS(obj), (name)))
378 * @class: The C type to use for the return value.
379 * @obj: The object to obtain the class for.
380 * @name: The QOM typename of @obj.
382 * This function will return a specific class for a given object. Its generally
383 * used by each type to provide a type safe macro to get a specific class type
386 #define OBJECT_GET_CLASS(class, obj, name) \
387 OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
391 * @parent_class: the base class
393 * The class for all interfaces. Subclasses of this class should only add
396 struct InterfaceClass
398 ObjectClass parent_class
;
403 * @type: The name of the interface.
404 * @interface_initfn: This method is called during class initialization and is
405 * used to initialize an interface associated with a class. This function
406 * should initialize any default virtual functions for a class and/or override
407 * virtual functions in a parent class.
409 * The information associated with an interface.
415 void (*interface_initfn
)(ObjectClass
*class, void *data
);
418 #define TYPE_INTERFACE "interface"
422 * @typename: The name of the type of the object to instantiate.
424 * This function will initialize a new object using heap allocated memory. This
425 * function should be paired with object_delete() to free the resources
426 * associated with the object.
428 * Returns: The newly allocated and instantiated object.
430 Object
*object_new(const char *typename
);
433 * object_new_with_type:
434 * @type: The type of the object to instantiate.
436 * This function will initialize a new object using heap allocated memory. This
437 * function should be paired with object_delete() to free the resources
438 * associated with the object.
440 * Returns: The newly allocated and instantiated object.
442 Object
*object_new_with_type(Type type
);
446 * @obj: The object to free.
448 * Finalize an object and then free the memory associated with it. This should
449 * be paired with object_new() to free the resources associated with an object.
451 void object_delete(Object
*obj
);
454 * object_initialize_with_type:
455 * @obj: A pointer to the memory to be used for the object.
456 * @type: The type of the object to instantiate.
458 * This function will initialize an object. The memory for the object should
459 * have already been allocated.
461 void object_initialize_with_type(void *data
, Type type
);
465 * @obj: A pointer to the memory to be used for the object.
466 * @typename: The name of the type of the object to instantiate.
468 * This function will initialize an object. The memory for the object should
469 * have already been allocated.
471 void object_initialize(void *obj
, const char *typename
);
475 * @obj: The object to finalize.
477 * This function destroys and object without freeing the memory associated with
480 void object_finalize(void *obj
);
483 * object_dynamic_cast:
484 * @obj: The object to cast.
485 * @typename: The @typename to cast to.
487 * This function will determine if @obj is-a @typename. @obj can refer to an
488 * object or an interface associated with an object.
490 * Returns: This function returns @obj on success or #NULL on failure.
492 Object
*object_dynamic_cast(Object
*obj
, const char *typename
);
495 * object_dynamic_cast_assert:
497 * See object_dynamic_cast() for a description of the parameters of this
498 * function. The only difference in behavior is that this function asserts
499 * instead of returning #NULL on failure.
501 Object
*object_dynamic_cast_assert(Object
*obj
, const char *typename
);
505 * @obj: A derivative of #Object
507 * Returns: The #ObjectClass of the type associated with @obj.
509 ObjectClass
*object_get_class(Object
*obj
);
512 * object_get_typename:
513 * @obj: A derivative of #Object.
515 * Returns: The QOM typename of @obj.
517 const char *object_get_typename(Object
*obj
);
520 * type_register_static:
521 * @info: The #TypeInfo of the new type.
523 * @info and all of the strings it points to should exist for the life time
524 * that the type is registered.
526 * Returns: 0 on failure, the new #Type on success.
528 Type
type_register_static(const TypeInfo
*info
);
532 * @info: The #TypeInfo of the new type
534 * Unlike type_register_static(), this call does not require @info or its
535 * string members to continue to exist after the call returns.
537 * Returns: 0 on failure, the new #Type on success.
539 Type
type_register(const TypeInfo
*info
);
542 * object_class_dynamic_cast_assert:
543 * @klass: The #ObjectClass to attempt to cast.
544 * @typename: The QOM typename of the class to cast to.
546 * Returns: This function always returns @klass and asserts on failure.
548 ObjectClass
*object_class_dynamic_cast_assert(ObjectClass
*klass
,
549 const char *typename
);
551 ObjectClass
*object_class_dynamic_cast(ObjectClass
*klass
,
552 const char *typename
);
555 * object_class_get_parent:
556 * @klass: The class to obtain the parent for.
558 * Returns: The parent for @klass or %NULL if none.
560 ObjectClass
*object_class_get_parent(ObjectClass
*klass
);
563 * object_class_get_name:
564 * @klass: The class to obtain the QOM typename for.
566 * Returns: The QOM typename for @klass.
568 const char *object_class_get_name(ObjectClass
*klass
);
571 * object_class_by_name:
572 * @typename: The QOM typename to obtain the class for.
574 * Returns: The class for @typename or %NULL if not found.
576 ObjectClass
*object_class_by_name(const char *typename
);
578 void object_class_foreach(void (*fn
)(ObjectClass
*klass
, void *opaque
),
579 const char *implements_type
, bool include_abstract
,
583 * object_class_get_list:
584 * @implements_type: The type to filter for, including its derivatives.
585 * @include_abstract: Whether to include abstract classes.
587 * Returns: A singly-linked list of the classes in reverse hashtable order.
589 GSList
*object_class_get_list(const char *implements_type
,
590 bool include_abstract
);
596 * Increase the reference count of a object. A object cannot be freed as long
597 * as its reference count is greater than zero.
599 void object_ref(Object
*obj
);
605 * Decrease the reference count of a object. A object cannot be freed as long
606 * as its reference count is greater than zero.
608 void object_unref(Object
*obj
);
611 * object_property_add:
612 * @obj: the object to add a property to
613 * @name: the name of the property. This can contain any character except for
614 * a forward slash. In general, you should use hyphens '-' instead of
615 * underscores '_' when naming properties.
616 * @type: the type name of the property. This namespace is pretty loosely
617 * defined. Sub namespaces are constructed by using a prefix and then
618 * to angle brackets. For instance, the type 'virtio-net-pci' in the
619 * 'link' namespace would be 'link<virtio-net-pci>'.
620 * @get: The getter to be called to read a property. If this is NULL, then
621 * the property cannot be read.
622 * @set: the setter to be called to write a property. If this is NULL,
623 * then the property cannot be written.
624 * @release: called when the property is removed from the object. This is
625 * meant to allow a property to free its opaque upon object
626 * destruction. This may be NULL.
627 * @opaque: an opaque pointer to pass to the callbacks for the property
628 * @errp: returns an error if this function fails
630 void object_property_add(Object
*obj
, const char *name
, const char *type
,
631 ObjectPropertyAccessor
*get
,
632 ObjectPropertyAccessor
*set
,
633 ObjectPropertyRelease
*release
,
634 void *opaque
, struct Error
**errp
);
636 void object_property_del(Object
*obj
, const char *name
, struct Error
**errp
);
639 * object_property_find:
641 * @name: the name of the property
642 * @errp: returns an error if this function fails
644 * Look up a property for an object and return its #ObjectProperty if found.
646 ObjectProperty
*object_property_find(Object
*obj
, const char *name
,
647 struct Error
**errp
);
649 void object_unparent(Object
*obj
);
652 * object_property_get:
654 * @v: the visitor that will receive the property value. This should be an
655 * Output visitor and the data will be written with @name as the name.
656 * @name: the name of the property
657 * @errp: returns an error if this function fails
659 * Reads a property from a object.
661 void object_property_get(Object
*obj
, struct Visitor
*v
, const char *name
,
662 struct Error
**errp
);
665 * object_property_set_str:
666 * @value: the value to be written to the property
667 * @name: the name of the property
668 * @errp: returns an error if this function fails
670 * Writes a string value to a property.
672 void object_property_set_str(Object
*obj
, const char *value
,
673 const char *name
, struct Error
**errp
);
676 * object_property_get_str:
678 * @name: the name of the property
679 * @errp: returns an error if this function fails
681 * Returns: the value of the property, converted to a C string, or NULL if
682 * an error occurs (including when the property value is not a string).
683 * The caller should free the string.
685 char *object_property_get_str(Object
*obj
, const char *name
,
686 struct Error
**errp
);
689 * object_property_set_link:
690 * @value: the value to be written to the property
691 * @name: the name of the property
692 * @errp: returns an error if this function fails
694 * Writes an object's canonical path to a property.
696 void object_property_set_link(Object
*obj
, Object
*value
,
697 const char *name
, struct Error
**errp
);
700 * object_property_get_link:
702 * @name: the name of the property
703 * @errp: returns an error if this function fails
705 * Returns: the value of the property, resolved from a path to an Object,
706 * or NULL if an error occurs (including when the property value is not a
707 * string or not a valid object path).
709 Object
*object_property_get_link(Object
*obj
, const char *name
,
710 struct Error
**errp
);
713 * object_property_set_bool:
714 * @value: the value to be written to the property
715 * @name: the name of the property
716 * @errp: returns an error if this function fails
718 * Writes a bool value to a property.
720 void object_property_set_bool(Object
*obj
, bool value
,
721 const char *name
, struct Error
**errp
);
724 * object_property_get_bool:
726 * @name: the name of the property
727 * @errp: returns an error if this function fails
729 * Returns: the value of the property, converted to a boolean, or NULL if
730 * an error occurs (including when the property value is not a bool).
732 bool object_property_get_bool(Object
*obj
, const char *name
,
733 struct Error
**errp
);
736 * object_property_set_int:
737 * @value: the value to be written to the property
738 * @name: the name of the property
739 * @errp: returns an error if this function fails
741 * Writes an integer value to a property.
743 void object_property_set_int(Object
*obj
, int64_t value
,
744 const char *name
, struct Error
**errp
);
747 * object_property_get_int:
749 * @name: the name of the property
750 * @errp: returns an error if this function fails
752 * Returns: the value of the property, converted to an integer, or NULL if
753 * an error occurs (including when the property value is not an integer).
755 int64_t object_property_get_int(Object
*obj
, const char *name
,
756 struct Error
**errp
);
759 * object_property_set:
761 * @v: the visitor that will be used to write the property value. This should
762 * be an Input visitor and the data will be first read with @name as the
763 * name and then written as the property value.
764 * @name: the name of the property
765 * @errp: returns an error if this function fails
767 * Writes a property to a object.
769 void object_property_set(Object
*obj
, struct Visitor
*v
, const char *name
,
770 struct Error
**errp
);
773 * object_property_parse:
775 * @string: the string that will be used to parse the property value.
776 * @name: the name of the property
777 * @errp: returns an error if this function fails
779 * Parses a string and writes the result into a property of an object.
781 void object_property_parse(Object
*obj
, const char *string
,
782 const char *name
, struct Error
**errp
);
785 * object_property_print:
787 * @name: the name of the property
788 * @errp: returns an error if this function fails
790 * Returns a string representation of the value of the property. The
791 * caller shall free the string.
793 char *object_property_print(Object
*obj
, const char *name
,
794 struct Error
**errp
);
797 * object_property_get_type:
799 * @name: the name of the property
800 * @errp: returns an error if this function fails
802 * Returns: The type name of the property.
804 const char *object_property_get_type(Object
*obj
, const char *name
,
805 struct Error
**errp
);
810 * Returns: the root object of the composition tree
812 Object
*object_get_root(void);
815 * object_get_canonical_path:
817 * Returns: The canonical path for a object. This is the path within the
818 * composition tree starting from the root.
820 gchar
*object_get_canonical_path(Object
*obj
);
823 * object_resolve_path:
824 * @path: the path to resolve
825 * @ambiguous: returns true if the path resolution failed because of an
828 * There are two types of supported paths--absolute paths and partial paths.
830 * Absolute paths are derived from the root object and can follow child<> or
831 * link<> properties. Since they can follow link<> properties, they can be
832 * arbitrarily long. Absolute paths look like absolute filenames and are
833 * prefixed with a leading slash.
835 * Partial paths look like relative filenames. They do not begin with a
836 * prefix. The matching rules for partial paths are subtle but designed to make
837 * specifying objects easy. At each level of the composition tree, the partial
838 * path is matched as an absolute path. The first match is not returned. At
839 * least two matches are searched for. A successful result is only returned if
840 * only one match is found. If more than one match is found, a flag is
841 * returned to indicate that the match was ambiguous.
843 * Returns: The matched object or NULL on path lookup failure.
845 Object
*object_resolve_path(const char *path
, bool *ambiguous
);
848 * object_resolve_path_type:
849 * @path: the path to resolve
850 * @typename: the type to look for.
851 * @ambiguous: returns true if the path resolution failed because of an
854 * This is similar to object_resolve_path. However, when looking for a
855 * partial path only matches that implement the given type are considered.
856 * This restricts the search and avoids spuriously flagging matches as
859 * For both partial and absolute paths, the return value goes through
860 * a dynamic cast to @typename. This is important if either the link,
861 * or the typename itself are of interface types.
863 * Returns: The matched object or NULL on path lookup failure.
865 Object
*object_resolve_path_type(const char *path
, const char *typename
,
869 * object_resolve_path_component:
870 * @parent: the object in which to resolve the path
871 * @part: the component to resolve.
873 * This is similar to object_resolve_path with an absolute path, but it
874 * only resolves one element (@part) and takes the others from @parent.
876 * Returns: The resolved object or NULL on path lookup failure.
878 Object
*object_resolve_path_component(Object
*parent
, gchar
*part
);
881 * object_property_add_child:
882 * @obj: the object to add a property to
883 * @name: the name of the property
884 * @child: the child object
885 * @errp: if an error occurs, a pointer to an area to store the area
887 * Child properties form the composition tree. All objects need to be a child
888 * of another object. Objects can only be a child of one object.
890 * There is no way for a child to determine what its parent is. It is not
891 * a bidirectional relationship. This is by design.
893 * The value of a child property as a C string will be the child object's
894 * canonical path. It can be retrieved using object_property_get_str().
895 * The child object itself can be retrieved using object_property_get_link().
897 void object_property_add_child(Object
*obj
, const char *name
,
898 Object
*child
, struct Error
**errp
);
901 * object_property_add_link:
902 * @obj: the object to add a property to
903 * @name: the name of the property
904 * @type: the qobj type of the link
905 * @child: a pointer to where the link object reference is stored
906 * @errp: if an error occurs, a pointer to an area to store the area
908 * Links establish relationships between objects. Links are unidirectional
909 * although two links can be combined to form a bidirectional relationship
912 * Links form the graph in the object model.
914 void object_property_add_link(Object
*obj
, const char *name
,
915 const char *type
, Object
**child
,
916 struct Error
**errp
);
919 * object_property_add_str:
920 * @obj: the object to add a property to
921 * @name: the name of the property
922 * @get: the getter or NULL if the property is write-only. This function must
923 * return a string to be freed by g_free().
924 * @set: the setter or NULL if the property is read-only
925 * @errp: if an error occurs, a pointer to an area to store the error
927 * Add a string property using getters/setters. This function will add a
928 * property of type 'string'.
930 void object_property_add_str(Object
*obj
, const char *name
,
931 char *(*get
)(Object
*, struct Error
**),
932 void (*set
)(Object
*, const char *, struct Error
**),
933 struct Error
**errp
);
936 * object_child_foreach:
937 * @obj: the object whose children will be navigated
938 * @fn: the iterator function to be called
939 * @opaque: an opaque value that will be passed to the iterator
941 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
944 * Returns: The last value returned by @fn, or 0 if there is no child.
946 int object_child_foreach(Object
*obj
, int (*fn
)(Object
*child
, void *opaque
),
951 * @root: root of the #path, e.g., object_get_root()
952 * @path: path to the container
954 * Return a container object whose path is @path. Create more containers
955 * along the path if necessary.
957 * Returns: the container object.
959 Object
*container_get(Object
*root
, const char *path
);