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