qom: Put name parameter before value / visitor parameter
[qemu/ar7.git] / include / qom / object.h
blob7c2c6791a4a7daee22920774a449577e37a38baa
1 /*
2 * QEMU Object Model
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #ifndef QEMU_OBJECT_H
15 #define QEMU_OBJECT_H
17 #include "qapi/qapi-builtin-types.h"
18 #include "qemu/module.h"
20 struct TypeImpl;
21 typedef struct TypeImpl *Type;
23 typedef struct TypeInfo TypeInfo;
25 typedef struct InterfaceClass InterfaceClass;
26 typedef struct InterfaceInfo InterfaceInfo;
28 #define TYPE_OBJECT "object"
30 /**
31 * SECTION:object.h
32 * @title:Base Object Type System
33 * @short_description: interfaces for creating new types and objects
35 * The QEMU Object Model provides a framework for registering user creatable
36 * types and instantiating objects from those types. QOM provides the following
37 * features:
39 * - System for dynamically registering types
40 * - Support for single-inheritance of types
41 * - Multiple inheritance of stateless interfaces
43 * <example>
44 * <title>Creating a minimal type</title>
45 * <programlisting>
46 * #include "qdev.h"
48 * #define TYPE_MY_DEVICE "my-device"
50 * // No new virtual functions: we can reuse the typedef for the
51 * // superclass.
52 * typedef DeviceClass MyDeviceClass;
53 * typedef struct MyDevice
54 * {
55 * DeviceState parent;
57 * int reg0, reg1, reg2;
58 * } MyDevice;
60 * static const TypeInfo my_device_info = {
61 * .name = TYPE_MY_DEVICE,
62 * .parent = TYPE_DEVICE,
63 * .instance_size = sizeof(MyDevice),
64 * };
66 * static void my_device_register_types(void)
67 * {
68 * type_register_static(&my_device_info);
69 * }
71 * type_init(my_device_register_types)
72 * </programlisting>
73 * </example>
75 * In the above example, we create a simple type that is described by #TypeInfo.
76 * #TypeInfo describes information about the type including what it inherits
77 * from, the instance and class size, and constructor/destructor hooks.
79 * Alternatively several static types could be registered using helper macro
80 * DEFINE_TYPES()
82 * <example>
83 * <programlisting>
84 * static const TypeInfo device_types_info[] = {
85 * {
86 * .name = TYPE_MY_DEVICE_A,
87 * .parent = TYPE_DEVICE,
88 * .instance_size = sizeof(MyDeviceA),
89 * },
90 * {
91 * .name = TYPE_MY_DEVICE_B,
92 * .parent = TYPE_DEVICE,
93 * .instance_size = sizeof(MyDeviceB),
94 * },
95 * };
97 * DEFINE_TYPES(device_types_info)
98 * </programlisting>
99 * </example>
101 * Every type has an #ObjectClass associated with it. #ObjectClass derivatives
102 * are instantiated dynamically but there is only ever one instance for any
103 * given type. The #ObjectClass typically holds a table of function pointers
104 * for the virtual methods implemented by this type.
106 * Using object_new(), a new #Object derivative will be instantiated. You can
107 * cast an #Object to a subclass (or base-class) type using
108 * object_dynamic_cast(). You typically want to define macro wrappers around
109 * OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a
110 * specific type:
112 * <example>
113 * <title>Typecasting macros</title>
114 * <programlisting>
115 * #define MY_DEVICE_GET_CLASS(obj) \
116 * OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE)
117 * #define MY_DEVICE_CLASS(klass) \
118 * OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE)
119 * #define MY_DEVICE(obj) \
120 * OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
121 * </programlisting>
122 * </example>
124 * # Class Initialization #
126 * Before an object is initialized, the class for the object must be
127 * initialized. There is only one class object for all instance objects
128 * that is created lazily.
130 * Classes are initialized by first initializing any parent classes (if
131 * necessary). After the parent class object has initialized, it will be
132 * copied into the current class object and any additional storage in the
133 * class object is zero filled.
135 * The effect of this is that classes automatically inherit any virtual
136 * function pointers that the parent class has already initialized. All
137 * other fields will be zero filled.
139 * Once all of the parent classes have been initialized, #TypeInfo::class_init
140 * is called to let the class being instantiated provide default initialize for
141 * its virtual functions. Here is how the above example might be modified
142 * to introduce an overridden virtual function:
144 * <example>
145 * <title>Overriding a virtual function</title>
146 * <programlisting>
147 * #include "qdev.h"
149 * void my_device_class_init(ObjectClass *klass, void *class_data)
151 * DeviceClass *dc = DEVICE_CLASS(klass);
152 * dc->reset = my_device_reset;
155 * static const TypeInfo my_device_info = {
156 * .name = TYPE_MY_DEVICE,
157 * .parent = TYPE_DEVICE,
158 * .instance_size = sizeof(MyDevice),
159 * .class_init = my_device_class_init,
160 * };
161 * </programlisting>
162 * </example>
164 * Introducing new virtual methods requires a class to define its own
165 * struct and to add a .class_size member to the #TypeInfo. Each method
166 * will also have a wrapper function to call it easily:
168 * <example>
169 * <title>Defining an abstract class</title>
170 * <programlisting>
171 * #include "qdev.h"
173 * typedef struct MyDeviceClass
175 * DeviceClass parent;
177 * void (*frobnicate) (MyDevice *obj);
178 * } MyDeviceClass;
180 * static const TypeInfo my_device_info = {
181 * .name = TYPE_MY_DEVICE,
182 * .parent = TYPE_DEVICE,
183 * .instance_size = sizeof(MyDevice),
184 * .abstract = true, // or set a default in my_device_class_init
185 * .class_size = sizeof(MyDeviceClass),
186 * };
188 * void my_device_frobnicate(MyDevice *obj)
190 * MyDeviceClass *klass = MY_DEVICE_GET_CLASS(obj);
192 * klass->frobnicate(obj);
194 * </programlisting>
195 * </example>
197 * # Interfaces #
199 * Interfaces allow a limited form of multiple inheritance. Instances are
200 * similar to normal types except for the fact that are only defined by
201 * their classes and never carry any state. As a consequence, a pointer to
202 * an interface instance should always be of incomplete type in order to be
203 * sure it cannot be dereferenced. That is, you should define the
204 * 'typedef struct SomethingIf SomethingIf' so that you can pass around
205 * 'SomethingIf *si' arguments, but not define a 'struct SomethingIf { ... }'.
206 * The only things you can validly do with a 'SomethingIf *' are to pass it as
207 * an argument to a method on its corresponding SomethingIfClass, or to
208 * dynamically cast it to an object that implements the interface.
210 * # Methods #
212 * A <emphasis>method</emphasis> is a function within the namespace scope of
213 * a class. It usually operates on the object instance by passing it as a
214 * strongly-typed first argument.
215 * If it does not operate on an object instance, it is dubbed
216 * <emphasis>class method</emphasis>.
218 * Methods cannot be overloaded. That is, the #ObjectClass and method name
219 * uniquely identity the function to be called; the signature does not vary
220 * except for trailing varargs.
222 * Methods are always <emphasis>virtual</emphasis>. Overriding a method in
223 * #TypeInfo.class_init of a subclass leads to any user of the class obtained
224 * via OBJECT_GET_CLASS() accessing the overridden function.
225 * The original function is not automatically invoked. It is the responsibility
226 * of the overriding class to determine whether and when to invoke the method
227 * being overridden.
229 * To invoke the method being overridden, the preferred solution is to store
230 * the original value in the overriding class before overriding the method.
231 * This corresponds to |[ {super,base}.method(...) ]| in Java and C#
232 * respectively; this frees the overriding class from hardcoding its parent
233 * class, which someone might choose to change at some point.
235 * <example>
236 * <title>Overriding a virtual method</title>
237 * <programlisting>
238 * typedef struct MyState MyState;
240 * typedef void (*MyDoSomething)(MyState *obj);
242 * typedef struct MyClass {
243 * ObjectClass parent_class;
245 * MyDoSomething do_something;
246 * } MyClass;
248 * static void my_do_something(MyState *obj)
250 * // do something
253 * static void my_class_init(ObjectClass *oc, void *data)
255 * MyClass *mc = MY_CLASS(oc);
257 * mc->do_something = my_do_something;
260 * static const TypeInfo my_type_info = {
261 * .name = TYPE_MY,
262 * .parent = TYPE_OBJECT,
263 * .instance_size = sizeof(MyState),
264 * .class_size = sizeof(MyClass),
265 * .class_init = my_class_init,
266 * };
268 * typedef struct DerivedClass {
269 * MyClass parent_class;
271 * MyDoSomething parent_do_something;
272 * } DerivedClass;
274 * static void derived_do_something(MyState *obj)
276 * DerivedClass *dc = DERIVED_GET_CLASS(obj);
278 * // do something here
279 * dc->parent_do_something(obj);
280 * // do something else here
283 * static void derived_class_init(ObjectClass *oc, void *data)
285 * MyClass *mc = MY_CLASS(oc);
286 * DerivedClass *dc = DERIVED_CLASS(oc);
288 * dc->parent_do_something = mc->do_something;
289 * mc->do_something = derived_do_something;
292 * static const TypeInfo derived_type_info = {
293 * .name = TYPE_DERIVED,
294 * .parent = TYPE_MY,
295 * .class_size = sizeof(DerivedClass),
296 * .class_init = derived_class_init,
297 * };
298 * </programlisting>
299 * </example>
301 * Alternatively, object_class_by_name() can be used to obtain the class and
302 * its non-overridden methods for a specific type. This would correspond to
303 * |[ MyClass::method(...) ]| in C++.
305 * The first example of such a QOM method was #CPUClass.reset,
306 * another example is #DeviceClass.realize.
310 typedef struct ObjectProperty ObjectProperty;
313 * ObjectPropertyAccessor:
314 * @obj: the object that owns the property
315 * @v: the visitor that contains the property data
316 * @name: the name of the property
317 * @opaque: the object property opaque
318 * @errp: a pointer to an Error that is filled if getting/setting fails.
320 * Called when trying to get/set a property.
322 typedef void (ObjectPropertyAccessor)(Object *obj,
323 Visitor *v,
324 const char *name,
325 void *opaque,
326 Error **errp);
329 * ObjectPropertyResolve:
330 * @obj: the object that owns the property
331 * @opaque: the opaque registered with the property
332 * @part: the name of the property
334 * Resolves the #Object corresponding to property @part.
336 * The returned object can also be used as a starting point
337 * to resolve a relative path starting with "@part".
339 * Returns: If @path is the path that led to @obj, the function
340 * returns the #Object corresponding to "@path/@part".
341 * If "@path/@part" is not a valid object path, it returns #NULL.
343 typedef Object *(ObjectPropertyResolve)(Object *obj,
344 void *opaque,
345 const char *part);
348 * ObjectPropertyRelease:
349 * @obj: the object that owns the property
350 * @name: the name of the property
351 * @opaque: the opaque registered with the property
353 * Called when a property is removed from a object.
355 typedef void (ObjectPropertyRelease)(Object *obj,
356 const char *name,
357 void *opaque);
360 * ObjectPropertyInit:
361 * @obj: the object that owns the property
362 * @prop: the property to set
364 * Called when a property is initialized.
366 typedef void (ObjectPropertyInit)(Object *obj, ObjectProperty *prop);
368 struct ObjectProperty
370 char *name;
371 char *type;
372 char *description;
373 ObjectPropertyAccessor *get;
374 ObjectPropertyAccessor *set;
375 ObjectPropertyResolve *resolve;
376 ObjectPropertyRelease *release;
377 ObjectPropertyInit *init;
378 void *opaque;
379 QObject *defval;
383 * ObjectUnparent:
384 * @obj: the object that is being removed from the composition tree
386 * Called when an object is being removed from the QOM composition tree.
387 * The function should remove any backlinks from children objects to @obj.
389 typedef void (ObjectUnparent)(Object *obj);
392 * ObjectFree:
393 * @obj: the object being freed
395 * Called when an object's last reference is removed.
397 typedef void (ObjectFree)(void *obj);
399 #define OBJECT_CLASS_CAST_CACHE 4
402 * ObjectClass:
404 * The base for all classes. The only thing that #ObjectClass contains is an
405 * integer type handle.
407 struct ObjectClass
409 /*< private >*/
410 Type type;
411 GSList *interfaces;
413 const char *object_cast_cache[OBJECT_CLASS_CAST_CACHE];
414 const char *class_cast_cache[OBJECT_CLASS_CAST_CACHE];
416 ObjectUnparent *unparent;
418 GHashTable *properties;
422 * Object:
424 * The base for all objects. The first member of this object is a pointer to
425 * a #ObjectClass. Since C guarantees that the first member of a structure
426 * always begins at byte 0 of that structure, as long as any sub-object places
427 * its parent as the first member, we can cast directly to a #Object.
429 * As a result, #Object contains a reference to the objects type as its
430 * first member. This allows identification of the real type of the object at
431 * run time.
433 struct Object
435 /*< private >*/
436 ObjectClass *class;
437 ObjectFree *free;
438 GHashTable *properties;
439 uint32_t ref;
440 Object *parent;
444 * TypeInfo:
445 * @name: The name of the type.
446 * @parent: The name of the parent type.
447 * @instance_size: The size of the object (derivative of #Object). If
448 * @instance_size is 0, then the size of the object will be the size of the
449 * parent object.
450 * @instance_init: This function is called to initialize an object. The parent
451 * class will have already been initialized so the type is only responsible
452 * for initializing its own members.
453 * @instance_post_init: This function is called to finish initialization of
454 * an object, after all @instance_init functions were called.
455 * @instance_finalize: This function is called during object destruction. This
456 * is called before the parent @instance_finalize function has been called.
457 * An object should only free the members that are unique to its type in this
458 * function.
459 * @abstract: If this field is true, then the class is considered abstract and
460 * cannot be directly instantiated.
461 * @class_size: The size of the class object (derivative of #ObjectClass)
462 * for this object. If @class_size is 0, then the size of the class will be
463 * assumed to be the size of the parent class. This allows a type to avoid
464 * implementing an explicit class type if they are not adding additional
465 * virtual functions.
466 * @class_init: This function is called after all parent class initialization
467 * has occurred to allow a class to set its default virtual method pointers.
468 * This is also the function to use to override virtual methods from a parent
469 * class.
470 * @class_base_init: This function is called for all base classes after all
471 * parent class initialization has occurred, but before the class itself
472 * is initialized. This is the function to use to undo the effects of
473 * memcpy from the parent class to the descendants.
474 * @class_data: Data to pass to the @class_init,
475 * @class_base_init. This can be useful when building dynamic
476 * classes.
477 * @interfaces: The list of interfaces associated with this type. This
478 * should point to a static array that's terminated with a zero filled
479 * element.
481 struct TypeInfo
483 const char *name;
484 const char *parent;
486 size_t instance_size;
487 void (*instance_init)(Object *obj);
488 void (*instance_post_init)(Object *obj);
489 void (*instance_finalize)(Object *obj);
491 bool abstract;
492 size_t class_size;
494 void (*class_init)(ObjectClass *klass, void *data);
495 void (*class_base_init)(ObjectClass *klass, void *data);
496 void *class_data;
498 InterfaceInfo *interfaces;
502 * OBJECT:
503 * @obj: A derivative of #Object
505 * Converts an object to a #Object. Since all objects are #Objects,
506 * this function will always succeed.
508 #define OBJECT(obj) \
509 ((Object *)(obj))
512 * OBJECT_CLASS:
513 * @class: A derivative of #ObjectClass.
515 * Converts a class to an #ObjectClass. Since all objects are #Objects,
516 * this function will always succeed.
518 #define OBJECT_CLASS(class) \
519 ((ObjectClass *)(class))
522 * OBJECT_CHECK:
523 * @type: The C type to use for the return value.
524 * @obj: A derivative of @type to cast.
525 * @name: The QOM typename of @type
527 * A type safe version of @object_dynamic_cast_assert. Typically each class
528 * will define a macro based on this type to perform type safe dynamic_casts to
529 * this object type.
531 * If an invalid object is passed to this function, a run time assert will be
532 * generated.
534 #define OBJECT_CHECK(type, obj, name) \
535 ((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \
536 __FILE__, __LINE__, __func__))
539 * OBJECT_CLASS_CHECK:
540 * @class_type: The C type to use for the return value.
541 * @class: A derivative class of @class_type to cast.
542 * @name: the QOM typename of @class_type.
544 * A type safe version of @object_class_dynamic_cast_assert. This macro is
545 * typically wrapped by each type to perform type safe casts of a class to a
546 * specific class type.
548 #define OBJECT_CLASS_CHECK(class_type, class, name) \
549 ((class_type *)object_class_dynamic_cast_assert(OBJECT_CLASS(class), (name), \
550 __FILE__, __LINE__, __func__))
553 * OBJECT_GET_CLASS:
554 * @class: The C type to use for the return value.
555 * @obj: The object to obtain the class for.
556 * @name: The QOM typename of @obj.
558 * This function will return a specific class for a given object. Its generally
559 * used by each type to provide a type safe macro to get a specific class type
560 * from an object.
562 #define OBJECT_GET_CLASS(class, obj, name) \
563 OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
566 * InterfaceInfo:
567 * @type: The name of the interface.
569 * The information associated with an interface.
571 struct InterfaceInfo {
572 const char *type;
576 * InterfaceClass:
577 * @parent_class: the base class
579 * The class for all interfaces. Subclasses of this class should only add
580 * virtual methods.
582 struct InterfaceClass
584 ObjectClass parent_class;
585 /*< private >*/
586 ObjectClass *concrete_class;
587 Type interface_type;
590 #define TYPE_INTERFACE "interface"
593 * INTERFACE_CLASS:
594 * @klass: class to cast from
595 * Returns: An #InterfaceClass or raise an error if cast is invalid
597 #define INTERFACE_CLASS(klass) \
598 OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE)
601 * INTERFACE_CHECK:
602 * @interface: the type to return
603 * @obj: the object to convert to an interface
604 * @name: the interface type name
606 * Returns: @obj casted to @interface if cast is valid, otherwise raise error.
608 #define INTERFACE_CHECK(interface, obj, name) \
609 ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \
610 __FILE__, __LINE__, __func__))
613 * object_new_with_class:
614 * @klass: The class to instantiate.
616 * This function will initialize a new object using heap allocated memory.
617 * The returned object has a reference count of 1, and will be freed when
618 * the last reference is dropped.
620 * Returns: The newly allocated and instantiated object.
622 Object *object_new_with_class(ObjectClass *klass);
625 * object_new:
626 * @typename: The name of the type of the object to instantiate.
628 * This function will initialize a new object using heap allocated memory.
629 * The returned object has a reference count of 1, and will be freed when
630 * the last reference is dropped.
632 * Returns: The newly allocated and instantiated object.
634 Object *object_new(const char *typename);
637 * object_new_with_props:
638 * @typename: The name of the type of the object to instantiate.
639 * @parent: the parent object
640 * @id: The unique ID of the object
641 * @errp: pointer to error object
642 * @...: list of property names and values
644 * This function will initialize a new object using heap allocated memory.
645 * The returned object has a reference count of 1, and will be freed when
646 * the last reference is dropped.
648 * The @id parameter will be used when registering the object as a
649 * child of @parent in the composition tree.
651 * The variadic parameters are a list of pairs of (propname, propvalue)
652 * strings. The propname of %NULL indicates the end of the property
653 * list. If the object implements the user creatable interface, the
654 * object will be marked complete once all the properties have been
655 * processed.
657 * <example>
658 * <title>Creating an object with properties</title>
659 * <programlisting>
660 * Error *err = NULL;
661 * Object *obj;
663 * obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE,
664 * object_get_objects_root(),
665 * "hostmem0",
666 * &err,
667 * "share", "yes",
668 * "mem-path", "/dev/shm/somefile",
669 * "prealloc", "yes",
670 * "size", "1048576",
671 * NULL);
673 * if (!obj) {
674 * error_reportf_err(err, "Cannot create memory backend: ");
676 * </programlisting>
677 * </example>
679 * The returned object will have one stable reference maintained
680 * for as long as it is present in the object hierarchy.
682 * Returns: The newly allocated, instantiated & initialized object.
684 Object *object_new_with_props(const char *typename,
685 Object *parent,
686 const char *id,
687 Error **errp,
688 ...) QEMU_SENTINEL;
691 * object_new_with_propv:
692 * @typename: The name of the type of the object to instantiate.
693 * @parent: the parent object
694 * @id: The unique ID of the object
695 * @errp: pointer to error object
696 * @vargs: list of property names and values
698 * See object_new_with_props() for documentation.
700 Object *object_new_with_propv(const char *typename,
701 Object *parent,
702 const char *id,
703 Error **errp,
704 va_list vargs);
706 void object_apply_global_props(Object *obj, const GPtrArray *props,
707 Error **errp);
708 void object_set_machine_compat_props(GPtrArray *compat_props);
709 void object_set_accelerator_compat_props(GPtrArray *compat_props);
710 void object_register_sugar_prop(const char *driver, const char *prop, const char *value);
711 void object_apply_compat_props(Object *obj);
714 * object_set_props:
715 * @obj: the object instance to set properties on
716 * @errp: pointer to error object
717 * @...: list of property names and values
719 * This function will set a list of properties on an existing object
720 * instance.
722 * The variadic parameters are a list of pairs of (propname, propvalue)
723 * strings. The propname of %NULL indicates the end of the property
724 * list.
726 * <example>
727 * <title>Update an object's properties</title>
728 * <programlisting>
729 * Error *err = NULL;
730 * Object *obj = ...get / create object...;
732 * obj = object_set_props(obj,
733 * &err,
734 * "share", "yes",
735 * "mem-path", "/dev/shm/somefile",
736 * "prealloc", "yes",
737 * "size", "1048576",
738 * NULL);
740 * if (!obj) {
741 * error_reportf_err(err, "Cannot set properties: ");
743 * </programlisting>
744 * </example>
746 * The returned object will have one stable reference maintained
747 * for as long as it is present in the object hierarchy.
749 * Returns: -1 on error, 0 on success
751 int object_set_props(Object *obj,
752 Error **errp,
753 ...) QEMU_SENTINEL;
756 * object_set_propv:
757 * @obj: the object instance to set properties on
758 * @errp: pointer to error object
759 * @vargs: list of property names and values
761 * See object_set_props() for documentation.
763 * Returns: -1 on error, 0 on success
765 int object_set_propv(Object *obj,
766 Error **errp,
767 va_list vargs);
770 * object_initialize:
771 * @obj: A pointer to the memory to be used for the object.
772 * @size: The maximum size available at @obj for the object.
773 * @typename: The name of the type of the object to instantiate.
775 * This function will initialize an object. The memory for the object should
776 * have already been allocated. The returned object has a reference count of 1,
777 * and will be finalized when the last reference is dropped.
779 void object_initialize(void *obj, size_t size, const char *typename);
782 * object_initialize_child_with_props:
783 * @parentobj: The parent object to add a property to
784 * @propname: The name of the property
785 * @childobj: A pointer to the memory to be used for the object.
786 * @size: The maximum size available at @childobj for the object.
787 * @type: The name of the type of the object to instantiate.
788 * @errp: If an error occurs, a pointer to an area to store the error
789 * @...: list of property names and values
791 * This function will initialize an object. The memory for the object should
792 * have already been allocated. The object will then be added as child property
793 * to a parent with object_property_add_child() function. The returned object
794 * has a reference count of 1 (for the "child<...>" property from the parent),
795 * so the object will be finalized automatically when the parent gets removed.
797 * The variadic parameters are a list of pairs of (propname, propvalue)
798 * strings. The propname of %NULL indicates the end of the property list.
799 * If the object implements the user creatable interface, the object will
800 * be marked complete once all the properties have been processed.
802 void object_initialize_child_with_props(Object *parentobj,
803 const char *propname,
804 void *childobj, size_t size, const char *type,
805 Error **errp, ...) QEMU_SENTINEL;
808 * object_initialize_child_with_propsv:
809 * @parentobj: The parent object to add a property to
810 * @propname: The name of the property
811 * @childobj: A pointer to the memory to be used for the object.
812 * @size: The maximum size available at @childobj for the object.
813 * @type: The name of the type of the object to instantiate.
814 * @errp: If an error occurs, a pointer to an area to store the error
815 * @vargs: list of property names and values
817 * See object_initialize_child() for documentation.
819 void object_initialize_child_with_propsv(Object *parentobj,
820 const char *propname,
821 void *childobj, size_t size, const char *type,
822 Error **errp, va_list vargs);
825 * object_initialize_child:
826 * @parent: The parent object to add a property to
827 * @propname: The name of the property
828 * @child: A precisely typed pointer to the memory to be used for the
829 * object.
830 * @type: The name of the type of the object to instantiate.
832 * This is like
833 * object_initialize_child_with_props(parent, propname,
834 * child, sizeof(*child), type,
835 * &error_abort, NULL)
837 #define object_initialize_child(parent, propname, child, type) \
838 object_initialize_child_internal((parent), (propname), \
839 (child), sizeof(*(child)), (type))
840 void object_initialize_child_internal(Object *parent, const char *propname,
841 void *child, size_t size,
842 const char *type);
845 * object_dynamic_cast:
846 * @obj: The object to cast.
847 * @typename: The @typename to cast to.
849 * This function will determine if @obj is-a @typename. @obj can refer to an
850 * object or an interface associated with an object.
852 * Returns: This function returns @obj on success or #NULL on failure.
854 Object *object_dynamic_cast(Object *obj, const char *typename);
857 * object_dynamic_cast_assert:
859 * See object_dynamic_cast() for a description of the parameters of this
860 * function. The only difference in behavior is that this function asserts
861 * instead of returning #NULL on failure if QOM cast debugging is enabled.
862 * This function is not meant to be called directly, but only through
863 * the wrapper macro OBJECT_CHECK.
865 Object *object_dynamic_cast_assert(Object *obj, const char *typename,
866 const char *file, int line, const char *func);
869 * object_get_class:
870 * @obj: A derivative of #Object
872 * Returns: The #ObjectClass of the type associated with @obj.
874 ObjectClass *object_get_class(Object *obj);
877 * object_get_typename:
878 * @obj: A derivative of #Object.
880 * Returns: The QOM typename of @obj.
882 const char *object_get_typename(const Object *obj);
885 * type_register_static:
886 * @info: The #TypeInfo of the new type.
888 * @info and all of the strings it points to should exist for the life time
889 * that the type is registered.
891 * Returns: the new #Type.
893 Type type_register_static(const TypeInfo *info);
896 * type_register:
897 * @info: The #TypeInfo of the new type
899 * Unlike type_register_static(), this call does not require @info or its
900 * string members to continue to exist after the call returns.
902 * Returns: the new #Type.
904 Type type_register(const TypeInfo *info);
907 * type_register_static_array:
908 * @infos: The array of the new type #TypeInfo structures.
909 * @nr_infos: number of entries in @infos
911 * @infos and all of the strings it points to should exist for the life time
912 * that the type is registered.
914 void type_register_static_array(const TypeInfo *infos, int nr_infos);
917 * DEFINE_TYPES:
918 * @type_array: The array containing #TypeInfo structures to register
920 * @type_array should be static constant that exists for the life time
921 * that the type is registered.
923 #define DEFINE_TYPES(type_array) \
924 static void do_qemu_init_ ## type_array(void) \
926 type_register_static_array(type_array, ARRAY_SIZE(type_array)); \
928 type_init(do_qemu_init_ ## type_array)
931 * object_class_dynamic_cast_assert:
932 * @klass: The #ObjectClass to attempt to cast.
933 * @typename: The QOM typename of the class to cast to.
935 * See object_class_dynamic_cast() for a description of the parameters
936 * of this function. The only difference in behavior is that this function
937 * asserts instead of returning #NULL on failure if QOM cast debugging is
938 * enabled. This function is not meant to be called directly, but only through
939 * the wrapper macros OBJECT_CLASS_CHECK and INTERFACE_CHECK.
941 ObjectClass *object_class_dynamic_cast_assert(ObjectClass *klass,
942 const char *typename,
943 const char *file, int line,
944 const char *func);
947 * object_class_dynamic_cast:
948 * @klass: The #ObjectClass to attempt to cast.
949 * @typename: The QOM typename of the class to cast to.
951 * Returns: If @typename is a class, this function returns @klass if
952 * @typename is a subtype of @klass, else returns #NULL.
954 * If @typename is an interface, this function returns the interface
955 * definition for @klass if @klass implements it unambiguously; #NULL
956 * is returned if @klass does not implement the interface or if multiple
957 * classes or interfaces on the hierarchy leading to @klass implement
958 * it. (FIXME: perhaps this can be detected at type definition time?)
960 ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
961 const char *typename);
964 * object_class_get_parent:
965 * @klass: The class to obtain the parent for.
967 * Returns: The parent for @klass or %NULL if none.
969 ObjectClass *object_class_get_parent(ObjectClass *klass);
972 * object_class_get_name:
973 * @klass: The class to obtain the QOM typename for.
975 * Returns: The QOM typename for @klass.
977 const char *object_class_get_name(ObjectClass *klass);
980 * object_class_is_abstract:
981 * @klass: The class to obtain the abstractness for.
983 * Returns: %true if @klass is abstract, %false otherwise.
985 bool object_class_is_abstract(ObjectClass *klass);
988 * object_class_by_name:
989 * @typename: The QOM typename to obtain the class for.
991 * Returns: The class for @typename or %NULL if not found.
993 ObjectClass *object_class_by_name(const char *typename);
996 * module_object_class_by_name:
997 * @typename: The QOM typename to obtain the class for.
999 * For objects which might be provided by a module. Behaves like
1000 * object_class_by_name, but additionally tries to load the module
1001 * needed in case the class is not available.
1003 * Returns: The class for @typename or %NULL if not found.
1005 ObjectClass *module_object_class_by_name(const char *typename);
1007 void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
1008 const char *implements_type, bool include_abstract,
1009 void *opaque);
1012 * object_class_get_list:
1013 * @implements_type: The type to filter for, including its derivatives.
1014 * @include_abstract: Whether to include abstract classes.
1016 * Returns: A singly-linked list of the classes in reverse hashtable order.
1018 GSList *object_class_get_list(const char *implements_type,
1019 bool include_abstract);
1022 * object_class_get_list_sorted:
1023 * @implements_type: The type to filter for, including its derivatives.
1024 * @include_abstract: Whether to include abstract classes.
1026 * Returns: A singly-linked list of the classes in alphabetical
1027 * case-insensitive order.
1029 GSList *object_class_get_list_sorted(const char *implements_type,
1030 bool include_abstract);
1033 * object_ref:
1034 * @obj: the object
1036 * Increase the reference count of a object. A object cannot be freed as long
1037 * as its reference count is greater than zero.
1038 * Returns: @obj
1040 Object *object_ref(Object *obj);
1043 * object_unref:
1044 * @obj: the object
1046 * Decrease the reference count of a object. A object cannot be freed as long
1047 * as its reference count is greater than zero.
1049 void object_unref(Object *obj);
1052 * object_property_add:
1053 * @obj: the object to add a property to
1054 * @name: the name of the property. This can contain any character except for
1055 * a forward slash. In general, you should use hyphens '-' instead of
1056 * underscores '_' when naming properties.
1057 * @type: the type name of the property. This namespace is pretty loosely
1058 * defined. Sub namespaces are constructed by using a prefix and then
1059 * to angle brackets. For instance, the type 'virtio-net-pci' in the
1060 * 'link' namespace would be 'link<virtio-net-pci>'.
1061 * @get: The getter to be called to read a property. If this is NULL, then
1062 * the property cannot be read.
1063 * @set: the setter to be called to write a property. If this is NULL,
1064 * then the property cannot be written.
1065 * @release: called when the property is removed from the object. This is
1066 * meant to allow a property to free its opaque upon object
1067 * destruction. This may be NULL.
1068 * @opaque: an opaque pointer to pass to the callbacks for the property
1070 * Returns: The #ObjectProperty; this can be used to set the @resolve
1071 * callback for child and link properties.
1073 ObjectProperty *object_property_add(Object *obj, const char *name,
1074 const char *type,
1075 ObjectPropertyAccessor *get,
1076 ObjectPropertyAccessor *set,
1077 ObjectPropertyRelease *release,
1078 void *opaque);
1080 void object_property_del(Object *obj, const char *name);
1082 ObjectProperty *object_class_property_add(ObjectClass *klass, const char *name,
1083 const char *type,
1084 ObjectPropertyAccessor *get,
1085 ObjectPropertyAccessor *set,
1086 ObjectPropertyRelease *release,
1087 void *opaque);
1090 * object_property_set_default_bool:
1091 * @prop: the property to set
1092 * @value: the value to be written to the property
1094 * Set the property default value.
1096 void object_property_set_default_bool(ObjectProperty *prop, bool value);
1099 * object_property_set_default_str:
1100 * @prop: the property to set
1101 * @value: the value to be written to the property
1103 * Set the property default value.
1105 void object_property_set_default_str(ObjectProperty *prop, const char *value);
1108 * object_property_set_default_int:
1109 * @prop: the property to set
1110 * @value: the value to be written to the property
1112 * Set the property default value.
1114 void object_property_set_default_int(ObjectProperty *prop, int64_t value);
1117 * object_property_set_default_uint:
1118 * @prop: the property to set
1119 * @value: the value to be written to the property
1121 * Set the property default value.
1123 void object_property_set_default_uint(ObjectProperty *prop, uint64_t value);
1126 * object_property_find:
1127 * @obj: the object
1128 * @name: the name of the property
1129 * @errp: returns an error if this function fails
1131 * Look up a property for an object and return its #ObjectProperty if found.
1133 ObjectProperty *object_property_find(Object *obj, const char *name,
1134 Error **errp);
1135 ObjectProperty *object_class_property_find(ObjectClass *klass, const char *name,
1136 Error **errp);
1138 typedef struct ObjectPropertyIterator {
1139 ObjectClass *nextclass;
1140 GHashTableIter iter;
1141 } ObjectPropertyIterator;
1144 * object_property_iter_init:
1145 * @obj: the object
1147 * Initializes an iterator for traversing all properties
1148 * registered against an object instance, its class and all parent classes.
1150 * It is forbidden to modify the property list while iterating,
1151 * whether removing or adding properties.
1153 * Typical usage pattern would be
1155 * <example>
1156 * <title>Using object property iterators</title>
1157 * <programlisting>
1158 * ObjectProperty *prop;
1159 * ObjectPropertyIterator iter;
1161 * object_property_iter_init(&iter, obj);
1162 * while ((prop = object_property_iter_next(&iter))) {
1163 * ... do something with prop ...
1165 * </programlisting>
1166 * </example>
1168 void object_property_iter_init(ObjectPropertyIterator *iter,
1169 Object *obj);
1172 * object_class_property_iter_init:
1173 * @klass: the class
1175 * Initializes an iterator for traversing all properties
1176 * registered against an object class and all parent classes.
1178 * It is forbidden to modify the property list while iterating,
1179 * whether removing or adding properties.
1181 * This can be used on abstract classes as it does not create a temporary
1182 * instance.
1184 void object_class_property_iter_init(ObjectPropertyIterator *iter,
1185 ObjectClass *klass);
1188 * object_property_iter_next:
1189 * @iter: the iterator instance
1191 * Return the next available property. If no further properties
1192 * are available, a %NULL value will be returned and the @iter
1193 * pointer should not be used again after this point without
1194 * re-initializing it.
1196 * Returns: the next property, or %NULL when all properties
1197 * have been traversed.
1199 ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
1201 void object_unparent(Object *obj);
1204 * object_property_get:
1205 * @obj: the object
1206 * @name: the name of the property
1207 * @v: the visitor that will receive the property value. This should be an
1208 * Output visitor and the data will be written with @name as the name.
1209 * @errp: returns an error if this function fails
1211 * Reads a property from a object.
1213 void object_property_get(Object *obj, const char *name, Visitor *v,
1214 Error **errp);
1217 * object_property_set_str:
1218 * @name: the name of the property
1219 * @value: the value to be written to the property
1220 * @errp: returns an error if this function fails
1222 * Writes a string value to a property.
1224 void object_property_set_str(Object *obj, const char *name,
1225 const char *value, Error **errp);
1228 * object_property_get_str:
1229 * @obj: the object
1230 * @name: the name of the property
1231 * @errp: returns an error if this function fails
1233 * Returns: the value of the property, converted to a C string, or NULL if
1234 * an error occurs (including when the property value is not a string).
1235 * The caller should free the string.
1237 char *object_property_get_str(Object *obj, const char *name,
1238 Error **errp);
1241 * object_property_set_link:
1242 * @name: the name of the property
1243 * @value: the value to be written to the property
1244 * @errp: returns an error if this function fails
1246 * Writes an object's canonical path to a property.
1248 * If the link property was created with
1249 * <code>OBJ_PROP_LINK_STRONG</code> bit, the old target object is
1250 * unreferenced, and a reference is added to the new target object.
1253 void object_property_set_link(Object *obj, const char *name,
1254 Object *value, Error **errp);
1257 * object_property_get_link:
1258 * @obj: the object
1259 * @name: the name of the property
1260 * @errp: returns an error if this function fails
1262 * Returns: the value of the property, resolved from a path to an Object,
1263 * or NULL if an error occurs (including when the property value is not a
1264 * string or not a valid object path).
1266 Object *object_property_get_link(Object *obj, const char *name,
1267 Error **errp);
1270 * object_property_set_bool:
1271 * @name: the name of the property
1272 * @value: the value to be written to the property
1273 * @errp: returns an error if this function fails
1275 * Writes a bool value to a property.
1277 void object_property_set_bool(Object *obj, const char *name,
1278 bool value, Error **errp);
1281 * object_property_get_bool:
1282 * @obj: the object
1283 * @name: the name of the property
1284 * @errp: returns an error if this function fails
1286 * Returns: the value of the property, converted to a boolean, or NULL if
1287 * an error occurs (including when the property value is not a bool).
1289 bool object_property_get_bool(Object *obj, const char *name,
1290 Error **errp);
1293 * object_property_set_int:
1294 * @name: the name of the property
1295 * @value: the value to be written to the property
1296 * @errp: returns an error if this function fails
1298 * Writes an integer value to a property.
1300 void object_property_set_int(Object *obj, const char *name,
1301 int64_t value, Error **errp);
1304 * object_property_get_int:
1305 * @obj: the object
1306 * @name: the name of the property
1307 * @errp: returns an error if this function fails
1309 * Returns: the value of the property, converted to an integer, or negative if
1310 * an error occurs (including when the property value is not an integer).
1312 int64_t object_property_get_int(Object *obj, const char *name,
1313 Error **errp);
1316 * object_property_set_uint:
1317 * @name: the name of the property
1318 * @value: the value to be written to the property
1319 * @errp: returns an error if this function fails
1321 * Writes an unsigned integer value to a property.
1323 void object_property_set_uint(Object *obj, const char *name,
1324 uint64_t value, Error **errp);
1327 * object_property_get_uint:
1328 * @obj: the object
1329 * @name: the name of the property
1330 * @errp: returns an error if this function fails
1332 * Returns: the value of the property, converted to an unsigned integer, or 0
1333 * an error occurs (including when the property value is not an integer).
1335 uint64_t object_property_get_uint(Object *obj, const char *name,
1336 Error **errp);
1339 * object_property_get_enum:
1340 * @obj: the object
1341 * @name: the name of the property
1342 * @typename: the name of the enum data type
1343 * @errp: returns an error if this function fails
1345 * Returns: the value of the property, converted to an integer, or
1346 * undefined if an error occurs (including when the property value is not
1347 * an enum).
1349 int object_property_get_enum(Object *obj, const char *name,
1350 const char *typename, Error **errp);
1353 * object_property_set:
1354 * @obj: the object
1355 * @name: the name of the property
1356 * @v: the visitor that will be used to write the property value. This should
1357 * be an Input visitor and the data will be first read with @name as the
1358 * name and then written as the property value.
1359 * @errp: returns an error if this function fails
1361 * Writes a property to a object.
1363 void object_property_set(Object *obj, const char *name, Visitor *v,
1364 Error **errp);
1367 * object_property_parse:
1368 * @obj: the object
1369 * @name: the name of the property
1370 * @string: the string that will be used to parse the property value.
1371 * @errp: returns an error if this function fails
1373 * Parses a string and writes the result into a property of an object.
1375 void object_property_parse(Object *obj, const char *name,
1376 const char *string, Error **errp);
1379 * object_property_print:
1380 * @obj: the object
1381 * @name: the name of the property
1382 * @human: if true, print for human consumption
1383 * @errp: returns an error if this function fails
1385 * Returns a string representation of the value of the property. The
1386 * caller shall free the string.
1388 char *object_property_print(Object *obj, const char *name, bool human,
1389 Error **errp);
1392 * object_property_get_type:
1393 * @obj: the object
1394 * @name: the name of the property
1395 * @errp: returns an error if this function fails
1397 * Returns: The type name of the property.
1399 const char *object_property_get_type(Object *obj, const char *name,
1400 Error **errp);
1403 * object_get_root:
1405 * Returns: the root object of the composition tree
1407 Object *object_get_root(void);
1411 * object_get_objects_root:
1413 * Get the container object that holds user created
1414 * object instances. This is the object at path
1415 * "/objects"
1417 * Returns: the user object container
1419 Object *object_get_objects_root(void);
1422 * object_get_internal_root:
1424 * Get the container object that holds internally used object
1425 * instances. Any object which is put into this container must not be
1426 * user visible, and it will not be exposed in the QOM tree.
1428 * Returns: the internal object container
1430 Object *object_get_internal_root(void);
1433 * object_get_canonical_path_component:
1435 * Returns: The final component in the object's canonical path. The canonical
1436 * path is the path within the composition tree starting from the root.
1437 * %NULL if the object doesn't have a parent (and thus a canonical path).
1439 char *object_get_canonical_path_component(const Object *obj);
1442 * object_get_canonical_path:
1444 * Returns: The canonical path for a object. This is the path within the
1445 * composition tree starting from the root.
1447 char *object_get_canonical_path(const Object *obj);
1450 * object_resolve_path:
1451 * @path: the path to resolve
1452 * @ambiguous: returns true if the path resolution failed because of an
1453 * ambiguous match
1455 * There are two types of supported paths--absolute paths and partial paths.
1457 * Absolute paths are derived from the root object and can follow child<> or
1458 * link<> properties. Since they can follow link<> properties, they can be
1459 * arbitrarily long. Absolute paths look like absolute filenames and are
1460 * prefixed with a leading slash.
1462 * Partial paths look like relative filenames. They do not begin with a
1463 * prefix. The matching rules for partial paths are subtle but designed to make
1464 * specifying objects easy. At each level of the composition tree, the partial
1465 * path is matched as an absolute path. The first match is not returned. At
1466 * least two matches are searched for. A successful result is only returned if
1467 * only one match is found. If more than one match is found, a flag is
1468 * returned to indicate that the match was ambiguous.
1470 * Returns: The matched object or NULL on path lookup failure.
1472 Object *object_resolve_path(const char *path, bool *ambiguous);
1475 * object_resolve_path_type:
1476 * @path: the path to resolve
1477 * @typename: the type to look for.
1478 * @ambiguous: returns true if the path resolution failed because of an
1479 * ambiguous match
1481 * This is similar to object_resolve_path. However, when looking for a
1482 * partial path only matches that implement the given type are considered.
1483 * This restricts the search and avoids spuriously flagging matches as
1484 * ambiguous.
1486 * For both partial and absolute paths, the return value goes through
1487 * a dynamic cast to @typename. This is important if either the link,
1488 * or the typename itself are of interface types.
1490 * Returns: The matched object or NULL on path lookup failure.
1492 Object *object_resolve_path_type(const char *path, const char *typename,
1493 bool *ambiguous);
1496 * object_resolve_path_component:
1497 * @parent: the object in which to resolve the path
1498 * @part: the component to resolve.
1500 * This is similar to object_resolve_path with an absolute path, but it
1501 * only resolves one element (@part) and takes the others from @parent.
1503 * Returns: The resolved object or NULL on path lookup failure.
1505 Object *object_resolve_path_component(Object *parent, const char *part);
1508 * object_property_add_child:
1509 * @obj: the object to add a property to
1510 * @name: the name of the property
1511 * @child: the child object
1513 * Child properties form the composition tree. All objects need to be a child
1514 * of another object. Objects can only be a child of one object.
1516 * There is no way for a child to determine what its parent is. It is not
1517 * a bidirectional relationship. This is by design.
1519 * The value of a child property as a C string will be the child object's
1520 * canonical path. It can be retrieved using object_property_get_str().
1521 * The child object itself can be retrieved using object_property_get_link().
1523 * Returns: The newly added property on success, or %NULL on failure.
1525 ObjectProperty *object_property_add_child(Object *obj, const char *name,
1526 Object *child);
1528 typedef enum {
1529 /* Unref the link pointer when the property is deleted */
1530 OBJ_PROP_LINK_STRONG = 0x1,
1532 /* private */
1533 OBJ_PROP_LINK_DIRECT = 0x2,
1534 OBJ_PROP_LINK_CLASS = 0x4,
1535 } ObjectPropertyLinkFlags;
1538 * object_property_allow_set_link:
1540 * The default implementation of the object_property_add_link() check()
1541 * callback function. It allows the link property to be set and never returns
1542 * an error.
1544 void object_property_allow_set_link(const Object *, const char *,
1545 Object *, Error **);
1548 * object_property_add_link:
1549 * @obj: the object to add a property to
1550 * @name: the name of the property
1551 * @type: the qobj type of the link
1552 * @targetp: a pointer to where the link object reference is stored
1553 * @check: callback to veto setting or NULL if the property is read-only
1554 * @flags: additional options for the link
1556 * Links establish relationships between objects. Links are unidirectional
1557 * although two links can be combined to form a bidirectional relationship
1558 * between objects.
1560 * Links form the graph in the object model.
1562 * The <code>@check()</code> callback is invoked when
1563 * object_property_set_link() is called and can raise an error to prevent the
1564 * link being set. If <code>@check</code> is NULL, the property is read-only
1565 * and cannot be set.
1567 * Ownership of the pointer that @child points to is transferred to the
1568 * link property. The reference count for <code>*@child</code> is
1569 * managed by the property from after the function returns till the
1570 * property is deleted with object_property_del(). If the
1571 * <code>@flags</code> <code>OBJ_PROP_LINK_STRONG</code> bit is set,
1572 * the reference count is decremented when the property is deleted or
1573 * modified.
1575 * Returns: The newly added property on success, or %NULL on failure.
1577 ObjectProperty *object_property_add_link(Object *obj, const char *name,
1578 const char *type, Object **targetp,
1579 void (*check)(const Object *obj, const char *name,
1580 Object *val, Error **errp),
1581 ObjectPropertyLinkFlags flags);
1583 ObjectProperty *object_class_property_add_link(ObjectClass *oc,
1584 const char *name,
1585 const char *type, ptrdiff_t offset,
1586 void (*check)(const Object *obj, const char *name,
1587 Object *val, Error **errp),
1588 ObjectPropertyLinkFlags flags);
1591 * object_property_add_str:
1592 * @obj: the object to add a property to
1593 * @name: the name of the property
1594 * @get: the getter or NULL if the property is write-only. This function must
1595 * return a string to be freed by g_free().
1596 * @set: the setter or NULL if the property is read-only
1598 * Add a string property using getters/setters. This function will add a
1599 * property of type 'string'.
1601 * Returns: The newly added property on success, or %NULL on failure.
1603 ObjectProperty *object_property_add_str(Object *obj, const char *name,
1604 char *(*get)(Object *, Error **),
1605 void (*set)(Object *, const char *, Error **));
1607 ObjectProperty *object_class_property_add_str(ObjectClass *klass,
1608 const char *name,
1609 char *(*get)(Object *, Error **),
1610 void (*set)(Object *, const char *,
1611 Error **));
1614 * object_property_add_bool:
1615 * @obj: the object to add a property to
1616 * @name: the name of the property
1617 * @get: the getter or NULL if the property is write-only.
1618 * @set: the setter or NULL if the property is read-only
1620 * Add a bool property using getters/setters. This function will add a
1621 * property of type 'bool'.
1623 * Returns: The newly added property on success, or %NULL on failure.
1625 ObjectProperty *object_property_add_bool(Object *obj, const char *name,
1626 bool (*get)(Object *, Error **),
1627 void (*set)(Object *, bool, Error **));
1629 ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
1630 const char *name,
1631 bool (*get)(Object *, Error **),
1632 void (*set)(Object *, bool, Error **));
1635 * object_property_add_enum:
1636 * @obj: the object to add a property to
1637 * @name: the name of the property
1638 * @typename: the name of the enum data type
1639 * @get: the getter or %NULL if the property is write-only.
1640 * @set: the setter or %NULL if the property is read-only
1642 * Add an enum property using getters/setters. This function will add a
1643 * property of type '@typename'.
1645 * Returns: The newly added property on success, or %NULL on failure.
1647 ObjectProperty *object_property_add_enum(Object *obj, const char *name,
1648 const char *typename,
1649 const QEnumLookup *lookup,
1650 int (*get)(Object *, Error **),
1651 void (*set)(Object *, int, Error **));
1653 ObjectProperty *object_class_property_add_enum(ObjectClass *klass,
1654 const char *name,
1655 const char *typename,
1656 const QEnumLookup *lookup,
1657 int (*get)(Object *, Error **),
1658 void (*set)(Object *, int, Error **));
1661 * object_property_add_tm:
1662 * @obj: the object to add a property to
1663 * @name: the name of the property
1664 * @get: the getter or NULL if the property is write-only.
1666 * Add a read-only struct tm valued property using a getter function.
1667 * This function will add a property of type 'struct tm'.
1669 * Returns: The newly added property on success, or %NULL on failure.
1671 ObjectProperty *object_property_add_tm(Object *obj, const char *name,
1672 void (*get)(Object *, struct tm *, Error **));
1674 ObjectProperty *object_class_property_add_tm(ObjectClass *klass,
1675 const char *name,
1676 void (*get)(Object *, struct tm *, Error **));
1678 typedef enum {
1679 /* Automatically add a getter to the property */
1680 OBJ_PROP_FLAG_READ = 1 << 0,
1681 /* Automatically add a setter to the property */
1682 OBJ_PROP_FLAG_WRITE = 1 << 1,
1683 /* Automatically add a getter and a setter to the property */
1684 OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ | OBJ_PROP_FLAG_WRITE),
1685 } ObjectPropertyFlags;
1688 * object_property_add_uint8_ptr:
1689 * @obj: the object to add a property to
1690 * @name: the name of the property
1691 * @v: pointer to value
1692 * @flags: bitwise-or'd ObjectPropertyFlags
1694 * Add an integer property in memory. This function will add a
1695 * property of type 'uint8'.
1697 * Returns: The newly added property on success, or %NULL on failure.
1699 ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,
1700 const uint8_t *v,
1701 ObjectPropertyFlags flags);
1703 ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass,
1704 const char *name,
1705 const uint8_t *v,
1706 ObjectPropertyFlags flags);
1709 * object_property_add_uint16_ptr:
1710 * @obj: the object to add a property to
1711 * @name: the name of the property
1712 * @v: pointer to value
1713 * @flags: bitwise-or'd ObjectPropertyFlags
1715 * Add an integer property in memory. This function will add a
1716 * property of type 'uint16'.
1718 * Returns: The newly added property on success, or %NULL on failure.
1720 ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,
1721 const uint16_t *v,
1722 ObjectPropertyFlags flags);
1724 ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
1725 const char *name,
1726 const uint16_t *v,
1727 ObjectPropertyFlags flags);
1730 * object_property_add_uint32_ptr:
1731 * @obj: the object to add a property to
1732 * @name: the name of the property
1733 * @v: pointer to value
1734 * @flags: bitwise-or'd ObjectPropertyFlags
1736 * Add an integer property in memory. This function will add a
1737 * property of type 'uint32'.
1739 * Returns: The newly added property on success, or %NULL on failure.
1741 ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,
1742 const uint32_t *v,
1743 ObjectPropertyFlags flags);
1745 ObjectProperty *object_class_property_add_uint32_ptr(ObjectClass *klass,
1746 const char *name,
1747 const uint32_t *v,
1748 ObjectPropertyFlags flags);
1751 * object_property_add_uint64_ptr:
1752 * @obj: the object to add a property to
1753 * @name: the name of the property
1754 * @v: pointer to value
1755 * @flags: bitwise-or'd ObjectPropertyFlags
1757 * Add an integer property in memory. This function will add a
1758 * property of type 'uint64'.
1760 * Returns: The newly added property on success, or %NULL on failure.
1762 ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,
1763 const uint64_t *v,
1764 ObjectPropertyFlags flags);
1766 ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
1767 const char *name,
1768 const uint64_t *v,
1769 ObjectPropertyFlags flags);
1772 * object_property_add_alias:
1773 * @obj: the object to add a property to
1774 * @name: the name of the property
1775 * @target_obj: the object to forward property access to
1776 * @target_name: the name of the property on the forwarded object
1778 * Add an alias for a property on an object. This function will add a property
1779 * of the same type as the forwarded property.
1781 * The caller must ensure that <code>@target_obj</code> stays alive as long as
1782 * this property exists. In the case of a child object or an alias on the same
1783 * object this will be the case. For aliases to other objects the caller is
1784 * responsible for taking a reference.
1786 * Returns: The newly added property on success, or %NULL on failure.
1788 ObjectProperty *object_property_add_alias(Object *obj, const char *name,
1789 Object *target_obj, const char *target_name);
1792 * object_property_add_const_link:
1793 * @obj: the object to add a property to
1794 * @name: the name of the property
1795 * @target: the object to be referred by the link
1797 * Add an unmodifiable link for a property on an object. This function will
1798 * add a property of type link<TYPE> where TYPE is the type of @target.
1800 * The caller must ensure that @target stays alive as long as
1801 * this property exists. In the case @target is a child of @obj,
1802 * this will be the case. Otherwise, the caller is responsible for
1803 * taking a reference.
1805 * Returns: The newly added property on success, or %NULL on failure.
1807 ObjectProperty *object_property_add_const_link(Object *obj, const char *name,
1808 Object *target);
1811 * object_property_set_description:
1812 * @obj: the object owning the property
1813 * @name: the name of the property
1814 * @description: the description of the property on the object
1816 * Set an object property's description.
1819 void object_property_set_description(Object *obj, const char *name,
1820 const char *description);
1821 void object_class_property_set_description(ObjectClass *klass, const char *name,
1822 const char *description);
1825 * object_child_foreach:
1826 * @obj: the object whose children will be navigated
1827 * @fn: the iterator function to be called
1828 * @opaque: an opaque value that will be passed to the iterator
1830 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1831 * non-zero.
1833 * It is forbidden to add or remove children from @obj from the @fn
1834 * callback.
1836 * Returns: The last value returned by @fn, or 0 if there is no child.
1838 int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
1839 void *opaque);
1842 * object_child_foreach_recursive:
1843 * @obj: the object whose children will be navigated
1844 * @fn: the iterator function to be called
1845 * @opaque: an opaque value that will be passed to the iterator
1847 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1848 * non-zero. Calls recursively, all child nodes of @obj will also be passed
1849 * all the way down to the leaf nodes of the tree. Depth first ordering.
1851 * It is forbidden to add or remove children from @obj (or its
1852 * child nodes) from the @fn callback.
1854 * Returns: The last value returned by @fn, or 0 if there is no child.
1856 int object_child_foreach_recursive(Object *obj,
1857 int (*fn)(Object *child, void *opaque),
1858 void *opaque);
1860 * container_get:
1861 * @root: root of the #path, e.g., object_get_root()
1862 * @path: path to the container
1864 * Return a container object whose path is @path. Create more containers
1865 * along the path if necessary.
1867 * Returns: the container object.
1869 Object *container_get(Object *root, const char *path);
1872 * object_type_get_instance_size:
1873 * @typename: Name of the Type whose instance_size is required
1875 * Returns the instance_size of the given @typename.
1877 size_t object_type_get_instance_size(const char *typename);
1880 * object_property_help:
1881 * @name: the name of the property
1882 * @type: the type of the property
1883 * @defval: the default value
1884 * @description: description of the property
1886 * Returns: a user-friendly formatted string describing the property
1887 * for help purposes.
1889 char *object_property_help(const char *name, const char *type,
1890 QObject *defval, const char *description);
1892 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref)
1894 #endif