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"
19 #include "qom/object.h"
22 typedef struct TypeImpl
*Type
;
24 typedef struct TypeInfo TypeInfo
;
26 typedef struct InterfaceClass InterfaceClass
;
27 typedef struct InterfaceInfo InterfaceInfo
;
29 #define TYPE_OBJECT "object"
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 * 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 * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
272 * This macro is typically used in a source file, and will:
274 * - declare prototypes for _finalize, _class_init and _init methods
275 * - declare the TypeInfo struct instance
276 * - provide the constructor to register the type
278 * After using this macro, implementations of the _finalize, _class_init,
279 * and _init methods need to be written. Any of these can be zero-line
280 * no-op impls if no special logic is required for a given type.
282 * This macro should rarely be used, instead one of the more specialized
283 * macros is usually a better choice.
285 #define OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
286 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
289 module_obj_name##_finalize(Object *obj); \
291 module_obj_name##_class_init(ObjectClass *oc, void *data); \
293 module_obj_name##_init(Object *obj); \
295 static const TypeInfo module_obj_name##_info = { \
296 .parent = TYPE_##PARENT_MODULE_OBJ_NAME, \
297 .name = TYPE_##MODULE_OBJ_NAME, \
298 .instance_size = sizeof(ModuleObjName), \
299 .instance_align = __alignof__(ModuleObjName), \
300 .instance_init = module_obj_name##_init, \
301 .instance_finalize = module_obj_name##_finalize, \
302 .class_size = sizeof(ModuleObjName##Class), \
303 .class_init = module_obj_name##_class_init, \
304 .abstract = ABSTRACT, \
305 .interfaces = (InterfaceInfo[]) { __VA_ARGS__ } , \
309 module_obj_name##_register_types(void) \
311 type_register_static(&module_obj_name##_info); \
313 type_init(module_obj_name##_register_types);
316 * OBJECT_DEFINE_TYPE:
317 * @ModuleObjName: the object name with initial caps
318 * @module_obj_name: the object name in lowercase with underscore separators
319 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
320 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
323 * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable
324 * for the common case of a non-abstract type, without any interfaces.
326 #define OBJECT_DEFINE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME, \
327 PARENT_MODULE_OBJ_NAME) \
328 OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
329 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
333 * OBJECT_DEFINE_TYPE_WITH_INTERFACES:
334 * @ModuleObjName: the object name with initial caps
335 * @module_obj_name: the object name in lowercase with underscore separators
336 * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
337 * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with underscore
339 * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
341 * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable
342 * for the common case of a non-abstract type, with one or more implemented
345 * Note when passing the list of interfaces, be sure to include the final
346 * NULL entry, e.g. { TYPE_USER_CREATABLE }, { NULL }
348 #define OBJECT_DEFINE_TYPE_WITH_INTERFACES(ModuleObjName, 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_ABSTRACT_TYPE:
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
363 * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable
364 * for defining an abstract type, without any interfaces.
366 #define OBJECT_DEFINE_ABSTRACT_TYPE(ModuleObjName, module_obj_name, \
367 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME) \
368 OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
369 MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
374 * @name: The name of the type.
375 * @parent: The name of the parent type.
376 * @instance_size: The size of the object (derivative of #Object). If
377 * @instance_size is 0, then the size of the object will be the size of the
379 * @instance_align: The required alignment of the object. If @instance_align
380 * is 0, then normal malloc alignment is sufficient; if non-zero, then we
381 * must use qemu_memalign for allocation.
382 * @instance_init: This function is called to initialize an object. The parent
383 * class will have already been initialized so the type is only responsible
384 * for initializing its own members.
385 * @instance_post_init: This function is called to finish initialization of
386 * an object, after all @instance_init functions were called.
387 * @instance_finalize: This function is called during object destruction. This
388 * is called before the parent @instance_finalize function has been called.
389 * An object should only free the members that are unique to its type in this
391 * @abstract: If this field is true, then the class is considered abstract and
392 * cannot be directly instantiated.
393 * @class_size: The size of the class object (derivative of #ObjectClass)
394 * for this object. If @class_size is 0, then the size of the class will be
395 * assumed to be the size of the parent class. This allows a type to avoid
396 * implementing an explicit class type if they are not adding additional
398 * @class_init: This function is called after all parent class initialization
399 * has occurred to allow a class to set its default virtual method pointers.
400 * This is also the function to use to override virtual methods from a parent
402 * @class_base_init: This function is called for all base classes after all
403 * parent class initialization has occurred, but before the class itself
404 * is initialized. This is the function to use to undo the effects of
405 * memcpy from the parent class to the descendants.
406 * @class_data: Data to pass to the @class_init,
407 * @class_base_init. This can be useful when building dynamic
409 * @interfaces: The list of interfaces associated with this type. This
410 * should point to a static array that's terminated with a zero filled
418 size_t instance_size
;
419 size_t instance_align
;
420 void (*instance_init
)(Object
*obj
);
421 void (*instance_post_init
)(Object
*obj
);
422 void (*instance_finalize
)(Object
*obj
);
427 void (*class_init
)(ObjectClass
*klass
, void *data
);
428 void (*class_base_init
)(ObjectClass
*klass
, void *data
);
431 InterfaceInfo
*interfaces
;
436 * @obj: A derivative of #Object
438 * Converts an object to a #Object. Since all objects are #Objects,
439 * this function will always succeed.
441 #define OBJECT(obj) \
446 * @class: A derivative of #ObjectClass.
448 * Converts a class to an #ObjectClass. Since all objects are #Objects,
449 * this function will always succeed.
451 #define OBJECT_CLASS(class) \
452 ((ObjectClass *)(class))
456 * @type: The C type to use for the return value.
457 * @obj: A derivative of @type to cast.
458 * @name: The QOM typename of @type
460 * A type safe version of @object_dynamic_cast_assert. Typically each class
461 * will define a macro based on this type to perform type safe dynamic_casts to
464 * If an invalid object is passed to this function, a run time assert will be
467 #define OBJECT_CHECK(type, obj, name) \
468 ((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \
469 __FILE__, __LINE__, __func__))
472 * OBJECT_CLASS_CHECK:
473 * @class_type: The C type to use for the return value.
474 * @class: A derivative class of @class_type to cast.
475 * @name: the QOM typename of @class_type.
477 * A type safe version of @object_class_dynamic_cast_assert. This macro is
478 * typically wrapped by each type to perform type safe casts of a class to a
479 * specific class type.
481 #define OBJECT_CLASS_CHECK(class_type, class, name) \
482 ((class_type *)object_class_dynamic_cast_assert(OBJECT_CLASS(class), (name), \
483 __FILE__, __LINE__, __func__))
487 * @class: The C type to use for the return value.
488 * @obj: The object to obtain the class for.
489 * @name: The QOM typename of @obj.
491 * This function will return a specific class for a given object. Its generally
492 * used by each type to provide a type safe macro to get a specific class type
495 #define OBJECT_GET_CLASS(class, obj, name) \
496 OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
499 * struct InterfaceInfo:
500 * @type: The name of the interface.
502 * The information associated with an interface.
504 struct InterfaceInfo
{
509 * struct InterfaceClass:
510 * @parent_class: the base class
512 * The class for all interfaces. Subclasses of this class should only add
515 struct InterfaceClass
517 ObjectClass parent_class
;
519 ObjectClass
*concrete_class
;
523 #define TYPE_INTERFACE "interface"
527 * @klass: class to cast from
528 * Returns: An #InterfaceClass or raise an error if cast is invalid
530 #define INTERFACE_CLASS(klass) \
531 OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE)
535 * @interface: the type to return
536 * @obj: the object to convert to an interface
537 * @name: the interface type name
539 * Returns: @obj casted to @interface if cast is valid, otherwise raise error.
541 #define INTERFACE_CHECK(interface, obj, name) \
542 ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \
543 __FILE__, __LINE__, __func__))
546 * object_new_with_class:
547 * @klass: The class to instantiate.
549 * This function will initialize a new object using heap allocated memory.
550 * The returned object has a reference count of 1, and will be freed when
551 * the last reference is dropped.
553 * Returns: The newly allocated and instantiated object.
555 Object
*object_new_with_class(ObjectClass
*klass
);
559 * @typename: The name of the type of the object to instantiate.
561 * This function will initialize a new object using heap allocated memory.
562 * The returned object has a reference count of 1, and will be freed when
563 * the last reference is dropped.
565 * Returns: The newly allocated and instantiated object.
567 Object
*object_new(const char *typename
);
570 * object_new_with_props:
571 * @typename: The name of the type of the object to instantiate.
572 * @parent: the parent object
573 * @id: The unique ID of the object
574 * @errp: pointer to error object
575 * @...: list of property names and values
577 * This function will initialize a new object using heap allocated memory.
578 * The returned object has a reference count of 1, and will be freed when
579 * the last reference is dropped.
581 * The @id parameter will be used when registering the object as a
582 * child of @parent in the composition tree.
584 * The variadic parameters are a list of pairs of (propname, propvalue)
585 * strings. The propname of %NULL indicates the end of the property
586 * list. If the object implements the user creatable interface, the
587 * object will be marked complete once all the properties have been
591 * :caption: Creating an object with properties
596 * obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE,
597 * object_get_objects_root(),
601 * "mem-path", "/dev/shm/somefile",
607 * error_reportf_err(err, "Cannot create memory backend: ");
610 * The returned object will have one stable reference maintained
611 * for as long as it is present in the object hierarchy.
613 * Returns: The newly allocated, instantiated & initialized object.
615 Object
*object_new_with_props(const char *typename
,
622 * object_new_with_propv:
623 * @typename: The name of the type of the object to instantiate.
624 * @parent: the parent object
625 * @id: The unique ID of the object
626 * @errp: pointer to error object
627 * @vargs: list of property names and values
629 * See object_new_with_props() for documentation.
631 Object
*object_new_with_propv(const char *typename
,
637 bool object_apply_global_props(Object
*obj
, const GPtrArray
*props
,
639 void object_set_machine_compat_props(GPtrArray
*compat_props
);
640 void object_set_accelerator_compat_props(GPtrArray
*compat_props
);
641 void object_register_sugar_prop(const char *driver
, const char *prop
,
642 const char *value
, bool optional
);
643 void object_apply_compat_props(Object
*obj
);
647 * @obj: the object instance to set properties on
648 * @errp: pointer to error object
649 * @...: list of property names and values
651 * This function will set a list of properties on an existing object
654 * The variadic parameters are a list of pairs of (propname, propvalue)
655 * strings. The propname of %NULL indicates the end of the property
659 * :caption: Update an object's properties
662 * Object *obj = ...get / create object...;
664 * if (!object_set_props(obj,
667 * "mem-path", "/dev/shm/somefile",
671 * error_reportf_err(err, "Cannot set properties: ");
674 * The returned object will have one stable reference maintained
675 * for as long as it is present in the object hierarchy.
677 * Returns: %true on success, %false on error.
679 bool object_set_props(Object
*obj
, Error
**errp
, ...) QEMU_SENTINEL
;
683 * @obj: the object instance to set properties on
684 * @errp: pointer to error object
685 * @vargs: list of property names and values
687 * See object_set_props() for documentation.
689 * Returns: %true on success, %false on error.
691 bool object_set_propv(Object
*obj
, Error
**errp
, va_list vargs
);
695 * @obj: A pointer to the memory to be used for the object.
696 * @size: The maximum size available at @obj for the object.
697 * @typename: The name of the type of the object to instantiate.
699 * This function will initialize an object. The memory for the object should
700 * have already been allocated. The returned object has a reference count of 1,
701 * and will be finalized when the last reference is dropped.
703 void object_initialize(void *obj
, size_t size
, const char *typename
);
706 * object_initialize_child_with_props:
707 * @parentobj: The parent object to add a property to
708 * @propname: The name of the property
709 * @childobj: A pointer to the memory to be used for the object.
710 * @size: The maximum size available at @childobj for the object.
711 * @type: The name of the type of the object to instantiate.
712 * @errp: If an error occurs, a pointer to an area to store the error
713 * @...: list of property names and values
715 * This function will initialize an object. The memory for the object should
716 * have already been allocated. The object will then be added as child property
717 * to a parent with object_property_add_child() function. The returned object
718 * has a reference count of 1 (for the "child<...>" property from the parent),
719 * so the object will be finalized automatically when the parent gets removed.
721 * The variadic parameters are a list of pairs of (propname, propvalue)
722 * strings. The propname of %NULL indicates the end of the property list.
723 * If the object implements the user creatable interface, the object will
724 * be marked complete once all the properties have been processed.
726 * Returns: %true on success, %false on failure.
728 bool object_initialize_child_with_props(Object
*parentobj
,
729 const char *propname
,
730 void *childobj
, size_t size
, const char *type
,
731 Error
**errp
, ...) QEMU_SENTINEL
;
734 * object_initialize_child_with_propsv:
735 * @parentobj: The parent object to add a property to
736 * @propname: The name of the property
737 * @childobj: A pointer to the memory to be used for the object.
738 * @size: The maximum size available at @childobj for the object.
739 * @type: The name of the type of the object to instantiate.
740 * @errp: If an error occurs, a pointer to an area to store the error
741 * @vargs: list of property names and values
743 * See object_initialize_child() for documentation.
745 * Returns: %true on success, %false on failure.
747 bool object_initialize_child_with_propsv(Object
*parentobj
,
748 const char *propname
,
749 void *childobj
, size_t size
, const char *type
,
750 Error
**errp
, va_list vargs
);
753 * object_initialize_child:
754 * @parent: The parent object to add a property to
755 * @propname: The name of the property
756 * @child: A precisely typed pointer to the memory to be used for the
758 * @type: The name of the type of the object to instantiate.
762 * object_initialize_child_with_props(parent, propname,
763 * child, sizeof(*child), type,
764 * &error_abort, NULL)
766 #define object_initialize_child(parent, propname, child, type) \
767 object_initialize_child_internal((parent), (propname), \
768 (child), sizeof(*(child)), (type))
769 void object_initialize_child_internal(Object
*parent
, const char *propname
,
770 void *child
, size_t size
,
774 * object_dynamic_cast:
775 * @obj: The object to cast.
776 * @typename: The @typename to cast to.
778 * This function will determine if @obj is-a @typename. @obj can refer to an
779 * object or an interface associated with an object.
781 * Returns: This function returns @obj on success or #NULL on failure.
783 Object
*object_dynamic_cast(Object
*obj
, const char *typename
);
786 * object_dynamic_cast_assert:
787 * @obj: The object to cast.
788 * @typename: The @typename to cast to.
789 * @file: Source code file where function was called
790 * @line: Source code line where function was called
791 * @func: Name of function where this function was called
793 * See object_dynamic_cast() for a description of the parameters of this
794 * function. The only difference in behavior is that this function asserts
795 * instead of returning #NULL on failure if QOM cast debugging is enabled.
796 * This function is not meant to be called directly, but only through
797 * the wrapper macro OBJECT_CHECK.
799 Object
*object_dynamic_cast_assert(Object
*obj
, const char *typename
,
800 const char *file
, int line
, const char *func
);
804 * @obj: A derivative of #Object
806 * Returns: The #ObjectClass of the type associated with @obj.
808 ObjectClass
*object_get_class(Object
*obj
);
811 * object_get_typename:
812 * @obj: A derivative of #Object.
814 * Returns: The QOM typename of @obj.
816 const char *object_get_typename(const Object
*obj
);
819 * type_register_static:
820 * @info: The #TypeInfo of the new type.
822 * @info and all of the strings it points to should exist for the life time
823 * that the type is registered.
825 * Returns: the new #Type.
827 Type
type_register_static(const TypeInfo
*info
);
831 * @info: The #TypeInfo of the new type
833 * Unlike type_register_static(), this call does not require @info or its
834 * string members to continue to exist after the call returns.
836 * Returns: the new #Type.
838 Type
type_register(const TypeInfo
*info
);
841 * type_register_static_array:
842 * @infos: The array of the new type #TypeInfo structures.
843 * @nr_infos: number of entries in @infos
845 * @infos and all of the strings it points to should exist for the life time
846 * that the type is registered.
848 void type_register_static_array(const TypeInfo
*infos
, int nr_infos
);
852 * @type_array: The array containing #TypeInfo structures to register
854 * @type_array should be static constant that exists for the life time
855 * that the type is registered.
857 #define DEFINE_TYPES(type_array) \
858 static void do_qemu_init_ ## type_array(void) \
860 type_register_static_array(type_array, ARRAY_SIZE(type_array)); \
862 type_init(do_qemu_init_ ## type_array)
865 * type_print_class_properties:
866 * @type: a QOM class name
868 * Print the object's class properties to stdout or the monitor.
869 * Return whether an object was found.
871 bool type_print_class_properties(const char *type
);
874 * object_set_properties_from_keyval:
876 * @qdict: a dictionary with the properties to be set
877 * @from_json: true if leaf values of @qdict are typed, false if they
879 * @errp: pointer to error object
881 * For each key in the dictionary, parse the value string if needed,
882 * then set the corresponding property in @obj.
884 void object_set_properties_from_keyval(Object
*obj
, const QDict
*qdict
,
885 bool from_json
, Error
**errp
);
888 * object_class_dynamic_cast_assert:
889 * @klass: The #ObjectClass to attempt to cast.
890 * @typename: The QOM typename of the class to cast to.
891 * @file: Source code file where function was called
892 * @line: Source code line where function was called
893 * @func: Name of function where this function was called
895 * See object_class_dynamic_cast() for a description of the parameters
896 * of this function. The only difference in behavior is that this function
897 * asserts instead of returning #NULL on failure if QOM cast debugging is
898 * enabled. This function is not meant to be called directly, but only through
899 * the wrapper macro OBJECT_CLASS_CHECK.
901 ObjectClass
*object_class_dynamic_cast_assert(ObjectClass
*klass
,
902 const char *typename
,
903 const char *file
, int line
,
907 * object_class_dynamic_cast:
908 * @klass: The #ObjectClass to attempt to cast.
909 * @typename: The QOM typename of the class to cast to.
911 * Returns: If @typename is a class, this function returns @klass if
912 * @typename is a subtype of @klass, else returns #NULL.
914 * If @typename is an interface, this function returns the interface
915 * definition for @klass if @klass implements it unambiguously; #NULL
916 * is returned if @klass does not implement the interface or if multiple
917 * classes or interfaces on the hierarchy leading to @klass implement
918 * it. (FIXME: perhaps this can be detected at type definition time?)
920 ObjectClass
*object_class_dynamic_cast(ObjectClass
*klass
,
921 const char *typename
);
924 * object_class_get_parent:
925 * @klass: The class to obtain the parent for.
927 * Returns: The parent for @klass or %NULL if none.
929 ObjectClass
*object_class_get_parent(ObjectClass
*klass
);
932 * object_class_get_name:
933 * @klass: The class to obtain the QOM typename for.
935 * Returns: The QOM typename for @klass.
937 const char *object_class_get_name(ObjectClass
*klass
);
940 * object_class_is_abstract:
941 * @klass: The class to obtain the abstractness for.
943 * Returns: %true if @klass is abstract, %false otherwise.
945 bool object_class_is_abstract(ObjectClass
*klass
);
948 * object_class_by_name:
949 * @typename: The QOM typename to obtain the class for.
951 * Returns: The class for @typename or %NULL if not found.
953 ObjectClass
*object_class_by_name(const char *typename
);
956 * module_object_class_by_name:
957 * @typename: The QOM typename to obtain the class for.
959 * For objects which might be provided by a module. Behaves like
960 * object_class_by_name, but additionally tries to load the module
961 * needed in case the class is not available.
963 * Returns: The class for @typename or %NULL if not found.
965 ObjectClass
*module_object_class_by_name(const char *typename
);
967 void object_class_foreach(void (*fn
)(ObjectClass
*klass
, void *opaque
),
968 const char *implements_type
, bool include_abstract
,
972 * object_class_get_list:
973 * @implements_type: The type to filter for, including its derivatives.
974 * @include_abstract: Whether to include abstract classes.
976 * Returns: A singly-linked list of the classes in reverse hashtable order.
978 GSList
*object_class_get_list(const char *implements_type
,
979 bool include_abstract
);
982 * object_class_get_list_sorted:
983 * @implements_type: The type to filter for, including its derivatives.
984 * @include_abstract: Whether to include abstract classes.
986 * Returns: A singly-linked list of the classes in alphabetical
987 * case-insensitive order.
989 GSList
*object_class_get_list_sorted(const char *implements_type
,
990 bool include_abstract
);
996 * Increase the reference count of a object. A object cannot be freed as long
997 * as its reference count is greater than zero.
1000 Object
*object_ref(void *obj
);
1006 * Decrease the reference count of a object. A object cannot be freed as long
1007 * as its reference count is greater than zero.
1009 void object_unref(void *obj
);
1012 * object_property_try_add:
1013 * @obj: the object to add a property to
1014 * @name: the name of the property. This can contain any character except for
1015 * a forward slash. In general, you should use hyphens '-' instead of
1016 * underscores '_' when naming properties.
1017 * @type: the type name of the property. This namespace is pretty loosely
1018 * defined. Sub namespaces are constructed by using a prefix and then
1019 * to angle brackets. For instance, the type 'virtio-net-pci' in the
1020 * 'link' namespace would be 'link<virtio-net-pci>'.
1021 * @get: The getter to be called to read a property. If this is NULL, then
1022 * the property cannot be read.
1023 * @set: the setter to be called to write a property. If this is NULL,
1024 * then the property cannot be written.
1025 * @release: called when the property is removed from the object. This is
1026 * meant to allow a property to free its opaque upon object
1027 * destruction. This may be NULL.
1028 * @opaque: an opaque pointer to pass to the callbacks for the property
1029 * @errp: pointer to error object
1031 * Returns: The #ObjectProperty; this can be used to set the @resolve
1032 * callback for child and link properties.
1034 ObjectProperty
*object_property_try_add(Object
*obj
, const char *name
,
1036 ObjectPropertyAccessor
*get
,
1037 ObjectPropertyAccessor
*set
,
1038 ObjectPropertyRelease
*release
,
1039 void *opaque
, Error
**errp
);
1042 * object_property_add:
1043 * Same as object_property_try_add() with @errp hardcoded to
1046 * @obj: the object to add a property to
1047 * @name: the name of the property. This can contain any character except for
1048 * a forward slash. In general, you should use hyphens '-' instead of
1049 * underscores '_' when naming properties.
1050 * @type: the type name of the property. This namespace is pretty loosely
1051 * defined. Sub namespaces are constructed by using a prefix and then
1052 * to angle brackets. For instance, the type 'virtio-net-pci' in the
1053 * 'link' namespace would be 'link<virtio-net-pci>'.
1054 * @get: The getter to be called to read a property. If this is NULL, then
1055 * the property cannot be read.
1056 * @set: the setter to be called to write a property. If this is NULL,
1057 * then the property cannot be written.
1058 * @release: called when the property is removed from the object. This is
1059 * meant to allow a property to free its opaque upon object
1060 * destruction. This may be NULL.
1061 * @opaque: an opaque pointer to pass to the callbacks for the property
1063 ObjectProperty
*object_property_add(Object
*obj
, const char *name
,
1065 ObjectPropertyAccessor
*get
,
1066 ObjectPropertyAccessor
*set
,
1067 ObjectPropertyRelease
*release
,
1070 void object_property_del(Object
*obj
, const char *name
);
1072 ObjectProperty
*object_class_property_add(ObjectClass
*klass
, const char *name
,
1074 ObjectPropertyAccessor
*get
,
1075 ObjectPropertyAccessor
*set
,
1076 ObjectPropertyRelease
*release
,
1080 * object_property_set_default_bool:
1081 * @prop: the property to set
1082 * @value: the value to be written to the property
1084 * Set the property default value.
1086 void object_property_set_default_bool(ObjectProperty
*prop
, bool value
);
1089 * object_property_set_default_str:
1090 * @prop: the property to set
1091 * @value: the value to be written to the property
1093 * Set the property default value.
1095 void object_property_set_default_str(ObjectProperty
*prop
, const char *value
);
1098 * object_property_set_default_int:
1099 * @prop: the property to set
1100 * @value: the value to be written to the property
1102 * Set the property default value.
1104 void object_property_set_default_int(ObjectProperty
*prop
, int64_t value
);
1107 * object_property_set_default_uint:
1108 * @prop: the property to set
1109 * @value: the value to be written to the property
1111 * Set the property default value.
1113 void object_property_set_default_uint(ObjectProperty
*prop
, uint64_t value
);
1116 * object_property_find:
1118 * @name: the name of the property
1120 * Look up a property for an object.
1122 * Return its #ObjectProperty if found, or NULL.
1124 ObjectProperty
*object_property_find(Object
*obj
, const char *name
);
1127 * object_property_find_err:
1129 * @name: the name of the property
1130 * @errp: returns an error if this function fails
1132 * Look up a property for an object.
1134 * Return its #ObjectProperty if found, or NULL.
1136 ObjectProperty
*object_property_find_err(Object
*obj
,
1141 * object_class_property_find:
1142 * @klass: the object class
1143 * @name: the name of the property
1145 * Look up a property for an object class.
1147 * Return its #ObjectProperty if found, or NULL.
1149 ObjectProperty
*object_class_property_find(ObjectClass
*klass
,
1153 * object_class_property_find_err:
1154 * @klass: the object class
1155 * @name: the name of the property
1156 * @errp: returns an error if this function fails
1158 * Look up a property for an object class.
1160 * Return its #ObjectProperty if found, or NULL.
1162 ObjectProperty
*object_class_property_find_err(ObjectClass
*klass
,
1166 typedef struct ObjectPropertyIterator
{
1167 ObjectClass
*nextclass
;
1168 GHashTableIter iter
;
1169 } ObjectPropertyIterator
;
1172 * object_property_iter_init:
1173 * @iter: the iterator instance
1176 * Initializes an iterator for traversing all properties
1177 * registered against an object instance, its class and all parent classes.
1179 * It is forbidden to modify the property list while iterating,
1180 * whether removing or adding properties.
1182 * Typical usage pattern would be
1185 * :caption: Using object property iterators
1187 * ObjectProperty *prop;
1188 * ObjectPropertyIterator iter;
1190 * object_property_iter_init(&iter, obj);
1191 * while ((prop = object_property_iter_next(&iter))) {
1192 * ... do something with prop ...
1195 void object_property_iter_init(ObjectPropertyIterator
*iter
,
1199 * object_class_property_iter_init:
1200 * @iter: the iterator instance
1203 * Initializes an iterator for traversing all properties
1204 * registered against an object class and all parent classes.
1206 * It is forbidden to modify the property list while iterating,
1207 * whether removing or adding properties.
1209 * This can be used on abstract classes as it does not create a temporary
1212 void object_class_property_iter_init(ObjectPropertyIterator
*iter
,
1213 ObjectClass
*klass
);
1216 * object_property_iter_next:
1217 * @iter: the iterator instance
1219 * Return the next available property. If no further properties
1220 * are available, a %NULL value will be returned and the @iter
1221 * pointer should not be used again after this point without
1222 * re-initializing it.
1224 * Returns: the next property, or %NULL when all properties
1225 * have been traversed.
1227 ObjectProperty
*object_property_iter_next(ObjectPropertyIterator
*iter
);
1229 void object_unparent(Object
*obj
);
1232 * object_property_get:
1234 * @name: the name of the property
1235 * @v: the visitor that will receive the property value. This should be an
1236 * Output visitor and the data will be written with @name as the name.
1237 * @errp: returns an error if this function fails
1239 * Reads a property from a object.
1241 * Returns: %true on success, %false on failure.
1243 bool object_property_get(Object
*obj
, const char *name
, Visitor
*v
,
1247 * object_property_set_str:
1249 * @name: the name of the property
1250 * @value: the value to be written to the property
1251 * @errp: returns an error if this function fails
1253 * Writes a string value to a property.
1255 * Returns: %true on success, %false on failure.
1257 bool object_property_set_str(Object
*obj
, const char *name
,
1258 const char *value
, Error
**errp
);
1261 * object_property_get_str:
1263 * @name: the name of the property
1264 * @errp: returns an error if this function fails
1266 * Returns: the value of the property, converted to a C string, or NULL if
1267 * an error occurs (including when the property value is not a string).
1268 * The caller should free the string.
1270 char *object_property_get_str(Object
*obj
, const char *name
,
1274 * object_property_set_link:
1276 * @name: the name of the property
1277 * @value: the value to be written to the property
1278 * @errp: returns an error if this function fails
1280 * Writes an object's canonical path to a property.
1282 * If the link property was created with
1283 * %OBJ_PROP_LINK_STRONG bit, the old target object is
1284 * unreferenced, and a reference is added to the new target object.
1286 * Returns: %true on success, %false on failure.
1288 bool object_property_set_link(Object
*obj
, const char *name
,
1289 Object
*value
, Error
**errp
);
1292 * object_property_get_link:
1294 * @name: the name of the property
1295 * @errp: returns an error if this function fails
1297 * Returns: the value of the property, resolved from a path to an Object,
1298 * or NULL if an error occurs (including when the property value is not a
1299 * string or not a valid object path).
1301 Object
*object_property_get_link(Object
*obj
, const char *name
,
1305 * object_property_set_bool:
1307 * @name: the name of the property
1308 * @value: the value to be written to the property
1309 * @errp: returns an error if this function fails
1311 * Writes a bool value to a property.
1313 * Returns: %true on success, %false on failure.
1315 bool object_property_set_bool(Object
*obj
, const char *name
,
1316 bool value
, Error
**errp
);
1319 * object_property_get_bool:
1321 * @name: the name of the property
1322 * @errp: returns an error if this function fails
1324 * Returns: the value of the property, converted to a boolean, or false if
1325 * an error occurs (including when the property value is not a bool).
1327 bool object_property_get_bool(Object
*obj
, const char *name
,
1331 * object_property_set_int:
1333 * @name: the name of the property
1334 * @value: the value to be written to the property
1335 * @errp: returns an error if this function fails
1337 * Writes an integer value to a property.
1339 * Returns: %true on success, %false on failure.
1341 bool object_property_set_int(Object
*obj
, const char *name
,
1342 int64_t value
, Error
**errp
);
1345 * object_property_get_int:
1347 * @name: the name of the property
1348 * @errp: returns an error if this function fails
1350 * Returns: the value of the property, converted to an integer, or -1 if
1351 * an error occurs (including when the property value is not an integer).
1353 int64_t object_property_get_int(Object
*obj
, const char *name
,
1357 * object_property_set_uint:
1359 * @name: the name of the property
1360 * @value: the value to be written to the property
1361 * @errp: returns an error if this function fails
1363 * Writes an unsigned integer value to a property.
1365 * Returns: %true on success, %false on failure.
1367 bool object_property_set_uint(Object
*obj
, const char *name
,
1368 uint64_t value
, Error
**errp
);
1371 * object_property_get_uint:
1373 * @name: the name of the property
1374 * @errp: returns an error if this function fails
1376 * Returns: the value of the property, converted to an unsigned integer, or 0
1377 * an error occurs (including when the property value is not an integer).
1379 uint64_t object_property_get_uint(Object
*obj
, const char *name
,
1383 * object_property_get_enum:
1385 * @name: the name of the property
1386 * @typename: the name of the enum data type
1387 * @errp: returns an error if this function fails
1389 * Returns: the value of the property, converted to an integer (which
1390 * can't be negative), or -1 on error (including when the property
1391 * value is not an enum).
1393 int object_property_get_enum(Object
*obj
, const char *name
,
1394 const char *typename
, Error
**errp
);
1397 * object_property_set:
1399 * @name: the name of the property
1400 * @v: the visitor that will be used to write the property value. This should
1401 * be an Input visitor and the data will be first read with @name as the
1402 * name and then written as the property value.
1403 * @errp: returns an error if this function fails
1405 * Writes a property to a object.
1407 * Returns: %true on success, %false on failure.
1409 bool object_property_set(Object
*obj
, const char *name
, Visitor
*v
,
1413 * object_property_parse:
1415 * @name: the name of the property
1416 * @string: the string that will be used to parse the property value.
1417 * @errp: returns an error if this function fails
1419 * Parses a string and writes the result into a property of an object.
1421 * Returns: %true on success, %false on failure.
1423 bool object_property_parse(Object
*obj
, const char *name
,
1424 const char *string
, Error
**errp
);
1427 * object_property_print:
1429 * @name: the name of the property
1430 * @human: if true, print for human consumption
1431 * @errp: returns an error if this function fails
1433 * Returns a string representation of the value of the property. The
1434 * caller shall free the string.
1436 char *object_property_print(Object
*obj
, const char *name
, bool human
,
1440 * object_property_get_type:
1442 * @name: the name of the property
1443 * @errp: returns an error if this function fails
1445 * Returns: The type name of the property.
1447 const char *object_property_get_type(Object
*obj
, const char *name
,
1453 * Returns: the root object of the composition tree
1455 Object
*object_get_root(void);
1459 * object_get_objects_root:
1461 * Get the container object that holds user created
1462 * object instances. This is the object at path
1465 * Returns: the user object container
1467 Object
*object_get_objects_root(void);
1470 * object_get_internal_root:
1472 * Get the container object that holds internally used object
1473 * instances. Any object which is put into this container must not be
1474 * user visible, and it will not be exposed in the QOM tree.
1476 * Returns: the internal object container
1478 Object
*object_get_internal_root(void);
1481 * object_get_canonical_path_component:
1484 * Returns: The final component in the object's canonical path. The canonical
1485 * path is the path within the composition tree starting from the root.
1486 * %NULL if the object doesn't have a parent (and thus a canonical path).
1488 const char *object_get_canonical_path_component(const Object
*obj
);
1491 * object_get_canonical_path:
1494 * Returns: The canonical path for a object, newly allocated. This is
1495 * the path within the composition tree starting from the root. Use
1496 * g_free() to free it.
1498 char *object_get_canonical_path(const Object
*obj
);
1501 * object_resolve_path:
1502 * @path: the path to resolve
1503 * @ambiguous: returns true if the path resolution failed because of an
1506 * There are two types of supported paths--absolute paths and partial paths.
1508 * Absolute paths are derived from the root object and can follow child<> or
1509 * link<> properties. Since they can follow link<> properties, they can be
1510 * arbitrarily long. Absolute paths look like absolute filenames and are
1511 * prefixed with a leading slash.
1513 * Partial paths look like relative filenames. They do not begin with a
1514 * prefix. The matching rules for partial paths are subtle but designed to make
1515 * specifying objects easy. At each level of the composition tree, the partial
1516 * path is matched as an absolute path. The first match is not returned. At
1517 * least two matches are searched for. A successful result is only returned if
1518 * only one match is found. If more than one match is found, a flag is
1519 * returned to indicate that the match was ambiguous.
1521 * Returns: The matched object or NULL on path lookup failure.
1523 Object
*object_resolve_path(const char *path
, bool *ambiguous
);
1526 * object_resolve_path_type:
1527 * @path: the path to resolve
1528 * @typename: the type to look for.
1529 * @ambiguous: returns true if the path resolution failed because of an
1532 * This is similar to object_resolve_path. However, when looking for a
1533 * partial path only matches that implement the given type are considered.
1534 * This restricts the search and avoids spuriously flagging matches as
1537 * For both partial and absolute paths, the return value goes through
1538 * a dynamic cast to @typename. This is important if either the link,
1539 * or the typename itself are of interface types.
1541 * Returns: The matched object or NULL on path lookup failure.
1543 Object
*object_resolve_path_type(const char *path
, const char *typename
,
1547 * object_resolve_path_at:
1548 * @parent: the object in which to resolve the path
1549 * @path: the path to resolve
1551 * This is like object_resolve_path(), except paths not starting with
1552 * a slash are relative to @parent.
1554 * Returns: The resolved object or NULL on path lookup failure.
1556 Object
*object_resolve_path_at(Object
*parent
, const char *path
);
1559 * object_resolve_path_component:
1560 * @parent: the object in which to resolve the path
1561 * @part: the component to resolve.
1563 * This is similar to object_resolve_path with an absolute path, but it
1564 * only resolves one element (@part) and takes the others from @parent.
1566 * Returns: The resolved object or NULL on path lookup failure.
1568 Object
*object_resolve_path_component(Object
*parent
, const char *part
);
1571 * object_property_try_add_child:
1572 * @obj: the object to add a property to
1573 * @name: the name of the property
1574 * @child: the child object
1575 * @errp: pointer to error object
1577 * Child properties form the composition tree. All objects need to be a child
1578 * of another object. Objects can only be a child of one object.
1580 * There is no way for a child to determine what its parent is. It is not
1581 * a bidirectional relationship. This is by design.
1583 * The value of a child property as a C string will be the child object's
1584 * canonical path. It can be retrieved using object_property_get_str().
1585 * The child object itself can be retrieved using object_property_get_link().
1587 * Returns: The newly added property on success, or %NULL on failure.
1589 ObjectProperty
*object_property_try_add_child(Object
*obj
, const char *name
,
1590 Object
*child
, Error
**errp
);
1593 * object_property_add_child:
1594 * @obj: the object to add a property to
1595 * @name: the name of the property
1596 * @child: the child object
1598 * Same as object_property_try_add_child() with @errp hardcoded to
1601 ObjectProperty
*object_property_add_child(Object
*obj
, const char *name
,
1605 /* Unref the link pointer when the property is deleted */
1606 OBJ_PROP_LINK_STRONG
= 0x1,
1609 OBJ_PROP_LINK_DIRECT
= 0x2,
1610 OBJ_PROP_LINK_CLASS
= 0x4,
1611 } ObjectPropertyLinkFlags
;
1614 * object_property_allow_set_link:
1615 * @obj: the object to add a property to
1616 * @name: the name of the property
1617 * @child: the child object
1618 * @errp: pointer to error object
1620 * The default implementation of the object_property_add_link() check()
1621 * callback function. It allows the link property to be set and never returns
1624 void object_property_allow_set_link(const Object
*obj
, const char *name
,
1625 Object
*child
, Error
**errp
);
1628 * object_property_add_link:
1629 * @obj: the object to add a property to
1630 * @name: the name of the property
1631 * @type: the qobj type of the link
1632 * @targetp: a pointer to where the link object reference is stored
1633 * @check: callback to veto setting or NULL if the property is read-only
1634 * @flags: additional options for the link
1636 * Links establish relationships between objects. Links are unidirectional
1637 * although two links can be combined to form a bidirectional relationship
1640 * Links form the graph in the object model.
1642 * The @check() callback is invoked when
1643 * object_property_set_link() is called and can raise an error to prevent the
1644 * link being set. If @check is NULL, the property is read-only
1645 * and cannot be set.
1647 * Ownership of the pointer that @child points to is transferred to the
1648 * link property. The reference count for *@child is
1649 * managed by the property from after the function returns till the
1650 * property is deleted with object_property_del(). If the
1651 * @flags %OBJ_PROP_LINK_STRONG bit is set,
1652 * the reference count is decremented when the property is deleted or
1655 * Returns: The newly added property on success, or %NULL on failure.
1657 ObjectProperty
*object_property_add_link(Object
*obj
, const char *name
,
1658 const char *type
, Object
**targetp
,
1659 void (*check
)(const Object
*obj
, const char *name
,
1660 Object
*val
, Error
**errp
),
1661 ObjectPropertyLinkFlags flags
);
1663 ObjectProperty
*object_class_property_add_link(ObjectClass
*oc
,
1665 const char *type
, ptrdiff_t offset
,
1666 void (*check
)(const Object
*obj
, const char *name
,
1667 Object
*val
, Error
**errp
),
1668 ObjectPropertyLinkFlags flags
);
1671 * object_property_add_str:
1672 * @obj: the object to add a property to
1673 * @name: the name of the property
1674 * @get: the getter or NULL if the property is write-only. This function must
1675 * return a string to be freed by g_free().
1676 * @set: the setter or NULL if the property is read-only
1678 * Add a string property using getters/setters. This function will add a
1679 * property of type 'string'.
1681 * Returns: The newly added property on success, or %NULL on failure.
1683 ObjectProperty
*object_property_add_str(Object
*obj
, const char *name
,
1684 char *(*get
)(Object
*, Error
**),
1685 void (*set
)(Object
*, const char *, Error
**));
1687 ObjectProperty
*object_class_property_add_str(ObjectClass
*klass
,
1689 char *(*get
)(Object
*, Error
**),
1690 void (*set
)(Object
*, const char *,
1694 * object_property_add_bool:
1695 * @obj: the object to add a property to
1696 * @name: the name of the property
1697 * @get: the getter or NULL if the property is write-only.
1698 * @set: the setter or NULL if the property is read-only
1700 * Add a bool property using getters/setters. This function will add a
1701 * property of type 'bool'.
1703 * Returns: The newly added property on success, or %NULL on failure.
1705 ObjectProperty
*object_property_add_bool(Object
*obj
, const char *name
,
1706 bool (*get
)(Object
*, Error
**),
1707 void (*set
)(Object
*, bool, Error
**));
1709 ObjectProperty
*object_class_property_add_bool(ObjectClass
*klass
,
1711 bool (*get
)(Object
*, Error
**),
1712 void (*set
)(Object
*, bool, Error
**));
1715 * object_property_add_enum:
1716 * @obj: the object to add a property to
1717 * @name: the name of the property
1718 * @typename: the name of the enum data type
1719 * @lookup: enum value namelookup table
1720 * @get: the getter or %NULL if the property is write-only.
1721 * @set: the setter or %NULL if the property is read-only
1723 * Add an enum property using getters/setters. This function will add a
1724 * property of type '@typename'.
1726 * Returns: The newly added property on success, or %NULL on failure.
1728 ObjectProperty
*object_property_add_enum(Object
*obj
, const char *name
,
1729 const char *typename
,
1730 const QEnumLookup
*lookup
,
1731 int (*get
)(Object
*, Error
**),
1732 void (*set
)(Object
*, int, Error
**));
1734 ObjectProperty
*object_class_property_add_enum(ObjectClass
*klass
,
1736 const char *typename
,
1737 const QEnumLookup
*lookup
,
1738 int (*get
)(Object
*, Error
**),
1739 void (*set
)(Object
*, int, Error
**));
1742 * object_property_add_tm:
1743 * @obj: the object to add a property to
1744 * @name: the name of the property
1745 * @get: the getter or NULL if the property is write-only.
1747 * Add a read-only struct tm valued property using a getter function.
1748 * This function will add a property of type 'struct tm'.
1750 * Returns: The newly added property on success, or %NULL on failure.
1752 ObjectProperty
*object_property_add_tm(Object
*obj
, const char *name
,
1753 void (*get
)(Object
*, struct tm
*, Error
**));
1755 ObjectProperty
*object_class_property_add_tm(ObjectClass
*klass
,
1757 void (*get
)(Object
*, struct tm
*, Error
**));
1760 /* Automatically add a getter to the property */
1761 OBJ_PROP_FLAG_READ
= 1 << 0,
1762 /* Automatically add a setter to the property */
1763 OBJ_PROP_FLAG_WRITE
= 1 << 1,
1764 /* Automatically add a getter and a setter to the property */
1765 OBJ_PROP_FLAG_READWRITE
= (OBJ_PROP_FLAG_READ
| OBJ_PROP_FLAG_WRITE
),
1766 } ObjectPropertyFlags
;
1769 * object_property_add_uint8_ptr:
1770 * @obj: the object to add a property to
1771 * @name: the name of the property
1772 * @v: pointer to value
1773 * @flags: bitwise-or'd ObjectPropertyFlags
1775 * Add an integer property in memory. This function will add a
1776 * property of type 'uint8'.
1778 * Returns: The newly added property on success, or %NULL on failure.
1780 ObjectProperty
*object_property_add_uint8_ptr(Object
*obj
, const char *name
,
1782 ObjectPropertyFlags flags
);
1784 ObjectProperty
*object_class_property_add_uint8_ptr(ObjectClass
*klass
,
1787 ObjectPropertyFlags flags
);
1790 * object_property_add_uint16_ptr:
1791 * @obj: the object to add a property to
1792 * @name: the name of the property
1793 * @v: pointer to value
1794 * @flags: bitwise-or'd ObjectPropertyFlags
1796 * Add an integer property in memory. This function will add a
1797 * property of type 'uint16'.
1799 * Returns: The newly added property on success, or %NULL on failure.
1801 ObjectProperty
*object_property_add_uint16_ptr(Object
*obj
, const char *name
,
1803 ObjectPropertyFlags flags
);
1805 ObjectProperty
*object_class_property_add_uint16_ptr(ObjectClass
*klass
,
1808 ObjectPropertyFlags flags
);
1811 * object_property_add_uint32_ptr:
1812 * @obj: the object to add a property to
1813 * @name: the name of the property
1814 * @v: pointer to value
1815 * @flags: bitwise-or'd ObjectPropertyFlags
1817 * Add an integer property in memory. This function will add a
1818 * property of type 'uint32'.
1820 * Returns: The newly added property on success, or %NULL on failure.
1822 ObjectProperty
*object_property_add_uint32_ptr(Object
*obj
, const char *name
,
1824 ObjectPropertyFlags flags
);
1826 ObjectProperty
*object_class_property_add_uint32_ptr(ObjectClass
*klass
,
1829 ObjectPropertyFlags flags
);
1832 * object_property_add_uint64_ptr:
1833 * @obj: the object to add a property to
1834 * @name: the name of the property
1835 * @v: pointer to value
1836 * @flags: bitwise-or'd ObjectPropertyFlags
1838 * Add an integer property in memory. This function will add a
1839 * property of type 'uint64'.
1841 * Returns: The newly added property on success, or %NULL on failure.
1843 ObjectProperty
*object_property_add_uint64_ptr(Object
*obj
, const char *name
,
1845 ObjectPropertyFlags flags
);
1847 ObjectProperty
*object_class_property_add_uint64_ptr(ObjectClass
*klass
,
1850 ObjectPropertyFlags flags
);
1853 * object_property_add_alias:
1854 * @obj: the object to add a property to
1855 * @name: the name of the property
1856 * @target_obj: the object to forward property access to
1857 * @target_name: the name of the property on the forwarded object
1859 * Add an alias for a property on an object. This function will add a property
1860 * of the same type as the forwarded property.
1862 * The caller must ensure that @target_obj stays alive as long as
1863 * this property exists. In the case of a child object or an alias on the same
1864 * object this will be the case. For aliases to other objects the caller is
1865 * responsible for taking a reference.
1867 * Returns: The newly added property on success, or %NULL on failure.
1869 ObjectProperty
*object_property_add_alias(Object
*obj
, const char *name
,
1870 Object
*target_obj
, const char *target_name
);
1873 * object_property_add_const_link:
1874 * @obj: the object to add a property to
1875 * @name: the name of the property
1876 * @target: the object to be referred by the link
1878 * Add an unmodifiable link for a property on an object. This function will
1879 * add a property of type link<TYPE> where TYPE is the type of @target.
1881 * The caller must ensure that @target stays alive as long as
1882 * this property exists. In the case @target is a child of @obj,
1883 * this will be the case. Otherwise, the caller is responsible for
1884 * taking a reference.
1886 * Returns: The newly added property on success, or %NULL on failure.
1888 ObjectProperty
*object_property_add_const_link(Object
*obj
, const char *name
,
1892 * object_property_set_description:
1893 * @obj: the object owning the property
1894 * @name: the name of the property
1895 * @description: the description of the property on the object
1897 * Set an object property's description.
1899 * Returns: %true on success, %false on failure.
1901 void object_property_set_description(Object
*obj
, const char *name
,
1902 const char *description
);
1903 void object_class_property_set_description(ObjectClass
*klass
, const char *name
,
1904 const char *description
);
1907 * object_child_foreach:
1908 * @obj: the object whose children will be navigated
1909 * @fn: the iterator function to be called
1910 * @opaque: an opaque value that will be passed to the iterator
1912 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1915 * It is forbidden to add or remove children from @obj from the @fn
1918 * Returns: The last value returned by @fn, or 0 if there is no child.
1920 int object_child_foreach(Object
*obj
, int (*fn
)(Object
*child
, void *opaque
),
1924 * object_child_foreach_recursive:
1925 * @obj: the object whose children will be navigated
1926 * @fn: the iterator function to be called
1927 * @opaque: an opaque value that will be passed to the iterator
1929 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1930 * non-zero. Calls recursively, all child nodes of @obj will also be passed
1931 * all the way down to the leaf nodes of the tree. Depth first ordering.
1933 * It is forbidden to add or remove children from @obj (or its
1934 * child nodes) from the @fn callback.
1936 * Returns: The last value returned by @fn, or 0 if there is no child.
1938 int object_child_foreach_recursive(Object
*obj
,
1939 int (*fn
)(Object
*child
, void *opaque
),
1943 * @root: root of the #path, e.g., object_get_root()
1944 * @path: path to the container
1946 * Return a container object whose path is @path. Create more containers
1947 * along the path if necessary.
1949 * Returns: the container object.
1951 Object
*container_get(Object
*root
, const char *path
);
1954 * object_type_get_instance_size:
1955 * @typename: Name of the Type whose instance_size is required
1957 * Returns the instance_size of the given @typename.
1959 size_t object_type_get_instance_size(const char *typename
);
1962 * object_property_help:
1963 * @name: the name of the property
1964 * @type: the type of the property
1965 * @defval: the default value
1966 * @description: description of the property
1968 * Returns: a user-friendly formatted string describing the property
1969 * for help purposes.
1971 char *object_property_help(const char *name
, const char *type
,
1972 QObject
*defval
, const char *description
);
1974 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object
, object_unref
)