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