xref: /openbmc/qemu/include/qom/object.h (revision d341d9f3)
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 <glib.h>
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include "qemu/queue.h"
21 #include "qapi/error.h"
22 
23 struct Visitor;
24 
25 struct TypeImpl;
26 typedef struct TypeImpl *Type;
27 
28 typedef struct ObjectClass ObjectClass;
29 typedef struct Object Object;
30 
31 typedef struct TypeInfo TypeInfo;
32 
33 typedef struct InterfaceClass InterfaceClass;
34 typedef struct InterfaceInfo InterfaceInfo;
35 
36 #define TYPE_OBJECT "object"
37 
38 /**
39  * SECTION:object.h
40  * @title:Base Object Type System
41  * @short_description: interfaces for creating new types and objects
42  *
43  * The QEMU Object Model provides a framework for registering user creatable
44  * types and instantiating objects from those types.  QOM provides the following
45  * features:
46  *
47  *  - System for dynamically registering types
48  *  - Support for single-inheritance of types
49  *  - Multiple inheritance of stateless interfaces
50  *
51  * <example>
52  *   <title>Creating a minimal type</title>
53  *   <programlisting>
54  * #include "qdev.h"
55  *
56  * #define TYPE_MY_DEVICE "my-device"
57  *
58  * // No new virtual functions: we can reuse the typedef for the
59  * // superclass.
60  * typedef DeviceClass MyDeviceClass;
61  * typedef struct MyDevice
62  * {
63  *     DeviceState parent;
64  *
65  *     int reg0, reg1, reg2;
66  * } MyDevice;
67  *
68  * static const TypeInfo my_device_info = {
69  *     .name = TYPE_MY_DEVICE,
70  *     .parent = TYPE_DEVICE,
71  *     .instance_size = sizeof(MyDevice),
72  * };
73  *
74  * static void my_device_register_types(void)
75  * {
76  *     type_register_static(&my_device_info);
77  * }
78  *
79  * type_init(my_device_register_types)
80  *   </programlisting>
81  * </example>
82  *
83  * In the above example, we create a simple type that is described by #TypeInfo.
84  * #TypeInfo describes information about the type including what it inherits
85  * from, the instance and class size, and constructor/destructor hooks.
86  *
87  * Every type has an #ObjectClass associated with it.  #ObjectClass derivatives
88  * are instantiated dynamically but there is only ever one instance for any
89  * given type.  The #ObjectClass typically holds a table of function pointers
90  * for the virtual methods implemented by this type.
91  *
92  * Using object_new(), a new #Object derivative will be instantiated.  You can
93  * cast an #Object to a subclass (or base-class) type using
94  * object_dynamic_cast().  You typically want to define macro wrappers around
95  * OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a
96  * specific type:
97  *
98  * <example>
99  *   <title>Typecasting macros</title>
100  *   <programlisting>
101  *    #define MY_DEVICE_GET_CLASS(obj) \
102  *       OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE)
103  *    #define MY_DEVICE_CLASS(klass) \
104  *       OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE)
105  *    #define MY_DEVICE(obj) \
106  *       OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
107  *   </programlisting>
108  * </example>
109  *
110  * # Class Initialization #
111  *
112  * Before an object is initialized, the class for the object must be
113  * initialized.  There is only one class object for all instance objects
114  * that is created lazily.
115  *
116  * Classes are initialized by first initializing any parent classes (if
117  * necessary).  After the parent class object has initialized, it will be
118  * copied into the current class object and any additional storage in the
119  * class object is zero filled.
120  *
121  * The effect of this is that classes automatically inherit any virtual
122  * function pointers that the parent class has already initialized.  All
123  * other fields will be zero filled.
124  *
125  * Once all of the parent classes have been initialized, #TypeInfo::class_init
126  * is called to let the class being instantiated provide default initialize for
127  * its virtual functions.  Here is how the above example might be modified
128  * to introduce an overridden virtual function:
129  *
130  * <example>
131  *   <title>Overriding a virtual function</title>
132  *   <programlisting>
133  * #include "qdev.h"
134  *
135  * void my_device_class_init(ObjectClass *klass, void *class_data)
136  * {
137  *     DeviceClass *dc = DEVICE_CLASS(klass);
138  *     dc->reset = my_device_reset;
139  * }
140  *
141  * static const TypeInfo my_device_info = {
142  *     .name = TYPE_MY_DEVICE,
143  *     .parent = TYPE_DEVICE,
144  *     .instance_size = sizeof(MyDevice),
145  *     .class_init = my_device_class_init,
146  * };
147  *   </programlisting>
148  * </example>
149  *
150  * Introducing new virtual methods requires a class to define its own
151  * struct and to add a .class_size member to the #TypeInfo.  Each method
152  * will also have a wrapper function to call it easily:
153  *
154  * <example>
155  *   <title>Defining an abstract class</title>
156  *   <programlisting>
157  * #include "qdev.h"
158  *
159  * typedef struct MyDeviceClass
160  * {
161  *     DeviceClass parent;
162  *
163  *     void (*frobnicate) (MyDevice *obj);
164  * } MyDeviceClass;
165  *
166  * static const TypeInfo my_device_info = {
167  *     .name = TYPE_MY_DEVICE,
168  *     .parent = TYPE_DEVICE,
169  *     .instance_size = sizeof(MyDevice),
170  *     .abstract = true, // or set a default in my_device_class_init
171  *     .class_size = sizeof(MyDeviceClass),
172  * };
173  *
174  * void my_device_frobnicate(MyDevice *obj)
175  * {
176  *     MyDeviceClass *klass = MY_DEVICE_GET_CLASS(obj);
177  *
178  *     klass->frobnicate(obj);
179  * }
180  *   </programlisting>
181  * </example>
182  *
183  * # Interfaces #
184  *
185  * Interfaces allow a limited form of multiple inheritance.  Instances are
186  * similar to normal types except for the fact that are only defined by
187  * their classes and never carry any state.  You can dynamically cast an object
188  * to one of its #Interface types and vice versa.
189  *
190  * # Methods #
191  *
192  * A <emphasis>method</emphasis> is a function within the namespace scope of
193  * a class. It usually operates on the object instance by passing it as a
194  * strongly-typed first argument.
195  * If it does not operate on an object instance, it is dubbed
196  * <emphasis>class method</emphasis>.
197  *
198  * Methods cannot be overloaded. That is, the #ObjectClass and method name
199  * uniquely identity the function to be called; the signature does not vary
200  * except for trailing varargs.
201  *
202  * Methods are always <emphasis>virtual</emphasis>. Overriding a method in
203  * #TypeInfo.class_init of a subclass leads to any user of the class obtained
204  * via OBJECT_GET_CLASS() accessing the overridden function.
205  * The original function is not automatically invoked. It is the responsibility
206  * of the overriding class to determine whether and when to invoke the method
207  * being overridden.
208  *
209  * To invoke the method being overridden, the preferred solution is to store
210  * the original value in the overriding class before overriding the method.
211  * This corresponds to |[ {super,base}.method(...) ]| in Java and C#
212  * respectively; this frees the overriding class from hardcoding its parent
213  * class, which someone might choose to change at some point.
214  *
215  * <example>
216  *   <title>Overriding a virtual method</title>
217  *   <programlisting>
218  * typedef struct MyState MyState;
219  *
220  * typedef void (*MyDoSomething)(MyState *obj);
221  *
222  * typedef struct MyClass {
223  *     ObjectClass parent_class;
224  *
225  *     MyDoSomething do_something;
226  * } MyClass;
227  *
228  * static void my_do_something(MyState *obj)
229  * {
230  *     // do something
231  * }
232  *
233  * static void my_class_init(ObjectClass *oc, void *data)
234  * {
235  *     MyClass *mc = MY_CLASS(oc);
236  *
237  *     mc->do_something = my_do_something;
238  * }
239  *
240  * static const TypeInfo my_type_info = {
241  *     .name = TYPE_MY,
242  *     .parent = TYPE_OBJECT,
243  *     .instance_size = sizeof(MyState),
244  *     .class_size = sizeof(MyClass),
245  *     .class_init = my_class_init,
246  * };
247  *
248  * typedef struct DerivedClass {
249  *     MyClass parent_class;
250  *
251  *     MyDoSomething parent_do_something;
252  * } DerivedClass;
253  *
254  * static void derived_do_something(MyState *obj)
255  * {
256  *     DerivedClass *dc = DERIVED_GET_CLASS(obj);
257  *
258  *     // do something here
259  *     dc->parent_do_something(obj);
260  *     // do something else here
261  * }
262  *
263  * static void derived_class_init(ObjectClass *oc, void *data)
264  * {
265  *     MyClass *mc = MY_CLASS(oc);
266  *     DerivedClass *dc = DERIVED_CLASS(oc);
267  *
268  *     dc->parent_do_something = mc->do_something;
269  *     mc->do_something = derived_do_something;
270  * }
271  *
272  * static const TypeInfo derived_type_info = {
273  *     .name = TYPE_DERIVED,
274  *     .parent = TYPE_MY,
275  *     .class_size = sizeof(DerivedClass),
276  *     .class_init = derived_class_init,
277  * };
278  *   </programlisting>
279  * </example>
280  *
281  * Alternatively, object_class_by_name() can be used to obtain the class and
282  * its non-overridden methods for a specific type. This would correspond to
283  * |[ MyClass::method(...) ]| in C++.
284  *
285  * The first example of such a QOM method was #CPUClass.reset,
286  * another example is #DeviceClass.realize.
287  */
288 
289 
290 /**
291  * ObjectPropertyAccessor:
292  * @obj: the object that owns the property
293  * @v: the visitor that contains the property data
294  * @opaque: the object property opaque
295  * @name: the name of the property
296  * @errp: a pointer to an Error that is filled if getting/setting fails.
297  *
298  * Called when trying to get/set a property.
299  */
300 typedef void (ObjectPropertyAccessor)(Object *obj,
301                                       struct Visitor *v,
302                                       void *opaque,
303                                       const char *name,
304                                       Error **errp);
305 
306 /**
307  * ObjectPropertyResolve:
308  * @obj: the object that owns the property
309  * @opaque: the opaque registered with the property
310  * @part: the name of the property
311  *
312  * Resolves the #Object corresponding to property @part.
313  *
314  * The returned object can also be used as a starting point
315  * to resolve a relative path starting with "@part".
316  *
317  * Returns: If @path is the path that led to @obj, the function
318  * returns the #Object corresponding to "@path/@part".
319  * If "@path/@part" is not a valid object path, it returns #NULL.
320  */
321 typedef Object *(ObjectPropertyResolve)(Object *obj,
322                                         void *opaque,
323                                         const char *part);
324 
325 /**
326  * ObjectPropertyRelease:
327  * @obj: the object that owns the property
328  * @name: the name of the property
329  * @opaque: the opaque registered with the property
330  *
331  * Called when a property is removed from a object.
332  */
333 typedef void (ObjectPropertyRelease)(Object *obj,
334                                      const char *name,
335                                      void *opaque);
336 
337 typedef struct ObjectProperty
338 {
339     gchar *name;
340     gchar *type;
341     gchar *description;
342     ObjectPropertyAccessor *get;
343     ObjectPropertyAccessor *set;
344     ObjectPropertyResolve *resolve;
345     ObjectPropertyRelease *release;
346     void *opaque;
347 } ObjectProperty;
348 
349 /**
350  * ObjectUnparent:
351  * @obj: the object that is being removed from the composition tree
352  *
353  * Called when an object is being removed from the QOM composition tree.
354  * The function should remove any backlinks from children objects to @obj.
355  */
356 typedef void (ObjectUnparent)(Object *obj);
357 
358 /**
359  * ObjectFree:
360  * @obj: the object being freed
361  *
362  * Called when an object's last reference is removed.
363  */
364 typedef void (ObjectFree)(void *obj);
365 
366 #define OBJECT_CLASS_CAST_CACHE 4
367 
368 /**
369  * ObjectClass:
370  *
371  * The base for all classes.  The only thing that #ObjectClass contains is an
372  * integer type handle.
373  */
374 struct ObjectClass
375 {
376     /*< private >*/
377     Type type;
378     GSList *interfaces;
379 
380     const char *object_cast_cache[OBJECT_CLASS_CAST_CACHE];
381     const char *class_cast_cache[OBJECT_CLASS_CAST_CACHE];
382 
383     ObjectUnparent *unparent;
384 
385     GHashTable *properties;
386 };
387 
388 /**
389  * Object:
390  *
391  * The base for all objects.  The first member of this object is a pointer to
392  * a #ObjectClass.  Since C guarantees that the first member of a structure
393  * always begins at byte 0 of that structure, as long as any sub-object places
394  * its parent as the first member, we can cast directly to a #Object.
395  *
396  * As a result, #Object contains a reference to the objects type as its
397  * first member.  This allows identification of the real type of the object at
398  * run time.
399  */
400 struct Object
401 {
402     /*< private >*/
403     ObjectClass *class;
404     ObjectFree *free;
405     GHashTable *properties;
406     uint32_t ref;
407     Object *parent;
408 };
409 
410 /**
411  * TypeInfo:
412  * @name: The name of the type.
413  * @parent: The name of the parent type.
414  * @instance_size: The size of the object (derivative of #Object).  If
415  *   @instance_size is 0, then the size of the object will be the size of the
416  *   parent object.
417  * @instance_init: This function is called to initialize an object.  The parent
418  *   class will have already been initialized so the type is only responsible
419  *   for initializing its own members.
420  * @instance_post_init: This function is called to finish initialization of
421  *   an object, after all @instance_init functions were called.
422  * @instance_finalize: This function is called during object destruction.  This
423  *   is called before the parent @instance_finalize function has been called.
424  *   An object should only free the members that are unique to its type in this
425  *   function.
426  * @abstract: If this field is true, then the class is considered abstract and
427  *   cannot be directly instantiated.
428  * @class_size: The size of the class object (derivative of #ObjectClass)
429  *   for this object.  If @class_size is 0, then the size of the class will be
430  *   assumed to be the size of the parent class.  This allows a type to avoid
431  *   implementing an explicit class type if they are not adding additional
432  *   virtual functions.
433  * @class_init: This function is called after all parent class initialization
434  *   has occurred to allow a class to set its default virtual method pointers.
435  *   This is also the function to use to override virtual methods from a parent
436  *   class.
437  * @class_base_init: This function is called for all base classes after all
438  *   parent class initialization has occurred, but before the class itself
439  *   is initialized.  This is the function to use to undo the effects of
440  *   memcpy from the parent class to the descendents.
441  * @class_finalize: This function is called during class destruction and is
442  *   meant to release and dynamic parameters allocated by @class_init.
443  * @class_data: Data to pass to the @class_init, @class_base_init and
444  *   @class_finalize functions.  This can be useful when building dynamic
445  *   classes.
446  * @interfaces: The list of interfaces associated with this type.  This
447  *   should point to a static array that's terminated with a zero filled
448  *   element.
449  */
450 struct TypeInfo
451 {
452     const char *name;
453     const char *parent;
454 
455     size_t instance_size;
456     void (*instance_init)(Object *obj);
457     void (*instance_post_init)(Object *obj);
458     void (*instance_finalize)(Object *obj);
459 
460     bool abstract;
461     size_t class_size;
462 
463     void (*class_init)(ObjectClass *klass, void *data);
464     void (*class_base_init)(ObjectClass *klass, void *data);
465     void (*class_finalize)(ObjectClass *klass, void *data);
466     void *class_data;
467 
468     InterfaceInfo *interfaces;
469 };
470 
471 /**
472  * OBJECT:
473  * @obj: A derivative of #Object
474  *
475  * Converts an object to a #Object.  Since all objects are #Objects,
476  * this function will always succeed.
477  */
478 #define OBJECT(obj) \
479     ((Object *)(obj))
480 
481 /**
482  * OBJECT_CLASS:
483  * @class: A derivative of #ObjectClass.
484  *
485  * Converts a class to an #ObjectClass.  Since all objects are #Objects,
486  * this function will always succeed.
487  */
488 #define OBJECT_CLASS(class) \
489     ((ObjectClass *)(class))
490 
491 /**
492  * OBJECT_CHECK:
493  * @type: The C type to use for the return value.
494  * @obj: A derivative of @type to cast.
495  * @name: The QOM typename of @type
496  *
497  * A type safe version of @object_dynamic_cast_assert.  Typically each class
498  * will define a macro based on this type to perform type safe dynamic_casts to
499  * this object type.
500  *
501  * If an invalid object is passed to this function, a run time assert will be
502  * generated.
503  */
504 #define OBJECT_CHECK(type, obj, name) \
505     ((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \
506                                         __FILE__, __LINE__, __func__))
507 
508 /**
509  * OBJECT_CLASS_CHECK:
510  * @class_type: The C type to use for the return value.
511  * @class: A derivative class of @class_type to cast.
512  * @name: the QOM typename of @class_type.
513  *
514  * A type safe version of @object_class_dynamic_cast_assert.  This macro is
515  * typically wrapped by each type to perform type safe casts of a class to a
516  * specific class type.
517  */
518 #define OBJECT_CLASS_CHECK(class_type, class, name) \
519     ((class_type *)object_class_dynamic_cast_assert(OBJECT_CLASS(class), (name), \
520                                                __FILE__, __LINE__, __func__))
521 
522 /**
523  * OBJECT_GET_CLASS:
524  * @class: The C type to use for the return value.
525  * @obj: The object to obtain the class for.
526  * @name: The QOM typename of @obj.
527  *
528  * This function will return a specific class for a given object.  Its generally
529  * used by each type to provide a type safe macro to get a specific class type
530  * from an object.
531  */
532 #define OBJECT_GET_CLASS(class, obj, name) \
533     OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
534 
535 /**
536  * InterfaceInfo:
537  * @type: The name of the interface.
538  *
539  * The information associated with an interface.
540  */
541 struct InterfaceInfo {
542     const char *type;
543 };
544 
545 /**
546  * InterfaceClass:
547  * @parent_class: the base class
548  *
549  * The class for all interfaces.  Subclasses of this class should only add
550  * virtual methods.
551  */
552 struct InterfaceClass
553 {
554     ObjectClass parent_class;
555     /*< private >*/
556     ObjectClass *concrete_class;
557     Type interface_type;
558 };
559 
560 #define TYPE_INTERFACE "interface"
561 
562 /**
563  * INTERFACE_CLASS:
564  * @klass: class to cast from
565  * Returns: An #InterfaceClass or raise an error if cast is invalid
566  */
567 #define INTERFACE_CLASS(klass) \
568     OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE)
569 
570 /**
571  * INTERFACE_CHECK:
572  * @interface: the type to return
573  * @obj: the object to convert to an interface
574  * @name: the interface type name
575  *
576  * Returns: @obj casted to @interface if cast is valid, otherwise raise error.
577  */
578 #define INTERFACE_CHECK(interface, obj, name) \
579     ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \
580                                              __FILE__, __LINE__, __func__))
581 
582 /**
583  * object_new:
584  * @typename: The name of the type of the object to instantiate.
585  *
586  * This function will initialize a new object using heap allocated memory.
587  * The returned object has a reference count of 1, and will be freed when
588  * the last reference is dropped.
589  *
590  * Returns: The newly allocated and instantiated object.
591  */
592 Object *object_new(const char *typename);
593 
594 /**
595  * object_new_with_type:
596  * @type: The type of the object to instantiate.
597  *
598  * This function will initialize a new object using heap allocated memory.
599  * The returned object has a reference count of 1, and will be freed when
600  * the last reference is dropped.
601  *
602  * Returns: The newly allocated and instantiated object.
603  */
604 Object *object_new_with_type(Type type);
605 
606 /**
607  * object_new_with_props:
608  * @typename:  The name of the type of the object to instantiate.
609  * @parent: the parent object
610  * @id: The unique ID of the object
611  * @errp: pointer to error object
612  * @...: list of property names and values
613  *
614  * This function will initialize a new object using heap allocated memory.
615  * The returned object has a reference count of 1, and will be freed when
616  * the last reference is dropped.
617  *
618  * The @id parameter will be used when registering the object as a
619  * child of @parent in the composition tree.
620  *
621  * The variadic parameters are a list of pairs of (propname, propvalue)
622  * strings. The propname of %NULL indicates the end of the property
623  * list. If the object implements the user creatable interface, the
624  * object will be marked complete once all the properties have been
625  * processed.
626  *
627  * <example>
628  *   <title>Creating an object with properties</title>
629  *   <programlisting>
630  *   Error *err = NULL;
631  *   Object *obj;
632  *
633  *   obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE,
634  *                               object_get_objects_root(),
635  *                               "hostmem0",
636  *                               &err,
637  *                               "share", "yes",
638  *                               "mem-path", "/dev/shm/somefile",
639  *                               "prealloc", "yes",
640  *                               "size", "1048576",
641  *                               NULL);
642  *
643  *   if (!obj) {
644  *     g_printerr("Cannot create memory backend: %s\n",
645  *                error_get_pretty(err));
646  *   }
647  *   </programlisting>
648  * </example>
649  *
650  * The returned object will have one stable reference maintained
651  * for as long as it is present in the object hierarchy.
652  *
653  * Returns: The newly allocated, instantiated & initialized object.
654  */
655 Object *object_new_with_props(const char *typename,
656                               Object *parent,
657                               const char *id,
658                               Error **errp,
659                               ...) QEMU_SENTINEL;
660 
661 /**
662  * object_new_with_propv:
663  * @typename:  The name of the type of the object to instantiate.
664  * @parent: the parent object
665  * @id: The unique ID of the object
666  * @errp: pointer to error object
667  * @vargs: list of property names and values
668  *
669  * See object_new_with_props() for documentation.
670  */
671 Object *object_new_with_propv(const char *typename,
672                               Object *parent,
673                               const char *id,
674                               Error **errp,
675                               va_list vargs);
676 
677 /**
678  * object_set_props:
679  * @obj: the object instance to set properties on
680  * @errp: pointer to error object
681  * @...: list of property names and values
682  *
683  * This function will set a list of properties on an existing object
684  * instance.
685  *
686  * The variadic parameters are a list of pairs of (propname, propvalue)
687  * strings. The propname of %NULL indicates the end of the property
688  * list.
689  *
690  * <example>
691  *   <title>Update an object's properties</title>
692  *   <programlisting>
693  *   Error *err = NULL;
694  *   Object *obj = ...get / create object...;
695  *
696  *   obj = object_set_props(obj,
697  *                          &err,
698  *                          "share", "yes",
699  *                          "mem-path", "/dev/shm/somefile",
700  *                          "prealloc", "yes",
701  *                          "size", "1048576",
702  *                          NULL);
703  *
704  *   if (!obj) {
705  *     g_printerr("Cannot set properties: %s\n",
706  *                error_get_pretty(err));
707  *   }
708  *   </programlisting>
709  * </example>
710  *
711  * The returned object will have one stable reference maintained
712  * for as long as it is present in the object hierarchy.
713  *
714  * Returns: -1 on error, 0 on success
715  */
716 int object_set_props(Object *obj,
717                      Error **errp,
718                      ...) QEMU_SENTINEL;
719 
720 /**
721  * object_set_propv:
722  * @obj: the object instance to set properties on
723  * @errp: pointer to error object
724  * @vargs: list of property names and values
725  *
726  * See object_set_props() for documentation.
727  *
728  * Returns: -1 on error, 0 on success
729  */
730 int object_set_propv(Object *obj,
731                      Error **errp,
732                      va_list vargs);
733 
734 /**
735  * object_initialize_with_type:
736  * @data: A pointer to the memory to be used for the object.
737  * @size: The maximum size available at @data for the object.
738  * @type: The type of the object to instantiate.
739  *
740  * This function will initialize an object.  The memory for the object should
741  * have already been allocated.  The returned object has a reference count of 1,
742  * and will be finalized when the last reference is dropped.
743  */
744 void object_initialize_with_type(void *data, size_t size, Type type);
745 
746 /**
747  * object_initialize:
748  * @obj: A pointer to the memory to be used for the object.
749  * @size: The maximum size available at @obj for the object.
750  * @typename: The name of the type of the object to instantiate.
751  *
752  * This function will initialize an object.  The memory for the object should
753  * have already been allocated.  The returned object has a reference count of 1,
754  * and will be finalized when the last reference is dropped.
755  */
756 void object_initialize(void *obj, size_t size, const char *typename);
757 
758 /**
759  * object_dynamic_cast:
760  * @obj: The object to cast.
761  * @typename: The @typename to cast to.
762  *
763  * This function will determine if @obj is-a @typename.  @obj can refer to an
764  * object or an interface associated with an object.
765  *
766  * Returns: This function returns @obj on success or #NULL on failure.
767  */
768 Object *object_dynamic_cast(Object *obj, const char *typename);
769 
770 /**
771  * object_dynamic_cast_assert:
772  *
773  * See object_dynamic_cast() for a description of the parameters of this
774  * function.  The only difference in behavior is that this function asserts
775  * instead of returning #NULL on failure if QOM cast debugging is enabled.
776  * This function is not meant to be called directly, but only through
777  * the wrapper macro OBJECT_CHECK.
778  */
779 Object *object_dynamic_cast_assert(Object *obj, const char *typename,
780                                    const char *file, int line, const char *func);
781 
782 /**
783  * object_get_class:
784  * @obj: A derivative of #Object
785  *
786  * Returns: The #ObjectClass of the type associated with @obj.
787  */
788 ObjectClass *object_get_class(Object *obj);
789 
790 /**
791  * object_get_typename:
792  * @obj: A derivative of #Object.
793  *
794  * Returns: The QOM typename of @obj.
795  */
796 const char *object_get_typename(Object *obj);
797 
798 /**
799  * type_register_static:
800  * @info: The #TypeInfo of the new type.
801  *
802  * @info and all of the strings it points to should exist for the life time
803  * that the type is registered.
804  *
805  * Returns: 0 on failure, the new #Type on success.
806  */
807 Type type_register_static(const TypeInfo *info);
808 
809 /**
810  * type_register:
811  * @info: The #TypeInfo of the new type
812  *
813  * Unlike type_register_static(), this call does not require @info or its
814  * string members to continue to exist after the call returns.
815  *
816  * Returns: 0 on failure, the new #Type on success.
817  */
818 Type type_register(const TypeInfo *info);
819 
820 /**
821  * object_class_dynamic_cast_assert:
822  * @klass: The #ObjectClass to attempt to cast.
823  * @typename: The QOM typename of the class to cast to.
824  *
825  * See object_class_dynamic_cast() for a description of the parameters
826  * of this function.  The only difference in behavior is that this function
827  * asserts instead of returning #NULL on failure if QOM cast debugging is
828  * enabled.  This function is not meant to be called directly, but only through
829  * the wrapper macros OBJECT_CLASS_CHECK and INTERFACE_CHECK.
830  */
831 ObjectClass *object_class_dynamic_cast_assert(ObjectClass *klass,
832                                               const char *typename,
833                                               const char *file, int line,
834                                               const char *func);
835 
836 /**
837  * object_class_dynamic_cast:
838  * @klass: The #ObjectClass to attempt to cast.
839  * @typename: The QOM typename of the class to cast to.
840  *
841  * Returns: If @typename is a class, this function returns @klass if
842  * @typename is a subtype of @klass, else returns #NULL.
843  *
844  * If @typename is an interface, this function returns the interface
845  * definition for @klass if @klass implements it unambiguously; #NULL
846  * is returned if @klass does not implement the interface or if multiple
847  * classes or interfaces on the hierarchy leading to @klass implement
848  * it.  (FIXME: perhaps this can be detected at type definition time?)
849  */
850 ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
851                                        const char *typename);
852 
853 /**
854  * object_class_get_parent:
855  * @klass: The class to obtain the parent for.
856  *
857  * Returns: The parent for @klass or %NULL if none.
858  */
859 ObjectClass *object_class_get_parent(ObjectClass *klass);
860 
861 /**
862  * object_class_get_name:
863  * @klass: The class to obtain the QOM typename for.
864  *
865  * Returns: The QOM typename for @klass.
866  */
867 const char *object_class_get_name(ObjectClass *klass);
868 
869 /**
870  * object_class_is_abstract:
871  * @klass: The class to obtain the abstractness for.
872  *
873  * Returns: %true if @klass is abstract, %false otherwise.
874  */
875 bool object_class_is_abstract(ObjectClass *klass);
876 
877 /**
878  * object_class_by_name:
879  * @typename: The QOM typename to obtain the class for.
880  *
881  * Returns: The class for @typename or %NULL if not found.
882  */
883 ObjectClass *object_class_by_name(const char *typename);
884 
885 void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
886                           const char *implements_type, bool include_abstract,
887                           void *opaque);
888 
889 /**
890  * object_class_get_list:
891  * @implements_type: The type to filter for, including its derivatives.
892  * @include_abstract: Whether to include abstract classes.
893  *
894  * Returns: A singly-linked list of the classes in reverse hashtable order.
895  */
896 GSList *object_class_get_list(const char *implements_type,
897                               bool include_abstract);
898 
899 /**
900  * object_ref:
901  * @obj: the object
902  *
903  * Increase the reference count of a object.  A object cannot be freed as long
904  * as its reference count is greater than zero.
905  */
906 void object_ref(Object *obj);
907 
908 /**
909  * qdef_unref:
910  * @obj: the object
911  *
912  * Decrease the reference count of a object.  A object cannot be freed as long
913  * as its reference count is greater than zero.
914  */
915 void object_unref(Object *obj);
916 
917 /**
918  * object_property_add:
919  * @obj: the object to add a property to
920  * @name: the name of the property.  This can contain any character except for
921  *  a forward slash.  In general, you should use hyphens '-' instead of
922  *  underscores '_' when naming properties.
923  * @type: the type name of the property.  This namespace is pretty loosely
924  *   defined.  Sub namespaces are constructed by using a prefix and then
925  *   to angle brackets.  For instance, the type 'virtio-net-pci' in the
926  *   'link' namespace would be 'link<virtio-net-pci>'.
927  * @get: The getter to be called to read a property.  If this is NULL, then
928  *   the property cannot be read.
929  * @set: the setter to be called to write a property.  If this is NULL,
930  *   then the property cannot be written.
931  * @release: called when the property is removed from the object.  This is
932  *   meant to allow a property to free its opaque upon object
933  *   destruction.  This may be NULL.
934  * @opaque: an opaque pointer to pass to the callbacks for the property
935  * @errp: returns an error if this function fails
936  *
937  * Returns: The #ObjectProperty; this can be used to set the @resolve
938  * callback for child and link properties.
939  */
940 ObjectProperty *object_property_add(Object *obj, const char *name,
941                                     const char *type,
942                                     ObjectPropertyAccessor *get,
943                                     ObjectPropertyAccessor *set,
944                                     ObjectPropertyRelease *release,
945                                     void *opaque, Error **errp);
946 
947 void object_property_del(Object *obj, const char *name, Error **errp);
948 
949 ObjectProperty *object_class_property_add(ObjectClass *klass, const char *name,
950                                           const char *type,
951                                           ObjectPropertyAccessor *get,
952                                           ObjectPropertyAccessor *set,
953                                           ObjectPropertyRelease *release,
954                                           void *opaque, Error **errp);
955 
956 /**
957  * object_property_find:
958  * @obj: the object
959  * @name: the name of the property
960  * @errp: returns an error if this function fails
961  *
962  * Look up a property for an object and return its #ObjectProperty if found.
963  */
964 ObjectProperty *object_property_find(Object *obj, const char *name,
965                                      Error **errp);
966 ObjectProperty *object_class_property_find(ObjectClass *klass, const char *name,
967                                            Error **errp);
968 
969 typedef struct ObjectPropertyIterator {
970     ObjectClass *nextclass;
971     GHashTableIter iter;
972 } ObjectPropertyIterator;
973 
974 /**
975  * object_property_iter_init:
976  * @obj: the object
977  *
978  * Initializes an iterator for traversing all properties
979  * registered against an object instance, its class and all parent classes.
980  *
981  * It is forbidden to modify the property list while iterating,
982  * whether removing or adding properties.
983  *
984  * Typical usage pattern would be
985  *
986  * <example>
987  *   <title>Using object property iterators</title>
988  *   <programlisting>
989  *   ObjectProperty *prop;
990  *   ObjectPropertyIterator iter;
991  *
992  *   object_property_iter_init(&iter, obj);
993  *   while ((prop = object_property_iter_next(&iter))) {
994  *     ... do something with prop ...
995  *   }
996  *   </programlisting>
997  * </example>
998  */
999 void object_property_iter_init(ObjectPropertyIterator *iter,
1000                                Object *obj);
1001 
1002 /**
1003  * object_property_iter_next:
1004  * @iter: the iterator instance
1005  *
1006  * Return the next available property. If no further properties
1007  * are available, a %NULL value will be returned and the @iter
1008  * pointer should not be used again after this point without
1009  * re-initializing it.
1010  *
1011  * Returns: the next property, or %NULL when all properties
1012  * have been traversed.
1013  */
1014 ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
1015 
1016 void object_unparent(Object *obj);
1017 
1018 /**
1019  * object_property_get:
1020  * @obj: the object
1021  * @v: the visitor that will receive the property value.  This should be an
1022  *   Output visitor and the data will be written with @name as the name.
1023  * @name: the name of the property
1024  * @errp: returns an error if this function fails
1025  *
1026  * Reads a property from a object.
1027  */
1028 void object_property_get(Object *obj, struct Visitor *v, const char *name,
1029                          Error **errp);
1030 
1031 /**
1032  * object_property_set_str:
1033  * @value: the value to be written to the property
1034  * @name: the name of the property
1035  * @errp: returns an error if this function fails
1036  *
1037  * Writes a string value to a property.
1038  */
1039 void object_property_set_str(Object *obj, const char *value,
1040                              const char *name, Error **errp);
1041 
1042 /**
1043  * object_property_get_str:
1044  * @obj: the object
1045  * @name: the name of the property
1046  * @errp: returns an error if this function fails
1047  *
1048  * Returns: the value of the property, converted to a C string, or NULL if
1049  * an error occurs (including when the property value is not a string).
1050  * The caller should free the string.
1051  */
1052 char *object_property_get_str(Object *obj, const char *name,
1053                               Error **errp);
1054 
1055 /**
1056  * object_property_set_link:
1057  * @value: the value to be written to the property
1058  * @name: the name of the property
1059  * @errp: returns an error if this function fails
1060  *
1061  * Writes an object's canonical path to a property.
1062  */
1063 void object_property_set_link(Object *obj, Object *value,
1064                               const char *name, Error **errp);
1065 
1066 /**
1067  * object_property_get_link:
1068  * @obj: the object
1069  * @name: the name of the property
1070  * @errp: returns an error if this function fails
1071  *
1072  * Returns: the value of the property, resolved from a path to an Object,
1073  * or NULL if an error occurs (including when the property value is not a
1074  * string or not a valid object path).
1075  */
1076 Object *object_property_get_link(Object *obj, const char *name,
1077                                  Error **errp);
1078 
1079 /**
1080  * object_property_set_bool:
1081  * @value: the value to be written to the property
1082  * @name: the name of the property
1083  * @errp: returns an error if this function fails
1084  *
1085  * Writes a bool value to a property.
1086  */
1087 void object_property_set_bool(Object *obj, bool value,
1088                               const char *name, Error **errp);
1089 
1090 /**
1091  * object_property_get_bool:
1092  * @obj: the object
1093  * @name: the name of the property
1094  * @errp: returns an error if this function fails
1095  *
1096  * Returns: the value of the property, converted to a boolean, or NULL if
1097  * an error occurs (including when the property value is not a bool).
1098  */
1099 bool object_property_get_bool(Object *obj, const char *name,
1100                               Error **errp);
1101 
1102 /**
1103  * object_property_set_int:
1104  * @value: the value to be written to the property
1105  * @name: the name of the property
1106  * @errp: returns an error if this function fails
1107  *
1108  * Writes an integer value to a property.
1109  */
1110 void object_property_set_int(Object *obj, int64_t value,
1111                              const char *name, Error **errp);
1112 
1113 /**
1114  * object_property_get_int:
1115  * @obj: the object
1116  * @name: the name of the property
1117  * @errp: returns an error if this function fails
1118  *
1119  * Returns: the value of the property, converted to an integer, or NULL if
1120  * an error occurs (including when the property value is not an integer).
1121  */
1122 int64_t object_property_get_int(Object *obj, const char *name,
1123                                 Error **errp);
1124 
1125 /**
1126  * object_property_get_enum:
1127  * @obj: the object
1128  * @name: the name of the property
1129  * @typename: the name of the enum data type
1130  * @errp: returns an error if this function fails
1131  *
1132  * Returns: the value of the property, converted to an integer, or
1133  * undefined if an error occurs (including when the property value is not
1134  * an enum).
1135  */
1136 int object_property_get_enum(Object *obj, const char *name,
1137                              const char *typename, Error **errp);
1138 
1139 /**
1140  * object_property_get_uint16List:
1141  * @obj: the object
1142  * @name: the name of the property
1143  * @list: the returned int list
1144  * @errp: returns an error if this function fails
1145  *
1146  * Returns: the value of the property, converted to integers, or
1147  * undefined if an error occurs (including when the property value is not
1148  * an list of integers).
1149  */
1150 void object_property_get_uint16List(Object *obj, const char *name,
1151                                     uint16List **list, Error **errp);
1152 
1153 /**
1154  * object_property_set:
1155  * @obj: the object
1156  * @v: the visitor that will be used to write the property value.  This should
1157  *   be an Input visitor and the data will be first read with @name as the
1158  *   name and then written as the property value.
1159  * @name: the name of the property
1160  * @errp: returns an error if this function fails
1161  *
1162  * Writes a property to a object.
1163  */
1164 void object_property_set(Object *obj, struct Visitor *v, const char *name,
1165                          Error **errp);
1166 
1167 /**
1168  * object_property_parse:
1169  * @obj: the object
1170  * @string: the string that will be used to parse the property value.
1171  * @name: the name of the property
1172  * @errp: returns an error if this function fails
1173  *
1174  * Parses a string and writes the result into a property of an object.
1175  */
1176 void object_property_parse(Object *obj, const char *string,
1177                            const char *name, Error **errp);
1178 
1179 /**
1180  * object_property_print:
1181  * @obj: the object
1182  * @name: the name of the property
1183  * @human: if true, print for human consumption
1184  * @errp: returns an error if this function fails
1185  *
1186  * Returns a string representation of the value of the property.  The
1187  * caller shall free the string.
1188  */
1189 char *object_property_print(Object *obj, const char *name, bool human,
1190                             Error **errp);
1191 
1192 /**
1193  * object_property_get_type:
1194  * @obj: the object
1195  * @name: the name of the property
1196  * @errp: returns an error if this function fails
1197  *
1198  * Returns:  The type name of the property.
1199  */
1200 const char *object_property_get_type(Object *obj, const char *name,
1201                                      Error **errp);
1202 
1203 /**
1204  * object_get_root:
1205  *
1206  * Returns: the root object of the composition tree
1207  */
1208 Object *object_get_root(void);
1209 
1210 
1211 /**
1212  * object_get_objects_root:
1213  *
1214  * Get the container object that holds user created
1215  * object instances. This is the object at path
1216  * "/objects"
1217  *
1218  * Returns: the user object container
1219  */
1220 Object *object_get_objects_root(void);
1221 
1222 /**
1223  * object_get_canonical_path_component:
1224  *
1225  * Returns: The final component in the object's canonical path.  The canonical
1226  * path is the path within the composition tree starting from the root.
1227  */
1228 gchar *object_get_canonical_path_component(Object *obj);
1229 
1230 /**
1231  * object_get_canonical_path:
1232  *
1233  * Returns: The canonical path for a object.  This is the path within the
1234  * composition tree starting from the root.
1235  */
1236 gchar *object_get_canonical_path(Object *obj);
1237 
1238 /**
1239  * object_resolve_path:
1240  * @path: the path to resolve
1241  * @ambiguous: returns true if the path resolution failed because of an
1242  *   ambiguous match
1243  *
1244  * There are two types of supported paths--absolute paths and partial paths.
1245  *
1246  * Absolute paths are derived from the root object and can follow child<> or
1247  * link<> properties.  Since they can follow link<> properties, they can be
1248  * arbitrarily long.  Absolute paths look like absolute filenames and are
1249  * prefixed with a leading slash.
1250  *
1251  * Partial paths look like relative filenames.  They do not begin with a
1252  * prefix.  The matching rules for partial paths are subtle but designed to make
1253  * specifying objects easy.  At each level of the composition tree, the partial
1254  * path is matched as an absolute path.  The first match is not returned.  At
1255  * least two matches are searched for.  A successful result is only returned if
1256  * only one match is found.  If more than one match is found, a flag is
1257  * returned to indicate that the match was ambiguous.
1258  *
1259  * Returns: The matched object or NULL on path lookup failure.
1260  */
1261 Object *object_resolve_path(const char *path, bool *ambiguous);
1262 
1263 /**
1264  * object_resolve_path_type:
1265  * @path: the path to resolve
1266  * @typename: the type to look for.
1267  * @ambiguous: returns true if the path resolution failed because of an
1268  *   ambiguous match
1269  *
1270  * This is similar to object_resolve_path.  However, when looking for a
1271  * partial path only matches that implement the given type are considered.
1272  * This restricts the search and avoids spuriously flagging matches as
1273  * ambiguous.
1274  *
1275  * For both partial and absolute paths, the return value goes through
1276  * a dynamic cast to @typename.  This is important if either the link,
1277  * or the typename itself are of interface types.
1278  *
1279  * Returns: The matched object or NULL on path lookup failure.
1280  */
1281 Object *object_resolve_path_type(const char *path, const char *typename,
1282                                  bool *ambiguous);
1283 
1284 /**
1285  * object_resolve_path_component:
1286  * @parent: the object in which to resolve the path
1287  * @part: the component to resolve.
1288  *
1289  * This is similar to object_resolve_path with an absolute path, but it
1290  * only resolves one element (@part) and takes the others from @parent.
1291  *
1292  * Returns: The resolved object or NULL on path lookup failure.
1293  */
1294 Object *object_resolve_path_component(Object *parent, const gchar *part);
1295 
1296 /**
1297  * object_property_add_child:
1298  * @obj: the object to add a property to
1299  * @name: the name of the property
1300  * @child: the child object
1301  * @errp: if an error occurs, a pointer to an area to store the area
1302  *
1303  * Child properties form the composition tree.  All objects need to be a child
1304  * of another object.  Objects can only be a child of one object.
1305  *
1306  * There is no way for a child to determine what its parent is.  It is not
1307  * a bidirectional relationship.  This is by design.
1308  *
1309  * The value of a child property as a C string will be the child object's
1310  * canonical path. It can be retrieved using object_property_get_str().
1311  * The child object itself can be retrieved using object_property_get_link().
1312  */
1313 void object_property_add_child(Object *obj, const char *name,
1314                                Object *child, Error **errp);
1315 
1316 typedef enum {
1317     /* Unref the link pointer when the property is deleted */
1318     OBJ_PROP_LINK_UNREF_ON_RELEASE = 0x1,
1319 } ObjectPropertyLinkFlags;
1320 
1321 /**
1322  * object_property_allow_set_link:
1323  *
1324  * The default implementation of the object_property_add_link() check()
1325  * callback function.  It allows the link property to be set and never returns
1326  * an error.
1327  */
1328 void object_property_allow_set_link(Object *, const char *,
1329                                     Object *, Error **);
1330 
1331 /**
1332  * object_property_add_link:
1333  * @obj: the object to add a property to
1334  * @name: the name of the property
1335  * @type: the qobj type of the link
1336  * @child: a pointer to where the link object reference is stored
1337  * @check: callback to veto setting or NULL if the property is read-only
1338  * @flags: additional options for the link
1339  * @errp: if an error occurs, a pointer to an area to store the area
1340  *
1341  * Links establish relationships between objects.  Links are unidirectional
1342  * although two links can be combined to form a bidirectional relationship
1343  * between objects.
1344  *
1345  * Links form the graph in the object model.
1346  *
1347  * The <code>@check()</code> callback is invoked when
1348  * object_property_set_link() is called and can raise an error to prevent the
1349  * link being set.  If <code>@check</code> is NULL, the property is read-only
1350  * and cannot be set.
1351  *
1352  * Ownership of the pointer that @child points to is transferred to the
1353  * link property.  The reference count for <code>*@child</code> is
1354  * managed by the property from after the function returns till the
1355  * property is deleted with object_property_del().  If the
1356  * <code>@flags</code> <code>OBJ_PROP_LINK_UNREF_ON_RELEASE</code> bit is set,
1357  * the reference count is decremented when the property is deleted.
1358  */
1359 void object_property_add_link(Object *obj, const char *name,
1360                               const char *type, Object **child,
1361                               void (*check)(Object *obj, const char *name,
1362                                             Object *val, Error **errp),
1363                               ObjectPropertyLinkFlags flags,
1364                               Error **errp);
1365 
1366 /**
1367  * object_property_add_str:
1368  * @obj: the object to add a property to
1369  * @name: the name of the property
1370  * @get: the getter or NULL if the property is write-only.  This function must
1371  *   return a string to be freed by g_free().
1372  * @set: the setter or NULL if the property is read-only
1373  * @errp: if an error occurs, a pointer to an area to store the error
1374  *
1375  * Add a string property using getters/setters.  This function will add a
1376  * property of type 'string'.
1377  */
1378 void object_property_add_str(Object *obj, const char *name,
1379                              char *(*get)(Object *, Error **),
1380                              void (*set)(Object *, const char *, Error **),
1381                              Error **errp);
1382 
1383 void object_class_property_add_str(ObjectClass *klass, const char *name,
1384                                    char *(*get)(Object *, Error **),
1385                                    void (*set)(Object *, const char *,
1386                                                Error **),
1387                                    Error **errp);
1388 
1389 /**
1390  * object_property_add_bool:
1391  * @obj: the object to add a property to
1392  * @name: the name of the property
1393  * @get: the getter or NULL if the property is write-only.
1394  * @set: the setter or NULL if the property is read-only
1395  * @errp: if an error occurs, a pointer to an area to store the error
1396  *
1397  * Add a bool property using getters/setters.  This function will add a
1398  * property of type 'bool'.
1399  */
1400 void object_property_add_bool(Object *obj, const char *name,
1401                               bool (*get)(Object *, Error **),
1402                               void (*set)(Object *, bool, Error **),
1403                               Error **errp);
1404 
1405 void object_class_property_add_bool(ObjectClass *klass, const char *name,
1406                                     bool (*get)(Object *, Error **),
1407                                     void (*set)(Object *, bool, Error **),
1408                                     Error **errp);
1409 
1410 /**
1411  * object_property_add_enum:
1412  * @obj: the object to add a property to
1413  * @name: the name of the property
1414  * @typename: the name of the enum data type
1415  * @get: the getter or %NULL if the property is write-only.
1416  * @set: the setter or %NULL if the property is read-only
1417  * @errp: if an error occurs, a pointer to an area to store the error
1418  *
1419  * Add an enum property using getters/setters.  This function will add a
1420  * property of type '@typename'.
1421  */
1422 void object_property_add_enum(Object *obj, const char *name,
1423                               const char *typename,
1424                               const char * const *strings,
1425                               int (*get)(Object *, Error **),
1426                               void (*set)(Object *, int, Error **),
1427                               Error **errp);
1428 
1429 void object_class_property_add_enum(ObjectClass *klass, const char *name,
1430                                     const char *typename,
1431                                     const char * const *strings,
1432                                     int (*get)(Object *, Error **),
1433                                     void (*set)(Object *, int, Error **),
1434                                     Error **errp);
1435 
1436 /**
1437  * object_property_add_tm:
1438  * @obj: the object to add a property to
1439  * @name: the name of the property
1440  * @get: the getter or NULL if the property is write-only.
1441  * @errp: if an error occurs, a pointer to an area to store the error
1442  *
1443  * Add a read-only struct tm valued property using a getter function.
1444  * This function will add a property of type 'struct tm'.
1445  */
1446 void object_property_add_tm(Object *obj, const char *name,
1447                             void (*get)(Object *, struct tm *, Error **),
1448                             Error **errp);
1449 
1450 void object_class_property_add_tm(ObjectClass *klass, const char *name,
1451                                   void (*get)(Object *, struct tm *, Error **),
1452                                   Error **errp);
1453 
1454 /**
1455  * object_property_add_uint8_ptr:
1456  * @obj: the object to add a property to
1457  * @name: the name of the property
1458  * @v: pointer to value
1459  * @errp: if an error occurs, a pointer to an area to store the error
1460  *
1461  * Add an integer property in memory.  This function will add a
1462  * property of type 'uint8'.
1463  */
1464 void object_property_add_uint8_ptr(Object *obj, const char *name,
1465                                    const uint8_t *v, Error **errp);
1466 void object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
1467                                          const uint8_t *v, Error **errp);
1468 
1469 /**
1470  * object_property_add_uint16_ptr:
1471  * @obj: the object to add a property to
1472  * @name: the name of the property
1473  * @v: pointer to value
1474  * @errp: if an error occurs, a pointer to an area to store the error
1475  *
1476  * Add an integer property in memory.  This function will add a
1477  * property of type 'uint16'.
1478  */
1479 void object_property_add_uint16_ptr(Object *obj, const char *name,
1480                                     const uint16_t *v, Error **errp);
1481 void object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
1482                                           const uint16_t *v, Error **errp);
1483 
1484 /**
1485  * object_property_add_uint32_ptr:
1486  * @obj: the object to add a property to
1487  * @name: the name of the property
1488  * @v: pointer to value
1489  * @errp: if an error occurs, a pointer to an area to store the error
1490  *
1491  * Add an integer property in memory.  This function will add a
1492  * property of type 'uint32'.
1493  */
1494 void object_property_add_uint32_ptr(Object *obj, const char *name,
1495                                     const uint32_t *v, Error **errp);
1496 void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
1497                                           const uint32_t *v, Error **errp);
1498 
1499 /**
1500  * object_property_add_uint64_ptr:
1501  * @obj: the object to add a property to
1502  * @name: the name of the property
1503  * @v: pointer to value
1504  * @errp: if an error occurs, a pointer to an area to store the error
1505  *
1506  * Add an integer property in memory.  This function will add a
1507  * property of type 'uint64'.
1508  */
1509 void object_property_add_uint64_ptr(Object *obj, const char *name,
1510                                     const uint64_t *v, Error **Errp);
1511 void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
1512                                           const uint64_t *v, Error **Errp);
1513 
1514 /**
1515  * object_property_add_alias:
1516  * @obj: the object to add a property to
1517  * @name: the name of the property
1518  * @target_obj: the object to forward property access to
1519  * @target_name: the name of the property on the forwarded object
1520  * @errp: if an error occurs, a pointer to an area to store the error
1521  *
1522  * Add an alias for a property on an object.  This function will add a property
1523  * of the same type as the forwarded property.
1524  *
1525  * The caller must ensure that <code>@target_obj</code> stays alive as long as
1526  * this property exists.  In the case of a child object or an alias on the same
1527  * object this will be the case.  For aliases to other objects the caller is
1528  * responsible for taking a reference.
1529  */
1530 void object_property_add_alias(Object *obj, const char *name,
1531                                Object *target_obj, const char *target_name,
1532                                Error **errp);
1533 
1534 /**
1535  * object_property_add_const_link:
1536  * @obj: the object to add a property to
1537  * @name: the name of the property
1538  * @target: the object to be referred by the link
1539  * @errp: if an error occurs, a pointer to an area to store the error
1540  *
1541  * Add an unmodifiable link for a property on an object.  This function will
1542  * add a property of type link<TYPE> where TYPE is the type of @target.
1543  *
1544  * The caller must ensure that @target stays alive as long as
1545  * this property exists.  In the case @target is a child of @obj,
1546  * this will be the case.  Otherwise, the caller is responsible for
1547  * taking a reference.
1548  */
1549 void object_property_add_const_link(Object *obj, const char *name,
1550                                     Object *target, Error **errp);
1551 
1552 /**
1553  * object_property_set_description:
1554  * @obj: the object owning the property
1555  * @name: the name of the property
1556  * @description: the description of the property on the object
1557  * @errp: if an error occurs, a pointer to an area to store the error
1558  *
1559  * Set an object property's description.
1560  *
1561  */
1562 void object_property_set_description(Object *obj, const char *name,
1563                                      const char *description, Error **errp);
1564 void object_class_property_set_description(ObjectClass *klass, const char *name,
1565                                            const char *description,
1566                                            Error **errp);
1567 
1568 /**
1569  * object_child_foreach:
1570  * @obj: the object whose children will be navigated
1571  * @fn: the iterator function to be called
1572  * @opaque: an opaque value that will be passed to the iterator
1573  *
1574  * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1575  * non-zero.
1576  *
1577  * It is forbidden to add or remove children from @obj from the @fn
1578  * callback.
1579  *
1580  * Returns: The last value returned by @fn, or 0 if there is no child.
1581  */
1582 int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
1583                          void *opaque);
1584 
1585 /**
1586  * object_child_foreach_recursive:
1587  * @obj: the object whose children will be navigated
1588  * @fn: the iterator function to be called
1589  * @opaque: an opaque value that will be passed to the iterator
1590  *
1591  * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1592  * non-zero. Calls recursively, all child nodes of @obj will also be passed
1593  * all the way down to the leaf nodes of the tree. Depth first ordering.
1594  *
1595  * It is forbidden to add or remove children from @obj (or its
1596  * child nodes) from the @fn callback.
1597  *
1598  * Returns: The last value returned by @fn, or 0 if there is no child.
1599  */
1600 int object_child_foreach_recursive(Object *obj,
1601                                    int (*fn)(Object *child, void *opaque),
1602                                    void *opaque);
1603 /**
1604  * container_get:
1605  * @root: root of the #path, e.g., object_get_root()
1606  * @path: path to the container
1607  *
1608  * Return a container object whose path is @path.  Create more containers
1609  * along the path if necessary.
1610  *
1611  * Returns: the container object.
1612  */
1613 Object *container_get(Object *root, const char *path);
1614 
1615 
1616 #endif
1617