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