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 TypeInfo TypeInfo
;
25 typedef struct InterfaceClass InterfaceClass
;
26 typedef struct InterfaceInfo InterfaceInfo
;
28 #define TYPE_OBJECT "object"
29 #define TYPE_CONTAINER "container"
31 typedef struct ObjectProperty ObjectProperty
;
34 * typedef ObjectPropertyAccessor:
35 * @obj: the object that owns the property
36 * @v: the visitor that contains the property data
37 * @name: the name of the property
38 * @opaque: the object property opaque
39 * @errp: a pointer to an Error that is filled if getting/setting fails.
41 * Called when trying to get/set a property.
43 typedef void (ObjectPropertyAccessor
)(Object
*obj
,
50 * typedef ObjectPropertyResolve:
51 * @obj: the object that owns the property
52 * @opaque: the opaque registered with the property
53 * @part: the name of the property
55 * Resolves the #Object corresponding to property @part.
57 * The returned object can also be used as a starting point
58 * to resolve a relative path starting with "@part".
60 * Returns: If @path is the path that led to @obj, the function
61 * returns the #Object corresponding to "@path/@part".
62 * If "@path/@part" is not a valid object path, it returns #NULL.
64 typedef Object
*(ObjectPropertyResolve
)(Object
*obj
,
69 * typedef ObjectPropertyRelease:
70 * @obj: the object that owns the property
71 * @name: the name of the property
72 * @opaque: the opaque registered with the property
74 * Called when a property is removed from a object.
76 typedef void (ObjectPropertyRelease
)(Object
*obj
,
81 * typedef ObjectPropertyInit:
82 * @obj: the object that owns the property
83 * @prop: the property to set
85 * Called when a property is initialized.
87 typedef void (ObjectPropertyInit
)(Object
*obj
, ObjectProperty
*prop
);
94 ObjectPropertyAccessor
*get
;
95 ObjectPropertyAccessor
*set
;
96 ObjectPropertyResolve
*resolve
;
97 ObjectPropertyRelease
*release
;
98 ObjectPropertyInit
*init
;
104 * typedef ObjectUnparent:
105 * @obj: the object that is being removed from the composition tree
107 * Called when an object is being removed from the QOM composition tree.
108 * The function should remove any backlinks from children objects to @obj.
110 typedef void (ObjectUnparent
)(Object
*obj
);
113 * typedef ObjectFree:
114 * @obj: the object being freed
116 * Called when an object's last reference is removed.
118 typedef void (ObjectFree
)(void *obj
);
120 #define OBJECT_CLASS_CAST_CACHE 4
123 * struct ObjectClass:
125 * The base for all classes. The only thing that #ObjectClass contains is an
126 * integer type handle.
134 const char *object_cast_cache
[OBJECT_CLASS_CAST_CACHE
];
135 const char *class_cast_cache
[OBJECT_CLASS_CAST_CACHE
];
137 ObjectUnparent
*unparent
;
139 GHashTable
*properties
;
145 * The base for all objects. The first member of this object is a pointer to
146 * a #ObjectClass. Since C guarantees that the first member of a structure
147 * always begins at byte 0 of that structure, as long as any sub-object places
148 * its parent as the first member, we can cast directly to a #Object.
150 * As a result, #Object contains a reference to the objects type as its
151 * first member. This allows identification of the real type of the object at
159 GHashTable
*properties
;
165 * DECLARE_INSTANCE_CHECKER:
166 * @InstanceType: instance struct name
167 * @OBJ_NAME: the object name in uppercase with underscore separators
168 * @TYPENAME: type name
170 * Direct usage of this macro should be avoided, and the complete
171 * OBJECT_DECLARE_TYPE macro is recommended instead.
173 * This macro will provide the instance type cast functions for a
176 #define DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \
177 static inline G_GNUC_UNUSED InstanceType * \
178 OBJ_NAME(const void *obj) \
179 { return OBJECT_CHECK(InstanceType, obj, TYPENAME); }
182 * DECLARE_CLASS_CHECKERS:
183 * @ClassType: class struct name
184 * @OBJ_NAME: the object name in uppercase with underscore separators
185 * @TYPENAME: type name
187 * Direct usage of this macro should be avoided, and the complete
188 * OBJECT_DECLARE_TYPE macro is recommended instead.
190 * This macro will provide the class type cast functions for a
193 #define DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME) \
194 static inline G_GNUC_UNUSED ClassType * \
195 OBJ_NAME##_GET_CLASS(const void *obj) \
196 { return OBJECT_GET_CLASS(ClassType, obj, TYPENAME); } \
198 static inline G_GNUC_UNUSED ClassType * \
199 OBJ_NAME##_CLASS(const void *klass) \
200 { return OBJECT_CLASS_CHECK(ClassType, klass, TYPENAME); }
203 * DECLARE_OBJ_CHECKERS:
204 * @InstanceType: instance struct name
205 * @ClassType: class struct name
206 * @OBJ_NAME: the object name in uppercase with underscore separators
207 * @TYPENAME: type name
209 * Direct usage of this macro should be avoided, and the complete
210 * OBJECT_DECLARE_TYPE macro is recommended instead.
212 * This macro will provide the three standard type cast functions for a
215 #define DECLARE_OBJ_CHECKERS(InstanceType, ClassType, OBJ_NAME, TYPENAME) \
216 DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \
218 DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME)
221 * OBJECT_DECLARE_TYPE:
222 * @InstanceType: instance struct name
223 * @ClassType: class struct name
224 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
226 * This macro is typically used in a header file, and will:
228 * - create the typedefs for the object and class structs
229 * - register the type for use with g_autoptr
230 * - provide three standard type cast functions
232 * The object struct and class struct need to be declared manually.
234 #define OBJECT_DECLARE_TYPE(InstanceType, ClassType, MODULE_OBJ_NAME) \
235 typedef struct InstanceType InstanceType; \
236 typedef struct ClassType ClassType; \
238 G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstanceType, object_unref) \
240 DECLARE_OBJ_CHECKERS(InstanceType, ClassType, \
241 MODULE_OBJ_NAME, TYPE_##MODULE_OBJ_NAME)
244 * OBJECT_DECLARE_SIMPLE_TYPE:
245 * @InstanceType: instance struct name
246 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
248 * This does the same as OBJECT_DECLARE_TYPE(), but with no class struct
251 * This macro should be used unless the class struct needs to have
252 * virtual methods declared.
254 #define OBJECT_DECLARE_SIMPLE_TYPE(InstanceType, MODULE_OBJ_NAME) \
255 typedef struct InstanceType InstanceType; \
257 G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstanceType, object_unref) \
259 DECLARE_INSTANCE_CHECKER(InstanceType, MODULE_OBJ_NAME, TYPE_##MODULE_OBJ_NAME)
263 * DO_OBJECT_DEFINE_TYPE_EXTENDED:
264 * @ModuleObjName: the object name with initial caps
265 * @module_obj_name: the object name in lowercase with underscore separators
266 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
267 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
269 * @ABSTRACT: boolean flag to indicate whether the object can be instantiated
270 * @CLASS_SIZE: size of the type's class
271 * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
273 * This is the base macro used to implement all the OBJECT_DEFINE_*
274 * macros. It should never be used directly in a source file.
276 #define DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
278 PARENT_MODULE_OBJ_NAME, \
279 ABSTRACT, CLASS_SIZE, ...) \
281 module_obj_name##_finalize(Object *obj); \
283 module_obj_name##_class_init(ObjectClass *oc, const void *data); \
285 module_obj_name##_init(Object *obj); \
287 static const TypeInfo module_obj_name##_info = { \
288 .parent = TYPE_##PARENT_MODULE_OBJ_NAME, \
289 .name = TYPE_##MODULE_OBJ_NAME, \
290 .instance_size = sizeof(ModuleObjName), \
291 .instance_align = __alignof__(ModuleObjName), \
292 .instance_init = module_obj_name##_init, \
293 .instance_finalize = module_obj_name##_finalize, \
294 .class_size = CLASS_SIZE, \
295 .class_init = module_obj_name##_class_init, \
296 .abstract = ABSTRACT, \
297 .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
301 module_obj_name##_register_types(void) \
303 type_register_static(&module_obj_name##_info); \
305 type_init(module_obj_name##_register_types);
308 * OBJECT_DEFINE_TYPE_EXTENDED:
309 * @ModuleObjName: the object name with initial caps
310 * @module_obj_name: the object name in lowercase with underscore separators
311 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
312 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
314 * @ABSTRACT: boolean flag to indicate whether the object can be instantiated
315 * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
317 * This macro is typically used in a source file, and will:
319 * - declare prototypes for _finalize, _class_init and _init methods
320 * - declare the TypeInfo struct instance
321 * - provide the constructor to register the type
323 * After using this macro, implementations of the _finalize, _class_init,
324 * and _init methods need to be written. Any of these can be zero-line
325 * no-op impls if no special logic is required for a given type.
327 * This macro should rarely be used, instead one of the more specialized
328 * macros is usually a better choice.
330 #define OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
331 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
333 DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
334 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
335 ABSTRACT, sizeof(ModuleObjName##Class), \
339 * OBJECT_DEFINE_TYPE:
340 * @ModuleObjName: the object name with initial caps
341 * @module_obj_name: the object name in lowercase with underscore separators
342 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
343 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
346 * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable
347 * for the common case of a non-abstract type, without any interfaces.
349 #define OBJECT_DEFINE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME, \
350 PARENT_MODULE_OBJ_NAME) \
351 OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
352 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
356 * OBJECT_DEFINE_TYPE_WITH_INTERFACES:
357 * @ModuleObjName: the object name with initial caps
358 * @module_obj_name: the object name in lowercase with underscore separators
359 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
360 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
362 * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
364 * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable
365 * for the common case of a non-abstract type, with one or more implemented
368 * Note when passing the list of interfaces, be sure to include the final
369 * NULL entry, e.g. { TYPE_USER_CREATABLE }, { NULL }
371 #define OBJECT_DEFINE_TYPE_WITH_INTERFACES(ModuleObjName, module_obj_name, \
373 PARENT_MODULE_OBJ_NAME, ...) \
374 OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
375 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
379 * OBJECT_DEFINE_ABSTRACT_TYPE:
380 * @ModuleObjName: the object name with initial caps
381 * @module_obj_name: the object name in lowercase with underscore separators
382 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
383 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
386 * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable
387 * for defining an abstract type, without any interfaces.
389 #define OBJECT_DEFINE_ABSTRACT_TYPE(ModuleObjName, module_obj_name, \
390 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME) \
391 OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
392 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
396 * OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES:
397 * @ModuleObjName: the object name with initial caps
398 * @module_obj_name: the object name in lowercase with underscore separators
399 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
400 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
403 * This is a variant of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable for
404 * the case of a non-abstract type, with interfaces, and with no requirement
405 * for a class struct.
407 #define OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(ModuleObjName, \
410 PARENT_MODULE_OBJ_NAME, ...) \
411 DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
412 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
413 false, 0, __VA_ARGS__)
416 * OBJECT_DEFINE_SIMPLE_TYPE:
417 * @ModuleObjName: the object name with initial caps
418 * @module_obj_name: the object name in lowercase with underscore separators
419 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
420 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
423 * This is a variant of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable for
424 * the common case of a non-abstract type, without any interfaces, and with
425 * no requirement for a class struct. If you declared your type with
426 * OBJECT_DECLARE_SIMPLE_TYPE then this is probably the right choice for
429 #define OBJECT_DEFINE_SIMPLE_TYPE(ModuleObjName, module_obj_name, \
430 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME) \
431 OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(ModuleObjName, module_obj_name, \
432 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, { NULL })
436 * @name: The name of the type.
437 * @parent: The name of the parent type.
438 * @instance_size: The size of the object (derivative of #Object). If
439 * @instance_size is 0, then the size of the object will be the size of the
441 * @instance_align: The required alignment of the object. If @instance_align
442 * is 0, then normal malloc alignment is sufficient; if non-zero, then we
443 * must use qemu_memalign for allocation.
444 * @instance_init: This function is called to initialize an object. The parent
445 * class will have already been initialized so the type is only responsible
446 * for initializing its own members.
447 * @instance_post_init: This function is called to finish initialization of
448 * an object, after all @instance_init functions were called, as well as
449 * @instance_post_init functions for the parent classes.
450 * @instance_finalize: This function is called during object destruction. This
451 * is called before the parent @instance_finalize function has been called.
452 * An object should only free the members that are unique to its type in this
454 * @abstract: If this field is true, then the class is considered abstract and
455 * cannot be directly instantiated.
456 * @class_size: The size of the class object (derivative of #ObjectClass)
457 * for this object. If @class_size is 0, then the size of the class will be
458 * assumed to be the size of the parent class. This allows a type to avoid
459 * implementing an explicit class type if they are not adding additional
461 * @class_init: This function is called after all parent class initialization
462 * has occurred to allow a class to set its default virtual method pointers.
463 * This is also the function to use to override virtual methods from a parent
465 * @class_base_init: This function is called for all base classes after all
466 * parent class initialization has occurred, but before the class itself
467 * is initialized. This is the function to use to undo the effects of
468 * memcpy from the parent class to the descendants.
469 * @class_data: Data to pass to the @class_init,
470 * @class_base_init. This can be useful when building dynamic
472 * @interfaces: The list of interfaces associated with this type. This
473 * should point to a static array that's terminated with a zero filled
481 size_t instance_size
;
482 size_t instance_align
;
483 void (*instance_init
)(Object
*obj
);
484 void (*instance_post_init
)(Object
*obj
);
485 void (*instance_finalize
)(Object
*obj
);
490 void (*class_init
)(ObjectClass
*klass
, const void *data
);
491 void (*class_base_init
)(ObjectClass
*klass
, const void *data
);
492 const void *class_data
;
494 const InterfaceInfo
*interfaces
;
499 * @obj: A derivative of #Object
501 * Converts an object to a #Object. Since all objects are #Objects,
502 * this function will always succeed.
504 #define OBJECT(obj) \
509 * @class: A derivative of #ObjectClass.
511 * Converts a class to an #ObjectClass. Since all objects are #Objects,
512 * this function will always succeed.
514 #define OBJECT_CLASS(class) \
515 ((ObjectClass *)(class))
519 * @type: The C type to use for the return value.
520 * @obj: A derivative of @type to cast.
521 * @name: The QOM typename of @type
523 * A type safe version of @object_dynamic_cast_assert. Typically each class
524 * will define a macro based on this type to perform type safe dynamic_casts to
527 * If an invalid object is passed to this function, a run time assert will be
530 #define OBJECT_CHECK(type, obj, name) \
531 ((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \
532 __FILE__, __LINE__, __func__))
535 * OBJECT_CLASS_CHECK:
536 * @class_type: The C type to use for the return value.
537 * @class: A derivative class of @class_type to cast.
538 * @name: the QOM typename of @class_type.
540 * A type safe version of @object_class_dynamic_cast_assert. This macro is
541 * typically wrapped by each type to perform type safe casts of a class to a
542 * specific class type.
544 #define OBJECT_CLASS_CHECK(class_type, class, name) \
545 ((class_type *)object_class_dynamic_cast_assert(OBJECT_CLASS(class), (name), \
546 __FILE__, __LINE__, __func__))
550 * @class: The C type to use for the return value.
551 * @obj: The object to obtain the class for.
552 * @name: The QOM typename of @obj.
554 * This function will return a specific class for a given object. Its generally
555 * used by each type to provide a type safe macro to get a specific class type
558 #define OBJECT_GET_CLASS(class, obj, name) \
559 OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
562 * struct InterfaceInfo:
563 * @type: The name of the interface.
565 * The information associated with an interface.
567 struct InterfaceInfo
{
572 * struct InterfaceClass:
573 * @parent_class: the base class
575 * The class for all interfaces. Subclasses of this class should only add
578 * Note that most of the fields of ObjectClass are unused (all except
579 * "type", in fact). They are only present in InterfaceClass to allow
580 * @object_class_dynamic_cast to work with both regular classes and interfaces.
582 struct InterfaceClass
584 ObjectClass parent_class
;
589 #define TYPE_INTERFACE "interface"
593 * @klass: class to cast from
594 * Returns: An #InterfaceClass or raise an error if cast is invalid
596 #define INTERFACE_CLASS(klass) \
597 OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE)
601 * @interface: the type to return
602 * @obj: the object to convert to an interface
603 * @name: the interface type name
605 * Returns: @obj casted to @interface if cast is valid, otherwise raise error.
607 #define INTERFACE_CHECK(interface, obj, name) \
608 ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \
609 __FILE__, __LINE__, __func__))
612 * object_new_with_class:
613 * @klass: The class to instantiate.
615 * This function will initialize a new object using heap allocated memory.
616 * The returned object has a reference count of 1, and will be freed when
617 * the last reference is dropped.
619 * Returns: The newly allocated and instantiated object.
621 Object
*object_new_with_class(ObjectClass
*klass
);
625 * @typename: The name of the type of the object to instantiate.
627 * This function will initialize a new object using heap allocated memory.
628 * The returned object has a reference count of 1, and will be freed when
629 * the last reference is dropped.
631 * Returns: The newly allocated and instantiated object.
633 Object
*object_new(const char *typename
);
636 * object_new_with_props:
637 * @typename: The name of the type of the object to instantiate.
638 * @parent: the parent object
639 * @id: The unique ID of the object
640 * @errp: pointer to error object
641 * @...: list of property names and values
643 * This function will initialize a new object using heap allocated memory.
644 * The returned object has a reference count of 1, and will be freed when
645 * the last reference is dropped.
647 * The @id parameter will be used when registering the object as a
648 * child of @parent in the composition tree.
650 * The variadic parameters are a list of pairs of (propname, propvalue)
651 * strings. The propname of %NULL indicates the end of the property
652 * list. If the object implements the user creatable interface, the
653 * object will be marked complete once all the properties have been
657 * :caption: Creating an object with properties
662 * obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE,
663 * object_get_objects_root(),
667 * "mem-path", "/dev/shm/somefile",
673 * error_reportf_err(err, "Cannot create memory backend: ");
676 * The returned object will have one stable reference maintained
677 * for as long as it is present in the object hierarchy.
679 * Returns: The newly allocated, instantiated & initialized object.
681 Object
*object_new_with_props(const char *typename
,
685 ...) G_GNUC_NULL_TERMINATED
;
688 * object_new_with_propv:
689 * @typename: The name of the type of the object to instantiate.
690 * @parent: the parent object
691 * @id: The unique ID of the object
692 * @errp: pointer to error object
693 * @vargs: list of property names and values
695 * See object_new_with_props() for documentation.
697 Object
*object_new_with_propv(const char *typename
,
703 bool object_apply_global_props(Object
*obj
, const GPtrArray
*props
,
705 void object_set_machine_compat_props(GPtrArray
*compat_props
);
706 void object_set_accelerator_compat_props(GPtrArray
*compat_props
);
707 void object_register_sugar_prop(const char *driver
, const char *prop
,
708 const char *value
, bool optional
);
709 void object_apply_compat_props(Object
*obj
);
713 * @obj: the object instance to set properties on
714 * @errp: pointer to error object
715 * @...: list of property names and values
717 * This function will set a list of properties on an existing object
720 * The variadic parameters are a list of pairs of (propname, propvalue)
721 * strings. The propname of %NULL indicates the end of the property
725 * :caption: Update an object's properties
728 * Object *obj = ...get / create object...;
730 * if (!object_set_props(obj,
733 * "mem-path", "/dev/shm/somefile",
737 * error_reportf_err(err, "Cannot set properties: ");
740 * The returned object will have one stable reference maintained
741 * for as long as it is present in the object hierarchy.
743 * Returns: %true on success, %false on error.
745 bool object_set_props(Object
*obj
, Error
**errp
, ...) G_GNUC_NULL_TERMINATED
;
749 * @obj: the object instance to set properties on
750 * @errp: pointer to error object
751 * @vargs: list of property names and values
753 * See object_set_props() for documentation.
755 * Returns: %true on success, %false on error.
757 bool object_set_propv(Object
*obj
, Error
**errp
, va_list vargs
);
761 * @obj: A pointer to the memory to be used for the object.
762 * @size: The maximum size available at @obj for the object.
763 * @typename: The name of the type of the object to instantiate.
765 * This function will initialize an object. The memory for the object should
766 * have already been allocated. The returned object has a reference count of 1,
767 * and will be finalized when the last reference is dropped.
769 void object_initialize(void *obj
, size_t size
, const char *typename
);
772 * object_initialize_child_with_props:
773 * @parentobj: The parent object to add a property to
774 * @propname: The name of the property
775 * @childobj: A pointer to the memory to be used for the object.
776 * @size: The maximum size available at @childobj for the object.
777 * @type: The name of the type of the object to instantiate.
778 * @errp: If an error occurs, a pointer to an area to store the error
779 * @...: list of property names and values
781 * This function will initialize an object. The memory for the object should
782 * have already been allocated. The object will then be added as child property
783 * to a parent with object_property_add_child() function. The returned object
784 * has a reference count of 1 (for the "child<...>" property from the parent),
785 * so the object will be finalized automatically when the parent gets removed.
787 * The variadic parameters are a list of pairs of (propname, propvalue)
788 * strings. The propname of %NULL indicates the end of the property list.
789 * If the object implements the user creatable interface, the object will
790 * be marked complete once all the properties have been processed.
792 * Returns: %true on success, %false on failure.
794 bool object_initialize_child_with_props(Object
*parentobj
,
795 const char *propname
,
796 void *childobj
, size_t size
, const char *type
,
797 Error
**errp
, ...) G_GNUC_NULL_TERMINATED
;
800 * object_initialize_child_with_propsv:
801 * @parentobj: The parent object to add a property to
802 * @propname: The name of the property
803 * @childobj: A pointer to the memory to be used for the object.
804 * @size: The maximum size available at @childobj for the object.
805 * @type: The name of the type of the object to instantiate.
806 * @errp: If an error occurs, a pointer to an area to store the error
807 * @vargs: list of property names and values
809 * See object_initialize_child() for documentation.
811 * Returns: %true on success, %false on failure.
813 bool object_initialize_child_with_propsv(Object
*parentobj
,
814 const char *propname
,
815 void *childobj
, size_t size
, const char *type
,
816 Error
**errp
, va_list vargs
);
819 * object_initialize_child:
820 * @parent: The parent object to add a property to
821 * @propname: The name of the property
822 * @child: A precisely typed pointer to the memory to be used for the
824 * @type: The name of the type of the object to instantiate.
828 * object_initialize_child_with_props(parent, propname,
829 * child, sizeof(*child), type,
830 * &error_abort, NULL)
832 #define object_initialize_child(parent, propname, child, type) \
833 object_initialize_child_internal((parent), (propname), \
834 (child), sizeof(*(child)), (type))
835 void object_initialize_child_internal(Object
*parent
, const char *propname
,
836 void *child
, size_t size
,
840 * object_dynamic_cast:
841 * @obj: The object to cast.
842 * @typename: The @typename to cast to.
844 * This function will determine if @obj is-a @typename. @obj can refer to an
845 * object or an interface associated with an object.
847 * Returns: This function returns @obj on success or #NULL on failure.
849 Object
*object_dynamic_cast(Object
*obj
, const char *typename
);
852 * object_dynamic_cast_assert:
853 * @obj: The object to cast.
854 * @typename: The @typename to cast to.
855 * @file: Source code file where function was called
856 * @line: Source code line where function was called
857 * @func: Name of function where this function was called
859 * See object_dynamic_cast() for a description of the parameters of this
860 * function. The only difference in behavior is that this function asserts
861 * instead of returning #NULL on failure if QOM cast debugging is enabled.
862 * This function is not meant to be called directly, but only through
863 * the wrapper macro OBJECT_CHECK.
865 Object
*object_dynamic_cast_assert(Object
*obj
, const char *typename
,
866 const char *file
, int line
, const char *func
);
870 * @obj: A derivative of #Object
872 * Returns: The #ObjectClass of the type associated with @obj.
874 ObjectClass
*object_get_class(Object
*obj
);
877 * object_get_typename:
878 * @obj: A derivative of #Object.
880 * Returns: The QOM typename of @obj.
882 const char *object_get_typename(const Object
*obj
);
885 * type_register_static:
886 * @info: The #TypeInfo of the new type.
888 * Returns: the new #Type.
890 Type
type_register_static(const TypeInfo
*info
);
893 * type_register_static_array:
894 * @infos: The array of the new type #TypeInfo structures.
895 * @nr_infos: number of entries in @infos
897 * @infos and all of the strings it points to should exist for the life time
898 * that the type is registered.
900 void type_register_static_array(const TypeInfo
*infos
, int nr_infos
);
904 * @type_array: The array containing #TypeInfo structures to register
906 * @type_array should be static constant that exists for the life time
907 * that the type is registered.
909 #define DEFINE_TYPES(type_array) \
910 static void do_qemu_init_ ## type_array(void) \
912 type_register_static_array(type_array, ARRAY_SIZE(type_array)); \
914 type_init(do_qemu_init_ ## type_array)
917 * type_print_class_properties:
918 * @type: a QOM class name
920 * Print the object's class properties to stdout or the monitor.
921 * Return whether an object was found.
923 bool type_print_class_properties(const char *type
);
926 * object_set_properties_from_keyval:
928 * @qdict: a dictionary with the properties to be set
929 * @from_json: true if leaf values of @qdict are typed, false if they
931 * @errp: pointer to error object
933 * For each key in the dictionary, parse the value string if needed,
934 * then set the corresponding property in @obj.
936 void object_set_properties_from_keyval(Object
*obj
, const QDict
*qdict
,
937 bool from_json
, Error
**errp
);
940 * object_class_dynamic_cast_assert:
941 * @klass: The #ObjectClass to attempt to cast.
942 * @typename: The QOM typename of the class to cast to.
943 * @file: Source code file where function was called
944 * @line: Source code line where function was called
945 * @func: Name of function where this function was called
947 * See object_class_dynamic_cast() for a description of the parameters
948 * of this function. The only difference in behavior is that this function
949 * asserts instead of returning #NULL on failure if QOM cast debugging is
950 * enabled. This function is not meant to be called directly, but only through
951 * the wrapper macro OBJECT_CLASS_CHECK.
953 ObjectClass
*object_class_dynamic_cast_assert(ObjectClass
*klass
,
954 const char *typename
,
955 const char *file
, int line
,
959 * object_class_dynamic_cast:
960 * @klass: The #ObjectClass to attempt to cast.
961 * @typename: The QOM typename of the class to cast to.
963 * Returns: If @typename is a class, this function returns @klass if
964 * @typename is a subtype of @klass, else returns #NULL.
966 * If @typename is an interface, this function returns the interface
967 * definition for @klass if @klass implements it unambiguously; #NULL
968 * is returned if @klass does not implement the interface or if multiple
969 * classes or interfaces on the hierarchy leading to @klass implement
970 * it. (FIXME: perhaps this can be detected at type definition time?)
972 ObjectClass
*object_class_dynamic_cast(ObjectClass
*klass
,
973 const char *typename
);
976 * object_class_get_parent:
977 * @klass: The class to obtain the parent for.
979 * Returns: The parent for @klass or %NULL if none.
981 ObjectClass
*object_class_get_parent(ObjectClass
*klass
);
984 * object_class_get_name:
985 * @klass: The class to obtain the QOM typename for.
987 * Returns: The QOM typename for @klass.
989 const char *object_class_get_name(ObjectClass
*klass
);
992 * object_class_is_abstract:
993 * @klass: The class to obtain the abstractness for.
995 * Returns: %true if @klass is abstract, %false otherwise.
997 bool object_class_is_abstract(ObjectClass
*klass
);
1000 * object_class_by_name:
1001 * @typename: The QOM typename to obtain the class for.
1003 * Returns: The class for @typename or %NULL if not found.
1005 ObjectClass
*object_class_by_name(const char *typename
);
1008 * module_object_class_by_name:
1009 * @typename: The QOM typename to obtain the class for.
1011 * For objects which might be provided by a module. Behaves like
1012 * object_class_by_name, but additionally tries to load the module
1013 * needed in case the class is not available.
1015 * Returns: The class for @typename or %NULL if not found.
1017 ObjectClass
*module_object_class_by_name(const char *typename
);
1019 void object_class_foreach(void (*fn
)(ObjectClass
*klass
, void *opaque
),
1020 const char *implements_type
, bool include_abstract
,
1024 * object_class_get_list:
1025 * @implements_type: The type to filter for, including its derivatives.
1026 * @include_abstract: Whether to include abstract classes.
1028 * Returns: A singly-linked list of the classes in reverse hashtable order.
1030 GSList
*object_class_get_list(const char *implements_type
,
1031 bool include_abstract
);
1034 * object_class_get_list_sorted:
1035 * @implements_type: The type to filter for, including its derivatives.
1036 * @include_abstract: Whether to include abstract classes.
1038 * Returns: A singly-linked list of the classes in alphabetical
1039 * case-insensitive order.
1041 GSList
*object_class_get_list_sorted(const char *implements_type
,
1042 bool include_abstract
);
1048 * Increase the reference count of a object. A object cannot be freed as long
1049 * as its reference count is greater than zero.
1052 Object
*object_ref(void *obj
);
1058 * Decrease the reference count of a object. A object cannot be freed as long
1059 * as its reference count is greater than zero.
1061 void object_unref(void *obj
);
1064 * object_property_try_add:
1065 * @obj: the object to add a property to
1066 * @name: the name of the property. This can contain any character except for
1067 * a forward slash. In general, you should use hyphens '-' instead of
1068 * underscores '_' when naming properties.
1069 * @type: the type name of the property. This namespace is pretty loosely
1070 * defined. Sub namespaces are constructed by using a prefix and then
1071 * to angle brackets. For instance, the type 'virtio-net-pci' in the
1072 * 'link' namespace would be 'link<virtio-net-pci>'.
1073 * @get: The getter to be called to read a property. If this is NULL, then
1074 * the property cannot be read.
1075 * @set: the setter to be called to write a property. If this is NULL,
1076 * then the property cannot be written.
1077 * @release: called when the property is removed from the object. This is
1078 * meant to allow a property to free its opaque upon object
1079 * destruction. This may be NULL.
1080 * @opaque: an opaque pointer to pass to the callbacks for the property
1081 * @errp: pointer to error object
1083 * Returns: The #ObjectProperty; this can be used to set the @resolve
1084 * callback for child and link properties.
1086 ObjectProperty
*object_property_try_add(Object
*obj
, const char *name
,
1088 ObjectPropertyAccessor
*get
,
1089 ObjectPropertyAccessor
*set
,
1090 ObjectPropertyRelease
*release
,
1091 void *opaque
, Error
**errp
);
1094 * object_property_add:
1095 * Same as object_property_try_add() with @errp hardcoded to
1098 * @obj: the object to add a property to
1099 * @name: the name of the property. This can contain any character except for
1100 * a forward slash. In general, you should use hyphens '-' instead of
1101 * underscores '_' when naming properties.
1102 * @type: the type name of the property. This namespace is pretty loosely
1103 * defined. Sub namespaces are constructed by using a prefix and then
1104 * to angle brackets. For instance, the type 'virtio-net-pci' in the
1105 * 'link' namespace would be 'link<virtio-net-pci>'.
1106 * @get: The getter to be called to read a property. If this is NULL, then
1107 * the property cannot be read.
1108 * @set: the setter to be called to write a property. If this is NULL,
1109 * then the property cannot be written.
1110 * @release: called when the property is removed from the object. This is
1111 * meant to allow a property to free its opaque upon object
1112 * destruction. This may be NULL.
1113 * @opaque: an opaque pointer to pass to the callbacks for the property
1115 ObjectProperty
*object_property_add(Object
*obj
, const char *name
,
1117 ObjectPropertyAccessor
*get
,
1118 ObjectPropertyAccessor
*set
,
1119 ObjectPropertyRelease
*release
,
1122 void object_property_del(Object
*obj
, const char *name
);
1124 ObjectProperty
*object_class_property_add(ObjectClass
*klass
, const char *name
,
1126 ObjectPropertyAccessor
*get
,
1127 ObjectPropertyAccessor
*set
,
1128 ObjectPropertyRelease
*release
,
1132 * object_property_set_default_bool:
1133 * @prop: the property to set
1134 * @value: the value to be written to the property
1136 * Set the property default value.
1138 void object_property_set_default_bool(ObjectProperty
*prop
, bool value
);
1141 * object_property_set_default_str:
1142 * @prop: the property to set
1143 * @value: the value to be written to the property
1145 * Set the property default value.
1147 void object_property_set_default_str(ObjectProperty
*prop
, const char *value
);
1150 * object_property_set_default_list:
1151 * @prop: the property to set
1153 * Set the property default value to be an empty list.
1155 void object_property_set_default_list(ObjectProperty
*prop
);
1158 * object_property_set_default_int:
1159 * @prop: the property to set
1160 * @value: the value to be written to the property
1162 * Set the property default value.
1164 void object_property_set_default_int(ObjectProperty
*prop
, int64_t value
);
1167 * object_property_set_default_uint:
1168 * @prop: the property to set
1169 * @value: the value to be written to the property
1171 * Set the property default value.
1173 void object_property_set_default_uint(ObjectProperty
*prop
, uint64_t value
);
1176 * object_property_find:
1178 * @name: the name of the property
1180 * Look up a property for an object.
1182 * Return its #ObjectProperty if found, or NULL.
1184 ObjectProperty
*object_property_find(Object
*obj
, const char *name
);
1187 * object_property_find_err:
1189 * @name: the name of the property
1190 * @errp: returns an error if this function fails
1192 * Look up a property for an object.
1194 * Return its #ObjectProperty if found, or NULL.
1196 ObjectProperty
*object_property_find_err(Object
*obj
,
1201 * object_class_property_find:
1202 * @klass: the object class
1203 * @name: the name of the property
1205 * Look up a property for an object class.
1207 * Return its #ObjectProperty if found, or NULL.
1209 ObjectProperty
*object_class_property_find(ObjectClass
*klass
,
1213 * object_class_property_find_err:
1214 * @klass: the object class
1215 * @name: the name of the property
1216 * @errp: returns an error if this function fails
1218 * Look up a property for an object class.
1220 * Return its #ObjectProperty if found, or NULL.
1222 ObjectProperty
*object_class_property_find_err(ObjectClass
*klass
,
1226 typedef struct ObjectPropertyIterator
{
1227 ObjectClass
*nextclass
;
1228 GHashTableIter iter
;
1229 } ObjectPropertyIterator
;
1232 * object_property_iter_init:
1233 * @iter: the iterator instance
1236 * Initializes an iterator for traversing all properties
1237 * registered against an object instance, its class and all parent classes.
1239 * It is forbidden to modify the property list while iterating,
1240 * whether removing or adding properties.
1242 * Typical usage pattern would be
1245 * :caption: Using object property iterators
1247 * ObjectProperty *prop;
1248 * ObjectPropertyIterator iter;
1250 * object_property_iter_init(&iter, obj);
1251 * while ((prop = object_property_iter_next(&iter))) {
1252 * ... do something with prop ...
1255 void object_property_iter_init(ObjectPropertyIterator
*iter
,
1259 * object_class_property_iter_init:
1260 * @iter: the iterator instance
1263 * Initializes an iterator for traversing all properties
1264 * registered against an object class and all parent classes.
1266 * It is forbidden to modify the property list while iterating,
1267 * whether removing or adding properties.
1269 * This can be used on abstract classes as it does not create a temporary
1272 void object_class_property_iter_init(ObjectPropertyIterator
*iter
,
1273 ObjectClass
*klass
);
1276 * object_property_iter_next:
1277 * @iter: the iterator instance
1279 * Return the next available property. If no further properties
1280 * are available, a %NULL value will be returned and the @iter
1281 * pointer should not be used again after this point without
1282 * re-initializing it.
1284 * Returns: the next property, or %NULL when all properties
1285 * have been traversed.
1287 ObjectProperty
*object_property_iter_next(ObjectPropertyIterator
*iter
);
1289 void object_unparent(Object
*obj
);
1292 * object_property_get:
1294 * @name: the name of the property
1295 * @v: the visitor that will receive the property value. This should be an
1296 * Output visitor and the data will be written with @name as the name.
1297 * @errp: returns an error if this function fails
1299 * Reads a property from a object.
1301 * Returns: %true on success, %false on failure.
1303 bool object_property_get(Object
*obj
, const char *name
, Visitor
*v
,
1307 * object_property_set_str:
1309 * @name: the name of the property
1310 * @value: the value to be written to the property
1311 * @errp: returns an error if this function fails
1313 * Writes a string value to a property.
1315 * Returns: %true on success, %false on failure.
1317 bool object_property_set_str(Object
*obj
, const char *name
,
1318 const char *value
, Error
**errp
);
1321 * object_property_get_str:
1323 * @name: the name of the property
1324 * @errp: returns an error if this function fails
1326 * Returns: the value of the property, converted to a C string, or NULL if
1327 * an error occurs (including when the property value is not a string).
1328 * The caller should free the string.
1330 char *object_property_get_str(Object
*obj
, const char *name
,
1334 * object_property_set_link:
1336 * @name: the name of the property
1337 * @value: the value to be written to the property
1338 * @errp: returns an error if this function fails
1340 * Writes an object's canonical path to a property.
1342 * If the link property was created with
1343 * %OBJ_PROP_LINK_STRONG bit, the old target object is
1344 * unreferenced, and a reference is added to the new target object.
1346 * Returns: %true on success, %false on failure.
1348 bool object_property_set_link(Object
*obj
, const char *name
,
1349 Object
*value
, Error
**errp
);
1352 * object_property_get_link:
1354 * @name: the name of the property
1355 * @errp: returns an error if this function fails
1357 * Returns: the value of the property, resolved from a path to an Object,
1358 * or NULL if an error occurs (including when the property value is not a
1359 * string or not a valid object path).
1361 Object
*object_property_get_link(Object
*obj
, const char *name
,
1365 * object_property_set_bool:
1367 * @name: the name of the property
1368 * @value: the value to be written to the property
1369 * @errp: returns an error if this function fails
1371 * Writes a bool value to a property.
1373 * Returns: %true on success, %false on failure.
1375 bool object_property_set_bool(Object
*obj
, const char *name
,
1376 bool value
, Error
**errp
);
1379 * object_property_get_bool:
1381 * @name: the name of the property
1382 * @errp: returns an error if this function fails
1384 * Returns: the value of the property, converted to a boolean, or false if
1385 * an error occurs (including when the property value is not a bool).
1387 bool object_property_get_bool(Object
*obj
, const char *name
,
1391 * object_property_set_int:
1393 * @name: the name of the property
1394 * @value: the value to be written to the property
1395 * @errp: returns an error if this function fails
1397 * Writes an integer value to a property.
1399 * Returns: %true on success, %false on failure.
1401 bool object_property_set_int(Object
*obj
, const char *name
,
1402 int64_t value
, Error
**errp
);
1405 * object_property_get_int:
1407 * @name: the name of the property
1408 * @errp: returns an error if this function fails
1410 * Returns: the value of the property, converted to an integer, or -1 if
1411 * an error occurs (including when the property value is not an integer).
1413 int64_t object_property_get_int(Object
*obj
, const char *name
,
1417 * object_property_set_uint:
1419 * @name: the name of the property
1420 * @value: the value to be written to the property
1421 * @errp: returns an error if this function fails
1423 * Writes an unsigned integer value to a property.
1425 * Returns: %true on success, %false on failure.
1427 bool object_property_set_uint(Object
*obj
, const char *name
,
1428 uint64_t value
, Error
**errp
);
1431 * object_property_get_uint:
1433 * @name: the name of the property
1434 * @errp: returns an error if this function fails
1436 * Returns: the value of the property, converted to an unsigned integer, or 0
1437 * an error occurs (including when the property value is not an integer).
1439 uint64_t object_property_get_uint(Object
*obj
, const char *name
,
1443 * object_property_get_enum:
1445 * @name: the name of the property
1446 * @typename: the name of the enum data type
1447 * @errp: returns an error if this function fails
1449 * Returns: the value of the property, converted to an integer (which
1450 * can't be negative), or -1 on error (including when the property
1451 * value is not an enum).
1453 int object_property_get_enum(Object
*obj
, const char *name
,
1454 const char *typename
, Error
**errp
);
1457 * object_property_set:
1459 * @name: the name of the property
1460 * @v: the visitor that will be used to write the property value. This should
1461 * be an Input visitor and the data will be first read with @name as the
1462 * name and then written as the property value.
1463 * @errp: returns an error if this function fails
1465 * Writes a property to a object.
1467 * Returns: %true on success, %false on failure.
1469 bool object_property_set(Object
*obj
, const char *name
, Visitor
*v
,
1473 * object_property_parse:
1475 * @name: the name of the property
1476 * @string: the string that will be used to parse the property value.
1477 * @errp: returns an error if this function fails
1479 * Parses a string and writes the result into a property of an object.
1481 * Returns: %true on success, %false on failure.
1483 bool object_property_parse(Object
*obj
, const char *name
,
1484 const char *string
, Error
**errp
);
1487 * object_property_print:
1489 * @name: the name of the property
1490 * @human: if true, print for human consumption
1491 * @errp: returns an error if this function fails
1493 * Returns a string representation of the value of the property. The
1494 * caller shall free the string.
1496 char *object_property_print(Object
*obj
, const char *name
, bool human
,
1500 * object_property_get_type:
1502 * @name: the name of the property
1503 * @errp: returns an error if this function fails
1505 * Returns: The type name of the property.
1507 const char *object_property_get_type(Object
*obj
, const char *name
,
1513 * Returns: the root object of the composition tree
1515 Object
*object_get_root(void);
1518 * object_get_container:
1519 * @name: the name of container to lookup
1521 * Lookup a root level container.
1523 * Returns: the container with @name.
1525 Object
*object_get_container(const char *name
);
1529 * object_get_objects_root:
1531 * Get the container object that holds user created
1532 * object instances. This is the object at path
1535 * Returns: the user object container
1537 Object
*object_get_objects_root(void);
1540 * object_get_internal_root:
1542 * Get the container object that holds internally used object
1543 * instances. Any object which is put into this container must not be
1544 * user visible, and it will not be exposed in the QOM tree.
1546 * Returns: the internal object container
1548 Object
*object_get_internal_root(void);
1551 * object_get_canonical_path_component:
1554 * Returns: The final component in the object's canonical path. The canonical
1555 * path is the path within the composition tree starting from the root.
1556 * %NULL if the object doesn't have a parent (and thus a canonical path).
1558 const char *object_get_canonical_path_component(const Object
*obj
);
1561 * object_get_canonical_path:
1564 * Returns: The canonical path for a object, newly allocated. This is
1565 * the path within the composition tree starting from the root. Use
1566 * g_free() to free it.
1568 char *object_get_canonical_path(const Object
*obj
);
1571 * object_resolve_path:
1572 * @path: the path to resolve
1573 * @ambiguous: (out) (optional): location to store whether the lookup failed
1574 * because it was ambiguous, or %NULL. Set to %false on success.
1576 * There are two types of supported paths--absolute paths and partial paths.
1578 * Absolute paths are derived from the root object and can follow child<> or
1579 * link<> properties. Since they can follow link<> properties, they can be
1580 * arbitrarily long. Absolute paths look like absolute filenames and are
1581 * prefixed with a leading slash.
1583 * Partial paths look like relative filenames. They do not begin with a
1584 * prefix. The matching rules for partial paths are subtle but designed to make
1585 * specifying objects easy. At each level of the composition tree, the partial
1586 * path is matched as an absolute path. The first match is not returned. At
1587 * least two matches are searched for. A successful result is only returned if
1588 * only one match is found. If more than one match is found, a flag is
1589 * returned to indicate that the match was ambiguous.
1591 * Returns: The matched object or %NULL on path lookup failure.
1593 Object
*object_resolve_path(const char *path
, bool *ambiguous
);
1596 * object_resolve_path_type:
1597 * @path: the path to resolve
1598 * @typename: the type to look for.
1599 * @ambiguous: (out) (optional): location to store whether the lookup failed
1600 * because it was ambiguous, or %NULL. Set to %false on success.
1602 * This is similar to object_resolve_path(). However, when looking for a
1603 * partial path only matches that implement the given type are considered.
1604 * This restricts the search and avoids spuriously flagging matches as
1607 * For both partial and absolute paths, the return value goes through
1608 * a dynamic cast to @typename. This is important if either the link,
1609 * or the typename itself are of interface types.
1611 * Returns: The matched object or NULL on path lookup failure.
1613 Object
*object_resolve_path_type(const char *path
, const char *typename
,
1617 * object_resolve_type_unambiguous:
1618 * @typename: the type to look for
1619 * @errp: pointer to error object
1621 * Return the only object in the QOM tree of type @typename.
1622 * If no match or more than one match is found, an error is
1625 * Returns: The matched object or NULL on path lookup failure.
1627 Object
*object_resolve_type_unambiguous(const char *typename
, Error
**errp
);
1630 * object_resolve_path_at:
1631 * @parent: the object in which to resolve the path
1632 * @path: the path to resolve
1634 * This is like object_resolve_path(), except paths not starting with
1635 * a slash are relative to @parent.
1637 * Returns: The resolved object or NULL on path lookup failure.
1639 Object
*object_resolve_path_at(Object
*parent
, const char *path
);
1642 * object_resolve_path_component:
1643 * @parent: the object in which to resolve the path
1644 * @part: the component to resolve.
1646 * This is similar to object_resolve_path with an absolute path, but it
1647 * only resolves one element (@part) and takes the others from @parent.
1649 * Returns: The resolved object or NULL on path lookup failure.
1651 Object
*object_resolve_path_component(Object
*parent
, const char *part
);
1654 * object_property_try_add_child:
1655 * @obj: the object to add a property to
1656 * @name: the name of the property
1657 * @child: the child object
1658 * @errp: pointer to error object
1660 * Child properties form the composition tree. All objects need to be a child
1661 * of another object. Objects can only be a child of one object.
1663 * There is no way for a child to determine what its parent is. It is not
1664 * a bidirectional relationship. This is by design.
1666 * The value of a child property as a C string will be the child object's
1667 * canonical path. It can be retrieved using object_property_get_str().
1668 * The child object itself can be retrieved using object_property_get_link().
1670 * Returns: The newly added property on success, or %NULL on failure.
1672 ObjectProperty
*object_property_try_add_child(Object
*obj
, const char *name
,
1673 Object
*child
, Error
**errp
);
1676 * object_property_add_child:
1677 * @obj: the object to add a property to
1678 * @name: the name of the property
1679 * @child: the child object
1681 * Same as object_property_try_add_child() with @errp hardcoded to
1684 ObjectProperty
*object_property_add_child(Object
*obj
, const char *name
,
1688 /* Unref the link pointer when the property is deleted */
1689 OBJ_PROP_LINK_STRONG
= 0x1,
1692 OBJ_PROP_LINK_DIRECT
= 0x2,
1693 OBJ_PROP_LINK_CLASS
= 0x4,
1694 } ObjectPropertyLinkFlags
;
1697 * object_property_allow_set_link:
1698 * @obj: the object to add a property to
1699 * @name: the name of the property
1700 * @child: the child object
1701 * @errp: pointer to error object
1703 * The default implementation of the object_property_add_link() check()
1704 * callback function. It allows the link property to be set and never returns
1707 void object_property_allow_set_link(const Object
*obj
, const char *name
,
1708 Object
*child
, Error
**errp
);
1711 * object_property_add_link:
1712 * @obj: the object to add a property to
1713 * @name: the name of the property
1714 * @type: the qobj type of the link
1715 * @targetp: a pointer to where the link object reference is stored
1716 * @check: callback to veto setting or NULL if the property is read-only
1717 * @flags: additional options for the link
1719 * Links establish relationships between objects. Links are unidirectional
1720 * although two links can be combined to form a bidirectional relationship
1723 * Links form the graph in the object model.
1725 * The @check() callback is invoked when
1726 * object_property_set_link() is called and can raise an error to prevent the
1727 * link being set. If @check is NULL, the property is read-only
1728 * and cannot be set.
1730 * Ownership of the pointer that @child points to is transferred to the
1731 * link property. The reference count for *@child is
1732 * managed by the property from after the function returns till the
1733 * property is deleted with object_property_del(). If the
1734 * @flags %OBJ_PROP_LINK_STRONG bit is set,
1735 * the reference count is decremented when the property is deleted or
1738 * Returns: The newly added property on success, or %NULL on failure.
1740 ObjectProperty
*object_property_add_link(Object
*obj
, const char *name
,
1741 const char *type
, Object
**targetp
,
1742 void (*check
)(const Object
*obj
, const char *name
,
1743 Object
*val
, Error
**errp
),
1744 ObjectPropertyLinkFlags flags
);
1746 ObjectProperty
*object_class_property_add_link(ObjectClass
*oc
,
1748 const char *type
, ptrdiff_t offset
,
1749 void (*check
)(const Object
*obj
, const char *name
,
1750 Object
*val
, Error
**errp
),
1751 ObjectPropertyLinkFlags flags
);
1754 * object_property_add_str:
1755 * @obj: the object to add a property to
1756 * @name: the name of the property
1757 * @get: the getter or NULL if the property is write-only. This function must
1758 * return a string to be freed by g_free().
1759 * @set: the setter or NULL if the property is read-only
1761 * Add a string property using getters/setters. This function will add a
1762 * property of type 'string'.
1764 * Returns: The newly added property on success, or %NULL on failure.
1766 ObjectProperty
*object_property_add_str(Object
*obj
, const char *name
,
1767 char *(*get
)(Object
*, Error
**),
1768 void (*set
)(Object
*, const char *, Error
**));
1770 ObjectProperty
*object_class_property_add_str(ObjectClass
*klass
,
1772 char *(*get
)(Object
*, Error
**),
1773 void (*set
)(Object
*, const char *,
1777 * object_property_add_bool:
1778 * @obj: the object to add a property to
1779 * @name: the name of the property
1780 * @get: the getter or NULL if the property is write-only.
1781 * @set: the setter or NULL if the property is read-only
1783 * Add a bool property using getters/setters. This function will add a
1784 * property of type 'bool'.
1786 * Returns: The newly added property on success, or %NULL on failure.
1788 ObjectProperty
*object_property_add_bool(Object
*obj
, const char *name
,
1789 bool (*get
)(Object
*, Error
**),
1790 void (*set
)(Object
*, bool, Error
**));
1792 ObjectProperty
*object_class_property_add_bool(ObjectClass
*klass
,
1794 bool (*get
)(Object
*, Error
**),
1795 void (*set
)(Object
*, bool, Error
**));
1798 * object_property_add_enum:
1799 * @obj: the object to add a property to
1800 * @name: the name of the property
1801 * @typename: the name of the enum data type
1802 * @lookup: enum value namelookup table
1803 * @get: the getter or %NULL if the property is write-only.
1804 * @set: the setter or %NULL if the property is read-only
1806 * Add an enum property using getters/setters. This function will add a
1807 * property of type '@typename'.
1809 * Returns: The newly added property on success, or %NULL on failure.
1811 ObjectProperty
*object_property_add_enum(Object
*obj
, const char *name
,
1812 const char *typename
,
1813 const QEnumLookup
*lookup
,
1814 int (*get
)(Object
*, Error
**),
1815 void (*set
)(Object
*, int, Error
**));
1817 ObjectProperty
*object_class_property_add_enum(ObjectClass
*klass
,
1819 const char *typename
,
1820 const QEnumLookup
*lookup
,
1821 int (*get
)(Object
*, Error
**),
1822 void (*set
)(Object
*, int, Error
**));
1825 * object_property_add_tm:
1826 * @obj: the object to add a property to
1827 * @name: the name of the property
1828 * @get: the getter or NULL if the property is write-only.
1830 * Add a read-only struct tm valued property using a getter function.
1831 * This function will add a property of type 'struct tm'.
1833 * Returns: The newly added property on success, or %NULL on failure.
1835 ObjectProperty
*object_property_add_tm(Object
*obj
, const char *name
,
1836 void (*get
)(Object
*, struct tm
*, Error
**));
1838 ObjectProperty
*object_class_property_add_tm(ObjectClass
*klass
,
1840 void (*get
)(Object
*, struct tm
*, Error
**));
1843 /* Automatically add a getter to the property */
1844 OBJ_PROP_FLAG_READ
= 1 << 0,
1845 /* Automatically add a setter to the property */
1846 OBJ_PROP_FLAG_WRITE
= 1 << 1,
1847 /* Automatically add a getter and a setter to the property */
1848 OBJ_PROP_FLAG_READWRITE
= (OBJ_PROP_FLAG_READ
| OBJ_PROP_FLAG_WRITE
),
1849 } ObjectPropertyFlags
;
1852 * object_property_add_uint8_ptr:
1853 * @obj: the object to add a property to
1854 * @name: the name of the property
1855 * @v: pointer to value
1856 * @flags: bitwise-or'd ObjectPropertyFlags
1858 * Add an integer property in memory. This function will add a
1859 * property of type 'uint8'.
1861 * Returns: The newly added property on success, or %NULL on failure.
1863 ObjectProperty
*object_property_add_uint8_ptr(Object
*obj
, const char *name
,
1865 ObjectPropertyFlags flags
);
1867 ObjectProperty
*object_class_property_add_uint8_ptr(ObjectClass
*klass
,
1870 ObjectPropertyFlags flags
);
1873 * object_property_add_uint16_ptr:
1874 * @obj: the object to add a property to
1875 * @name: the name of the property
1876 * @v: pointer to value
1877 * @flags: bitwise-or'd ObjectPropertyFlags
1879 * Add an integer property in memory. This function will add a
1880 * property of type 'uint16'.
1882 * Returns: The newly added property on success, or %NULL on failure.
1884 ObjectProperty
*object_property_add_uint16_ptr(Object
*obj
, const char *name
,
1886 ObjectPropertyFlags flags
);
1888 ObjectProperty
*object_class_property_add_uint16_ptr(ObjectClass
*klass
,
1891 ObjectPropertyFlags flags
);
1894 * object_property_add_uint32_ptr:
1895 * @obj: the object to add a property to
1896 * @name: the name of the property
1897 * @v: pointer to value
1898 * @flags: bitwise-or'd ObjectPropertyFlags
1900 * Add an integer property in memory. This function will add a
1901 * property of type 'uint32'.
1903 * Returns: The newly added property on success, or %NULL on failure.
1905 ObjectProperty
*object_property_add_uint32_ptr(Object
*obj
, const char *name
,
1907 ObjectPropertyFlags flags
);
1909 ObjectProperty
*object_class_property_add_uint32_ptr(ObjectClass
*klass
,
1912 ObjectPropertyFlags flags
);
1915 * object_property_add_uint64_ptr:
1916 * @obj: the object to add a property to
1917 * @name: the name of the property
1918 * @v: pointer to value
1919 * @flags: bitwise-or'd ObjectPropertyFlags
1921 * Add an integer property in memory. This function will add a
1922 * property of type 'uint64'.
1924 * Returns: The newly added property on success, or %NULL on failure.
1926 ObjectProperty
*object_property_add_uint64_ptr(Object
*obj
, const char *name
,
1928 ObjectPropertyFlags flags
);
1930 ObjectProperty
*object_class_property_add_uint64_ptr(ObjectClass
*klass
,
1933 ObjectPropertyFlags flags
);
1936 * object_property_add_alias:
1937 * @obj: the object to add a property to
1938 * @name: the name of the property
1939 * @target_obj: the object to forward property access to
1940 * @target_name: the name of the property on the forwarded object
1942 * Add an alias for a property on an object. This function will add a property
1943 * of the same type as the forwarded property.
1945 * The caller must ensure that @target_obj stays alive as long as
1946 * this property exists. In the case of a child object or an alias on the same
1947 * object this will be the case. For aliases to other objects the caller is
1948 * responsible for taking a reference.
1950 * Returns: The newly added property on success, or %NULL on failure.
1952 ObjectProperty
*object_property_add_alias(Object
*obj
, const char *name
,
1953 Object
*target_obj
, const char *target_name
);
1956 * object_property_add_const_link:
1957 * @obj: the object to add a property to
1958 * @name: the name of the property
1959 * @target: the object to be referred by the link
1961 * Add an unmodifiable link for a property on an object. This function will
1962 * add a property of type link<TYPE> where TYPE is the type of @target.
1964 * The caller must ensure that @target stays alive as long as
1965 * this property exists. In the case @target is a child of @obj,
1966 * this will be the case. Otherwise, the caller is responsible for
1967 * taking a reference.
1969 * Returns: The newly added property on success, or %NULL on failure.
1971 ObjectProperty
*object_property_add_const_link(Object
*obj
, const char *name
,
1975 * object_property_set_description:
1976 * @obj: the object owning the property
1977 * @name: the name of the property
1978 * @description: the description of the property on the object
1980 * Set an object property's description.
1982 * Returns: %true on success, %false on failure.
1984 void object_property_set_description(Object
*obj
, const char *name
,
1985 const char *description
);
1986 void object_class_property_set_description(ObjectClass
*klass
, const char *name
,
1987 const char *description
);
1990 * object_child_foreach:
1991 * @obj: the object whose children will be navigated
1992 * @fn: the iterator function to be called
1993 * @opaque: an opaque value that will be passed to the iterator
1995 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1998 * It is forbidden to add or remove children from @obj from the @fn
2001 * Returns: The last value returned by @fn, or 0 if there is no child.
2003 int object_child_foreach(Object
*obj
, int (*fn
)(Object
*child
, void *opaque
),
2007 * object_child_foreach_recursive:
2008 * @obj: the object whose children will be navigated
2009 * @fn: the iterator function to be called
2010 * @opaque: an opaque value that will be passed to the iterator
2012 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
2013 * non-zero. Calls recursively, all child nodes of @obj will also be passed
2014 * all the way down to the leaf nodes of the tree. Depth first ordering.
2016 * It is forbidden to add or remove children from @obj (or its
2017 * child nodes) from the @fn callback.
2019 * Returns: The last value returned by @fn, or 0 if there is no child.
2021 int object_child_foreach_recursive(Object
*obj
,
2022 int (*fn
)(Object
*child
, void *opaque
),
2026 * object_property_add_new_container:
2027 * @obj: the parent object
2028 * @name: the name of the parent object's property to add
2030 * Add a newly created container object to a parent object.
2032 * Returns: the newly created container object. Its reference count is 1,
2033 * and the reference is owned by the parent object.
2035 Object
*object_property_add_new_container(Object
*obj
, const char *name
);
2038 * object_property_help:
2039 * @name: the name of the property
2040 * @type: the type of the property
2041 * @defval: the default value
2042 * @description: description of the property
2044 * Returns: a user-friendly formatted string describing the property
2045 * for help purposes.
2047 char *object_property_help(const char *name
, const char *type
,
2048 QObject
*defval
, const char *description
);
2050 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object
, object_unref
)