]>
Commit | Line | Data |
---|---|---|
2f28d2ff AL |
1 | /* |
2 | * QEMU Object Model | |
3 | * | |
4 | * Copyright IBM, Corp. 2011 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
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" |
1de7afc9 | 18 | #include "qemu/queue.h" |
0b8fa32f | 19 | #include "qemu/module.h" |
57c9fafe | 20 | |
2f28d2ff AL |
21 | struct TypeImpl; |
22 | typedef struct TypeImpl *Type; | |
23 | ||
2f28d2ff AL |
24 | typedef struct Object Object; |
25 | ||
26 | typedef struct TypeInfo TypeInfo; | |
27 | ||
28 | typedef struct InterfaceClass InterfaceClass; | |
29 | typedef struct InterfaceInfo InterfaceInfo; | |
30 | ||
745549c8 | 31 | #define TYPE_OBJECT "object" |
2f28d2ff AL |
32 | |
33 | /** | |
34 | * SECTION:object.h | |
35 | * @title:Base Object Type System | |
36 | * @short_description: interfaces for creating new types and objects | |
37 | * | |
38 | * The QEMU Object Model provides a framework for registering user creatable | |
39 | * types and instantiating objects from those types. QOM provides the following | |
40 | * features: | |
41 | * | |
42 | * - System for dynamically registering types | |
43 | * - Support for single-inheritance of types | |
44 | * - Multiple inheritance of stateless interfaces | |
45 | * | |
46 | * <example> | |
47 | * <title>Creating a minimal type</title> | |
48 | * <programlisting> | |
49 | * #include "qdev.h" | |
50 | * | |
51 | * #define TYPE_MY_DEVICE "my-device" | |
52 | * | |
0815a859 PB |
53 | * // No new virtual functions: we can reuse the typedef for the |
54 | * // superclass. | |
55 | * typedef DeviceClass MyDeviceClass; | |
2f28d2ff AL |
56 | * typedef struct MyDevice |
57 | * { | |
58 | * DeviceState parent; | |
59 | * | |
60 | * int reg0, reg1, reg2; | |
61 | * } MyDevice; | |
62 | * | |
8c43a6f0 | 63 | * static const TypeInfo my_device_info = { |
2f28d2ff AL |
64 | * .name = TYPE_MY_DEVICE, |
65 | * .parent = TYPE_DEVICE, | |
66 | * .instance_size = sizeof(MyDevice), | |
67 | * }; | |
68 | * | |
83f7d43a | 69 | * static void my_device_register_types(void) |
2f28d2ff AL |
70 | * { |
71 | * type_register_static(&my_device_info); | |
72 | * } | |
73 | * | |
83f7d43a | 74 | * type_init(my_device_register_types) |
2f28d2ff AL |
75 | * </programlisting> |
76 | * </example> | |
77 | * | |
78 | * In the above example, we create a simple type that is described by #TypeInfo. | |
79 | * #TypeInfo describes information about the type including what it inherits | |
80 | * from, the instance and class size, and constructor/destructor hooks. | |
81 | * | |
38b5d79b IM |
82 | * Alternatively several static types could be registered using helper macro |
83 | * DEFINE_TYPES() | |
84 | * | |
85 | * <example> | |
86 | * <programlisting> | |
87 | * static const TypeInfo device_types_info[] = { | |
88 | * { | |
89 | * .name = TYPE_MY_DEVICE_A, | |
90 | * .parent = TYPE_DEVICE, | |
91 | * .instance_size = sizeof(MyDeviceA), | |
92 | * }, | |
93 | * { | |
94 | * .name = TYPE_MY_DEVICE_B, | |
95 | * .parent = TYPE_DEVICE, | |
96 | * .instance_size = sizeof(MyDeviceB), | |
97 | * }, | |
98 | * }; | |
99 | * | |
100 | * DEFINE_TYPES(device_types_info) | |
101 | * </programlisting> | |
102 | * </example> | |
103 | * | |
2f28d2ff AL |
104 | * Every type has an #ObjectClass associated with it. #ObjectClass derivatives |
105 | * are instantiated dynamically but there is only ever one instance for any | |
106 | * given type. The #ObjectClass typically holds a table of function pointers | |
107 | * for the virtual methods implemented by this type. | |
108 | * | |
109 | * Using object_new(), a new #Object derivative will be instantiated. You can | |
110 | * cast an #Object to a subclass (or base-class) type using | |
0815a859 PB |
111 | * object_dynamic_cast(). You typically want to define macro wrappers around |
112 | * OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a | |
113 | * specific type: | |
114 | * | |
115 | * <example> | |
116 | * <title>Typecasting macros</title> | |
117 | * <programlisting> | |
118 | * #define MY_DEVICE_GET_CLASS(obj) \ | |
119 | * OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE) | |
120 | * #define MY_DEVICE_CLASS(klass) \ | |
121 | * OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE) | |
122 | * #define MY_DEVICE(obj) \ | |
123 | * OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) | |
124 | * </programlisting> | |
125 | * </example> | |
2f28d2ff AL |
126 | * |
127 | * # Class Initialization # | |
128 | * | |
129 | * Before an object is initialized, the class for the object must be | |
130 | * initialized. There is only one class object for all instance objects | |
131 | * that is created lazily. | |
132 | * | |
133 | * Classes are initialized by first initializing any parent classes (if | |
134 | * necessary). After the parent class object has initialized, it will be | |
135 | * copied into the current class object and any additional storage in the | |
136 | * class object is zero filled. | |
137 | * | |
138 | * The effect of this is that classes automatically inherit any virtual | |
139 | * function pointers that the parent class has already initialized. All | |
140 | * other fields will be zero filled. | |
141 | * | |
142 | * Once all of the parent classes have been initialized, #TypeInfo::class_init | |
143 | * is called to let the class being instantiated provide default initialize for | |
93148aa5 | 144 | * its virtual functions. Here is how the above example might be modified |
0815a859 PB |
145 | * to introduce an overridden virtual function: |
146 | * | |
147 | * <example> | |
148 | * <title>Overriding a virtual function</title> | |
149 | * <programlisting> | |
150 | * #include "qdev.h" | |
151 | * | |
152 | * void my_device_class_init(ObjectClass *klass, void *class_data) | |
153 | * { | |
154 | * DeviceClass *dc = DEVICE_CLASS(klass); | |
155 | * dc->reset = my_device_reset; | |
156 | * } | |
157 | * | |
8c43a6f0 | 158 | * static const TypeInfo my_device_info = { |
0815a859 PB |
159 | * .name = TYPE_MY_DEVICE, |
160 | * .parent = TYPE_DEVICE, | |
161 | * .instance_size = sizeof(MyDevice), | |
162 | * .class_init = my_device_class_init, | |
163 | * }; | |
164 | * </programlisting> | |
165 | * </example> | |
166 | * | |
782beb52 AF |
167 | * Introducing new virtual methods requires a class to define its own |
168 | * struct and to add a .class_size member to the #TypeInfo. Each method | |
169 | * will also have a wrapper function to call it easily: | |
0815a859 PB |
170 | * |
171 | * <example> | |
172 | * <title>Defining an abstract class</title> | |
173 | * <programlisting> | |
174 | * #include "qdev.h" | |
175 | * | |
176 | * typedef struct MyDeviceClass | |
177 | * { | |
178 | * DeviceClass parent; | |
179 | * | |
180 | * void (*frobnicate) (MyDevice *obj); | |
181 | * } MyDeviceClass; | |
182 | * | |
8c43a6f0 | 183 | * static const TypeInfo my_device_info = { |
0815a859 PB |
184 | * .name = TYPE_MY_DEVICE, |
185 | * .parent = TYPE_DEVICE, | |
186 | * .instance_size = sizeof(MyDevice), | |
187 | * .abstract = true, // or set a default in my_device_class_init | |
188 | * .class_size = sizeof(MyDeviceClass), | |
189 | * }; | |
190 | * | |
191 | * void my_device_frobnicate(MyDevice *obj) | |
192 | * { | |
193 | * MyDeviceClass *klass = MY_DEVICE_GET_CLASS(obj); | |
194 | * | |
195 | * klass->frobnicate(obj); | |
196 | * } | |
197 | * </programlisting> | |
198 | * </example> | |
2f28d2ff AL |
199 | * |
200 | * # Interfaces # | |
201 | * | |
202 | * Interfaces allow a limited form of multiple inheritance. Instances are | |
203 | * similar to normal types except for the fact that are only defined by | |
204 | * their classes and never carry any state. You can dynamically cast an object | |
205 | * to one of its #Interface types and vice versa. | |
782beb52 AF |
206 | * |
207 | * # Methods # | |
208 | * | |
209 | * A <emphasis>method</emphasis> is a function within the namespace scope of | |
210 | * a class. It usually operates on the object instance by passing it as a | |
211 | * strongly-typed first argument. | |
212 | * If it does not operate on an object instance, it is dubbed | |
213 | * <emphasis>class method</emphasis>. | |
214 | * | |
215 | * Methods cannot be overloaded. That is, the #ObjectClass and method name | |
216 | * uniquely identity the function to be called; the signature does not vary | |
217 | * except for trailing varargs. | |
218 | * | |
219 | * Methods are always <emphasis>virtual</emphasis>. Overriding a method in | |
220 | * #TypeInfo.class_init of a subclass leads to any user of the class obtained | |
221 | * via OBJECT_GET_CLASS() accessing the overridden function. | |
085d8134 | 222 | * The original function is not automatically invoked. It is the responsibility |
782beb52 AF |
223 | * of the overriding class to determine whether and when to invoke the method |
224 | * being overridden. | |
225 | * | |
226 | * To invoke the method being overridden, the preferred solution is to store | |
227 | * the original value in the overriding class before overriding the method. | |
228 | * This corresponds to |[ {super,base}.method(...) ]| in Java and C# | |
229 | * respectively; this frees the overriding class from hardcoding its parent | |
230 | * class, which someone might choose to change at some point. | |
231 | * | |
232 | * <example> | |
233 | * <title>Overriding a virtual method</title> | |
234 | * <programlisting> | |
235 | * typedef struct MyState MyState; | |
236 | * | |
237 | * typedef void (*MyDoSomething)(MyState *obj); | |
238 | * | |
239 | * typedef struct MyClass { | |
240 | * ObjectClass parent_class; | |
241 | * | |
242 | * MyDoSomething do_something; | |
243 | * } MyClass; | |
244 | * | |
245 | * static void my_do_something(MyState *obj) | |
246 | * { | |
247 | * // do something | |
248 | * } | |
249 | * | |
250 | * static void my_class_init(ObjectClass *oc, void *data) | |
251 | * { | |
252 | * MyClass *mc = MY_CLASS(oc); | |
253 | * | |
254 | * mc->do_something = my_do_something; | |
255 | * } | |
256 | * | |
257 | * static const TypeInfo my_type_info = { | |
258 | * .name = TYPE_MY, | |
259 | * .parent = TYPE_OBJECT, | |
260 | * .instance_size = sizeof(MyState), | |
261 | * .class_size = sizeof(MyClass), | |
262 | * .class_init = my_class_init, | |
263 | * }; | |
264 | * | |
265 | * typedef struct DerivedClass { | |
266 | * MyClass parent_class; | |
267 | * | |
268 | * MyDoSomething parent_do_something; | |
70392912 | 269 | * } DerivedClass; |
782beb52 AF |
270 | * |
271 | * static void derived_do_something(MyState *obj) | |
272 | * { | |
273 | * DerivedClass *dc = DERIVED_GET_CLASS(obj); | |
274 | * | |
275 | * // do something here | |
276 | * dc->parent_do_something(obj); | |
277 | * // do something else here | |
278 | * } | |
279 | * | |
280 | * static void derived_class_init(ObjectClass *oc, void *data) | |
281 | * { | |
282 | * MyClass *mc = MY_CLASS(oc); | |
283 | * DerivedClass *dc = DERIVED_CLASS(oc); | |
284 | * | |
285 | * dc->parent_do_something = mc->do_something; | |
286 | * mc->do_something = derived_do_something; | |
287 | * } | |
288 | * | |
289 | * static const TypeInfo derived_type_info = { | |
290 | * .name = TYPE_DERIVED, | |
291 | * .parent = TYPE_MY, | |
292 | * .class_size = sizeof(DerivedClass), | |
f824e8ed | 293 | * .class_init = derived_class_init, |
782beb52 AF |
294 | * }; |
295 | * </programlisting> | |
296 | * </example> | |
297 | * | |
298 | * Alternatively, object_class_by_name() can be used to obtain the class and | |
299 | * its non-overridden methods for a specific type. This would correspond to | |
300 | * |[ MyClass::method(...) ]| in C++. | |
301 | * | |
302 | * The first example of such a QOM method was #CPUClass.reset, | |
303 | * another example is #DeviceClass.realize. | |
2f28d2ff AL |
304 | */ |
305 | ||
57c9fafe AL |
306 | |
307 | /** | |
308 | * ObjectPropertyAccessor: | |
309 | * @obj: the object that owns the property | |
310 | * @v: the visitor that contains the property data | |
57c9fafe | 311 | * @name: the name of the property |
d7bce999 | 312 | * @opaque: the object property opaque |
57c9fafe AL |
313 | * @errp: a pointer to an Error that is filled if getting/setting fails. |
314 | * | |
315 | * Called when trying to get/set a property. | |
316 | */ | |
317 | typedef void (ObjectPropertyAccessor)(Object *obj, | |
4fa45492 | 318 | Visitor *v, |
57c9fafe | 319 | const char *name, |
d7bce999 | 320 | void *opaque, |
e82df248 | 321 | Error **errp); |
57c9fafe | 322 | |
64607d08 PB |
323 | /** |
324 | * ObjectPropertyResolve: | |
325 | * @obj: the object that owns the property | |
326 | * @opaque: the opaque registered with the property | |
327 | * @part: the name of the property | |
328 | * | |
329 | * Resolves the #Object corresponding to property @part. | |
330 | * | |
331 | * The returned object can also be used as a starting point | |
332 | * to resolve a relative path starting with "@part". | |
333 | * | |
334 | * Returns: If @path is the path that led to @obj, the function | |
335 | * returns the #Object corresponding to "@path/@part". | |
336 | * If "@path/@part" is not a valid object path, it returns #NULL. | |
337 | */ | |
338 | typedef Object *(ObjectPropertyResolve)(Object *obj, | |
339 | void *opaque, | |
340 | const char *part); | |
341 | ||
57c9fafe AL |
342 | /** |
343 | * ObjectPropertyRelease: | |
344 | * @obj: the object that owns the property | |
345 | * @name: the name of the property | |
346 | * @opaque: the opaque registered with the property | |
347 | * | |
348 | * Called when a property is removed from a object. | |
349 | */ | |
350 | typedef void (ObjectPropertyRelease)(Object *obj, | |
351 | const char *name, | |
352 | void *opaque); | |
353 | ||
354 | typedef struct ObjectProperty | |
355 | { | |
356 | gchar *name; | |
357 | gchar *type; | |
80742642 | 358 | gchar *description; |
57c9fafe AL |
359 | ObjectPropertyAccessor *get; |
360 | ObjectPropertyAccessor *set; | |
64607d08 | 361 | ObjectPropertyResolve *resolve; |
57c9fafe AL |
362 | ObjectPropertyRelease *release; |
363 | void *opaque; | |
57c9fafe AL |
364 | } ObjectProperty; |
365 | ||
667d22d1 PB |
366 | /** |
367 | * ObjectUnparent: | |
368 | * @obj: the object that is being removed from the composition tree | |
369 | * | |
370 | * Called when an object is being removed from the QOM composition tree. | |
371 | * The function should remove any backlinks from children objects to @obj. | |
372 | */ | |
373 | typedef void (ObjectUnparent)(Object *obj); | |
374 | ||
fde9bf44 PB |
375 | /** |
376 | * ObjectFree: | |
377 | * @obj: the object being freed | |
378 | * | |
379 | * Called when an object's last reference is removed. | |
380 | */ | |
381 | typedef void (ObjectFree)(void *obj); | |
382 | ||
03587328 AL |
383 | #define OBJECT_CLASS_CAST_CACHE 4 |
384 | ||
2f28d2ff AL |
385 | /** |
386 | * ObjectClass: | |
387 | * | |
388 | * The base for all classes. The only thing that #ObjectClass contains is an | |
389 | * integer type handle. | |
390 | */ | |
391 | struct ObjectClass | |
392 | { | |
393 | /*< private >*/ | |
394 | Type type; | |
33e95c63 | 395 | GSList *interfaces; |
667d22d1 | 396 | |
0ab4c94c PC |
397 | const char *object_cast_cache[OBJECT_CLASS_CAST_CACHE]; |
398 | const char *class_cast_cache[OBJECT_CLASS_CAST_CACHE]; | |
03587328 | 399 | |
667d22d1 | 400 | ObjectUnparent *unparent; |
16bf7f52 DB |
401 | |
402 | GHashTable *properties; | |
2f28d2ff AL |
403 | }; |
404 | ||
405 | /** | |
406 | * Object: | |
407 | * | |
408 | * The base for all objects. The first member of this object is a pointer to | |
409 | * a #ObjectClass. Since C guarantees that the first member of a structure | |
410 | * always begins at byte 0 of that structure, as long as any sub-object places | |
411 | * its parent as the first member, we can cast directly to a #Object. | |
412 | * | |
413 | * As a result, #Object contains a reference to the objects type as its | |
414 | * first member. This allows identification of the real type of the object at | |
415 | * run time. | |
2f28d2ff AL |
416 | */ |
417 | struct Object | |
418 | { | |
419 | /*< private >*/ | |
420 | ObjectClass *class; | |
fde9bf44 | 421 | ObjectFree *free; |
b604a854 | 422 | GHashTable *properties; |
57c9fafe AL |
423 | uint32_t ref; |
424 | Object *parent; | |
2f28d2ff AL |
425 | }; |
426 | ||
427 | /** | |
428 | * TypeInfo: | |
429 | * @name: The name of the type. | |
430 | * @parent: The name of the parent type. | |
431 | * @instance_size: The size of the object (derivative of #Object). If | |
432 | * @instance_size is 0, then the size of the object will be the size of the | |
433 | * parent object. | |
434 | * @instance_init: This function is called to initialize an object. The parent | |
435 | * class will have already been initialized so the type is only responsible | |
436 | * for initializing its own members. | |
8231c2dd EH |
437 | * @instance_post_init: This function is called to finish initialization of |
438 | * an object, after all @instance_init functions were called. | |
2f28d2ff AL |
439 | * @instance_finalize: This function is called during object destruction. This |
440 | * is called before the parent @instance_finalize function has been called. | |
441 | * An object should only free the members that are unique to its type in this | |
442 | * function. | |
443 | * @abstract: If this field is true, then the class is considered abstract and | |
444 | * cannot be directly instantiated. | |
445 | * @class_size: The size of the class object (derivative of #ObjectClass) | |
446 | * for this object. If @class_size is 0, then the size of the class will be | |
447 | * assumed to be the size of the parent class. This allows a type to avoid | |
448 | * implementing an explicit class type if they are not adding additional | |
449 | * virtual functions. | |
450 | * @class_init: This function is called after all parent class initialization | |
441dd5eb | 451 | * has occurred to allow a class to set its default virtual method pointers. |
2f28d2ff AL |
452 | * This is also the function to use to override virtual methods from a parent |
453 | * class. | |
3b50e311 PB |
454 | * @class_base_init: This function is called for all base classes after all |
455 | * parent class initialization has occurred, but before the class itself | |
456 | * is initialized. This is the function to use to undo the effects of | |
39a1075a | 457 | * memcpy from the parent class to the descendants. |
37fdb2c5 MAL |
458 | * @class_data: Data to pass to the @class_init, |
459 | * @class_base_init. This can be useful when building dynamic | |
3b50e311 | 460 | * classes. |
2f28d2ff AL |
461 | * @interfaces: The list of interfaces associated with this type. This |
462 | * should point to a static array that's terminated with a zero filled | |
463 | * element. | |
464 | */ | |
465 | struct TypeInfo | |
466 | { | |
467 | const char *name; | |
468 | const char *parent; | |
469 | ||
470 | size_t instance_size; | |
471 | void (*instance_init)(Object *obj); | |
8231c2dd | 472 | void (*instance_post_init)(Object *obj); |
2f28d2ff AL |
473 | void (*instance_finalize)(Object *obj); |
474 | ||
475 | bool abstract; | |
476 | size_t class_size; | |
477 | ||
478 | void (*class_init)(ObjectClass *klass, void *data); | |
3b50e311 | 479 | void (*class_base_init)(ObjectClass *klass, void *data); |
2f28d2ff AL |
480 | void *class_data; |
481 | ||
482 | InterfaceInfo *interfaces; | |
483 | }; | |
484 | ||
485 | /** | |
486 | * OBJECT: | |
487 | * @obj: A derivative of #Object | |
488 | * | |
489 | * Converts an object to a #Object. Since all objects are #Objects, | |
490 | * this function will always succeed. | |
491 | */ | |
492 | #define OBJECT(obj) \ | |
493 | ((Object *)(obj)) | |
494 | ||
1ed5b918 PB |
495 | /** |
496 | * OBJECT_CLASS: | |
a0dbf408 | 497 | * @class: A derivative of #ObjectClass. |
1ed5b918 PB |
498 | * |
499 | * Converts a class to an #ObjectClass. Since all objects are #Objects, | |
500 | * this function will always succeed. | |
501 | */ | |
502 | #define OBJECT_CLASS(class) \ | |
503 | ((ObjectClass *)(class)) | |
504 | ||
2f28d2ff AL |
505 | /** |
506 | * OBJECT_CHECK: | |
507 | * @type: The C type to use for the return value. | |
508 | * @obj: A derivative of @type to cast. | |
509 | * @name: The QOM typename of @type | |
510 | * | |
511 | * A type safe version of @object_dynamic_cast_assert. Typically each class | |
512 | * will define a macro based on this type to perform type safe dynamic_casts to | |
513 | * this object type. | |
514 | * | |
515 | * If an invalid object is passed to this function, a run time assert will be | |
516 | * generated. | |
517 | */ | |
518 | #define OBJECT_CHECK(type, obj, name) \ | |
be17f18b PB |
519 | ((type *)object_dynamic_cast_assert(OBJECT(obj), (name), \ |
520 | __FILE__, __LINE__, __func__)) | |
2f28d2ff AL |
521 | |
522 | /** | |
523 | * OBJECT_CLASS_CHECK: | |
b30d8054 C |
524 | * @class_type: The C type to use for the return value. |
525 | * @class: A derivative class of @class_type to cast. | |
526 | * @name: the QOM typename of @class_type. | |
2f28d2ff | 527 | * |
1ed5b918 PB |
528 | * A type safe version of @object_class_dynamic_cast_assert. This macro is |
529 | * typically wrapped by each type to perform type safe casts of a class to a | |
530 | * specific class type. | |
2f28d2ff | 531 | */ |
b30d8054 C |
532 | #define OBJECT_CLASS_CHECK(class_type, class, name) \ |
533 | ((class_type *)object_class_dynamic_cast_assert(OBJECT_CLASS(class), (name), \ | |
be17f18b | 534 | __FILE__, __LINE__, __func__)) |
2f28d2ff AL |
535 | |
536 | /** | |
537 | * OBJECT_GET_CLASS: | |
538 | * @class: The C type to use for the return value. | |
539 | * @obj: The object to obtain the class for. | |
540 | * @name: The QOM typename of @obj. | |
541 | * | |
542 | * This function will return a specific class for a given object. Its generally | |
543 | * used by each type to provide a type safe macro to get a specific class type | |
544 | * from an object. | |
545 | */ | |
546 | #define OBJECT_GET_CLASS(class, obj, name) \ | |
547 | OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name) | |
548 | ||
33e95c63 AL |
549 | /** |
550 | * InterfaceInfo: | |
551 | * @type: The name of the interface. | |
552 | * | |
553 | * The information associated with an interface. | |
554 | */ | |
555 | struct InterfaceInfo { | |
556 | const char *type; | |
557 | }; | |
558 | ||
2f28d2ff AL |
559 | /** |
560 | * InterfaceClass: | |
561 | * @parent_class: the base class | |
562 | * | |
563 | * The class for all interfaces. Subclasses of this class should only add | |
564 | * virtual methods. | |
565 | */ | |
566 | struct InterfaceClass | |
567 | { | |
568 | ObjectClass parent_class; | |
33e95c63 AL |
569 | /*< private >*/ |
570 | ObjectClass *concrete_class; | |
b061dc41 | 571 | Type interface_type; |
2f28d2ff AL |
572 | }; |
573 | ||
33e95c63 AL |
574 | #define TYPE_INTERFACE "interface" |
575 | ||
2f28d2ff | 576 | /** |
33e95c63 AL |
577 | * INTERFACE_CLASS: |
578 | * @klass: class to cast from | |
579 | * Returns: An #InterfaceClass or raise an error if cast is invalid | |
2f28d2ff | 580 | */ |
33e95c63 AL |
581 | #define INTERFACE_CLASS(klass) \ |
582 | OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE) | |
2f28d2ff | 583 | |
33e95c63 AL |
584 | /** |
585 | * INTERFACE_CHECK: | |
586 | * @interface: the type to return | |
587 | * @obj: the object to convert to an interface | |
588 | * @name: the interface type name | |
589 | * | |
590 | * Returns: @obj casted to @interface if cast is valid, otherwise raise error. | |
591 | */ | |
592 | #define INTERFACE_CHECK(interface, obj, name) \ | |
be17f18b PB |
593 | ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \ |
594 | __FILE__, __LINE__, __func__)) | |
2f28d2ff AL |
595 | |
596 | /** | |
597 | * object_new: | |
598 | * @typename: The name of the type of the object to instantiate. | |
599 | * | |
b76facc3 PB |
600 | * This function will initialize a new object using heap allocated memory. |
601 | * The returned object has a reference count of 1, and will be freed when | |
602 | * the last reference is dropped. | |
2f28d2ff AL |
603 | * |
604 | * Returns: The newly allocated and instantiated object. | |
605 | */ | |
606 | Object *object_new(const char *typename); | |
607 | ||
a31bdae5 DB |
608 | /** |
609 | * object_new_with_props: | |
610 | * @typename: The name of the type of the object to instantiate. | |
611 | * @parent: the parent object | |
612 | * @id: The unique ID of the object | |
613 | * @errp: pointer to error object | |
614 | * @...: list of property names and values | |
615 | * | |
616 | * This function will initialize a new object using heap allocated memory. | |
617 | * The returned object has a reference count of 1, and will be freed when | |
618 | * the last reference is dropped. | |
619 | * | |
620 | * The @id parameter will be used when registering the object as a | |
621 | * child of @parent in the composition tree. | |
622 | * | |
623 | * The variadic parameters are a list of pairs of (propname, propvalue) | |
624 | * strings. The propname of %NULL indicates the end of the property | |
625 | * list. If the object implements the user creatable interface, the | |
626 | * object will be marked complete once all the properties have been | |
627 | * processed. | |
628 | * | |
629 | * <example> | |
630 | * <title>Creating an object with properties</title> | |
631 | * <programlisting> | |
632 | * Error *err = NULL; | |
633 | * Object *obj; | |
634 | * | |
635 | * obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE, | |
636 | * object_get_objects_root(), | |
637 | * "hostmem0", | |
638 | * &err, | |
639 | * "share", "yes", | |
640 | * "mem-path", "/dev/shm/somefile", | |
641 | * "prealloc", "yes", | |
642 | * "size", "1048576", | |
643 | * NULL); | |
644 | * | |
645 | * if (!obj) { | |
646 | * g_printerr("Cannot create memory backend: %s\n", | |
647 | * error_get_pretty(err)); | |
648 | * } | |
649 | * </programlisting> | |
650 | * </example> | |
651 | * | |
652 | * The returned object will have one stable reference maintained | |
653 | * for as long as it is present in the object hierarchy. | |
654 | * | |
655 | * Returns: The newly allocated, instantiated & initialized object. | |
656 | */ | |
657 | Object *object_new_with_props(const char *typename, | |
658 | Object *parent, | |
659 | const char *id, | |
660 | Error **errp, | |
661 | ...) QEMU_SENTINEL; | |
662 | ||
663 | /** | |
664 | * object_new_with_propv: | |
665 | * @typename: The name of the type of the object to instantiate. | |
666 | * @parent: the parent object | |
667 | * @id: The unique ID of the object | |
668 | * @errp: pointer to error object | |
669 | * @vargs: list of property names and values | |
670 | * | |
671 | * See object_new_with_props() for documentation. | |
672 | */ | |
673 | Object *object_new_with_propv(const char *typename, | |
674 | Object *parent, | |
675 | const char *id, | |
676 | Error **errp, | |
677 | va_list vargs); | |
678 | ||
ea9ce893 MAL |
679 | void object_apply_global_props(Object *obj, const GPtrArray *props, |
680 | Error **errp); | |
617902af MA |
681 | void object_set_machine_compat_props(GPtrArray *compat_props); |
682 | void object_set_accelerator_compat_props(GPtrArray *compat_props); | |
683 | void object_apply_compat_props(Object *obj); | |
ea9ce893 | 684 | |
a31bdae5 DB |
685 | /** |
686 | * object_set_props: | |
687 | * @obj: the object instance to set properties on | |
688 | * @errp: pointer to error object | |
689 | * @...: list of property names and values | |
690 | * | |
691 | * This function will set a list of properties on an existing object | |
692 | * instance. | |
693 | * | |
694 | * The variadic parameters are a list of pairs of (propname, propvalue) | |
695 | * strings. The propname of %NULL indicates the end of the property | |
696 | * list. | |
697 | * | |
698 | * <example> | |
699 | * <title>Update an object's properties</title> | |
700 | * <programlisting> | |
701 | * Error *err = NULL; | |
702 | * Object *obj = ...get / create object...; | |
703 | * | |
704 | * obj = object_set_props(obj, | |
705 | * &err, | |
706 | * "share", "yes", | |
707 | * "mem-path", "/dev/shm/somefile", | |
708 | * "prealloc", "yes", | |
709 | * "size", "1048576", | |
710 | * NULL); | |
711 | * | |
712 | * if (!obj) { | |
713 | * g_printerr("Cannot set properties: %s\n", | |
714 | * error_get_pretty(err)); | |
715 | * } | |
716 | * </programlisting> | |
717 | * </example> | |
718 | * | |
719 | * The returned object will have one stable reference maintained | |
720 | * for as long as it is present in the object hierarchy. | |
721 | * | |
722 | * Returns: -1 on error, 0 on success | |
723 | */ | |
724 | int object_set_props(Object *obj, | |
725 | Error **errp, | |
726 | ...) QEMU_SENTINEL; | |
727 | ||
728 | /** | |
729 | * object_set_propv: | |
730 | * @obj: the object instance to set properties on | |
731 | * @errp: pointer to error object | |
732 | * @vargs: list of property names and values | |
733 | * | |
734 | * See object_set_props() for documentation. | |
735 | * | |
736 | * Returns: -1 on error, 0 on success | |
737 | */ | |
738 | int object_set_propv(Object *obj, | |
739 | Error **errp, | |
740 | va_list vargs); | |
741 | ||
2f28d2ff AL |
742 | /** |
743 | * object_initialize: | |
744 | * @obj: A pointer to the memory to be used for the object. | |
213f0c4f | 745 | * @size: The maximum size available at @obj for the object. |
2f28d2ff AL |
746 | * @typename: The name of the type of the object to instantiate. |
747 | * | |
748 | * This function will initialize an object. The memory for the object should | |
b76facc3 PB |
749 | * have already been allocated. The returned object has a reference count of 1, |
750 | * and will be finalized when the last reference is dropped. | |
2f28d2ff | 751 | */ |
213f0c4f | 752 | void object_initialize(void *obj, size_t size, const char *typename); |
2f28d2ff | 753 | |
0210b39d TH |
754 | /** |
755 | * object_initialize_child: | |
756 | * @parentobj: The parent object to add a property to | |
757 | * @propname: The name of the property | |
758 | * @childobj: A pointer to the memory to be used for the object. | |
759 | * @size: The maximum size available at @childobj for the object. | |
760 | * @type: The name of the type of the object to instantiate. | |
761 | * @errp: If an error occurs, a pointer to an area to store the error | |
762 | * @...: list of property names and values | |
763 | * | |
764 | * This function will initialize an object. The memory for the object should | |
765 | * have already been allocated. The object will then be added as child property | |
766 | * to a parent with object_property_add_child() function. The returned object | |
767 | * has a reference count of 1 (for the "child<...>" property from the parent), | |
768 | * so the object will be finalized automatically when the parent gets removed. | |
769 | * | |
770 | * The variadic parameters are a list of pairs of (propname, propvalue) | |
771 | * strings. The propname of %NULL indicates the end of the property list. | |
772 | * If the object implements the user creatable interface, the object will | |
773 | * be marked complete once all the properties have been processed. | |
774 | */ | |
775 | void object_initialize_child(Object *parentobj, const char *propname, | |
776 | void *childobj, size_t size, const char *type, | |
777 | Error **errp, ...) QEMU_SENTINEL; | |
778 | ||
779 | /** | |
780 | * object_initialize_childv: | |
781 | * @parentobj: The parent object to add a property to | |
782 | * @propname: The name of the property | |
783 | * @childobj: A pointer to the memory to be used for the object. | |
784 | * @size: The maximum size available at @childobj for the object. | |
785 | * @type: The name of the type of the object to instantiate. | |
786 | * @errp: If an error occurs, a pointer to an area to store the error | |
787 | * @vargs: list of property names and values | |
788 | * | |
789 | * See object_initialize_child() for documentation. | |
790 | */ | |
791 | void object_initialize_childv(Object *parentobj, const char *propname, | |
792 | void *childobj, size_t size, const char *type, | |
793 | Error **errp, va_list vargs); | |
794 | ||
2f28d2ff AL |
795 | /** |
796 | * object_dynamic_cast: | |
797 | * @obj: The object to cast. | |
798 | * @typename: The @typename to cast to. | |
799 | * | |
800 | * This function will determine if @obj is-a @typename. @obj can refer to an | |
801 | * object or an interface associated with an object. | |
802 | * | |
803 | * Returns: This function returns @obj on success or #NULL on failure. | |
804 | */ | |
805 | Object *object_dynamic_cast(Object *obj, const char *typename); | |
806 | ||
807 | /** | |
438e1c79 | 808 | * object_dynamic_cast_assert: |
2f28d2ff AL |
809 | * |
810 | * See object_dynamic_cast() for a description of the parameters of this | |
811 | * function. The only difference in behavior is that this function asserts | |
3556c233 PB |
812 | * instead of returning #NULL on failure if QOM cast debugging is enabled. |
813 | * This function is not meant to be called directly, but only through | |
814 | * the wrapper macro OBJECT_CHECK. | |
2f28d2ff | 815 | */ |
be17f18b PB |
816 | Object *object_dynamic_cast_assert(Object *obj, const char *typename, |
817 | const char *file, int line, const char *func); | |
2f28d2ff AL |
818 | |
819 | /** | |
820 | * object_get_class: | |
821 | * @obj: A derivative of #Object | |
822 | * | |
823 | * Returns: The #ObjectClass of the type associated with @obj. | |
824 | */ | |
825 | ObjectClass *object_get_class(Object *obj); | |
826 | ||
827 | /** | |
828 | * object_get_typename: | |
829 | * @obj: A derivative of #Object. | |
830 | * | |
831 | * Returns: The QOM typename of @obj. | |
832 | */ | |
8f5d58ef | 833 | const char *object_get_typename(const Object *obj); |
2f28d2ff AL |
834 | |
835 | /** | |
836 | * type_register_static: | |
837 | * @info: The #TypeInfo of the new type. | |
838 | * | |
839 | * @info and all of the strings it points to should exist for the life time | |
840 | * that the type is registered. | |
841 | * | |
31b93521 | 842 | * Returns: the new #Type. |
2f28d2ff AL |
843 | */ |
844 | Type type_register_static(const TypeInfo *info); | |
845 | ||
846 | /** | |
847 | * type_register: | |
848 | * @info: The #TypeInfo of the new type | |
849 | * | |
93148aa5 | 850 | * Unlike type_register_static(), this call does not require @info or its |
2f28d2ff AL |
851 | * string members to continue to exist after the call returns. |
852 | * | |
31b93521 | 853 | * Returns: the new #Type. |
2f28d2ff AL |
854 | */ |
855 | Type type_register(const TypeInfo *info); | |
856 | ||
aa04c9d2 IM |
857 | /** |
858 | * type_register_static_array: | |
859 | * @infos: The array of the new type #TypeInfo structures. | |
860 | * @nr_infos: number of entries in @infos | |
861 | * | |
862 | * @infos and all of the strings it points to should exist for the life time | |
863 | * that the type is registered. | |
864 | */ | |
865 | void type_register_static_array(const TypeInfo *infos, int nr_infos); | |
866 | ||
38b5d79b IM |
867 | /** |
868 | * DEFINE_TYPES: | |
869 | * @type_array: The array containing #TypeInfo structures to register | |
870 | * | |
871 | * @type_array should be static constant that exists for the life time | |
872 | * that the type is registered. | |
873 | */ | |
874 | #define DEFINE_TYPES(type_array) \ | |
875 | static void do_qemu_init_ ## type_array(void) \ | |
876 | { \ | |
877 | type_register_static_array(type_array, ARRAY_SIZE(type_array)); \ | |
878 | } \ | |
879 | type_init(do_qemu_init_ ## type_array) | |
880 | ||
2f28d2ff AL |
881 | /** |
882 | * object_class_dynamic_cast_assert: | |
883 | * @klass: The #ObjectClass to attempt to cast. | |
884 | * @typename: The QOM typename of the class to cast to. | |
885 | * | |
33bc94eb PB |
886 | * See object_class_dynamic_cast() for a description of the parameters |
887 | * of this function. The only difference in behavior is that this function | |
3556c233 PB |
888 | * asserts instead of returning #NULL on failure if QOM cast debugging is |
889 | * enabled. This function is not meant to be called directly, but only through | |
890 | * the wrapper macros OBJECT_CLASS_CHECK and INTERFACE_CHECK. | |
2f28d2ff AL |
891 | */ |
892 | ObjectClass *object_class_dynamic_cast_assert(ObjectClass *klass, | |
be17f18b PB |
893 | const char *typename, |
894 | const char *file, int line, | |
895 | const char *func); | |
2f28d2ff | 896 | |
33bc94eb PB |
897 | /** |
898 | * object_class_dynamic_cast: | |
899 | * @klass: The #ObjectClass to attempt to cast. | |
900 | * @typename: The QOM typename of the class to cast to. | |
901 | * | |
902 | * Returns: If @typename is a class, this function returns @klass if | |
903 | * @typename is a subtype of @klass, else returns #NULL. | |
904 | * | |
905 | * If @typename is an interface, this function returns the interface | |
906 | * definition for @klass if @klass implements it unambiguously; #NULL | |
907 | * is returned if @klass does not implement the interface or if multiple | |
908 | * classes or interfaces on the hierarchy leading to @klass implement | |
909 | * it. (FIXME: perhaps this can be detected at type definition time?) | |
910 | */ | |
2f28d2ff AL |
911 | ObjectClass *object_class_dynamic_cast(ObjectClass *klass, |
912 | const char *typename); | |
913 | ||
e7cce67f PB |
914 | /** |
915 | * object_class_get_parent: | |
916 | * @klass: The class to obtain the parent for. | |
917 | * | |
918 | * Returns: The parent for @klass or %NULL if none. | |
919 | */ | |
920 | ObjectClass *object_class_get_parent(ObjectClass *klass); | |
921 | ||
2f28d2ff AL |
922 | /** |
923 | * object_class_get_name: | |
924 | * @klass: The class to obtain the QOM typename for. | |
925 | * | |
926 | * Returns: The QOM typename for @klass. | |
927 | */ | |
928 | const char *object_class_get_name(ObjectClass *klass); | |
929 | ||
17862378 AF |
930 | /** |
931 | * object_class_is_abstract: | |
932 | * @klass: The class to obtain the abstractness for. | |
933 | * | |
934 | * Returns: %true if @klass is abstract, %false otherwise. | |
935 | */ | |
936 | bool object_class_is_abstract(ObjectClass *klass); | |
937 | ||
0466e458 PB |
938 | /** |
939 | * object_class_by_name: | |
940 | * @typename: The QOM typename to obtain the class for. | |
941 | * | |
942 | * Returns: The class for @typename or %NULL if not found. | |
943 | */ | |
2f28d2ff AL |
944 | ObjectClass *object_class_by_name(const char *typename); |
945 | ||
946 | void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque), | |
93c511a1 | 947 | const char *implements_type, bool include_abstract, |
2f28d2ff | 948 | void *opaque); |
418ba9e5 AF |
949 | |
950 | /** | |
951 | * object_class_get_list: | |
952 | * @implements_type: The type to filter for, including its derivatives. | |
953 | * @include_abstract: Whether to include abstract classes. | |
954 | * | |
955 | * Returns: A singly-linked list of the classes in reverse hashtable order. | |
956 | */ | |
957 | GSList *object_class_get_list(const char *implements_type, | |
958 | bool include_abstract); | |
47c66009 PB |
959 | |
960 | /** | |
961 | * object_class_get_list_sorted: | |
962 | * @implements_type: The type to filter for, including its derivatives. | |
963 | * @include_abstract: Whether to include abstract classes. | |
964 | * | |
965 | * Returns: A singly-linked list of the classes in alphabetical | |
966 | * case-insensitive order. | |
967 | */ | |
968 | GSList *object_class_get_list_sorted(const char *implements_type, | |
969 | bool include_abstract); | |
418ba9e5 | 970 | |
57c9fafe AL |
971 | /** |
972 | * object_ref: | |
973 | * @obj: the object | |
974 | * | |
975 | * Increase the reference count of a object. A object cannot be freed as long | |
976 | * as its reference count is greater than zero. | |
977 | */ | |
978 | void object_ref(Object *obj); | |
979 | ||
980 | /** | |
ada03a0e | 981 | * object_unref: |
57c9fafe AL |
982 | * @obj: the object |
983 | * | |
984 | * Decrease the reference count of a object. A object cannot be freed as long | |
985 | * as its reference count is greater than zero. | |
986 | */ | |
987 | void object_unref(Object *obj); | |
988 | ||
989 | /** | |
990 | * object_property_add: | |
991 | * @obj: the object to add a property to | |
992 | * @name: the name of the property. This can contain any character except for | |
993 | * a forward slash. In general, you should use hyphens '-' instead of | |
994 | * underscores '_' when naming properties. | |
995 | * @type: the type name of the property. This namespace is pretty loosely | |
996 | * defined. Sub namespaces are constructed by using a prefix and then | |
997 | * to angle brackets. For instance, the type 'virtio-net-pci' in the | |
998 | * 'link' namespace would be 'link<virtio-net-pci>'. | |
999 | * @get: The getter to be called to read a property. If this is NULL, then | |
1000 | * the property cannot be read. | |
1001 | * @set: the setter to be called to write a property. If this is NULL, | |
1002 | * then the property cannot be written. | |
1003 | * @release: called when the property is removed from the object. This is | |
1004 | * meant to allow a property to free its opaque upon object | |
1005 | * destruction. This may be NULL. | |
1006 | * @opaque: an opaque pointer to pass to the callbacks for the property | |
1007 | * @errp: returns an error if this function fails | |
64607d08 PB |
1008 | * |
1009 | * Returns: The #ObjectProperty; this can be used to set the @resolve | |
1010 | * callback for child and link properties. | |
57c9fafe | 1011 | */ |
64607d08 PB |
1012 | ObjectProperty *object_property_add(Object *obj, const char *name, |
1013 | const char *type, | |
1014 | ObjectPropertyAccessor *get, | |
1015 | ObjectPropertyAccessor *set, | |
1016 | ObjectPropertyRelease *release, | |
1017 | void *opaque, Error **errp); | |
57c9fafe | 1018 | |
e82df248 | 1019 | void object_property_del(Object *obj, const char *name, Error **errp); |
57c9fafe | 1020 | |
16bf7f52 DB |
1021 | ObjectProperty *object_class_property_add(ObjectClass *klass, const char *name, |
1022 | const char *type, | |
1023 | ObjectPropertyAccessor *get, | |
1024 | ObjectPropertyAccessor *set, | |
1025 | ObjectPropertyRelease *release, | |
1026 | void *opaque, Error **errp); | |
1027 | ||
8cb6789a PB |
1028 | /** |
1029 | * object_property_find: | |
1030 | * @obj: the object | |
1031 | * @name: the name of the property | |
89bfe000 | 1032 | * @errp: returns an error if this function fails |
8cb6789a PB |
1033 | * |
1034 | * Look up a property for an object and return its #ObjectProperty if found. | |
1035 | */ | |
89bfe000 | 1036 | ObjectProperty *object_property_find(Object *obj, const char *name, |
e82df248 | 1037 | Error **errp); |
16bf7f52 DB |
1038 | ObjectProperty *object_class_property_find(ObjectClass *klass, const char *name, |
1039 | Error **errp); | |
8cb6789a | 1040 | |
7746abd8 DB |
1041 | typedef struct ObjectPropertyIterator { |
1042 | ObjectClass *nextclass; | |
1043 | GHashTableIter iter; | |
1044 | } ObjectPropertyIterator; | |
a00c9482 DB |
1045 | |
1046 | /** | |
1047 | * object_property_iter_init: | |
1048 | * @obj: the object | |
1049 | * | |
1050 | * Initializes an iterator for traversing all properties | |
16bf7f52 | 1051 | * registered against an object instance, its class and all parent classes. |
a00c9482 DB |
1052 | * |
1053 | * It is forbidden to modify the property list while iterating, | |
1054 | * whether removing or adding properties. | |
1055 | * | |
1056 | * Typical usage pattern would be | |
1057 | * | |
1058 | * <example> | |
1059 | * <title>Using object property iterators</title> | |
1060 | * <programlisting> | |
1061 | * ObjectProperty *prop; | |
7746abd8 | 1062 | * ObjectPropertyIterator iter; |
a00c9482 | 1063 | * |
7746abd8 DB |
1064 | * object_property_iter_init(&iter, obj); |
1065 | * while ((prop = object_property_iter_next(&iter))) { | |
a00c9482 DB |
1066 | * ... do something with prop ... |
1067 | * } | |
a00c9482 DB |
1068 | * </programlisting> |
1069 | * </example> | |
a00c9482 | 1070 | */ |
7746abd8 DB |
1071 | void object_property_iter_init(ObjectPropertyIterator *iter, |
1072 | Object *obj); | |
a00c9482 | 1073 | |
961c47bb AK |
1074 | /** |
1075 | * object_class_property_iter_init: | |
1076 | * @klass: the class | |
1077 | * | |
1078 | * Initializes an iterator for traversing all properties | |
1079 | * registered against an object class and all parent classes. | |
1080 | * | |
1081 | * It is forbidden to modify the property list while iterating, | |
1082 | * whether removing or adding properties. | |
1083 | * | |
1084 | * This can be used on abstract classes as it does not create a temporary | |
1085 | * instance. | |
1086 | */ | |
1087 | void object_class_property_iter_init(ObjectPropertyIterator *iter, | |
1088 | ObjectClass *klass); | |
1089 | ||
a00c9482 DB |
1090 | /** |
1091 | * object_property_iter_next: | |
1092 | * @iter: the iterator instance | |
1093 | * | |
7746abd8 DB |
1094 | * Return the next available property. If no further properties |
1095 | * are available, a %NULL value will be returned and the @iter | |
1096 | * pointer should not be used again after this point without | |
1097 | * re-initializing it. | |
1098 | * | |
a00c9482 DB |
1099 | * Returns: the next property, or %NULL when all properties |
1100 | * have been traversed. | |
1101 | */ | |
1102 | ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter); | |
1103 | ||
57c9fafe AL |
1104 | void object_unparent(Object *obj); |
1105 | ||
1106 | /** | |
1107 | * object_property_get: | |
1108 | * @obj: the object | |
1109 | * @v: the visitor that will receive the property value. This should be an | |
1110 | * Output visitor and the data will be written with @name as the name. | |
1111 | * @name: the name of the property | |
1112 | * @errp: returns an error if this function fails | |
1113 | * | |
1114 | * Reads a property from a object. | |
1115 | */ | |
4fa45492 | 1116 | void object_property_get(Object *obj, Visitor *v, const char *name, |
e82df248 | 1117 | Error **errp); |
57c9fafe | 1118 | |
7b7b7d18 PB |
1119 | /** |
1120 | * object_property_set_str: | |
1121 | * @value: the value to be written to the property | |
1122 | * @name: the name of the property | |
1123 | * @errp: returns an error if this function fails | |
1124 | * | |
1125 | * Writes a string value to a property. | |
1126 | */ | |
1127 | void object_property_set_str(Object *obj, const char *value, | |
e82df248 | 1128 | const char *name, Error **errp); |
7b7b7d18 PB |
1129 | |
1130 | /** | |
1131 | * object_property_get_str: | |
1132 | * @obj: the object | |
1133 | * @name: the name of the property | |
1134 | * @errp: returns an error if this function fails | |
1135 | * | |
1136 | * Returns: the value of the property, converted to a C string, or NULL if | |
1137 | * an error occurs (including when the property value is not a string). | |
1138 | * The caller should free the string. | |
1139 | */ | |
1140 | char *object_property_get_str(Object *obj, const char *name, | |
e82df248 | 1141 | Error **errp); |
7b7b7d18 | 1142 | |
1d9c5a12 PB |
1143 | /** |
1144 | * object_property_set_link: | |
1145 | * @value: the value to be written to the property | |
1146 | * @name: the name of the property | |
1147 | * @errp: returns an error if this function fails | |
1148 | * | |
1149 | * Writes an object's canonical path to a property. | |
265b578c MAL |
1150 | * |
1151 | * If the link property was created with | |
1152 | * <code>OBJ_PROP_LINK_STRONG</code> bit, the old target object is | |
1153 | * unreferenced, and a reference is added to the new target object. | |
1154 | * | |
1d9c5a12 PB |
1155 | */ |
1156 | void object_property_set_link(Object *obj, Object *value, | |
e82df248 | 1157 | const char *name, Error **errp); |
1d9c5a12 PB |
1158 | |
1159 | /** | |
1160 | * object_property_get_link: | |
1161 | * @obj: the object | |
1162 | * @name: the name of the property | |
1163 | * @errp: returns an error if this function fails | |
1164 | * | |
1165 | * Returns: the value of the property, resolved from a path to an Object, | |
1166 | * or NULL if an error occurs (including when the property value is not a | |
1167 | * string or not a valid object path). | |
1168 | */ | |
1169 | Object *object_property_get_link(Object *obj, const char *name, | |
e82df248 | 1170 | Error **errp); |
1d9c5a12 | 1171 | |
7b7b7d18 PB |
1172 | /** |
1173 | * object_property_set_bool: | |
1174 | * @value: the value to be written to the property | |
1175 | * @name: the name of the property | |
1176 | * @errp: returns an error if this function fails | |
1177 | * | |
1178 | * Writes a bool value to a property. | |
1179 | */ | |
1180 | void object_property_set_bool(Object *obj, bool value, | |
e82df248 | 1181 | const char *name, Error **errp); |
7b7b7d18 PB |
1182 | |
1183 | /** | |
1184 | * object_property_get_bool: | |
1185 | * @obj: the object | |
1186 | * @name: the name of the property | |
1187 | * @errp: returns an error if this function fails | |
1188 | * | |
1189 | * Returns: the value of the property, converted to a boolean, or NULL if | |
1190 | * an error occurs (including when the property value is not a bool). | |
1191 | */ | |
1192 | bool object_property_get_bool(Object *obj, const char *name, | |
e82df248 | 1193 | Error **errp); |
7b7b7d18 PB |
1194 | |
1195 | /** | |
1196 | * object_property_set_int: | |
1197 | * @value: the value to be written to the property | |
1198 | * @name: the name of the property | |
1199 | * @errp: returns an error if this function fails | |
1200 | * | |
1201 | * Writes an integer value to a property. | |
1202 | */ | |
1203 | void object_property_set_int(Object *obj, int64_t value, | |
e82df248 | 1204 | const char *name, Error **errp); |
7b7b7d18 PB |
1205 | |
1206 | /** | |
1207 | * object_property_get_int: | |
1208 | * @obj: the object | |
1209 | * @name: the name of the property | |
1210 | * @errp: returns an error if this function fails | |
1211 | * | |
b29b47e9 | 1212 | * Returns: the value of the property, converted to an integer, or negative if |
7b7b7d18 PB |
1213 | * an error occurs (including when the property value is not an integer). |
1214 | */ | |
1215 | int64_t object_property_get_int(Object *obj, const char *name, | |
e82df248 | 1216 | Error **errp); |
7b7b7d18 | 1217 | |
3152779c MAL |
1218 | /** |
1219 | * object_property_set_uint: | |
1220 | * @value: the value to be written to the property | |
1221 | * @name: the name of the property | |
1222 | * @errp: returns an error if this function fails | |
1223 | * | |
1224 | * Writes an unsigned integer value to a property. | |
1225 | */ | |
1226 | void object_property_set_uint(Object *obj, uint64_t value, | |
1227 | const char *name, Error **errp); | |
1228 | ||
1229 | /** | |
1230 | * object_property_get_uint: | |
1231 | * @obj: the object | |
1232 | * @name: the name of the property | |
1233 | * @errp: returns an error if this function fails | |
1234 | * | |
1235 | * Returns: the value of the property, converted to an unsigned integer, or 0 | |
1236 | * an error occurs (including when the property value is not an integer). | |
1237 | */ | |
1238 | uint64_t object_property_get_uint(Object *obj, const char *name, | |
1239 | Error **errp); | |
1240 | ||
1f21772d HT |
1241 | /** |
1242 | * object_property_get_enum: | |
1243 | * @obj: the object | |
1244 | * @name: the name of the property | |
a3590dac | 1245 | * @typename: the name of the enum data type |
1f21772d HT |
1246 | * @errp: returns an error if this function fails |
1247 | * | |
1248 | * Returns: the value of the property, converted to an integer, or | |
1249 | * undefined if an error occurs (including when the property value is not | |
1250 | * an enum). | |
1251 | */ | |
1252 | int object_property_get_enum(Object *obj, const char *name, | |
a3590dac | 1253 | const char *typename, Error **errp); |
1f21772d HT |
1254 | |
1255 | /** | |
1256 | * object_property_get_uint16List: | |
1257 | * @obj: the object | |
1258 | * @name: the name of the property | |
1259 | * @list: the returned int list | |
1260 | * @errp: returns an error if this function fails | |
1261 | * | |
1262 | * Returns: the value of the property, converted to integers, or | |
1263 | * undefined if an error occurs (including when the property value is not | |
1264 | * an list of integers). | |
1265 | */ | |
1266 | void object_property_get_uint16List(Object *obj, const char *name, | |
1267 | uint16List **list, Error **errp); | |
1268 | ||
57c9fafe AL |
1269 | /** |
1270 | * object_property_set: | |
1271 | * @obj: the object | |
1272 | * @v: the visitor that will be used to write the property value. This should | |
1273 | * be an Input visitor and the data will be first read with @name as the | |
1274 | * name and then written as the property value. | |
1275 | * @name: the name of the property | |
1276 | * @errp: returns an error if this function fails | |
1277 | * | |
1278 | * Writes a property to a object. | |
1279 | */ | |
4fa45492 | 1280 | void object_property_set(Object *obj, Visitor *v, const char *name, |
e82df248 | 1281 | Error **errp); |
57c9fafe | 1282 | |
b2cd7dee PB |
1283 | /** |
1284 | * object_property_parse: | |
1285 | * @obj: the object | |
1286 | * @string: the string that will be used to parse the property value. | |
1287 | * @name: the name of the property | |
1288 | * @errp: returns an error if this function fails | |
1289 | * | |
1290 | * Parses a string and writes the result into a property of an object. | |
1291 | */ | |
1292 | void object_property_parse(Object *obj, const char *string, | |
e82df248 | 1293 | const char *name, Error **errp); |
b2cd7dee PB |
1294 | |
1295 | /** | |
1296 | * object_property_print: | |
1297 | * @obj: the object | |
1298 | * @name: the name of the property | |
0b7593e0 | 1299 | * @human: if true, print for human consumption |
b2cd7dee PB |
1300 | * @errp: returns an error if this function fails |
1301 | * | |
1302 | * Returns a string representation of the value of the property. The | |
1303 | * caller shall free the string. | |
1304 | */ | |
0b7593e0 | 1305 | char *object_property_print(Object *obj, const char *name, bool human, |
e82df248 | 1306 | Error **errp); |
b2cd7dee | 1307 | |
57c9fafe | 1308 | /** |
438e1c79 | 1309 | * object_property_get_type: |
57c9fafe AL |
1310 | * @obj: the object |
1311 | * @name: the name of the property | |
1312 | * @errp: returns an error if this function fails | |
1313 | * | |
1314 | * Returns: The type name of the property. | |
1315 | */ | |
1316 | const char *object_property_get_type(Object *obj, const char *name, | |
e82df248 | 1317 | Error **errp); |
57c9fafe AL |
1318 | |
1319 | /** | |
1320 | * object_get_root: | |
1321 | * | |
1322 | * Returns: the root object of the composition tree | |
1323 | */ | |
1324 | Object *object_get_root(void); | |
1325 | ||
bc2256c4 DB |
1326 | |
1327 | /** | |
1328 | * object_get_objects_root: | |
1329 | * | |
1330 | * Get the container object that holds user created | |
1331 | * object instances. This is the object at path | |
1332 | * "/objects" | |
1333 | * | |
1334 | * Returns: the user object container | |
1335 | */ | |
1336 | Object *object_get_objects_root(void); | |
1337 | ||
7c47c4ea PX |
1338 | /** |
1339 | * object_get_internal_root: | |
1340 | * | |
1341 | * Get the container object that holds internally used object | |
1342 | * instances. Any object which is put into this container must not be | |
1343 | * user visible, and it will not be exposed in the QOM tree. | |
1344 | * | |
1345 | * Returns: the internal object container | |
1346 | */ | |
1347 | Object *object_get_internal_root(void); | |
1348 | ||
11f590b1 SH |
1349 | /** |
1350 | * object_get_canonical_path_component: | |
1351 | * | |
1352 | * Returns: The final component in the object's canonical path. The canonical | |
1353 | * path is the path within the composition tree starting from the root. | |
770dec26 | 1354 | * %NULL if the object doesn't have a parent (and thus a canonical path). |
11f590b1 SH |
1355 | */ |
1356 | gchar *object_get_canonical_path_component(Object *obj); | |
1357 | ||
57c9fafe AL |
1358 | /** |
1359 | * object_get_canonical_path: | |
1360 | * | |
1361 | * Returns: The canonical path for a object. This is the path within the | |
1362 | * composition tree starting from the root. | |
1363 | */ | |
1364 | gchar *object_get_canonical_path(Object *obj); | |
1365 | ||
1366 | /** | |
1367 | * object_resolve_path: | |
1368 | * @path: the path to resolve | |
1369 | * @ambiguous: returns true if the path resolution failed because of an | |
1370 | * ambiguous match | |
1371 | * | |
1372 | * There are two types of supported paths--absolute paths and partial paths. | |
1373 | * | |
1374 | * Absolute paths are derived from the root object and can follow child<> or | |
1375 | * link<> properties. Since they can follow link<> properties, they can be | |
1376 | * arbitrarily long. Absolute paths look like absolute filenames and are | |
1377 | * prefixed with a leading slash. | |
1378 | * | |
1379 | * Partial paths look like relative filenames. They do not begin with a | |
1380 | * prefix. The matching rules for partial paths are subtle but designed to make | |
1381 | * specifying objects easy. At each level of the composition tree, the partial | |
1382 | * path is matched as an absolute path. The first match is not returned. At | |
1383 | * least two matches are searched for. A successful result is only returned if | |
02fe2db6 PB |
1384 | * only one match is found. If more than one match is found, a flag is |
1385 | * returned to indicate that the match was ambiguous. | |
57c9fafe AL |
1386 | * |
1387 | * Returns: The matched object or NULL on path lookup failure. | |
1388 | */ | |
1389 | Object *object_resolve_path(const char *path, bool *ambiguous); | |
1390 | ||
02fe2db6 PB |
1391 | /** |
1392 | * object_resolve_path_type: | |
1393 | * @path: the path to resolve | |
1394 | * @typename: the type to look for. | |
1395 | * @ambiguous: returns true if the path resolution failed because of an | |
1396 | * ambiguous match | |
1397 | * | |
1398 | * This is similar to object_resolve_path. However, when looking for a | |
1399 | * partial path only matches that implement the given type are considered. | |
1400 | * This restricts the search and avoids spuriously flagging matches as | |
1401 | * ambiguous. | |
1402 | * | |
1403 | * For both partial and absolute paths, the return value goes through | |
1404 | * a dynamic cast to @typename. This is important if either the link, | |
1405 | * or the typename itself are of interface types. | |
1406 | * | |
1407 | * Returns: The matched object or NULL on path lookup failure. | |
1408 | */ | |
1409 | Object *object_resolve_path_type(const char *path, const char *typename, | |
1410 | bool *ambiguous); | |
1411 | ||
a612b2a6 PB |
1412 | /** |
1413 | * object_resolve_path_component: | |
1414 | * @parent: the object in which to resolve the path | |
1415 | * @part: the component to resolve. | |
1416 | * | |
1417 | * This is similar to object_resolve_path with an absolute path, but it | |
1418 | * only resolves one element (@part) and takes the others from @parent. | |
1419 | * | |
1420 | * Returns: The resolved object or NULL on path lookup failure. | |
1421 | */ | |
3e84b483 | 1422 | Object *object_resolve_path_component(Object *parent, const gchar *part); |
a612b2a6 | 1423 | |
57c9fafe AL |
1424 | /** |
1425 | * object_property_add_child: | |
1426 | * @obj: the object to add a property to | |
1427 | * @name: the name of the property | |
1428 | * @child: the child object | |
0210b39d | 1429 | * @errp: if an error occurs, a pointer to an area to store the error |
57c9fafe AL |
1430 | * |
1431 | * Child properties form the composition tree. All objects need to be a child | |
1432 | * of another object. Objects can only be a child of one object. | |
1433 | * | |
1434 | * There is no way for a child to determine what its parent is. It is not | |
1435 | * a bidirectional relationship. This is by design. | |
358b5465 AB |
1436 | * |
1437 | * The value of a child property as a C string will be the child object's | |
1438 | * canonical path. It can be retrieved using object_property_get_str(). | |
1439 | * The child object itself can be retrieved using object_property_get_link(). | |
57c9fafe AL |
1440 | */ |
1441 | void object_property_add_child(Object *obj, const char *name, | |
e82df248 | 1442 | Object *child, Error **errp); |
57c9fafe | 1443 | |
9561fda8 SH |
1444 | typedef enum { |
1445 | /* Unref the link pointer when the property is deleted */ | |
265b578c | 1446 | OBJ_PROP_LINK_STRONG = 0x1, |
9561fda8 SH |
1447 | } ObjectPropertyLinkFlags; |
1448 | ||
39f72ef9 SH |
1449 | /** |
1450 | * object_property_allow_set_link: | |
1451 | * | |
1452 | * The default implementation of the object_property_add_link() check() | |
1453 | * callback function. It allows the link property to be set and never returns | |
1454 | * an error. | |
1455 | */ | |
8f5d58ef | 1456 | void object_property_allow_set_link(const Object *, const char *, |
39f72ef9 SH |
1457 | Object *, Error **); |
1458 | ||
57c9fafe AL |
1459 | /** |
1460 | * object_property_add_link: | |
1461 | * @obj: the object to add a property to | |
1462 | * @name: the name of the property | |
1463 | * @type: the qobj type of the link | |
1464 | * @child: a pointer to where the link object reference is stored | |
39f72ef9 | 1465 | * @check: callback to veto setting or NULL if the property is read-only |
9561fda8 | 1466 | * @flags: additional options for the link |
0210b39d | 1467 | * @errp: if an error occurs, a pointer to an area to store the error |
57c9fafe AL |
1468 | * |
1469 | * Links establish relationships between objects. Links are unidirectional | |
1470 | * although two links can be combined to form a bidirectional relationship | |
1471 | * between objects. | |
1472 | * | |
1473 | * Links form the graph in the object model. | |
6c232d2f | 1474 | * |
39f72ef9 SH |
1475 | * The <code>@check()</code> callback is invoked when |
1476 | * object_property_set_link() is called and can raise an error to prevent the | |
1477 | * link being set. If <code>@check</code> is NULL, the property is read-only | |
1478 | * and cannot be set. | |
1479 | * | |
6c232d2f PB |
1480 | * Ownership of the pointer that @child points to is transferred to the |
1481 | * link property. The reference count for <code>*@child</code> is | |
1482 | * managed by the property from after the function returns till the | |
9561fda8 | 1483 | * property is deleted with object_property_del(). If the |
265b578c MAL |
1484 | * <code>@flags</code> <code>OBJ_PROP_LINK_STRONG</code> bit is set, |
1485 | * the reference count is decremented when the property is deleted or | |
1486 | * modified. | |
57c9fafe AL |
1487 | */ |
1488 | void object_property_add_link(Object *obj, const char *name, | |
1489 | const char *type, Object **child, | |
8f5d58ef | 1490 | void (*check)(const Object *obj, const char *name, |
39f72ef9 | 1491 | Object *val, Error **errp), |
9561fda8 | 1492 | ObjectPropertyLinkFlags flags, |
e82df248 | 1493 | Error **errp); |
57c9fafe AL |
1494 | |
1495 | /** | |
1496 | * object_property_add_str: | |
1497 | * @obj: the object to add a property to | |
1498 | * @name: the name of the property | |
1499 | * @get: the getter or NULL if the property is write-only. This function must | |
1500 | * return a string to be freed by g_free(). | |
1501 | * @set: the setter or NULL if the property is read-only | |
1502 | * @errp: if an error occurs, a pointer to an area to store the error | |
1503 | * | |
1504 | * Add a string property using getters/setters. This function will add a | |
1505 | * property of type 'string'. | |
1506 | */ | |
1507 | void object_property_add_str(Object *obj, const char *name, | |
e82df248 MT |
1508 | char *(*get)(Object *, Error **), |
1509 | void (*set)(Object *, const char *, Error **), | |
1510 | Error **errp); | |
2f28d2ff | 1511 | |
16bf7f52 DB |
1512 | void object_class_property_add_str(ObjectClass *klass, const char *name, |
1513 | char *(*get)(Object *, Error **), | |
1514 | void (*set)(Object *, const char *, | |
1515 | Error **), | |
1516 | Error **errp); | |
1517 | ||
0e558843 AL |
1518 | /** |
1519 | * object_property_add_bool: | |
1520 | * @obj: the object to add a property to | |
1521 | * @name: the name of the property | |
1522 | * @get: the getter or NULL if the property is write-only. | |
1523 | * @set: the setter or NULL if the property is read-only | |
1524 | * @errp: if an error occurs, a pointer to an area to store the error | |
1525 | * | |
1526 | * Add a bool property using getters/setters. This function will add a | |
1527 | * property of type 'bool'. | |
1528 | */ | |
1529 | void object_property_add_bool(Object *obj, const char *name, | |
e82df248 MT |
1530 | bool (*get)(Object *, Error **), |
1531 | void (*set)(Object *, bool, Error **), | |
1532 | Error **errp); | |
0e558843 | 1533 | |
16bf7f52 DB |
1534 | void object_class_property_add_bool(ObjectClass *klass, const char *name, |
1535 | bool (*get)(Object *, Error **), | |
1536 | void (*set)(Object *, bool, Error **), | |
1537 | Error **errp); | |
1538 | ||
a8e3fbed DB |
1539 | /** |
1540 | * object_property_add_enum: | |
1541 | * @obj: the object to add a property to | |
1542 | * @name: the name of the property | |
1543 | * @typename: the name of the enum data type | |
1544 | * @get: the getter or %NULL if the property is write-only. | |
1545 | * @set: the setter or %NULL if the property is read-only | |
1546 | * @errp: if an error occurs, a pointer to an area to store the error | |
1547 | * | |
1548 | * Add an enum property using getters/setters. This function will add a | |
1549 | * property of type '@typename'. | |
1550 | */ | |
1551 | void object_property_add_enum(Object *obj, const char *name, | |
1552 | const char *typename, | |
f7abe0ec | 1553 | const QEnumLookup *lookup, |
a8e3fbed DB |
1554 | int (*get)(Object *, Error **), |
1555 | void (*set)(Object *, int, Error **), | |
1556 | Error **errp); | |
1557 | ||
16bf7f52 DB |
1558 | void object_class_property_add_enum(ObjectClass *klass, const char *name, |
1559 | const char *typename, | |
f7abe0ec | 1560 | const QEnumLookup *lookup, |
16bf7f52 DB |
1561 | int (*get)(Object *, Error **), |
1562 | void (*set)(Object *, int, Error **), | |
1563 | Error **errp); | |
1564 | ||
8e099d14 DG |
1565 | /** |
1566 | * object_property_add_tm: | |
1567 | * @obj: the object to add a property to | |
1568 | * @name: the name of the property | |
1569 | * @get: the getter or NULL if the property is write-only. | |
1570 | * @errp: if an error occurs, a pointer to an area to store the error | |
1571 | * | |
1572 | * Add a read-only struct tm valued property using a getter function. | |
1573 | * This function will add a property of type 'struct tm'. | |
1574 | */ | |
1575 | void object_property_add_tm(Object *obj, const char *name, | |
1576 | void (*get)(Object *, struct tm *, Error **), | |
1577 | Error **errp); | |
1578 | ||
16bf7f52 DB |
1579 | void object_class_property_add_tm(ObjectClass *klass, const char *name, |
1580 | void (*get)(Object *, struct tm *, Error **), | |
1581 | Error **errp); | |
1582 | ||
a25ebcac MT |
1583 | /** |
1584 | * object_property_add_uint8_ptr: | |
1585 | * @obj: the object to add a property to | |
1586 | * @name: the name of the property | |
1587 | * @v: pointer to value | |
1588 | * @errp: if an error occurs, a pointer to an area to store the error | |
1589 | * | |
1590 | * Add an integer property in memory. This function will add a | |
1591 | * property of type 'uint8'. | |
1592 | */ | |
1593 | void object_property_add_uint8_ptr(Object *obj, const char *name, | |
1594 | const uint8_t *v, Error **errp); | |
16bf7f52 DB |
1595 | void object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name, |
1596 | const uint8_t *v, Error **errp); | |
a25ebcac MT |
1597 | |
1598 | /** | |
1599 | * object_property_add_uint16_ptr: | |
1600 | * @obj: the object to add a property to | |
1601 | * @name: the name of the property | |
1602 | * @v: pointer to value | |
1603 | * @errp: if an error occurs, a pointer to an area to store the error | |
1604 | * | |
1605 | * Add an integer property in memory. This function will add a | |
1606 | * property of type 'uint16'. | |
1607 | */ | |
1608 | void object_property_add_uint16_ptr(Object *obj, const char *name, | |
1609 | const uint16_t *v, Error **errp); | |
16bf7f52 DB |
1610 | void object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name, |
1611 | const uint16_t *v, Error **errp); | |
a25ebcac MT |
1612 | |
1613 | /** | |
1614 | * object_property_add_uint32_ptr: | |
1615 | * @obj: the object to add a property to | |
1616 | * @name: the name of the property | |
1617 | * @v: pointer to value | |
1618 | * @errp: if an error occurs, a pointer to an area to store the error | |
1619 | * | |
1620 | * Add an integer property in memory. This function will add a | |
1621 | * property of type 'uint32'. | |
1622 | */ | |
1623 | void object_property_add_uint32_ptr(Object *obj, const char *name, | |
1624 | const uint32_t *v, Error **errp); | |
16bf7f52 DB |
1625 | void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name, |
1626 | const uint32_t *v, Error **errp); | |
a25ebcac MT |
1627 | |
1628 | /** | |
1629 | * object_property_add_uint64_ptr: | |
1630 | * @obj: the object to add a property to | |
1631 | * @name: the name of the property | |
1632 | * @v: pointer to value | |
1633 | * @errp: if an error occurs, a pointer to an area to store the error | |
1634 | * | |
1635 | * Add an integer property in memory. This function will add a | |
1636 | * property of type 'uint64'. | |
1637 | */ | |
1638 | void object_property_add_uint64_ptr(Object *obj, const char *name, | |
1639 | const uint64_t *v, Error **Errp); | |
16bf7f52 DB |
1640 | void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name, |
1641 | const uint64_t *v, Error **Errp); | |
a25ebcac | 1642 | |
ef7c7ff6 SH |
1643 | /** |
1644 | * object_property_add_alias: | |
1645 | * @obj: the object to add a property to | |
1646 | * @name: the name of the property | |
1647 | * @target_obj: the object to forward property access to | |
1648 | * @target_name: the name of the property on the forwarded object | |
1649 | * @errp: if an error occurs, a pointer to an area to store the error | |
1650 | * | |
1651 | * Add an alias for a property on an object. This function will add a property | |
1652 | * of the same type as the forwarded property. | |
1653 | * | |
1654 | * The caller must ensure that <code>@target_obj</code> stays alive as long as | |
1655 | * this property exists. In the case of a child object or an alias on the same | |
1656 | * object this will be the case. For aliases to other objects the caller is | |
1657 | * responsible for taking a reference. | |
1658 | */ | |
1659 | void object_property_add_alias(Object *obj, const char *name, | |
1660 | Object *target_obj, const char *target_name, | |
1661 | Error **errp); | |
1662 | ||
fb9e7e33 PB |
1663 | /** |
1664 | * object_property_add_const_link: | |
1665 | * @obj: the object to add a property to | |
1666 | * @name: the name of the property | |
1667 | * @target: the object to be referred by the link | |
1668 | * @errp: if an error occurs, a pointer to an area to store the error | |
1669 | * | |
1670 | * Add an unmodifiable link for a property on an object. This function will | |
1671 | * add a property of type link<TYPE> where TYPE is the type of @target. | |
1672 | * | |
1673 | * The caller must ensure that @target stays alive as long as | |
1674 | * this property exists. In the case @target is a child of @obj, | |
1675 | * this will be the case. Otherwise, the caller is responsible for | |
1676 | * taking a reference. | |
1677 | */ | |
1678 | void object_property_add_const_link(Object *obj, const char *name, | |
1679 | Object *target, Error **errp); | |
1680 | ||
80742642 GA |
1681 | /** |
1682 | * object_property_set_description: | |
1683 | * @obj: the object owning the property | |
1684 | * @name: the name of the property | |
1685 | * @description: the description of the property on the object | |
1686 | * @errp: if an error occurs, a pointer to an area to store the error | |
1687 | * | |
1688 | * Set an object property's description. | |
1689 | * | |
1690 | */ | |
1691 | void object_property_set_description(Object *obj, const char *name, | |
1692 | const char *description, Error **errp); | |
16bf7f52 DB |
1693 | void object_class_property_set_description(ObjectClass *klass, const char *name, |
1694 | const char *description, | |
1695 | Error **errp); | |
80742642 | 1696 | |
32efc535 PB |
1697 | /** |
1698 | * object_child_foreach: | |
1699 | * @obj: the object whose children will be navigated | |
1700 | * @fn: the iterator function to be called | |
1701 | * @opaque: an opaque value that will be passed to the iterator | |
1702 | * | |
1703 | * Call @fn passing each child of @obj and @opaque to it, until @fn returns | |
1704 | * non-zero. | |
1705 | * | |
b604a854 PF |
1706 | * It is forbidden to add or remove children from @obj from the @fn |
1707 | * callback. | |
1708 | * | |
32efc535 PB |
1709 | * Returns: The last value returned by @fn, or 0 if there is no child. |
1710 | */ | |
1711 | int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque), | |
1712 | void *opaque); | |
1713 | ||
d714b8de PC |
1714 | /** |
1715 | * object_child_foreach_recursive: | |
1716 | * @obj: the object whose children will be navigated | |
1717 | * @fn: the iterator function to be called | |
1718 | * @opaque: an opaque value that will be passed to the iterator | |
1719 | * | |
1720 | * Call @fn passing each child of @obj and @opaque to it, until @fn returns | |
1721 | * non-zero. Calls recursively, all child nodes of @obj will also be passed | |
1722 | * all the way down to the leaf nodes of the tree. Depth first ordering. | |
1723 | * | |
b604a854 PF |
1724 | * It is forbidden to add or remove children from @obj (or its |
1725 | * child nodes) from the @fn callback. | |
1726 | * | |
d714b8de PC |
1727 | * Returns: The last value returned by @fn, or 0 if there is no child. |
1728 | */ | |
1729 | int object_child_foreach_recursive(Object *obj, | |
1730 | int (*fn)(Object *child, void *opaque), | |
1731 | void *opaque); | |
a612b2a6 PB |
1732 | /** |
1733 | * container_get: | |
dfe47e70 | 1734 | * @root: root of the #path, e.g., object_get_root() |
a612b2a6 PB |
1735 | * @path: path to the container |
1736 | * | |
1737 | * Return a container object whose path is @path. Create more containers | |
1738 | * along the path if necessary. | |
1739 | * | |
1740 | * Returns: the container object. | |
1741 | */ | |
dfe47e70 | 1742 | Object *container_get(Object *root, const char *path); |
a612b2a6 | 1743 | |
3f97b53a BR |
1744 | /** |
1745 | * object_type_get_instance_size: | |
1746 | * @typename: Name of the Type whose instance_size is required | |
1747 | * | |
1748 | * Returns the instance_size of the given @typename. | |
1749 | */ | |
1750 | size_t object_type_get_instance_size(const char *typename); | |
2f28d2ff | 1751 | #endif |