xref: /qemu/include/qom/object.h (revision d2c12785be06da708fe1c8e4e81d7134f4f3c56a)
1 /*
2  * QEMU Object Model
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
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.
11  *
12  */
13 
14 #ifndef QEMU_OBJECT_H
15 #define QEMU_OBJECT_H
16 
17 #include "qapi/qapi-builtin-types.h"
18 #include "qemu/module.h"
19 
20 struct TypeImpl;
21 typedef struct TypeImpl *Type;
22 
23 typedef struct TypeInfo TypeInfo;
24 
25 typedef struct InterfaceClass InterfaceClass;
26 typedef struct InterfaceInfo InterfaceInfo;
27 
28 #define TYPE_OBJECT "object"
29 #define TYPE_CONTAINER "container"
30 
31 typedef struct ObjectProperty ObjectProperty;
32 
33 /**
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.
40  *
41  * Called when trying to get/set a property.
42  */
43 typedef void (ObjectPropertyAccessor)(Object *obj,
44                                       Visitor *v,
45                                       const char *name,
46                                       void *opaque,
47                                       Error **errp);
48 
49 /**
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
54  *
55  * Resolves the #Object corresponding to property @part.
56  *
57  * The returned object can also be used as a starting point
58  * to resolve a relative path starting with "@part".
59  *
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.
63  */
64 typedef Object *(ObjectPropertyResolve)(Object *obj,
65                                         void *opaque,
66                                         const char *part);
67 
68 /**
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
73  *
74  * Called when a property is removed from a object.
75  */
76 typedef void (ObjectPropertyRelease)(Object *obj,
77                                      const char *name,
78                                      void *opaque);
79 
80 /**
81  * typedef ObjectPropertyInit:
82  * @obj: the object that owns the property
83  * @prop: the property to set
84  *
85  * Called when a property is initialized.
86  */
87 typedef void (ObjectPropertyInit)(Object *obj, ObjectProperty *prop);
88 
89 struct ObjectProperty
90 {
91     char *name;
92     char *type;
93     char *description;
94     ObjectPropertyAccessor *get;
95     ObjectPropertyAccessor *set;
96     ObjectPropertyResolve *resolve;
97     ObjectPropertyRelease *release;
98     ObjectPropertyInit *init;
99     void *opaque;
100     QObject *defval;
101 };
102 
103 /**
104  * typedef ObjectUnparent:
105  * @obj: the object that is being removed from the composition tree
106  *
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.
109  */
110 typedef void (ObjectUnparent)(Object *obj);
111 
112 /**
113  * typedef ObjectFree:
114  * @obj: the object being freed
115  *
116  * Called when an object's last reference is removed.
117  */
118 typedef void (ObjectFree)(void *obj);
119 
120 #define OBJECT_CLASS_CAST_CACHE 4
121 
122 /**
123  * struct ObjectClass:
124  *
125  * The base for all classes.  The only thing that #ObjectClass contains is an
126  * integer type handle.
127  */
128 struct ObjectClass
129 {
130     /* private: */
131     Type type;
132     GSList *interfaces;
133 
134     const char *object_cast_cache[OBJECT_CLASS_CAST_CACHE];
135     const char *class_cast_cache[OBJECT_CLASS_CAST_CACHE];
136 
137     ObjectUnparent *unparent;
138 
139     GHashTable *properties;
140 };
141 
142 /**
143  * struct Object:
144  *
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.
149  *
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
152  * run time.
153  */
154 struct Object
155 {
156     /* private: */
157     ObjectClass *class;
158     ObjectFree *free;
159     GHashTable *properties;
160     uint32_t ref;
161     Object *parent;
162 };
163 
164 /**
165  * DECLARE_INSTANCE_CHECKER:
166  * @InstanceType: instance struct name
167  * @OBJ_NAME: the object name in uppercase with underscore separators
168  * @TYPENAME: type name
169  *
170  * Direct usage of this macro should be avoided, and the complete
171  * OBJECT_DECLARE_TYPE macro is recommended instead.
172  *
173  * This macro will provide the instance type cast functions for a
174  * QOM type.
175  */
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); }
180 
181 /**
182  * DECLARE_CLASS_CHECKERS:
183  * @ClassType: class struct name
184  * @OBJ_NAME: the object name in uppercase with underscore separators
185  * @TYPENAME: type name
186  *
187  * Direct usage of this macro should be avoided, and the complete
188  * OBJECT_DECLARE_TYPE macro is recommended instead.
189  *
190  * This macro will provide the class type cast functions for a
191  * QOM type.
192  */
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); } \
197     \
198     static inline G_GNUC_UNUSED ClassType * \
199     OBJ_NAME##_CLASS(const void *klass) \
200     { return OBJECT_CLASS_CHECK(ClassType, klass, TYPENAME); }
201 
202 /**
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
208  *
209  * Direct usage of this macro should be avoided, and the complete
210  * OBJECT_DECLARE_TYPE macro is recommended instead.
211  *
212  * This macro will provide the three standard type cast functions for a
213  * QOM type.
214  */
215 #define DECLARE_OBJ_CHECKERS(InstanceType, ClassType, OBJ_NAME, TYPENAME) \
216     DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \
217     \
218     DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME)
219 
220 /**
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
225  *
226  * This macro is typically used in a header file, and will:
227  *
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
231  *
232  * The object struct and class struct need to be declared manually.
233  */
234 #define OBJECT_DECLARE_TYPE(InstanceType, ClassType, MODULE_OBJ_NAME) \
235     typedef struct InstanceType InstanceType; \
236     typedef struct ClassType ClassType; \
237     \
238     G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstanceType, object_unref) \
239     \
240     DECLARE_OBJ_CHECKERS(InstanceType, ClassType, \
241                          MODULE_OBJ_NAME, TYPE_##MODULE_OBJ_NAME)
242 
243 /**
244  * OBJECT_DECLARE_SIMPLE_TYPE:
245  * @InstanceType: instance struct name
246  * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
247  *
248  * This does the same as OBJECT_DECLARE_TYPE(), but with no class struct
249  * declared.
250  *
251  * This macro should be used unless the class struct needs to have
252  * virtual methods declared.
253  */
254 #define OBJECT_DECLARE_SIMPLE_TYPE(InstanceType, MODULE_OBJ_NAME) \
255     typedef struct InstanceType InstanceType; \
256     \
257     G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstanceType, object_unref) \
258     \
259     DECLARE_INSTANCE_CHECKER(InstanceType, MODULE_OBJ_NAME, TYPE_##MODULE_OBJ_NAME)
260 
261 
262 /**
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
268  *                          separators
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
272  *
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.
275  */
276 #define DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
277                                        MODULE_OBJ_NAME, \
278                                        PARENT_MODULE_OBJ_NAME, \
279                                        ABSTRACT, CLASS_SIZE, ...) \
280     static void \
281     module_obj_name##_finalize(Object *obj); \
282     static void \
283     module_obj_name##_class_init(ObjectClass *oc, void *data); \
284     static void \
285     module_obj_name##_init(Object *obj); \
286     \
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 = (InterfaceInfo[]) { __VA_ARGS__ } , \
298     }; \
299     \
300     static void \
301     module_obj_name##_register_types(void) \
302     { \
303         type_register_static(&module_obj_name##_info); \
304     } \
305     type_init(module_obj_name##_register_types);
306 
307 /**
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
313  *                          separators
314  * @ABSTRACT: boolean flag to indicate whether the object can be instantiated
315  * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
316  *
317  * This macro is typically used in a source file, and will:
318  *
319  *   - declare prototypes for _finalize, _class_init and _init methods
320  *   - declare the TypeInfo struct instance
321  *   - provide the constructor to register the type
322  *
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.
326  *
327  * This macro should rarely be used, instead one of the more specialized
328  * macros is usually a better choice.
329  */
330 #define OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
331                                     MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
332                                     ABSTRACT, ...) \
333     DO_OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \
334                                    MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \
335                                    ABSTRACT, sizeof(ModuleObjName##Class), \
336                                    __VA_ARGS__)
337 
338 /**
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
344  *                          separators
345  *
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.
348  */
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, \
353                                 false, { NULL })
354 
355 /**
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
361  *                          separators
362  * @...: list of initializers for "InterfaceInfo" to declare implemented interfaces
363  *
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
366  * interfaces.
367  *
368  * Note when passing the list of interfaces, be sure to include the final
369  * NULL entry, e.g.  { TYPE_USER_CREATABLE }, { NULL }
370  */
371 #define OBJECT_DEFINE_TYPE_WITH_INTERFACES(ModuleObjName, module_obj_name, \
372                                            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, \
376                                 false, __VA_ARGS__)
377 
378 /**
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
384  *                          separators
385  *
386  * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suitable
387  * for defining an abstract type, without any interfaces.
388  */
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, \
393                                 true, { NULL })
394 
395 /**
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
401  *                          separators
402  *
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.
406  */
407 #define OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(ModuleObjName, \
408                                                   module_obj_name, \
409                                                   MODULE_OBJ_NAME, \
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__)
414 
415 /**
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
421  *                          separators
422  *
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
427  * defining it.
428  */
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 })
433 
434 /**
435  * struct TypeInfo:
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
440  *   parent object.
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.
449  * @instance_finalize: This function is called during object destruction.  This
450  *   is called before the parent @instance_finalize function has been called.
451  *   An object should only free the members that are unique to its type in this
452  *   function.
453  * @abstract: If this field is true, then the class is considered abstract and
454  *   cannot be directly instantiated.
455  * @class_size: The size of the class object (derivative of #ObjectClass)
456  *   for this object.  If @class_size is 0, then the size of the class will be
457  *   assumed to be the size of the parent class.  This allows a type to avoid
458  *   implementing an explicit class type if they are not adding additional
459  *   virtual functions.
460  * @class_init: This function is called after all parent class initialization
461  *   has occurred to allow a class to set its default virtual method pointers.
462  *   This is also the function to use to override virtual methods from a parent
463  *   class.
464  * @class_base_init: This function is called for all base classes after all
465  *   parent class initialization has occurred, but before the class itself
466  *   is initialized.  This is the function to use to undo the effects of
467  *   memcpy from the parent class to the descendants.
468  * @class_data: Data to pass to the @class_init,
469  *   @class_base_init. This can be useful when building dynamic
470  *   classes.
471  * @interfaces: The list of interfaces associated with this type.  This
472  *   should point to a static array that's terminated with a zero filled
473  *   element.
474  */
475 struct TypeInfo
476 {
477     const char *name;
478     const char *parent;
479 
480     size_t instance_size;
481     size_t instance_align;
482     void (*instance_init)(Object *obj);
483     void (*instance_post_init)(Object *obj);
484     void (*instance_finalize)(Object *obj);
485 
486     bool abstract;
487     size_t class_size;
488 
489     void (*class_init)(ObjectClass *klass, void *data);
490     void (*class_base_init)(ObjectClass *klass, void *data);
491     void *class_data;
492 
493     InterfaceInfo *interfaces;
494 };
495 
496 /**
497  * OBJECT:
498  * @obj: A derivative of #Object
499  *
500  * Converts an object to a #Object.  Since all objects are #Objects,
501  * this function will always succeed.
502  */
503 #define OBJECT(obj) \
504     ((Object *)(obj))
505 
506 /**
507  * OBJECT_CLASS:
508  * @class: A derivative of #ObjectClass.
509  *
510  * Converts a class to an #ObjectClass.  Since all objects are #Objects,
511  * this function will always succeed.
512  */
513 #define OBJECT_CLASS(class) \
514     ((ObjectClass *)(class))
515 
516 /**
517  * OBJECT_CHECK:
518  * @type: The C type to use for the return value.
519  * @obj: A derivative of @type to cast.
520  * @name: The QOM typename of @type
521  *
522  * A type safe version of @object_dynamic_cast_assert.  Typically each class
523  * will define a macro based on this type to perform type safe dynamic_casts to
524  * this object type.
525  *
526  * If an invalid object is passed to this function, a run time assert will be
527  * generated.
528  */
529 #define OBJECT_CHECK(type, obj, name) \
530     ((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \
531                                         __FILE__, __LINE__, __func__))
532 
533 /**
534  * OBJECT_CLASS_CHECK:
535  * @class_type: The C type to use for the return value.
536  * @class: A derivative class of @class_type to cast.
537  * @name: the QOM typename of @class_type.
538  *
539  * A type safe version of @object_class_dynamic_cast_assert.  This macro is
540  * typically wrapped by each type to perform type safe casts of a class to a
541  * specific class type.
542  */
543 #define OBJECT_CLASS_CHECK(class_type, class, name) \
544     ((class_type *)object_class_dynamic_cast_assert(OBJECT_CLASS(class), (name), \
545                                                __FILE__, __LINE__, __func__))
546 
547 /**
548  * OBJECT_GET_CLASS:
549  * @class: The C type to use for the return value.
550  * @obj: The object to obtain the class for.
551  * @name: The QOM typename of @obj.
552  *
553  * This function will return a specific class for a given object.  Its generally
554  * used by each type to provide a type safe macro to get a specific class type
555  * from an object.
556  */
557 #define OBJECT_GET_CLASS(class, obj, name) \
558     OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
559 
560 /**
561  * struct InterfaceInfo:
562  * @type: The name of the interface.
563  *
564  * The information associated with an interface.
565  */
566 struct InterfaceInfo {
567     const char *type;
568 };
569 
570 /**
571  * struct InterfaceClass:
572  * @parent_class: the base class
573  *
574  * The class for all interfaces.  Subclasses of this class should only add
575  * virtual methods.
576  */
577 struct InterfaceClass
578 {
579     ObjectClass parent_class;
580     /* private: */
581     ObjectClass *concrete_class;
582     Type interface_type;
583 };
584 
585 #define TYPE_INTERFACE "interface"
586 
587 /**
588  * INTERFACE_CLASS:
589  * @klass: class to cast from
590  * Returns: An #InterfaceClass or raise an error if cast is invalid
591  */
592 #define INTERFACE_CLASS(klass) \
593     OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE)
594 
595 /**
596  * INTERFACE_CHECK:
597  * @interface: the type to return
598  * @obj: the object to convert to an interface
599  * @name: the interface type name
600  *
601  * Returns: @obj casted to @interface if cast is valid, otherwise raise error.
602  */
603 #define INTERFACE_CHECK(interface, obj, name) \
604     ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \
605                                              __FILE__, __LINE__, __func__))
606 
607 /**
608  * object_new_with_class:
609  * @klass: The class to instantiate.
610  *
611  * This function will initialize a new object using heap allocated memory.
612  * The returned object has a reference count of 1, and will be freed when
613  * the last reference is dropped.
614  *
615  * Returns: The newly allocated and instantiated object.
616  */
617 Object *object_new_with_class(ObjectClass *klass);
618 
619 /**
620  * object_new:
621  * @typename: The name of the type of the object to instantiate.
622  *
623  * This function will initialize a new object using heap allocated memory.
624  * The returned object has a reference count of 1, and will be freed when
625  * the last reference is dropped.
626  *
627  * Returns: The newly allocated and instantiated object.
628  */
629 Object *object_new(const char *typename);
630 
631 /**
632  * object_new_with_props:
633  * @typename:  The name of the type of the object to instantiate.
634  * @parent: the parent object
635  * @id: The unique ID of the object
636  * @errp: pointer to error object
637  * @...: list of property names and values
638  *
639  * This function will initialize a new object using heap allocated memory.
640  * The returned object has a reference count of 1, and will be freed when
641  * the last reference is dropped.
642  *
643  * The @id parameter will be used when registering the object as a
644  * child of @parent in the composition tree.
645  *
646  * The variadic parameters are a list of pairs of (propname, propvalue)
647  * strings. The propname of %NULL indicates the end of the property
648  * list. If the object implements the user creatable interface, the
649  * object will be marked complete once all the properties have been
650  * processed.
651  *
652  * .. code-block:: c
653  *    :caption: Creating an object with properties
654  *
655  *      Error *err = NULL;
656  *      Object *obj;
657  *
658  *      obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE,
659  *                                  object_get_objects_root(),
660  *                                  "hostmem0",
661  *                                  &err,
662  *                                  "share", "yes",
663  *                                  "mem-path", "/dev/shm/somefile",
664  *                                  "prealloc", "yes",
665  *                                  "size", "1048576",
666  *                                  NULL);
667  *
668  *      if (!obj) {
669  *        error_reportf_err(err, "Cannot create memory backend: ");
670  *      }
671  *
672  * The returned object will have one stable reference maintained
673  * for as long as it is present in the object hierarchy.
674  *
675  * Returns: The newly allocated, instantiated & initialized object.
676  */
677 Object *object_new_with_props(const char *typename,
678                               Object *parent,
679                               const char *id,
680                               Error **errp,
681                               ...) G_GNUC_NULL_TERMINATED;
682 
683 /**
684  * object_new_with_propv:
685  * @typename:  The name of the type of the object to instantiate.
686  * @parent: the parent object
687  * @id: The unique ID of the object
688  * @errp: pointer to error object
689  * @vargs: list of property names and values
690  *
691  * See object_new_with_props() for documentation.
692  */
693 Object *object_new_with_propv(const char *typename,
694                               Object *parent,
695                               const char *id,
696                               Error **errp,
697                               va_list vargs);
698 
699 bool object_apply_global_props(Object *obj, const GPtrArray *props,
700                                Error **errp);
701 void object_set_machine_compat_props(GPtrArray *compat_props);
702 void object_set_accelerator_compat_props(GPtrArray *compat_props);
703 void object_register_sugar_prop(const char *driver, const char *prop,
704                                 const char *value, bool optional);
705 void object_apply_compat_props(Object *obj);
706 
707 /**
708  * object_set_props:
709  * @obj: the object instance to set properties on
710  * @errp: pointer to error object
711  * @...: list of property names and values
712  *
713  * This function will set a list of properties on an existing object
714  * instance.
715  *
716  * The variadic parameters are a list of pairs of (propname, propvalue)
717  * strings. The propname of %NULL indicates the end of the property
718  * list.
719  *
720  * .. code-block:: c
721  *    :caption: Update an object's properties
722  *
723  *      Error *err = NULL;
724  *      Object *obj = ...get / create object...;
725  *
726  *      if (!object_set_props(obj,
727  *                            &err,
728  *                            "share", "yes",
729  *                            "mem-path", "/dev/shm/somefile",
730  *                            "prealloc", "yes",
731  *                            "size", "1048576",
732  *                            NULL)) {
733  *        error_reportf_err(err, "Cannot set properties: ");
734  *      }
735  *
736  * The returned object will have one stable reference maintained
737  * for as long as it is present in the object hierarchy.
738  *
739  * Returns: %true on success, %false on error.
740  */
741 bool object_set_props(Object *obj, Error **errp, ...) G_GNUC_NULL_TERMINATED;
742 
743 /**
744  * object_set_propv:
745  * @obj: the object instance to set properties on
746  * @errp: pointer to error object
747  * @vargs: list of property names and values
748  *
749  * See object_set_props() for documentation.
750  *
751  * Returns: %true on success, %false on error.
752  */
753 bool object_set_propv(Object *obj, Error **errp, va_list vargs);
754 
755 /**
756  * object_initialize:
757  * @obj: A pointer to the memory to be used for the object.
758  * @size: The maximum size available at @obj for the object.
759  * @typename: The name of the type of the object to instantiate.
760  *
761  * This function will initialize an object.  The memory for the object should
762  * have already been allocated.  The returned object has a reference count of 1,
763  * and will be finalized when the last reference is dropped.
764  */
765 void object_initialize(void *obj, size_t size, const char *typename);
766 
767 /**
768  * object_initialize_child_with_props:
769  * @parentobj: The parent object to add a property to
770  * @propname: The name of the property
771  * @childobj: A pointer to the memory to be used for the object.
772  * @size: The maximum size available at @childobj for the object.
773  * @type: The name of the type of the object to instantiate.
774  * @errp: If an error occurs, a pointer to an area to store the error
775  * @...: list of property names and values
776  *
777  * This function will initialize an object. The memory for the object should
778  * have already been allocated. The object will then be added as child property
779  * to a parent with object_property_add_child() function. The returned object
780  * has a reference count of 1 (for the "child<...>" property from the parent),
781  * so the object will be finalized automatically when the parent gets removed.
782  *
783  * The variadic parameters are a list of pairs of (propname, propvalue)
784  * strings. The propname of %NULL indicates the end of the property list.
785  * If the object implements the user creatable interface, the object will
786  * be marked complete once all the properties have been processed.
787  *
788  * Returns: %true on success, %false on failure.
789  */
790 bool object_initialize_child_with_props(Object *parentobj,
791                              const char *propname,
792                              void *childobj, size_t size, const char *type,
793                              Error **errp, ...) G_GNUC_NULL_TERMINATED;
794 
795 /**
796  * object_initialize_child_with_propsv:
797  * @parentobj: The parent object to add a property to
798  * @propname: The name of the property
799  * @childobj: A pointer to the memory to be used for the object.
800  * @size: The maximum size available at @childobj for the object.
801  * @type: The name of the type of the object to instantiate.
802  * @errp: If an error occurs, a pointer to an area to store the error
803  * @vargs: list of property names and values
804  *
805  * See object_initialize_child() for documentation.
806  *
807  * Returns: %true on success, %false on failure.
808  */
809 bool object_initialize_child_with_propsv(Object *parentobj,
810                               const char *propname,
811                               void *childobj, size_t size, const char *type,
812                               Error **errp, va_list vargs);
813 
814 /**
815  * object_initialize_child:
816  * @parent: The parent object to add a property to
817  * @propname: The name of the property
818  * @child: A precisely typed pointer to the memory to be used for the
819  * object.
820  * @type: The name of the type of the object to instantiate.
821  *
822  * This is like::
823  *
824  *   object_initialize_child_with_props(parent, propname,
825  *                                      child, sizeof(*child), type,
826  *                                      &error_abort, NULL)
827  */
828 #define object_initialize_child(parent, propname, child, type)          \
829     object_initialize_child_internal((parent), (propname),              \
830                                      (child), sizeof(*(child)), (type))
831 void object_initialize_child_internal(Object *parent, const char *propname,
832                                       void *child, size_t size,
833                                       const char *type);
834 
835 /**
836  * object_dynamic_cast:
837  * @obj: The object to cast.
838  * @typename: The @typename to cast to.
839  *
840  * This function will determine if @obj is-a @typename.  @obj can refer to an
841  * object or an interface associated with an object.
842  *
843  * Returns: This function returns @obj on success or #NULL on failure.
844  */
845 Object *object_dynamic_cast(Object *obj, const char *typename);
846 
847 /**
848  * object_dynamic_cast_assert:
849  * @obj: The object to cast.
850  * @typename: The @typename to cast to.
851  * @file: Source code file where function was called
852  * @line: Source code line where function was called
853  * @func: Name of function where this function was called
854  *
855  * See object_dynamic_cast() for a description of the parameters of this
856  * function.  The only difference in behavior is that this function asserts
857  * instead of returning #NULL on failure if QOM cast debugging is enabled.
858  * This function is not meant to be called directly, but only through
859  * the wrapper macro OBJECT_CHECK.
860  */
861 Object *object_dynamic_cast_assert(Object *obj, const char *typename,
862                                    const char *file, int line, const char *func);
863 
864 /**
865  * object_get_class:
866  * @obj: A derivative of #Object
867  *
868  * Returns: The #ObjectClass of the type associated with @obj.
869  */
870 ObjectClass *object_get_class(Object *obj);
871 
872 /**
873  * object_get_typename:
874  * @obj: A derivative of #Object.
875  *
876  * Returns: The QOM typename of @obj.
877  */
878 const char *object_get_typename(const Object *obj);
879 
880 /**
881  * type_register_static:
882  * @info: The #TypeInfo of the new type.
883  *
884  * Returns: the new #Type.
885  */
886 Type type_register_static(const TypeInfo *info);
887 
888 /**
889  * type_register_static_array:
890  * @infos: The array of the new type #TypeInfo structures.
891  * @nr_infos: number of entries in @infos
892  *
893  * @infos and all of the strings it points to should exist for the life time
894  * that the type is registered.
895  */
896 void type_register_static_array(const TypeInfo *infos, int nr_infos);
897 
898 /**
899  * DEFINE_TYPES:
900  * @type_array: The array containing #TypeInfo structures to register
901  *
902  * @type_array should be static constant that exists for the life time
903  * that the type is registered.
904  */
905 #define DEFINE_TYPES(type_array)                                            \
906 static void do_qemu_init_ ## type_array(void)                               \
907 {                                                                           \
908     type_register_static_array(type_array, ARRAY_SIZE(type_array));         \
909 }                                                                           \
910 type_init(do_qemu_init_ ## type_array)
911 
912 /**
913  * type_print_class_properties:
914  * @type: a QOM class name
915  *
916  * Print the object's class properties to stdout or the monitor.
917  * Return whether an object was found.
918  */
919 bool type_print_class_properties(const char *type);
920 
921 /**
922  * object_set_properties_from_keyval:
923  * @obj: a QOM object
924  * @qdict: a dictionary with the properties to be set
925  * @from_json: true if leaf values of @qdict are typed, false if they
926  * are strings
927  * @errp: pointer to error object
928  *
929  * For each key in the dictionary, parse the value string if needed,
930  * then set the corresponding property in @obj.
931  */
932 void object_set_properties_from_keyval(Object *obj, const QDict *qdict,
933                                        bool from_json, Error **errp);
934 
935 /**
936  * object_class_dynamic_cast_assert:
937  * @klass: The #ObjectClass to attempt to cast.
938  * @typename: The QOM typename of the class to cast to.
939  * @file: Source code file where function was called
940  * @line: Source code line where function was called
941  * @func: Name of function where this function was called
942  *
943  * See object_class_dynamic_cast() for a description of the parameters
944  * of this function.  The only difference in behavior is that this function
945  * asserts instead of returning #NULL on failure if QOM cast debugging is
946  * enabled.  This function is not meant to be called directly, but only through
947  * the wrapper macro OBJECT_CLASS_CHECK.
948  */
949 ObjectClass *object_class_dynamic_cast_assert(ObjectClass *klass,
950                                               const char *typename,
951                                               const char *file, int line,
952                                               const char *func);
953 
954 /**
955  * object_class_dynamic_cast:
956  * @klass: The #ObjectClass to attempt to cast.
957  * @typename: The QOM typename of the class to cast to.
958  *
959  * Returns: If @typename is a class, this function returns @klass if
960  * @typename is a subtype of @klass, else returns #NULL.
961  *
962  * If @typename is an interface, this function returns the interface
963  * definition for @klass if @klass implements it unambiguously; #NULL
964  * is returned if @klass does not implement the interface or if multiple
965  * classes or interfaces on the hierarchy leading to @klass implement
966  * it.  (FIXME: perhaps this can be detected at type definition time?)
967  */
968 ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
969                                        const char *typename);
970 
971 /**
972  * object_class_get_parent:
973  * @klass: The class to obtain the parent for.
974  *
975  * Returns: The parent for @klass or %NULL if none.
976  */
977 ObjectClass *object_class_get_parent(ObjectClass *klass);
978 
979 /**
980  * object_class_get_name:
981  * @klass: The class to obtain the QOM typename for.
982  *
983  * Returns: The QOM typename for @klass.
984  */
985 const char *object_class_get_name(ObjectClass *klass);
986 
987 /**
988  * object_class_is_abstract:
989  * @klass: The class to obtain the abstractness for.
990  *
991  * Returns: %true if @klass is abstract, %false otherwise.
992  */
993 bool object_class_is_abstract(ObjectClass *klass);
994 
995 /**
996  * object_class_by_name:
997  * @typename: The QOM typename to obtain the class for.
998  *
999  * Returns: The class for @typename or %NULL if not found.
1000  */
1001 ObjectClass *object_class_by_name(const char *typename);
1002 
1003 /**
1004  * module_object_class_by_name:
1005  * @typename: The QOM typename to obtain the class for.
1006  *
1007  * For objects which might be provided by a module.  Behaves like
1008  * object_class_by_name, but additionally tries to load the module
1009  * needed in case the class is not available.
1010  *
1011  * Returns: The class for @typename or %NULL if not found.
1012  */
1013 ObjectClass *module_object_class_by_name(const char *typename);
1014 
1015 void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
1016                           const char *implements_type, bool include_abstract,
1017                           void *opaque);
1018 
1019 /**
1020  * object_class_get_list:
1021  * @implements_type: The type to filter for, including its derivatives.
1022  * @include_abstract: Whether to include abstract classes.
1023  *
1024  * Returns: A singly-linked list of the classes in reverse hashtable order.
1025  */
1026 GSList *object_class_get_list(const char *implements_type,
1027                               bool include_abstract);
1028 
1029 /**
1030  * object_class_get_list_sorted:
1031  * @implements_type: The type to filter for, including its derivatives.
1032  * @include_abstract: Whether to include abstract classes.
1033  *
1034  * Returns: A singly-linked list of the classes in alphabetical
1035  * case-insensitive order.
1036  */
1037 GSList *object_class_get_list_sorted(const char *implements_type,
1038                               bool include_abstract);
1039 
1040 /**
1041  * object_ref:
1042  * @obj: the object
1043  *
1044  * Increase the reference count of a object.  A object cannot be freed as long
1045  * as its reference count is greater than zero.
1046  * Returns: @obj
1047  */
1048 Object *object_ref(void *obj);
1049 
1050 /**
1051  * object_unref:
1052  * @obj: the object
1053  *
1054  * Decrease the reference count of a object.  A object cannot be freed as long
1055  * as its reference count is greater than zero.
1056  */
1057 void object_unref(void *obj);
1058 
1059 /**
1060  * object_property_try_add:
1061  * @obj: the object to add a property to
1062  * @name: the name of the property.  This can contain any character except for
1063  *  a forward slash.  In general, you should use hyphens '-' instead of
1064  *  underscores '_' when naming properties.
1065  * @type: the type name of the property.  This namespace is pretty loosely
1066  *   defined.  Sub namespaces are constructed by using a prefix and then
1067  *   to angle brackets.  For instance, the type 'virtio-net-pci' in the
1068  *   'link' namespace would be 'link<virtio-net-pci>'.
1069  * @get: The getter to be called to read a property.  If this is NULL, then
1070  *   the property cannot be read.
1071  * @set: the setter to be called to write a property.  If this is NULL,
1072  *   then the property cannot be written.
1073  * @release: called when the property is removed from the object.  This is
1074  *   meant to allow a property to free its opaque upon object
1075  *   destruction.  This may be NULL.
1076  * @opaque: an opaque pointer to pass to the callbacks for the property
1077  * @errp: pointer to error object
1078  *
1079  * Returns: The #ObjectProperty; this can be used to set the @resolve
1080  * callback for child and link properties.
1081  */
1082 ObjectProperty *object_property_try_add(Object *obj, const char *name,
1083                                         const char *type,
1084                                         ObjectPropertyAccessor *get,
1085                                         ObjectPropertyAccessor *set,
1086                                         ObjectPropertyRelease *release,
1087                                         void *opaque, Error **errp);
1088 
1089 /**
1090  * object_property_add:
1091  * Same as object_property_try_add() with @errp hardcoded to
1092  * &error_abort.
1093  *
1094  * @obj: the object to add a property to
1095  * @name: the name of the property.  This can contain any character except for
1096  *  a forward slash.  In general, you should use hyphens '-' instead of
1097  *  underscores '_' when naming properties.
1098  * @type: the type name of the property.  This namespace is pretty loosely
1099  *   defined.  Sub namespaces are constructed by using a prefix and then
1100  *   to angle brackets.  For instance, the type 'virtio-net-pci' in the
1101  *   'link' namespace would be 'link<virtio-net-pci>'.
1102  * @get: The getter to be called to read a property.  If this is NULL, then
1103  *   the property cannot be read.
1104  * @set: the setter to be called to write a property.  If this is NULL,
1105  *   then the property cannot be written.
1106  * @release: called when the property is removed from the object.  This is
1107  *   meant to allow a property to free its opaque upon object
1108  *   destruction.  This may be NULL.
1109  * @opaque: an opaque pointer to pass to the callbacks for the property
1110  */
1111 ObjectProperty *object_property_add(Object *obj, const char *name,
1112                                     const char *type,
1113                                     ObjectPropertyAccessor *get,
1114                                     ObjectPropertyAccessor *set,
1115                                     ObjectPropertyRelease *release,
1116                                     void *opaque);
1117 
1118 void object_property_del(Object *obj, const char *name);
1119 
1120 ObjectProperty *object_class_property_add(ObjectClass *klass, const char *name,
1121                                           const char *type,
1122                                           ObjectPropertyAccessor *get,
1123                                           ObjectPropertyAccessor *set,
1124                                           ObjectPropertyRelease *release,
1125                                           void *opaque);
1126 
1127 /**
1128  * object_property_set_default_bool:
1129  * @prop: the property to set
1130  * @value: the value to be written to the property
1131  *
1132  * Set the property default value.
1133  */
1134 void object_property_set_default_bool(ObjectProperty *prop, bool value);
1135 
1136 /**
1137  * object_property_set_default_str:
1138  * @prop: the property to set
1139  * @value: the value to be written to the property
1140  *
1141  * Set the property default value.
1142  */
1143 void object_property_set_default_str(ObjectProperty *prop, const char *value);
1144 
1145 /**
1146  * object_property_set_default_list:
1147  * @prop: the property to set
1148  *
1149  * Set the property default value to be an empty list.
1150  */
1151 void object_property_set_default_list(ObjectProperty *prop);
1152 
1153 /**
1154  * object_property_set_default_int:
1155  * @prop: the property to set
1156  * @value: the value to be written to the property
1157  *
1158  * Set the property default value.
1159  */
1160 void object_property_set_default_int(ObjectProperty *prop, int64_t value);
1161 
1162 /**
1163  * object_property_set_default_uint:
1164  * @prop: the property to set
1165  * @value: the value to be written to the property
1166  *
1167  * Set the property default value.
1168  */
1169 void object_property_set_default_uint(ObjectProperty *prop, uint64_t value);
1170 
1171 /**
1172  * object_property_find:
1173  * @obj: the object
1174  * @name: the name of the property
1175  *
1176  * Look up a property for an object.
1177  *
1178  * Return its #ObjectProperty if found, or NULL.
1179  */
1180 ObjectProperty *object_property_find(Object *obj, const char *name);
1181 
1182 /**
1183  * object_property_find_err:
1184  * @obj: the object
1185  * @name: the name of the property
1186  * @errp: returns an error if this function fails
1187  *
1188  * Look up a property for an object.
1189  *
1190  * Return its #ObjectProperty if found, or NULL.
1191  */
1192 ObjectProperty *object_property_find_err(Object *obj,
1193                                          const char *name,
1194                                          Error **errp);
1195 
1196 /**
1197  * object_class_property_find:
1198  * @klass: the object class
1199  * @name: the name of the property
1200  *
1201  * Look up a property for an object class.
1202  *
1203  * Return its #ObjectProperty if found, or NULL.
1204  */
1205 ObjectProperty *object_class_property_find(ObjectClass *klass,
1206                                            const char *name);
1207 
1208 /**
1209  * object_class_property_find_err:
1210  * @klass: the object class
1211  * @name: the name of the property
1212  * @errp: returns an error if this function fails
1213  *
1214  * Look up a property for an object class.
1215  *
1216  * Return its #ObjectProperty if found, or NULL.
1217  */
1218 ObjectProperty *object_class_property_find_err(ObjectClass *klass,
1219                                                const char *name,
1220                                                Error **errp);
1221 
1222 typedef struct ObjectPropertyIterator {
1223     ObjectClass *nextclass;
1224     GHashTableIter iter;
1225 } ObjectPropertyIterator;
1226 
1227 /**
1228  * object_property_iter_init:
1229  * @iter: the iterator instance
1230  * @obj: the object
1231  *
1232  * Initializes an iterator for traversing all properties
1233  * registered against an object instance, its class and all parent classes.
1234  *
1235  * It is forbidden to modify the property list while iterating,
1236  * whether removing or adding properties.
1237  *
1238  * Typical usage pattern would be
1239  *
1240  * .. code-block:: c
1241  *    :caption: Using object property iterators
1242  *
1243  *      ObjectProperty *prop;
1244  *      ObjectPropertyIterator iter;
1245  *
1246  *      object_property_iter_init(&iter, obj);
1247  *      while ((prop = object_property_iter_next(&iter))) {
1248  *        ... do something with prop ...
1249  *      }
1250  */
1251 void object_property_iter_init(ObjectPropertyIterator *iter,
1252                                Object *obj);
1253 
1254 /**
1255  * object_class_property_iter_init:
1256  * @iter: the iterator instance
1257  * @klass: the class
1258  *
1259  * Initializes an iterator for traversing all properties
1260  * registered against an object class and all parent classes.
1261  *
1262  * It is forbidden to modify the property list while iterating,
1263  * whether removing or adding properties.
1264  *
1265  * This can be used on abstract classes as it does not create a temporary
1266  * instance.
1267  */
1268 void object_class_property_iter_init(ObjectPropertyIterator *iter,
1269                                      ObjectClass *klass);
1270 
1271 /**
1272  * object_property_iter_next:
1273  * @iter: the iterator instance
1274  *
1275  * Return the next available property. If no further properties
1276  * are available, a %NULL value will be returned and the @iter
1277  * pointer should not be used again after this point without
1278  * re-initializing it.
1279  *
1280  * Returns: the next property, or %NULL when all properties
1281  * have been traversed.
1282  */
1283 ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
1284 
1285 void object_unparent(Object *obj);
1286 
1287 /**
1288  * object_property_get:
1289  * @obj: the object
1290  * @name: the name of the property
1291  * @v: the visitor that will receive the property value.  This should be an
1292  *   Output visitor and the data will be written with @name as the name.
1293  * @errp: returns an error if this function fails
1294  *
1295  * Reads a property from a object.
1296  *
1297  * Returns: %true on success, %false on failure.
1298  */
1299 bool object_property_get(Object *obj, const char *name, Visitor *v,
1300                          Error **errp);
1301 
1302 /**
1303  * object_property_set_str:
1304  * @obj: the object
1305  * @name: the name of the property
1306  * @value: the value to be written to the property
1307  * @errp: returns an error if this function fails
1308  *
1309  * Writes a string value to a property.
1310  *
1311  * Returns: %true on success, %false on failure.
1312  */
1313 bool object_property_set_str(Object *obj, const char *name,
1314                              const char *value, Error **errp);
1315 
1316 /**
1317  * object_property_get_str:
1318  * @obj: the object
1319  * @name: the name of the property
1320  * @errp: returns an error if this function fails
1321  *
1322  * Returns: the value of the property, converted to a C string, or NULL if
1323  * an error occurs (including when the property value is not a string).
1324  * The caller should free the string.
1325  */
1326 char *object_property_get_str(Object *obj, const char *name,
1327                               Error **errp);
1328 
1329 /**
1330  * object_property_set_link:
1331  * @obj: the object
1332  * @name: the name of the property
1333  * @value: the value to be written to the property
1334  * @errp: returns an error if this function fails
1335  *
1336  * Writes an object's canonical path to a property.
1337  *
1338  * If the link property was created with
1339  * %OBJ_PROP_LINK_STRONG bit, the old target object is
1340  * unreferenced, and a reference is added to the new target object.
1341  *
1342  * Returns: %true on success, %false on failure.
1343  */
1344 bool object_property_set_link(Object *obj, const char *name,
1345                               Object *value, Error **errp);
1346 
1347 /**
1348  * object_property_get_link:
1349  * @obj: the object
1350  * @name: the name of the property
1351  * @errp: returns an error if this function fails
1352  *
1353  * Returns: the value of the property, resolved from a path to an Object,
1354  * or NULL if an error occurs (including when the property value is not a
1355  * string or not a valid object path).
1356  */
1357 Object *object_property_get_link(Object *obj, const char *name,
1358                                  Error **errp);
1359 
1360 /**
1361  * object_property_set_bool:
1362  * @obj: the object
1363  * @name: the name of the property
1364  * @value: the value to be written to the property
1365  * @errp: returns an error if this function fails
1366  *
1367  * Writes a bool value to a property.
1368  *
1369  * Returns: %true on success, %false on failure.
1370  */
1371 bool object_property_set_bool(Object *obj, const char *name,
1372                               bool value, Error **errp);
1373 
1374 /**
1375  * object_property_get_bool:
1376  * @obj: the object
1377  * @name: the name of the property
1378  * @errp: returns an error if this function fails
1379  *
1380  * Returns: the value of the property, converted to a boolean, or false if
1381  * an error occurs (including when the property value is not a bool).
1382  */
1383 bool object_property_get_bool(Object *obj, const char *name,
1384                               Error **errp);
1385 
1386 /**
1387  * object_property_set_int:
1388  * @obj: the object
1389  * @name: the name of the property
1390  * @value: the value to be written to the property
1391  * @errp: returns an error if this function fails
1392  *
1393  * Writes an integer value to a property.
1394  *
1395  * Returns: %true on success, %false on failure.
1396  */
1397 bool object_property_set_int(Object *obj, const char *name,
1398                              int64_t value, Error **errp);
1399 
1400 /**
1401  * object_property_get_int:
1402  * @obj: the object
1403  * @name: the name of the property
1404  * @errp: returns an error if this function fails
1405  *
1406  * Returns: the value of the property, converted to an integer, or -1 if
1407  * an error occurs (including when the property value is not an integer).
1408  */
1409 int64_t object_property_get_int(Object *obj, const char *name,
1410                                 Error **errp);
1411 
1412 /**
1413  * object_property_set_uint:
1414  * @obj: the object
1415  * @name: the name of the property
1416  * @value: the value to be written to the property
1417  * @errp: returns an error if this function fails
1418  *
1419  * Writes an unsigned integer value to a property.
1420  *
1421  * Returns: %true on success, %false on failure.
1422  */
1423 bool object_property_set_uint(Object *obj, const char *name,
1424                               uint64_t value, Error **errp);
1425 
1426 /**
1427  * object_property_get_uint:
1428  * @obj: the object
1429  * @name: the name of the property
1430  * @errp: returns an error if this function fails
1431  *
1432  * Returns: the value of the property, converted to an unsigned integer, or 0
1433  * an error occurs (including when the property value is not an integer).
1434  */
1435 uint64_t object_property_get_uint(Object *obj, const char *name,
1436                                   Error **errp);
1437 
1438 /**
1439  * object_property_get_enum:
1440  * @obj: the object
1441  * @name: the name of the property
1442  * @typename: the name of the enum data type
1443  * @errp: returns an error if this function fails
1444  *
1445  * Returns: the value of the property, converted to an integer (which
1446  * can't be negative), or -1 on error (including when the property
1447  * value is not an enum).
1448  */
1449 int object_property_get_enum(Object *obj, const char *name,
1450                              const char *typename, Error **errp);
1451 
1452 /**
1453  * object_property_set:
1454  * @obj: the object
1455  * @name: the name of the property
1456  * @v: the visitor that will be used to write the property value.  This should
1457  *   be an Input visitor and the data will be first read with @name as the
1458  *   name and then written as the property value.
1459  * @errp: returns an error if this function fails
1460  *
1461  * Writes a property to a object.
1462  *
1463  * Returns: %true on success, %false on failure.
1464  */
1465 bool object_property_set(Object *obj, const char *name, Visitor *v,
1466                          Error **errp);
1467 
1468 /**
1469  * object_property_parse:
1470  * @obj: the object
1471  * @name: the name of the property
1472  * @string: the string that will be used to parse the property value.
1473  * @errp: returns an error if this function fails
1474  *
1475  * Parses a string and writes the result into a property of an object.
1476  *
1477  * Returns: %true on success, %false on failure.
1478  */
1479 bool object_property_parse(Object *obj, const char *name,
1480                            const char *string, Error **errp);
1481 
1482 /**
1483  * object_property_print:
1484  * @obj: the object
1485  * @name: the name of the property
1486  * @human: if true, print for human consumption
1487  * @errp: returns an error if this function fails
1488  *
1489  * Returns a string representation of the value of the property.  The
1490  * caller shall free the string.
1491  */
1492 char *object_property_print(Object *obj, const char *name, bool human,
1493                             Error **errp);
1494 
1495 /**
1496  * object_property_get_type:
1497  * @obj: the object
1498  * @name: the name of the property
1499  * @errp: returns an error if this function fails
1500  *
1501  * Returns:  The type name of the property.
1502  */
1503 const char *object_property_get_type(Object *obj, const char *name,
1504                                      Error **errp);
1505 
1506 /**
1507  * object_get_root:
1508  *
1509  * Returns: the root object of the composition tree
1510  */
1511 Object *object_get_root(void);
1512 
1513 
1514 /**
1515  * object_get_objects_root:
1516  *
1517  * Get the container object that holds user created
1518  * object instances. This is the object at path
1519  * "/objects"
1520  *
1521  * Returns: the user object container
1522  */
1523 Object *object_get_objects_root(void);
1524 
1525 /**
1526  * object_get_internal_root:
1527  *
1528  * Get the container object that holds internally used object
1529  * instances.  Any object which is put into this container must not be
1530  * user visible, and it will not be exposed in the QOM tree.
1531  *
1532  * Returns: the internal object container
1533  */
1534 Object *object_get_internal_root(void);
1535 
1536 /**
1537  * object_get_canonical_path_component:
1538  * @obj: the object
1539  *
1540  * Returns: The final component in the object's canonical path.  The canonical
1541  * path is the path within the composition tree starting from the root.
1542  * %NULL if the object doesn't have a parent (and thus a canonical path).
1543  */
1544 const char *object_get_canonical_path_component(const Object *obj);
1545 
1546 /**
1547  * object_get_canonical_path:
1548  * @obj: the object
1549  *
1550  * Returns: The canonical path for a object, newly allocated.  This is
1551  * the path within the composition tree starting from the root.  Use
1552  * g_free() to free it.
1553  */
1554 char *object_get_canonical_path(const Object *obj);
1555 
1556 /**
1557  * object_resolve_path:
1558  * @path: the path to resolve
1559  * @ambiguous: (out) (optional): location to store whether the lookup failed
1560  *   because it was ambiguous, or %NULL. Set to %false on success.
1561  *
1562  * There are two types of supported paths--absolute paths and partial paths.
1563  *
1564  * Absolute paths are derived from the root object and can follow child<> or
1565  * link<> properties.  Since they can follow link<> properties, they can be
1566  * arbitrarily long.  Absolute paths look like absolute filenames and are
1567  * prefixed with a leading slash.
1568  *
1569  * Partial paths look like relative filenames.  They do not begin with a
1570  * prefix.  The matching rules for partial paths are subtle but designed to make
1571  * specifying objects easy.  At each level of the composition tree, the partial
1572  * path is matched as an absolute path.  The first match is not returned.  At
1573  * least two matches are searched for.  A successful result is only returned if
1574  * only one match is found.  If more than one match is found, a flag is
1575  * returned to indicate that the match was ambiguous.
1576  *
1577  * Returns: The matched object or %NULL on path lookup failure.
1578  */
1579 Object *object_resolve_path(const char *path, bool *ambiguous);
1580 
1581 /**
1582  * object_resolve_path_type:
1583  * @path: the path to resolve
1584  * @typename: the type to look for.
1585  * @ambiguous: (out) (optional): location to store whether the lookup failed
1586  *   because it was ambiguous, or %NULL. Set to %false on success.
1587  *
1588  * This is similar to object_resolve_path().  However, when looking for a
1589  * partial path only matches that implement the given type are considered.
1590  * This restricts the search and avoids spuriously flagging matches as
1591  * ambiguous.
1592  *
1593  * For both partial and absolute paths, the return value goes through
1594  * a dynamic cast to @typename.  This is important if either the link,
1595  * or the typename itself are of interface types.
1596  *
1597  * Returns: The matched object or NULL on path lookup failure.
1598  */
1599 Object *object_resolve_path_type(const char *path, const char *typename,
1600                                  bool *ambiguous);
1601 
1602 /**
1603  * object_resolve_type_unambiguous:
1604  * @typename: the type to look for
1605  * @errp: pointer to error object
1606  *
1607  * Return the only object in the QOM tree of type @typename.
1608  * If no match or more than one match is found, an error is
1609  * returned.
1610  *
1611  * Returns: The matched object or NULL on path lookup failure.
1612  */
1613 Object *object_resolve_type_unambiguous(const char *typename, Error **errp);
1614 
1615 /**
1616  * object_resolve_path_at:
1617  * @parent: the object in which to resolve the path
1618  * @path: the path to resolve
1619  *
1620  * This is like object_resolve_path(), except paths not starting with
1621  * a slash are relative to @parent.
1622  *
1623  * Returns: The resolved object or NULL on path lookup failure.
1624  */
1625 Object *object_resolve_path_at(Object *parent, const char *path);
1626 
1627 /**
1628  * object_resolve_path_component:
1629  * @parent: the object in which to resolve the path
1630  * @part: the component to resolve.
1631  *
1632  * This is similar to object_resolve_path with an absolute path, but it
1633  * only resolves one element (@part) and takes the others from @parent.
1634  *
1635  * Returns: The resolved object or NULL on path lookup failure.
1636  */
1637 Object *object_resolve_path_component(Object *parent, const char *part);
1638 
1639 /**
1640  * object_property_try_add_child:
1641  * @obj: the object to add a property to
1642  * @name: the name of the property
1643  * @child: the child object
1644  * @errp: pointer to error object
1645  *
1646  * Child properties form the composition tree.  All objects need to be a child
1647  * of another object.  Objects can only be a child of one object.
1648  *
1649  * There is no way for a child to determine what its parent is.  It is not
1650  * a bidirectional relationship.  This is by design.
1651  *
1652  * The value of a child property as a C string will be the child object's
1653  * canonical path. It can be retrieved using object_property_get_str().
1654  * The child object itself can be retrieved using object_property_get_link().
1655  *
1656  * Returns: The newly added property on success, or %NULL on failure.
1657  */
1658 ObjectProperty *object_property_try_add_child(Object *obj, const char *name,
1659                                               Object *child, Error **errp);
1660 
1661 /**
1662  * object_property_add_child:
1663  * @obj: the object to add a property to
1664  * @name: the name of the property
1665  * @child: the child object
1666  *
1667  * Same as object_property_try_add_child() with @errp hardcoded to
1668  * &error_abort
1669  */
1670 ObjectProperty *object_property_add_child(Object *obj, const char *name,
1671                                           Object *child);
1672 
1673 typedef enum {
1674     /* Unref the link pointer when the property is deleted */
1675     OBJ_PROP_LINK_STRONG = 0x1,
1676 
1677     /* private */
1678     OBJ_PROP_LINK_DIRECT = 0x2,
1679     OBJ_PROP_LINK_CLASS = 0x4,
1680 } ObjectPropertyLinkFlags;
1681 
1682 /**
1683  * object_property_allow_set_link:
1684  * @obj: the object to add a property to
1685  * @name: the name of the property
1686  * @child: the child object
1687  * @errp: pointer to error object
1688  *
1689  * The default implementation of the object_property_add_link() check()
1690  * callback function.  It allows the link property to be set and never returns
1691  * an error.
1692  */
1693 void object_property_allow_set_link(const Object *obj, const char *name,
1694                                     Object *child, Error **errp);
1695 
1696 /**
1697  * object_property_add_link:
1698  * @obj: the object to add a property to
1699  * @name: the name of the property
1700  * @type: the qobj type of the link
1701  * @targetp: a pointer to where the link object reference is stored
1702  * @check: callback to veto setting or NULL if the property is read-only
1703  * @flags: additional options for the link
1704  *
1705  * Links establish relationships between objects.  Links are unidirectional
1706  * although two links can be combined to form a bidirectional relationship
1707  * between objects.
1708  *
1709  * Links form the graph in the object model.
1710  *
1711  * The @check() callback is invoked when
1712  * object_property_set_link() is called and can raise an error to prevent the
1713  * link being set.  If @check is NULL, the property is read-only
1714  * and cannot be set.
1715  *
1716  * Ownership of the pointer that @child points to is transferred to the
1717  * link property.  The reference count for *@child is
1718  * managed by the property from after the function returns till the
1719  * property is deleted with object_property_del().  If the
1720  * @flags %OBJ_PROP_LINK_STRONG bit is set,
1721  * the reference count is decremented when the property is deleted or
1722  * modified.
1723  *
1724  * Returns: The newly added property on success, or %NULL on failure.
1725  */
1726 ObjectProperty *object_property_add_link(Object *obj, const char *name,
1727                               const char *type, Object **targetp,
1728                               void (*check)(const Object *obj, const char *name,
1729                                             Object *val, Error **errp),
1730                               ObjectPropertyLinkFlags flags);
1731 
1732 ObjectProperty *object_class_property_add_link(ObjectClass *oc,
1733                               const char *name,
1734                               const char *type, ptrdiff_t offset,
1735                               void (*check)(const Object *obj, const char *name,
1736                                             Object *val, Error **errp),
1737                               ObjectPropertyLinkFlags flags);
1738 
1739 /**
1740  * object_property_add_str:
1741  * @obj: the object to add a property to
1742  * @name: the name of the property
1743  * @get: the getter or NULL if the property is write-only.  This function must
1744  *   return a string to be freed by g_free().
1745  * @set: the setter or NULL if the property is read-only
1746  *
1747  * Add a string property using getters/setters.  This function will add a
1748  * property of type 'string'.
1749  *
1750  * Returns: The newly added property on success, or %NULL on failure.
1751  */
1752 ObjectProperty *object_property_add_str(Object *obj, const char *name,
1753                              char *(*get)(Object *, Error **),
1754                              void (*set)(Object *, const char *, Error **));
1755 
1756 ObjectProperty *object_class_property_add_str(ObjectClass *klass,
1757                                    const char *name,
1758                                    char *(*get)(Object *, Error **),
1759                                    void (*set)(Object *, const char *,
1760                                                Error **));
1761 
1762 /**
1763  * object_property_add_bool:
1764  * @obj: the object to add a property to
1765  * @name: the name of the property
1766  * @get: the getter or NULL if the property is write-only.
1767  * @set: the setter or NULL if the property is read-only
1768  *
1769  * Add a bool property using getters/setters.  This function will add a
1770  * property of type 'bool'.
1771  *
1772  * Returns: The newly added property on success, or %NULL on failure.
1773  */
1774 ObjectProperty *object_property_add_bool(Object *obj, const char *name,
1775                               bool (*get)(Object *, Error **),
1776                               void (*set)(Object *, bool, Error **));
1777 
1778 ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
1779                                     const char *name,
1780                                     bool (*get)(Object *, Error **),
1781                                     void (*set)(Object *, bool, Error **));
1782 
1783 /**
1784  * object_property_add_enum:
1785  * @obj: the object to add a property to
1786  * @name: the name of the property
1787  * @typename: the name of the enum data type
1788  * @lookup: enum value namelookup table
1789  * @get: the getter or %NULL if the property is write-only.
1790  * @set: the setter or %NULL if the property is read-only
1791  *
1792  * Add an enum property using getters/setters.  This function will add a
1793  * property of type '@typename'.
1794  *
1795  * Returns: The newly added property on success, or %NULL on failure.
1796  */
1797 ObjectProperty *object_property_add_enum(Object *obj, const char *name,
1798                               const char *typename,
1799                               const QEnumLookup *lookup,
1800                               int (*get)(Object *, Error **),
1801                               void (*set)(Object *, int, Error **));
1802 
1803 ObjectProperty *object_class_property_add_enum(ObjectClass *klass,
1804                                     const char *name,
1805                                     const char *typename,
1806                                     const QEnumLookup *lookup,
1807                                     int (*get)(Object *, Error **),
1808                                     void (*set)(Object *, int, Error **));
1809 
1810 /**
1811  * object_property_add_tm:
1812  * @obj: the object to add a property to
1813  * @name: the name of the property
1814  * @get: the getter or NULL if the property is write-only.
1815  *
1816  * Add a read-only struct tm valued property using a getter function.
1817  * This function will add a property of type 'struct tm'.
1818  *
1819  * Returns: The newly added property on success, or %NULL on failure.
1820  */
1821 ObjectProperty *object_property_add_tm(Object *obj, const char *name,
1822                             void (*get)(Object *, struct tm *, Error **));
1823 
1824 ObjectProperty *object_class_property_add_tm(ObjectClass *klass,
1825                             const char *name,
1826                             void (*get)(Object *, struct tm *, Error **));
1827 
1828 typedef enum {
1829     /* Automatically add a getter to the property */
1830     OBJ_PROP_FLAG_READ = 1 << 0,
1831     /* Automatically add a setter to the property */
1832     OBJ_PROP_FLAG_WRITE = 1 << 1,
1833     /* Automatically add a getter and a setter to the property */
1834     OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ | OBJ_PROP_FLAG_WRITE),
1835 } ObjectPropertyFlags;
1836 
1837 /**
1838  * object_property_add_uint8_ptr:
1839  * @obj: the object to add a property to
1840  * @name: the name of the property
1841  * @v: pointer to value
1842  * @flags: bitwise-or'd ObjectPropertyFlags
1843  *
1844  * Add an integer property in memory.  This function will add a
1845  * property of type 'uint8'.
1846  *
1847  * Returns: The newly added property on success, or %NULL on failure.
1848  */
1849 ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,
1850                                               const uint8_t *v,
1851                                               ObjectPropertyFlags flags);
1852 
1853 ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass,
1854                                          const char *name,
1855                                          const uint8_t *v,
1856                                          ObjectPropertyFlags flags);
1857 
1858 /**
1859  * object_property_add_uint16_ptr:
1860  * @obj: the object to add a property to
1861  * @name: the name of the property
1862  * @v: pointer to value
1863  * @flags: bitwise-or'd ObjectPropertyFlags
1864  *
1865  * Add an integer property in memory.  This function will add a
1866  * property of type 'uint16'.
1867  *
1868  * Returns: The newly added property on success, or %NULL on failure.
1869  */
1870 ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,
1871                                     const uint16_t *v,
1872                                     ObjectPropertyFlags flags);
1873 
1874 ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
1875                                           const char *name,
1876                                           const uint16_t *v,
1877                                           ObjectPropertyFlags flags);
1878 
1879 /**
1880  * object_property_add_uint32_ptr:
1881  * @obj: the object to add a property to
1882  * @name: the name of the property
1883  * @v: pointer to value
1884  * @flags: bitwise-or'd ObjectPropertyFlags
1885  *
1886  * Add an integer property in memory.  This function will add a
1887  * property of type 'uint32'.
1888  *
1889  * Returns: The newly added property on success, or %NULL on failure.
1890  */
1891 ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,
1892                                     const uint32_t *v,
1893                                     ObjectPropertyFlags flags);
1894 
1895 ObjectProperty *object_class_property_add_uint32_ptr(ObjectClass *klass,
1896                                           const char *name,
1897                                           const uint32_t *v,
1898                                           ObjectPropertyFlags flags);
1899 
1900 /**
1901  * object_property_add_uint64_ptr:
1902  * @obj: the object to add a property to
1903  * @name: the name of the property
1904  * @v: pointer to value
1905  * @flags: bitwise-or'd ObjectPropertyFlags
1906  *
1907  * Add an integer property in memory.  This function will add a
1908  * property of type 'uint64'.
1909  *
1910  * Returns: The newly added property on success, or %NULL on failure.
1911  */
1912 ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,
1913                                     const uint64_t *v,
1914                                     ObjectPropertyFlags flags);
1915 
1916 ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
1917                                           const char *name,
1918                                           const uint64_t *v,
1919                                           ObjectPropertyFlags flags);
1920 
1921 /**
1922  * object_property_add_alias:
1923  * @obj: the object to add a property to
1924  * @name: the name of the property
1925  * @target_obj: the object to forward property access to
1926  * @target_name: the name of the property on the forwarded object
1927  *
1928  * Add an alias for a property on an object.  This function will add a property
1929  * of the same type as the forwarded property.
1930  *
1931  * The caller must ensure that @target_obj stays alive as long as
1932  * this property exists.  In the case of a child object or an alias on the same
1933  * object this will be the case.  For aliases to other objects the caller is
1934  * responsible for taking a reference.
1935  *
1936  * Returns: The newly added property on success, or %NULL on failure.
1937  */
1938 ObjectProperty *object_property_add_alias(Object *obj, const char *name,
1939                                Object *target_obj, const char *target_name);
1940 
1941 /**
1942  * object_property_add_const_link:
1943  * @obj: the object to add a property to
1944  * @name: the name of the property
1945  * @target: the object to be referred by the link
1946  *
1947  * Add an unmodifiable link for a property on an object.  This function will
1948  * add a property of type link<TYPE> where TYPE is the type of @target.
1949  *
1950  * The caller must ensure that @target stays alive as long as
1951  * this property exists.  In the case @target is a child of @obj,
1952  * this will be the case.  Otherwise, the caller is responsible for
1953  * taking a reference.
1954  *
1955  * Returns: The newly added property on success, or %NULL on failure.
1956  */
1957 ObjectProperty *object_property_add_const_link(Object *obj, const char *name,
1958                                                Object *target);
1959 
1960 /**
1961  * object_property_set_description:
1962  * @obj: the object owning the property
1963  * @name: the name of the property
1964  * @description: the description of the property on the object
1965  *
1966  * Set an object property's description.
1967  *
1968  * Returns: %true on success, %false on failure.
1969  */
1970 void object_property_set_description(Object *obj, const char *name,
1971                                      const char *description);
1972 void object_class_property_set_description(ObjectClass *klass, const char *name,
1973                                            const char *description);
1974 
1975 /**
1976  * object_child_foreach:
1977  * @obj: the object whose children will be navigated
1978  * @fn: the iterator function to be called
1979  * @opaque: an opaque value that will be passed to the iterator
1980  *
1981  * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1982  * non-zero.
1983  *
1984  * It is forbidden to add or remove children from @obj from the @fn
1985  * callback.
1986  *
1987  * Returns: The last value returned by @fn, or 0 if there is no child.
1988  */
1989 int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
1990                          void *opaque);
1991 
1992 /**
1993  * object_child_foreach_recursive:
1994  * @obj: the object whose children will be navigated
1995  * @fn: the iterator function to be called
1996  * @opaque: an opaque value that will be passed to the iterator
1997  *
1998  * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1999  * non-zero. Calls recursively, all child nodes of @obj will also be passed
2000  * all the way down to the leaf nodes of the tree. Depth first ordering.
2001  *
2002  * It is forbidden to add or remove children from @obj (or its
2003  * child nodes) from the @fn callback.
2004  *
2005  * Returns: The last value returned by @fn, or 0 if there is no child.
2006  */
2007 int object_child_foreach_recursive(Object *obj,
2008                                    int (*fn)(Object *child, void *opaque),
2009                                    void *opaque);
2010 /**
2011  * container_get:
2012  * @root: root of the #path, e.g., object_get_root()
2013  * @path: path to the container
2014  *
2015  * Return a container object whose path is @path.  Create more containers
2016  * along the path if necessary.
2017  *
2018  * Returns: the container object.
2019  */
2020 Object *container_get(Object *root, const char *path);
2021 
2022 /**
2023  * object_property_add_new_container:
2024  * @obj: the parent object
2025  * @name: the name of the parent object's property to add
2026  *
2027  * Add a newly created container object to a parent object.
2028  *
2029  * Returns: the newly created container object.  Its reference count is 1,
2030  * and the reference is owned by the parent object.
2031  */
2032 Object *object_property_add_new_container(Object *obj, const char *name);
2033 
2034 /**
2035  * object_property_help:
2036  * @name: the name of the property
2037  * @type: the type of the property
2038  * @defval: the default value
2039  * @description: description of the property
2040  *
2041  * Returns: a user-friendly formatted string describing the property
2042  * for help purposes.
2043  */
2044 char *object_property_help(const char *name, const char *type,
2045                            QObject *defval, const char *description);
2046 
2047 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref)
2048 
2049 #endif
2050