]> git.proxmox.com Git - mirror_qemu.git/blame - include/qom/object.h
qom: Add object_property_set_default_list()
[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
125062e7
KW
1096/**
1097 * object_property_set_default_list:
1098 * @prop: the property to set
1099 *
1100 * Set the property default value to be an empty list.
1101 */
1102void object_property_set_default_list(ObjectProperty *prop);
1103
0e76ed0a
MAL
1104/**
1105 * object_property_set_default_int:
1106 * @prop: the property to set
1107 * @value: the value to be written to the property
1108 *
1109 * Set the property default value.
1110 */
1111void object_property_set_default_int(ObjectProperty *prop, int64_t value);
1112
1113/**
1114 * object_property_set_default_uint:
1115 * @prop: the property to set
1116 * @value: the value to be written to the property
1117 *
1118 * Set the property default value.
1119 */
1120void object_property_set_default_uint(ObjectProperty *prop, uint64_t value);
1121
8cb6789a
PB
1122/**
1123 * object_property_find:
1124 * @obj: the object
1125 * @name: the name of the property
efba1595
DB
1126 *
1127 * Look up a property for an object.
1128 *
1129 * Return its #ObjectProperty if found, or NULL.
1130 */
1131ObjectProperty *object_property_find(Object *obj, const char *name);
1132
1133/**
1134 * object_property_find_err:
1135 * @obj: the object
1136 * @name: the name of the property
89bfe000 1137 * @errp: returns an error if this function fails
8cb6789a 1138 *
efba1595
DB
1139 * Look up a property for an object.
1140 *
1141 * Return its #ObjectProperty if found, or NULL.
1142 */
1143ObjectProperty *object_property_find_err(Object *obj,
1144 const char *name,
1145 Error **errp);
1146
1147/**
1148 * object_class_property_find:
1149 * @klass: the object class
1150 * @name: the name of the property
1151 *
1152 * Look up a property for an object class.
1153 *
1154 * Return its #ObjectProperty if found, or NULL.
1155 */
1156ObjectProperty *object_class_property_find(ObjectClass *klass,
1157 const char *name);
1158
1159/**
1160 * object_class_property_find_err:
1161 * @klass: the object class
1162 * @name: the name of the property
1163 * @errp: returns an error if this function fails
1164 *
1165 * Look up a property for an object class.
1166 *
1167 * Return its #ObjectProperty if found, or NULL.
8cb6789a 1168 */
efba1595
DB
1169ObjectProperty *object_class_property_find_err(ObjectClass *klass,
1170 const char *name,
1171 Error **errp);
8cb6789a 1172
7746abd8
DB
1173typedef struct ObjectPropertyIterator {
1174 ObjectClass *nextclass;
1175 GHashTableIter iter;
1176} ObjectPropertyIterator;
a00c9482
DB
1177
1178/**
1179 * object_property_iter_init:
1827c35b 1180 * @iter: the iterator instance
a00c9482
DB
1181 * @obj: the object
1182 *
1183 * Initializes an iterator for traversing all properties
16bf7f52 1184 * registered against an object instance, its class and all parent classes.
a00c9482
DB
1185 *
1186 * It is forbidden to modify the property list while iterating,
1187 * whether removing or adding properties.
1188 *
1189 * Typical usage pattern would be
1190 *
6cf164c0
EH
1191 * .. code-block:: c
1192 * :caption: Using object property iterators
1193 *
9bbfd245
EH
1194 * ObjectProperty *prop;
1195 * ObjectPropertyIterator iter;
1196 *
1197 * object_property_iter_init(&iter, obj);
1198 * while ((prop = object_property_iter_next(&iter))) {
1199 * ... do something with prop ...
1200 * }
a00c9482 1201 */
7746abd8
DB
1202void object_property_iter_init(ObjectPropertyIterator *iter,
1203 Object *obj);
a00c9482 1204
961c47bb
AK
1205/**
1206 * object_class_property_iter_init:
1827c35b 1207 * @iter: the iterator instance
961c47bb
AK
1208 * @klass: the class
1209 *
1210 * Initializes an iterator for traversing all properties
1211 * registered against an object class and all parent classes.
1212 *
1213 * It is forbidden to modify the property list while iterating,
1214 * whether removing or adding properties.
1215 *
1216 * This can be used on abstract classes as it does not create a temporary
1217 * instance.
1218 */
1219void object_class_property_iter_init(ObjectPropertyIterator *iter,
1220 ObjectClass *klass);
1221
a00c9482
DB
1222/**
1223 * object_property_iter_next:
1224 * @iter: the iterator instance
1225 *
7746abd8
DB
1226 * Return the next available property. If no further properties
1227 * are available, a %NULL value will be returned and the @iter
1228 * pointer should not be used again after this point without
1229 * re-initializing it.
1230 *
a00c9482
DB
1231 * Returns: the next property, or %NULL when all properties
1232 * have been traversed.
1233 */
1234ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
1235
57c9fafe
AL
1236void object_unparent(Object *obj);
1237
1238/**
1239 * object_property_get:
1240 * @obj: the object
5325cc34 1241 * @name: the name of the property
57c9fafe
AL
1242 * @v: the visitor that will receive the property value. This should be an
1243 * Output visitor and the data will be written with @name as the name.
57c9fafe
AL
1244 * @errp: returns an error if this function fails
1245 *
1246 * Reads a property from a object.
6fd5bef1
MA
1247 *
1248 * Returns: %true on success, %false on failure.
57c9fafe 1249 */
6fd5bef1 1250bool object_property_get(Object *obj, const char *name, Visitor *v,
e82df248 1251 Error **errp);
57c9fafe 1252
7b7b7d18
PB
1253/**
1254 * object_property_set_str:
1827c35b 1255 * @obj: the object
7b7b7d18 1256 * @name: the name of the property
5325cc34 1257 * @value: the value to be written to the property
7b7b7d18
PB
1258 * @errp: returns an error if this function fails
1259 *
1260 * Writes a string value to a property.
6fd5bef1
MA
1261 *
1262 * Returns: %true on success, %false on failure.
7b7b7d18 1263 */
6fd5bef1 1264bool object_property_set_str(Object *obj, const char *name,
5325cc34 1265 const char *value, Error **errp);
7b7b7d18
PB
1266
1267/**
1268 * object_property_get_str:
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, converted to a C string, or NULL if
1274 * an error occurs (including when the property value is not a string).
1275 * The caller should free the string.
1276 */
1277char *object_property_get_str(Object *obj, const char *name,
e82df248 1278 Error **errp);
7b7b7d18 1279
1d9c5a12
PB
1280/**
1281 * object_property_set_link:
1827c35b 1282 * @obj: the object
1d9c5a12 1283 * @name: the name of the property
5325cc34 1284 * @value: the value to be written to the property
1d9c5a12
PB
1285 * @errp: returns an error if this function fails
1286 *
1287 * Writes an object's canonical path to a property.
265b578c
MAL
1288 *
1289 * If the link property was created with
b99e80cb 1290 * %OBJ_PROP_LINK_STRONG bit, the old target object is
265b578c
MAL
1291 * unreferenced, and a reference is added to the new target object.
1292 *
6fd5bef1 1293 * Returns: %true on success, %false on failure.
1d9c5a12 1294 */
6fd5bef1 1295bool object_property_set_link(Object *obj, const char *name,
5325cc34 1296 Object *value, Error **errp);
1d9c5a12
PB
1297
1298/**
1299 * object_property_get_link:
1300 * @obj: the object
1301 * @name: the name of the property
1302 * @errp: returns an error if this function fails
1303 *
1304 * Returns: the value of the property, resolved from a path to an Object,
1305 * or NULL if an error occurs (including when the property value is not a
1306 * string or not a valid object path).
1307 */
1308Object *object_property_get_link(Object *obj, const char *name,
e82df248 1309 Error **errp);
1d9c5a12 1310
7b7b7d18
PB
1311/**
1312 * object_property_set_bool:
1827c35b 1313 * @obj: the object
7b7b7d18 1314 * @name: the name of the property
5325cc34 1315 * @value: the value to be written to the property
7b7b7d18
PB
1316 * @errp: returns an error if this function fails
1317 *
1318 * Writes a bool value to a property.
6fd5bef1
MA
1319 *
1320 * Returns: %true on success, %false on failure.
7b7b7d18 1321 */
6fd5bef1 1322bool object_property_set_bool(Object *obj, const char *name,
5325cc34 1323 bool value, Error **errp);
7b7b7d18
PB
1324
1325/**
1326 * object_property_get_bool:
1327 * @obj: the object
1328 * @name: the name of the property
1329 * @errp: returns an error if this function fails
1330 *
a21e6607 1331 * Returns: the value of the property, converted to a boolean, or false if
7b7b7d18
PB
1332 * an error occurs (including when the property value is not a bool).
1333 */
1334bool object_property_get_bool(Object *obj, const char *name,
e82df248 1335 Error **errp);
7b7b7d18
PB
1336
1337/**
1338 * object_property_set_int:
1827c35b 1339 * @obj: the object
7b7b7d18 1340 * @name: the name of the property
5325cc34 1341 * @value: the value to be written to the property
7b7b7d18
PB
1342 * @errp: returns an error if this function fails
1343 *
1344 * Writes an integer value to a property.
6fd5bef1
MA
1345 *
1346 * Returns: %true on success, %false on failure.
7b7b7d18 1347 */
6fd5bef1 1348bool object_property_set_int(Object *obj, const char *name,
5325cc34 1349 int64_t value, Error **errp);
7b7b7d18
PB
1350
1351/**
1352 * object_property_get_int:
1353 * @obj: the object
1354 * @name: the name of the property
1355 * @errp: returns an error if this function fails
1356 *
a21e6607 1357 * Returns: the value of the property, converted to an integer, or -1 if
7b7b7d18
PB
1358 * an error occurs (including when the property value is not an integer).
1359 */
1360int64_t object_property_get_int(Object *obj, const char *name,
e82df248 1361 Error **errp);
7b7b7d18 1362
3152779c
MAL
1363/**
1364 * object_property_set_uint:
1827c35b 1365 * @obj: the object
3152779c 1366 * @name: the name of the property
5325cc34 1367 * @value: the value to be written to the property
3152779c
MAL
1368 * @errp: returns an error if this function fails
1369 *
1370 * Writes an unsigned integer value to a property.
6fd5bef1
MA
1371 *
1372 * Returns: %true on success, %false on failure.
3152779c 1373 */
6fd5bef1 1374bool object_property_set_uint(Object *obj, const char *name,
5325cc34 1375 uint64_t value, Error **errp);
3152779c
MAL
1376
1377/**
1378 * object_property_get_uint:
1379 * @obj: the object
1380 * @name: the name of the property
1381 * @errp: returns an error if this function fails
1382 *
1383 * Returns: the value of the property, converted to an unsigned integer, or 0
1384 * an error occurs (including when the property value is not an integer).
1385 */
1386uint64_t object_property_get_uint(Object *obj, const char *name,
1387 Error **errp);
1388
1f21772d
HT
1389/**
1390 * object_property_get_enum:
1391 * @obj: the object
1392 * @name: the name of the property
a3590dac 1393 * @typename: the name of the enum data type
1f21772d
HT
1394 * @errp: returns an error if this function fails
1395 *
d20f616e
MA
1396 * Returns: the value of the property, converted to an integer (which
1397 * can't be negative), or -1 on error (including when the property
1398 * value is not an enum).
1f21772d
HT
1399 */
1400int object_property_get_enum(Object *obj, const char *name,
a3590dac 1401 const char *typename, Error **errp);
1f21772d 1402
57c9fafe
AL
1403/**
1404 * object_property_set:
1405 * @obj: the object
5325cc34 1406 * @name: the name of the property
57c9fafe
AL
1407 * @v: the visitor that will be used to write the property value. This should
1408 * be an Input visitor and the data will be first read with @name as the
1409 * name and then written as the property value.
57c9fafe
AL
1410 * @errp: returns an error if this function fails
1411 *
1412 * Writes a property to a object.
6fd5bef1
MA
1413 *
1414 * Returns: %true on success, %false on failure.
57c9fafe 1415 */
6fd5bef1 1416bool object_property_set(Object *obj, const char *name, Visitor *v,
e82df248 1417 Error **errp);
57c9fafe 1418
b2cd7dee
PB
1419/**
1420 * object_property_parse:
1421 * @obj: the object
b2cd7dee 1422 * @name: the name of the property
5325cc34 1423 * @string: the string that will be used to parse the property value.
b2cd7dee
PB
1424 * @errp: returns an error if this function fails
1425 *
1426 * Parses a string and writes the result into a property of an object.
6fd5bef1
MA
1427 *
1428 * Returns: %true on success, %false on failure.
b2cd7dee 1429 */
6fd5bef1 1430bool object_property_parse(Object *obj, const char *name,
5325cc34 1431 const char *string, Error **errp);
b2cd7dee
PB
1432
1433/**
1434 * object_property_print:
1435 * @obj: the object
1436 * @name: the name of the property
0b7593e0 1437 * @human: if true, print for human consumption
b2cd7dee
PB
1438 * @errp: returns an error if this function fails
1439 *
1440 * Returns a string representation of the value of the property. The
1441 * caller shall free the string.
1442 */
0b7593e0 1443char *object_property_print(Object *obj, const char *name, bool human,
e82df248 1444 Error **errp);
b2cd7dee 1445
57c9fafe 1446/**
438e1c79 1447 * object_property_get_type:
57c9fafe
AL
1448 * @obj: the object
1449 * @name: the name of the property
1450 * @errp: returns an error if this function fails
1451 *
1452 * Returns: The type name of the property.
1453 */
1454const char *object_property_get_type(Object *obj, const char *name,
e82df248 1455 Error **errp);
57c9fafe
AL
1456
1457/**
1458 * object_get_root:
1459 *
1460 * Returns: the root object of the composition tree
1461 */
1462Object *object_get_root(void);
1463
bc2256c4
DB
1464
1465/**
1466 * object_get_objects_root:
1467 *
1468 * Get the container object that holds user created
1469 * object instances. This is the object at path
1470 * "/objects"
1471 *
1472 * Returns: the user object container
1473 */
1474Object *object_get_objects_root(void);
1475
7c47c4ea
PX
1476/**
1477 * object_get_internal_root:
1478 *
1479 * Get the container object that holds internally used object
1480 * instances. Any object which is put into this container must not be
1481 * user visible, and it will not be exposed in the QOM tree.
1482 *
1483 * Returns: the internal object container
1484 */
1485Object *object_get_internal_root(void);
1486
11f590b1
SH
1487/**
1488 * object_get_canonical_path_component:
1827c35b 1489 * @obj: the object
11f590b1
SH
1490 *
1491 * Returns: The final component in the object's canonical path. The canonical
1492 * path is the path within the composition tree starting from the root.
770dec26 1493 * %NULL if the object doesn't have a parent (and thus a canonical path).
11f590b1 1494 */
7a309cc9 1495const char *object_get_canonical_path_component(const Object *obj);
11f590b1 1496
57c9fafe
AL
1497/**
1498 * object_get_canonical_path:
1827c35b 1499 * @obj: the object
57c9fafe 1500 *
5bd929d2
MA
1501 * Returns: The canonical path for a object, newly allocated. This is
1502 * the path within the composition tree starting from the root. Use
1503 * g_free() to free it.
57c9fafe 1504 */
e8512dfa 1505char *object_get_canonical_path(const Object *obj);
57c9fafe
AL
1506
1507/**
1508 * object_resolve_path:
1509 * @path: the path to resolve
1510 * @ambiguous: returns true if the path resolution failed because of an
1511 * ambiguous match
1512 *
1513 * There are two types of supported paths--absolute paths and partial paths.
1514 *
1515 * Absolute paths are derived from the root object and can follow child<> or
1516 * link<> properties. Since they can follow link<> properties, they can be
1517 * arbitrarily long. Absolute paths look like absolute filenames and are
1518 * prefixed with a leading slash.
1519 *
1520 * Partial paths look like relative filenames. They do not begin with a
1521 * prefix. The matching rules for partial paths are subtle but designed to make
1522 * specifying objects easy. At each level of the composition tree, the partial
1523 * path is matched as an absolute path. The first match is not returned. At
1524 * least two matches are searched for. A successful result is only returned if
02fe2db6
PB
1525 * only one match is found. If more than one match is found, a flag is
1526 * returned to indicate that the match was ambiguous.
57c9fafe
AL
1527 *
1528 * Returns: The matched object or NULL on path lookup failure.
1529 */
1530Object *object_resolve_path(const char *path, bool *ambiguous);
1531
02fe2db6
PB
1532/**
1533 * object_resolve_path_type:
1534 * @path: the path to resolve
1535 * @typename: the type to look for.
1536 * @ambiguous: returns true if the path resolution failed because of an
1537 * ambiguous match
1538 *
1539 * This is similar to object_resolve_path. However, when looking for a
1540 * partial path only matches that implement the given type are considered.
1541 * This restricts the search and avoids spuriously flagging matches as
1542 * ambiguous.
1543 *
1544 * For both partial and absolute paths, the return value goes through
1545 * a dynamic cast to @typename. This is important if either the link,
1546 * or the typename itself are of interface types.
1547 *
1548 * Returns: The matched object or NULL on path lookup failure.
1549 */
1550Object *object_resolve_path_type(const char *path, const char *typename,
1551 bool *ambiguous);
1552
1bf4d329
MA
1553/**
1554 * object_resolve_path_at:
1555 * @parent: the object in which to resolve the path
1556 * @path: the path to resolve
1557 *
1558 * This is like object_resolve_path(), except paths not starting with
1559 * a slash are relative to @parent.
1560 *
1561 * Returns: The resolved object or NULL on path lookup failure.
1562 */
1563Object *object_resolve_path_at(Object *parent, const char *path);
1564
a612b2a6
PB
1565/**
1566 * object_resolve_path_component:
1567 * @parent: the object in which to resolve the path
1568 * @part: the component to resolve.
1569 *
1570 * This is similar to object_resolve_path with an absolute path, but it
1571 * only resolves one element (@part) and takes the others from @parent.
1572 *
1573 * Returns: The resolved object or NULL on path lookup failure.
1574 */
ddfb0baa 1575Object *object_resolve_path_component(Object *parent, const char *part);
a612b2a6 1576
57c9fafe 1577/**
db57fef1 1578 * object_property_try_add_child:
57c9fafe
AL
1579 * @obj: the object to add a property to
1580 * @name: the name of the property
1581 * @child: the child object
db57fef1 1582 * @errp: pointer to error object
57c9fafe
AL
1583 *
1584 * Child properties form the composition tree. All objects need to be a child
1585 * of another object. Objects can only be a child of one object.
1586 *
1587 * There is no way for a child to determine what its parent is. It is not
1588 * a bidirectional relationship. This is by design.
358b5465
AB
1589 *
1590 * The value of a child property as a C string will be the child object's
1591 * canonical path. It can be retrieved using object_property_get_str().
1592 * The child object itself can be retrieved using object_property_get_link().
70251887
MA
1593 *
1594 * Returns: The newly added property on success, or %NULL on failure.
57c9fafe 1595 */
db57fef1
EA
1596ObjectProperty *object_property_try_add_child(Object *obj, const char *name,
1597 Object *child, Error **errp);
1598
1599/**
1600 * object_property_add_child:
1827c35b
EH
1601 * @obj: the object to add a property to
1602 * @name: the name of the property
1603 * @child: the child object
1604 *
db57fef1
EA
1605 * Same as object_property_try_add_child() with @errp hardcoded to
1606 * &error_abort
1607 */
70251887 1608ObjectProperty *object_property_add_child(Object *obj, const char *name,
d2623129 1609 Object *child);
57c9fafe 1610
9561fda8
SH
1611typedef enum {
1612 /* Unref the link pointer when the property is deleted */
265b578c 1613 OBJ_PROP_LINK_STRONG = 0x1,
9941d37b
MAL
1614
1615 /* private */
1616 OBJ_PROP_LINK_DIRECT = 0x2,
840ecdfb 1617 OBJ_PROP_LINK_CLASS = 0x4,
9561fda8
SH
1618} ObjectPropertyLinkFlags;
1619
39f72ef9
SH
1620/**
1621 * object_property_allow_set_link:
1827c35b
EH
1622 * @obj: the object to add a property to
1623 * @name: the name of the property
1624 * @child: the child object
1625 * @errp: pointer to error object
39f72ef9
SH
1626 *
1627 * The default implementation of the object_property_add_link() check()
1628 * callback function. It allows the link property to be set and never returns
1629 * an error.
1630 */
1827c35b
EH
1631void object_property_allow_set_link(const Object *obj, const char *name,
1632 Object *child, Error **errp);
39f72ef9 1633
57c9fafe
AL
1634/**
1635 * object_property_add_link:
1636 * @obj: the object to add a property to
1637 * @name: the name of the property
1638 * @type: the qobj type of the link
36854207 1639 * @targetp: a pointer to where the link object reference is stored
39f72ef9 1640 * @check: callback to veto setting or NULL if the property is read-only
9561fda8 1641 * @flags: additional options for the link
57c9fafe
AL
1642 *
1643 * Links establish relationships between objects. Links are unidirectional
1644 * although two links can be combined to form a bidirectional relationship
1645 * between objects.
1646 *
1647 * Links form the graph in the object model.
6c232d2f 1648 *
b99e80cb 1649 * The @check() callback is invoked when
39f72ef9 1650 * object_property_set_link() is called and can raise an error to prevent the
b99e80cb 1651 * link being set. If @check is NULL, the property is read-only
39f72ef9
SH
1652 * and cannot be set.
1653 *
6c232d2f 1654 * Ownership of the pointer that @child points to is transferred to the
b99e80cb 1655 * link property. The reference count for *@child is
6c232d2f 1656 * managed by the property from after the function returns till the
9561fda8 1657 * property is deleted with object_property_del(). If the
b99e80cb 1658 * @flags %OBJ_PROP_LINK_STRONG bit is set,
265b578c
MAL
1659 * the reference count is decremented when the property is deleted or
1660 * modified.
70251887
MA
1661 *
1662 * Returns: The newly added property on success, or %NULL on failure.
57c9fafe 1663 */
70251887 1664ObjectProperty *object_property_add_link(Object *obj, const char *name,
36854207 1665 const char *type, Object **targetp,
8f5d58ef 1666 void (*check)(const Object *obj, const char *name,
39f72ef9 1667 Object *val, Error **errp),
d2623129 1668 ObjectPropertyLinkFlags flags);
57c9fafe 1669
840ecdfb
MAL
1670ObjectProperty *object_class_property_add_link(ObjectClass *oc,
1671 const char *name,
1672 const char *type, ptrdiff_t offset,
1673 void (*check)(const Object *obj, const char *name,
1674 Object *val, Error **errp),
d2623129 1675 ObjectPropertyLinkFlags flags);
840ecdfb 1676
57c9fafe
AL
1677/**
1678 * object_property_add_str:
1679 * @obj: the object to add a property to
1680 * @name: the name of the property
1681 * @get: the getter or NULL if the property is write-only. This function must
1682 * return a string to be freed by g_free().
1683 * @set: the setter or NULL if the property is read-only
57c9fafe
AL
1684 *
1685 * Add a string property using getters/setters. This function will add a
1686 * property of type 'string'.
70251887
MA
1687 *
1688 * Returns: The newly added property on success, or %NULL on failure.
57c9fafe 1689 */
70251887 1690ObjectProperty *object_property_add_str(Object *obj, const char *name,
e82df248 1691 char *(*get)(Object *, Error **),
d2623129 1692 void (*set)(Object *, const char *, Error **));
2f28d2ff 1693
a3a16211
MAL
1694ObjectProperty *object_class_property_add_str(ObjectClass *klass,
1695 const char *name,
16bf7f52
DB
1696 char *(*get)(Object *, Error **),
1697 void (*set)(Object *, const char *,
d2623129 1698 Error **));
16bf7f52 1699
0e558843
AL
1700/**
1701 * object_property_add_bool:
1702 * @obj: the object to add a property to
1703 * @name: the name of the property
1704 * @get: the getter or NULL if the property is write-only.
1705 * @set: the setter or NULL if the property is read-only
0e558843
AL
1706 *
1707 * Add a bool property using getters/setters. This function will add a
1708 * property of type 'bool'.
70251887
MA
1709 *
1710 * Returns: The newly added property on success, or %NULL on failure.
0e558843 1711 */
70251887 1712ObjectProperty *object_property_add_bool(Object *obj, const char *name,
e82df248 1713 bool (*get)(Object *, Error **),
d2623129 1714 void (*set)(Object *, bool, Error **));
0e558843 1715
a3a16211
MAL
1716ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
1717 const char *name,
16bf7f52 1718 bool (*get)(Object *, Error **),
d2623129 1719 void (*set)(Object *, bool, Error **));
16bf7f52 1720
a8e3fbed
DB
1721/**
1722 * object_property_add_enum:
1723 * @obj: the object to add a property to
1724 * @name: the name of the property
1725 * @typename: the name of the enum data type
1827c35b 1726 * @lookup: enum value namelookup table
a8e3fbed
DB
1727 * @get: the getter or %NULL if the property is write-only.
1728 * @set: the setter or %NULL if the property is read-only
a8e3fbed
DB
1729 *
1730 * Add an enum property using getters/setters. This function will add a
1731 * property of type '@typename'.
70251887
MA
1732 *
1733 * Returns: The newly added property on success, or %NULL on failure.
a8e3fbed 1734 */
70251887 1735ObjectProperty *object_property_add_enum(Object *obj, const char *name,
a8e3fbed 1736 const char *typename,
f7abe0ec 1737 const QEnumLookup *lookup,
a8e3fbed 1738 int (*get)(Object *, Error **),
d2623129 1739 void (*set)(Object *, int, Error **));
a8e3fbed 1740
a3a16211
MAL
1741ObjectProperty *object_class_property_add_enum(ObjectClass *klass,
1742 const char *name,
16bf7f52 1743 const char *typename,
f7abe0ec 1744 const QEnumLookup *lookup,
16bf7f52 1745 int (*get)(Object *, Error **),
d2623129 1746 void (*set)(Object *, int, Error **));
16bf7f52 1747
8e099d14
DG
1748/**
1749 * object_property_add_tm:
1750 * @obj: the object to add a property to
1751 * @name: the name of the property
1752 * @get: the getter or NULL if the property is write-only.
8e099d14
DG
1753 *
1754 * Add a read-only struct tm valued property using a getter function.
1755 * This function will add a property of type 'struct tm'.
70251887
MA
1756 *
1757 * Returns: The newly added property on success, or %NULL on failure.
8e099d14 1758 */
70251887 1759ObjectProperty *object_property_add_tm(Object *obj, const char *name,
d2623129 1760 void (*get)(Object *, struct tm *, Error **));
8e099d14 1761
a3a16211 1762ObjectProperty *object_class_property_add_tm(ObjectClass *klass,
d2623129
MA
1763 const char *name,
1764 void (*get)(Object *, struct tm *, Error **));
16bf7f52 1765
836e1b38
FF
1766typedef enum {
1767 /* Automatically add a getter to the property */
1768 OBJ_PROP_FLAG_READ = 1 << 0,
1769 /* Automatically add a setter to the property */
1770 OBJ_PROP_FLAG_WRITE = 1 << 1,
1771 /* Automatically add a getter and a setter to the property */
1772 OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ | OBJ_PROP_FLAG_WRITE),
1773} ObjectPropertyFlags;
1774
a25ebcac
MT
1775/**
1776 * object_property_add_uint8_ptr:
1777 * @obj: the object to add a property to
1778 * @name: the name of the property
1779 * @v: pointer to value
836e1b38 1780 * @flags: bitwise-or'd ObjectPropertyFlags
a25ebcac
MT
1781 *
1782 * Add an integer property in memory. This function will add a
1783 * property of type 'uint8'.
70251887
MA
1784 *
1785 * Returns: The newly added property on success, or %NULL on failure.
a25ebcac 1786 */
70251887 1787ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name,
d2623129
MA
1788 const uint8_t *v,
1789 ObjectPropertyFlags flags);
836e1b38 1790
a3a16211
MAL
1791ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass,
1792 const char *name,
836e1b38 1793 const uint8_t *v,
d2623129 1794 ObjectPropertyFlags flags);
a25ebcac
MT
1795
1796/**
1797 * object_property_add_uint16_ptr:
1798 * @obj: the object to add a property to
1799 * @name: the name of the property
1800 * @v: pointer to value
836e1b38 1801 * @flags: bitwise-or'd ObjectPropertyFlags
a25ebcac
MT
1802 *
1803 * Add an integer property in memory. This function will add a
1804 * property of type 'uint16'.
70251887
MA
1805 *
1806 * Returns: The newly added property on success, or %NULL on failure.
a25ebcac 1807 */
70251887 1808ObjectProperty *object_property_add_uint16_ptr(Object *obj, const char *name,
836e1b38 1809 const uint16_t *v,
d2623129 1810 ObjectPropertyFlags flags);
836e1b38 1811
a3a16211
MAL
1812ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
1813 const char *name,
836e1b38 1814 const uint16_t *v,
d2623129 1815 ObjectPropertyFlags flags);
a25ebcac
MT
1816
1817/**
1818 * object_property_add_uint32_ptr:
1819 * @obj: the object to add a property to
1820 * @name: the name of the property
1821 * @v: pointer to value
836e1b38 1822 * @flags: bitwise-or'd ObjectPropertyFlags
a25ebcac
MT
1823 *
1824 * Add an integer property in memory. This function will add a
1825 * property of type 'uint32'.
70251887
MA
1826 *
1827 * Returns: The newly added property on success, or %NULL on failure.
a25ebcac 1828 */
70251887 1829ObjectProperty *object_property_add_uint32_ptr(Object *obj, const char *name,
836e1b38 1830 const uint32_t *v,
d2623129 1831 ObjectPropertyFlags flags);
836e1b38 1832
a3a16211
MAL
1833ObjectProperty *object_class_property_add_uint32_ptr(ObjectClass *klass,
1834 const char *name,
836e1b38 1835 const uint32_t *v,
d2623129 1836 ObjectPropertyFlags flags);
a25ebcac
MT
1837
1838/**
1839 * object_property_add_uint64_ptr:
1840 * @obj: the object to add a property to
1841 * @name: the name of the property
1842 * @v: pointer to value
836e1b38 1843 * @flags: bitwise-or'd ObjectPropertyFlags
a25ebcac
MT
1844 *
1845 * Add an integer property in memory. This function will add a
1846 * property of type 'uint64'.
70251887
MA
1847 *
1848 * Returns: The newly added property on success, or %NULL on failure.
a25ebcac 1849 */
70251887 1850ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name,
836e1b38 1851 const uint64_t *v,
d2623129 1852 ObjectPropertyFlags flags);
836e1b38 1853
a3a16211
MAL
1854ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
1855 const char *name,
836e1b38 1856 const uint64_t *v,
d2623129 1857 ObjectPropertyFlags flags);
a25ebcac 1858
ef7c7ff6
SH
1859/**
1860 * object_property_add_alias:
1861 * @obj: the object to add a property to
1862 * @name: the name of the property
1863 * @target_obj: the object to forward property access to
1864 * @target_name: the name of the property on the forwarded object
ef7c7ff6
SH
1865 *
1866 * Add an alias for a property on an object. This function will add a property
1867 * of the same type as the forwarded property.
1868 *
b99e80cb 1869 * The caller must ensure that @target_obj stays alive as long as
ef7c7ff6
SH
1870 * this property exists. In the case of a child object or an alias on the same
1871 * object this will be the case. For aliases to other objects the caller is
1872 * responsible for taking a reference.
70251887
MA
1873 *
1874 * Returns: The newly added property on success, or %NULL on failure.
ef7c7ff6 1875 */
70251887 1876ObjectProperty *object_property_add_alias(Object *obj, const char *name,
d2623129 1877 Object *target_obj, const char *target_name);
ef7c7ff6 1878
fb9e7e33
PB
1879/**
1880 * object_property_add_const_link:
1881 * @obj: the object to add a property to
1882 * @name: the name of the property
1883 * @target: the object to be referred by the link
fb9e7e33
PB
1884 *
1885 * Add an unmodifiable link for a property on an object. This function will
1886 * add a property of type link<TYPE> where TYPE is the type of @target.
1887 *
1888 * The caller must ensure that @target stays alive as long as
1889 * this property exists. In the case @target is a child of @obj,
1890 * this will be the case. Otherwise, the caller is responsible for
1891 * taking a reference.
70251887
MA
1892 *
1893 * Returns: The newly added property on success, or %NULL on failure.
fb9e7e33 1894 */
70251887 1895ObjectProperty *object_property_add_const_link(Object *obj, const char *name,
d2623129 1896 Object *target);
fb9e7e33 1897
80742642
GA
1898/**
1899 * object_property_set_description:
1900 * @obj: the object owning the property
1901 * @name: the name of the property
1902 * @description: the description of the property on the object
80742642
GA
1903 *
1904 * Set an object property's description.
1905 *
6fd5bef1 1906 * Returns: %true on success, %false on failure.
80742642
GA
1907 */
1908void object_property_set_description(Object *obj, const char *name,
7eecec7d 1909 const char *description);
16bf7f52 1910void object_class_property_set_description(ObjectClass *klass, const char *name,
7eecec7d 1911 const char *description);
80742642 1912
32efc535
PB
1913/**
1914 * object_child_foreach:
1915 * @obj: the object whose children will be navigated
1916 * @fn: the iterator function to be called
1917 * @opaque: an opaque value that will be passed to the iterator
1918 *
1919 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1920 * non-zero.
1921 *
b604a854
PF
1922 * It is forbidden to add or remove children from @obj from the @fn
1923 * callback.
1924 *
32efc535
PB
1925 * Returns: The last value returned by @fn, or 0 if there is no child.
1926 */
1927int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
1928 void *opaque);
1929
d714b8de
PC
1930/**
1931 * object_child_foreach_recursive:
1932 * @obj: the object whose children will be navigated
1933 * @fn: the iterator function to be called
1934 * @opaque: an opaque value that will be passed to the iterator
1935 *
1936 * Call @fn passing each child of @obj and @opaque to it, until @fn returns
1937 * non-zero. Calls recursively, all child nodes of @obj will also be passed
1938 * all the way down to the leaf nodes of the tree. Depth first ordering.
1939 *
b604a854
PF
1940 * It is forbidden to add or remove children from @obj (or its
1941 * child nodes) from the @fn callback.
1942 *
d714b8de
PC
1943 * Returns: The last value returned by @fn, or 0 if there is no child.
1944 */
1945int object_child_foreach_recursive(Object *obj,
1946 int (*fn)(Object *child, void *opaque),
1947 void *opaque);
a612b2a6
PB
1948/**
1949 * container_get:
dfe47e70 1950 * @root: root of the #path, e.g., object_get_root()
a612b2a6
PB
1951 * @path: path to the container
1952 *
1953 * Return a container object whose path is @path. Create more containers
1954 * along the path if necessary.
1955 *
1956 * Returns: the container object.
1957 */
dfe47e70 1958Object *container_get(Object *root, const char *path);
a612b2a6 1959
3f97b53a
BR
1960/**
1961 * object_type_get_instance_size:
1962 * @typename: Name of the Type whose instance_size is required
1963 *
1964 * Returns the instance_size of the given @typename.
1965 */
1966size_t object_type_get_instance_size(const char *typename);
f60a1cdc 1967
4df81616
MAL
1968/**
1969 * object_property_help:
1970 * @name: the name of the property
1971 * @type: the type of the property
1972 * @defval: the default value
1973 * @description: description of the property
1974 *
1975 * Returns: a user-friendly formatted string describing the property
1976 * for help purposes.
1977 */
1978char *object_property_help(const char *name, const char *type,
1979 QObject *defval, const char *description);
1980
f60a1cdc
MAL
1981G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref)
1982
2f28d2ff 1983#endif