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