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