4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
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.
13 #include "qemu/object.h"
14 #include "qemu-common.h"
15 #include "qapi/qapi-visit-core.h"
16 #include "qapi/string-input-visitor.h"
17 #include "qapi/string-output-visitor.h"
19 /* TODO: replace QObject with a simpler visitor to avoid a dependency
20 * of the QOM core on QObject? */
21 #include "qemu/qom-qobject.h"
27 #define MAX_INTERFACES 32
29 typedef struct InterfaceImpl InterfaceImpl
;
30 typedef struct TypeImpl TypeImpl
;
35 void (*interface_initfn
)(ObjectClass
*class, void *data
);
47 void (*class_init
)(ObjectClass
*klass
, void *data
);
48 void (*class_finalize
)(ObjectClass
*klass
, void *data
);
52 void (*instance_init
)(Object
*obj
);
53 void (*instance_finalize
)(Object
*obj
);
58 TypeImpl
*parent_type
;
63 InterfaceImpl interfaces
[MAX_INTERFACES
];
66 typedef struct Interface
72 #define INTERFACE(obj) OBJECT_CHECK(Interface, obj, TYPE_INTERFACE)
74 static Type type_interface
;
76 static GHashTable
*type_table_get(void)
78 static GHashTable
*type_table
;
80 if (type_table
== NULL
) {
81 type_table
= g_hash_table_new(g_str_hash
, g_str_equal
);
87 static void type_table_add(TypeImpl
*ti
)
89 g_hash_table_insert(type_table_get(), (void *)ti
->name
, ti
);
92 static TypeImpl
*type_table_lookup(const char *name
)
94 return g_hash_table_lookup(type_table_get(), name
);
97 TypeImpl
*type_register(const TypeInfo
*info
)
99 TypeImpl
*ti
= g_malloc0(sizeof(*ti
));
101 g_assert(info
->name
!= NULL
);
103 if (type_table_lookup(info
->name
) != NULL
) {
104 fprintf(stderr
, "Registering `%s' which already exists\n", info
->name
);
108 ti
->name
= g_strdup(info
->name
);
109 ti
->parent
= g_strdup(info
->parent
);
111 ti
->class_size
= info
->class_size
;
112 ti
->instance_size
= info
->instance_size
;
114 ti
->class_init
= info
->class_init
;
115 ti
->class_finalize
= info
->class_finalize
;
116 ti
->class_data
= info
->class_data
;
118 ti
->instance_init
= info
->instance_init
;
119 ti
->instance_finalize
= info
->instance_finalize
;
121 ti
->abstract
= info
->abstract
;
123 if (info
->interfaces
) {
126 for (i
= 0; info
->interfaces
[i
].type
; i
++) {
127 ti
->interfaces
[i
].parent
= info
->interfaces
[i
].type
;
128 ti
->interfaces
[i
].interface_initfn
= info
->interfaces
[i
].interface_initfn
;
129 ti
->num_interfaces
++;
138 TypeImpl
*type_register_static(const TypeInfo
*info
)
140 return type_register(info
);
143 static TypeImpl
*type_get_by_name(const char *name
)
149 return type_table_lookup(name
);
152 static TypeImpl
*type_get_parent(TypeImpl
*type
)
154 if (!type
->parent_type
&& type
->parent
) {
155 type
->parent_type
= type_get_by_name(type
->parent
);
156 g_assert(type
->parent_type
!= NULL
);
159 return type
->parent_type
;
162 static bool type_has_parent(TypeImpl
*type
)
164 return (type
->parent
!= NULL
);
167 static size_t type_class_get_size(TypeImpl
*ti
)
169 if (ti
->class_size
) {
170 return ti
->class_size
;
173 if (type_has_parent(ti
)) {
174 return type_class_get_size(type_get_parent(ti
));
177 return sizeof(ObjectClass
);
180 static size_t type_object_get_size(TypeImpl
*ti
)
182 if (ti
->instance_size
) {
183 return ti
->instance_size
;
186 if (type_has_parent(ti
)) {
187 return type_object_get_size(type_get_parent(ti
));
193 static void type_class_interface_init(TypeImpl
*ti
, InterfaceImpl
*iface
)
196 .instance_size
= sizeof(Interface
),
197 .parent
= iface
->parent
,
198 .class_size
= sizeof(InterfaceClass
),
199 .class_init
= iface
->interface_initfn
,
202 char *name
= g_strdup_printf("<%s::%s>", ti
->name
, iface
->parent
);
205 iface
->type
= type_register(&info
);
209 static void type_initialize(TypeImpl
*ti
)
211 size_t class_size
= sizeof(ObjectClass
);
218 ti
->class_size
= type_class_get_size(ti
);
219 ti
->instance_size
= type_object_get_size(ti
);
221 ti
->class = g_malloc0(ti
->class_size
);
222 ti
->class->type
= ti
;
224 if (type_has_parent(ti
)) {
225 TypeImpl
*parent
= type_get_parent(ti
);
227 type_initialize(parent
);
229 class_size
= parent
->class_size
;
230 g_assert(parent
->class_size
<= ti
->class_size
);
232 memcpy((void *)ti
->class + sizeof(ObjectClass
),
233 (void *)parent
->class + sizeof(ObjectClass
),
234 parent
->class_size
- sizeof(ObjectClass
));
237 memset((void *)ti
->class + class_size
, 0, ti
->class_size
- class_size
);
239 for (i
= 0; i
< ti
->num_interfaces
; i
++) {
240 type_class_interface_init(ti
, &ti
->interfaces
[i
]);
243 if (ti
->class_init
) {
244 ti
->class_init(ti
->class, ti
->class_data
);
248 static void object_interface_init(Object
*obj
, InterfaceImpl
*iface
)
250 TypeImpl
*ti
= iface
->type
;
251 Interface
*iface_obj
;
253 iface_obj
= INTERFACE(object_new(ti
->name
));
254 iface_obj
->obj
= obj
;
256 obj
->interfaces
= g_slist_prepend(obj
->interfaces
, iface_obj
);
259 static void object_init_with_type(Object
*obj
, TypeImpl
*ti
)
263 if (type_has_parent(ti
)) {
264 object_init_with_type(obj
, type_get_parent(ti
));
267 for (i
= 0; i
< ti
->num_interfaces
; i
++) {
268 object_interface_init(obj
, &ti
->interfaces
[i
]);
271 if (ti
->instance_init
) {
272 ti
->instance_init(obj
);
276 void object_initialize_with_type(void *data
, TypeImpl
*type
)
280 g_assert(type
!= NULL
);
281 type_initialize(type
);
283 g_assert(type
->instance_size
>= sizeof(Object
));
284 g_assert(type
->abstract
== false);
286 memset(obj
, 0, type
->instance_size
);
287 obj
->class = type
->class;
288 QTAILQ_INIT(&obj
->properties
);
289 object_init_with_type(obj
, type
);
292 void object_initialize(void *data
, const char *typename
)
294 TypeImpl
*type
= type_get_by_name(typename
);
296 object_initialize_with_type(data
, type
);
299 static inline bool object_property_is_child(ObjectProperty
*prop
)
301 return strstart(prop
->type
, "child<", NULL
);
304 static inline bool object_property_is_link(ObjectProperty
*prop
)
306 return strstart(prop
->type
, "link<", NULL
);
309 static void object_property_del_all(Object
*obj
)
311 while (!QTAILQ_EMPTY(&obj
->properties
)) {
312 ObjectProperty
*prop
= QTAILQ_FIRST(&obj
->properties
);
314 QTAILQ_REMOVE(&obj
->properties
, prop
, node
);
317 prop
->release(obj
, prop
->name
, prop
->opaque
);
326 static void object_property_del_child(Object
*obj
, Object
*child
, Error
**errp
)
328 ObjectProperty
*prop
;
330 QTAILQ_FOREACH(prop
, &obj
->properties
, node
) {
331 if (object_property_is_child(prop
) && prop
->opaque
== child
) {
332 object_property_del(obj
, prop
->name
, errp
);
338 void object_unparent(Object
*obj
)
341 object_property_del_child(obj
->parent
, obj
, NULL
);
345 static void object_deinit(Object
*obj
, TypeImpl
*type
)
347 if (type
->instance_finalize
) {
348 type
->instance_finalize(obj
);
351 while (obj
->interfaces
) {
352 Interface
*iface_obj
= obj
->interfaces
->data
;
353 obj
->interfaces
= g_slist_delete_link(obj
->interfaces
, obj
->interfaces
);
354 object_delete(OBJECT(iface_obj
));
357 if (type_has_parent(type
)) {
358 object_deinit(obj
, type_get_parent(type
));
361 object_unparent(obj
);
364 void object_finalize(void *data
)
367 TypeImpl
*ti
= obj
->class->type
;
369 object_deinit(obj
, ti
);
370 object_property_del_all(obj
);
372 g_assert(obj
->ref
== 0);
375 Object
*object_new_with_type(Type type
)
379 g_assert(type
!= NULL
);
380 type_initialize(type
);
382 obj
= g_malloc(type
->instance_size
);
383 object_initialize_with_type(obj
, type
);
389 Object
*object_new(const char *typename
)
391 TypeImpl
*ti
= type_get_by_name(typename
);
393 return object_new_with_type(ti
);
396 void object_delete(Object
*obj
)
399 g_assert(obj
->ref
== 0);
403 static bool type_is_ancestor(TypeImpl
*type
, TypeImpl
*target_type
)
407 /* Check if typename is a direct ancestor of type */
409 if (type
== target_type
) {
413 type
= type_get_parent(type
);
419 static bool object_is_type(Object
*obj
, TypeImpl
*target_type
)
421 return !target_type
|| type_is_ancestor(obj
->class->type
, target_type
);
424 Object
*object_dynamic_cast(Object
*obj
, const char *typename
)
426 TypeImpl
*target_type
= type_get_by_name(typename
);
429 /* Check if typename is a direct ancestor. Special-case TYPE_OBJECT,
430 * we want to go back from interfaces to the parent.
432 if (target_type
&& object_is_type(obj
, target_type
)) {
436 /* Check if obj is an interface and its containing object is a direct
437 * ancestor of typename. In principle we could do this test at the very
438 * beginning of object_dynamic_cast, avoiding a second call to
439 * object_is_type. However, casting between interfaces is relatively
440 * rare, and object_is_type(obj, type_interface) would fail almost always.
442 * Perhaps we could add a magic value to the object header for increased
443 * (run-time) type safety and to speed up tests like this one. If we ever
444 * do that we can revisit the order here.
446 if (object_is_type(obj
, type_interface
)) {
447 assert(!obj
->interfaces
);
448 obj
= INTERFACE(obj
)->obj
;
449 if (object_is_type(obj
, target_type
)) {
458 /* Check if obj has an interface of typename */
459 for (i
= obj
->interfaces
; i
; i
= i
->next
) {
460 Interface
*iface
= i
->data
;
462 if (object_is_type(OBJECT(iface
), target_type
)) {
463 return OBJECT(iface
);
471 static void register_types(void)
473 static TypeInfo interface_info
= {
474 .name
= TYPE_INTERFACE
,
475 .instance_size
= sizeof(Interface
),
479 type_interface
= type_register_static(&interface_info
);
482 type_init(register_types
)
484 Object
*object_dynamic_cast_assert(Object
*obj
, const char *typename
)
488 inst
= object_dynamic_cast(obj
, typename
);
491 fprintf(stderr
, "Object %p is not an instance of type %s\n",
499 ObjectClass
*object_class_dynamic_cast(ObjectClass
*class,
500 const char *typename
)
502 TypeImpl
*target_type
= type_get_by_name(typename
);
503 TypeImpl
*type
= class->type
;
506 if (type
== target_type
) {
510 type
= type_get_parent(type
);
516 ObjectClass
*object_class_dynamic_cast_assert(ObjectClass
*class,
517 const char *typename
)
519 ObjectClass
*ret
= object_class_dynamic_cast(class, typename
);
522 fprintf(stderr
, "Object %p is not an instance of type %s\n",
530 const char *object_get_typename(Object
*obj
)
532 return obj
->class->type
->name
;
535 ObjectClass
*object_get_class(Object
*obj
)
540 const char *object_class_get_name(ObjectClass
*klass
)
542 return klass
->type
->name
;
545 ObjectClass
*object_class_by_name(const char *typename
)
547 TypeImpl
*type
= type_get_by_name(typename
);
553 type_initialize(type
);
558 ObjectClass
*object_class_get_parent(ObjectClass
*class)
560 TypeImpl
*type
= type_get_parent(class->type
);
566 type_initialize(type
);
571 typedef struct OCFData
573 void (*fn
)(ObjectClass
*klass
, void *opaque
);
574 const char *implements_type
;
575 bool include_abstract
;
579 static void object_class_foreach_tramp(gpointer key
, gpointer value
,
582 OCFData
*data
= opaque
;
583 TypeImpl
*type
= value
;
586 type_initialize(type
);
589 if (!data
->include_abstract
&& type
->abstract
) {
593 if (data
->implements_type
&&
594 !object_class_dynamic_cast(k
, data
->implements_type
)) {
598 data
->fn(k
, data
->opaque
);
601 void object_class_foreach(void (*fn
)(ObjectClass
*klass
, void *opaque
),
602 const char *implements_type
, bool include_abstract
,
605 OCFData data
= { fn
, implements_type
, include_abstract
, opaque
};
607 g_hash_table_foreach(type_table_get(), object_class_foreach_tramp
, &data
);
610 static void object_class_get_list_tramp(ObjectClass
*klass
, void *opaque
)
612 GSList
**list
= opaque
;
614 *list
= g_slist_prepend(*list
, klass
);
617 GSList
*object_class_get_list(const char *implements_type
,
618 bool include_abstract
)
622 object_class_foreach(object_class_get_list_tramp
,
623 implements_type
, include_abstract
, &list
);
627 void object_ref(Object
*obj
)
632 void object_unref(Object
*obj
)
634 g_assert(obj
->ref
> 0);
637 /* parent always holds a reference to its children */
639 object_finalize(obj
);
643 void object_property_add(Object
*obj
, const char *name
, const char *type
,
644 ObjectPropertyAccessor
*get
,
645 ObjectPropertyAccessor
*set
,
646 ObjectPropertyRelease
*release
,
647 void *opaque
, Error
**errp
)
649 ObjectProperty
*prop
= g_malloc0(sizeof(*prop
));
651 prop
->name
= g_strdup(name
);
652 prop
->type
= g_strdup(type
);
656 prop
->release
= release
;
657 prop
->opaque
= opaque
;
659 QTAILQ_INSERT_TAIL(&obj
->properties
, prop
, node
);
662 static ObjectProperty
*object_property_find(Object
*obj
, const char *name
)
664 ObjectProperty
*prop
;
666 QTAILQ_FOREACH(prop
, &obj
->properties
, node
) {
667 if (strcmp(prop
->name
, name
) == 0) {
675 void object_property_del(Object
*obj
, const char *name
, Error
**errp
)
677 ObjectProperty
*prop
= object_property_find(obj
, name
);
679 QTAILQ_REMOVE(&obj
->properties
, prop
, node
);
681 prop
->release(obj
, prop
->name
, prop
->opaque
);
688 void object_property_get(Object
*obj
, Visitor
*v
, const char *name
,
691 ObjectProperty
*prop
= object_property_find(obj
, name
);
694 error_set(errp
, QERR_PROPERTY_NOT_FOUND
, "", name
);
699 error_set(errp
, QERR_PERMISSION_DENIED
);
701 prop
->get(obj
, v
, prop
->opaque
, name
, errp
);
705 void object_property_set(Object
*obj
, Visitor
*v
, const char *name
,
708 ObjectProperty
*prop
= object_property_find(obj
, name
);
711 error_set(errp
, QERR_PROPERTY_NOT_FOUND
, "", name
);
716 error_set(errp
, QERR_PERMISSION_DENIED
);
718 prop
->set(obj
, v
, prop
->opaque
, name
, errp
);
722 void object_property_set_str(Object
*obj
, const char *value
,
723 const char *name
, Error
**errp
)
725 QString
*qstr
= qstring_from_str(value
);
726 object_property_set_qobject(obj
, QOBJECT(qstr
), name
, errp
);
731 char *object_property_get_str(Object
*obj
, const char *name
,
734 QObject
*ret
= object_property_get_qobject(obj
, name
, errp
);
741 qstring
= qobject_to_qstring(ret
);
743 error_set(errp
, QERR_INVALID_PARAMETER_TYPE
, name
, "string");
746 retval
= g_strdup(qstring_get_str(qstring
));
753 void object_property_set_link(Object
*obj
, Object
*value
,
754 const char *name
, Error
**errp
)
756 object_property_set_str(obj
, object_get_canonical_path(value
),
760 Object
*object_property_get_link(Object
*obj
, const char *name
,
763 char *str
= object_property_get_str(obj
, name
, errp
);
764 Object
*target
= NULL
;
767 target
= object_resolve_path(str
, NULL
);
769 error_set(errp
, QERR_DEVICE_NOT_FOUND
, str
);
777 void object_property_set_bool(Object
*obj
, bool value
,
778 const char *name
, Error
**errp
)
780 QBool
*qbool
= qbool_from_int(value
);
781 object_property_set_qobject(obj
, QOBJECT(qbool
), name
, errp
);
786 bool object_property_get_bool(Object
*obj
, const char *name
,
789 QObject
*ret
= object_property_get_qobject(obj
, name
, errp
);
796 qbool
= qobject_to_qbool(ret
);
798 error_set(errp
, QERR_INVALID_PARAMETER_TYPE
, name
, "boolean");
801 retval
= qbool_get_int(qbool
);
808 void object_property_set_int(Object
*obj
, int64_t value
,
809 const char *name
, Error
**errp
)
811 QInt
*qint
= qint_from_int(value
);
812 object_property_set_qobject(obj
, QOBJECT(qint
), name
, errp
);
817 int64_t object_property_get_int(Object
*obj
, const char *name
,
820 QObject
*ret
= object_property_get_qobject(obj
, name
, errp
);
827 qint
= qobject_to_qint(ret
);
829 error_set(errp
, QERR_INVALID_PARAMETER_TYPE
, name
, "int");
832 retval
= qint_get_int(qint
);
839 void object_property_parse(Object
*obj
, const char *string
,
840 const char *name
, Error
**errp
)
842 StringInputVisitor
*mi
;
843 mi
= string_input_visitor_new(string
);
844 object_property_set(obj
, string_input_get_visitor(mi
), name
, errp
);
846 string_input_visitor_cleanup(mi
);
849 char *object_property_print(Object
*obj
, const char *name
,
852 StringOutputVisitor
*mo
;
855 mo
= string_output_visitor_new();
856 object_property_get(obj
, string_output_get_visitor(mo
), name
, errp
);
857 string
= string_output_get_string(mo
);
858 string_output_visitor_cleanup(mo
);
862 const char *object_property_get_type(Object
*obj
, const char *name
, Error
**errp
)
864 ObjectProperty
*prop
= object_property_find(obj
, name
);
867 error_set(errp
, QERR_PROPERTY_NOT_FOUND
, "", name
);
874 Object
*object_get_root(void)
879 root
= object_new("container");
885 static void object_get_child_property(Object
*obj
, Visitor
*v
, void *opaque
,
886 const char *name
, Error
**errp
)
888 Object
*child
= opaque
;
891 path
= object_get_canonical_path(child
);
892 visit_type_str(v
, &path
, name
, errp
);
896 static void object_finalize_child_property(Object
*obj
, const char *name
,
899 Object
*child
= opaque
;
904 void object_property_add_child(Object
*obj
, const char *name
,
905 Object
*child
, Error
**errp
)
909 /* Registering an interface object in the composition tree will mightily
910 * confuse object_get_canonical_path (which, on the other hand, knows how
911 * to get the canonical path of an interface object).
913 assert(!object_is_type(obj
, type_interface
));
915 type
= g_strdup_printf("child<%s>", object_get_typename(OBJECT(child
)));
917 object_property_add(obj
, name
, type
, object_get_child_property
,
918 NULL
, object_finalize_child_property
, child
, errp
);
921 g_assert(child
->parent
== NULL
);
927 static void object_get_link_property(Object
*obj
, Visitor
*v
, void *opaque
,
928 const char *name
, Error
**errp
)
930 Object
**child
= opaque
;
934 path
= object_get_canonical_path(*child
);
935 visit_type_str(v
, &path
, name
, errp
);
939 visit_type_str(v
, &path
, name
, errp
);
943 static void object_set_link_property(Object
*obj
, Visitor
*v
, void *opaque
,
944 const char *name
, Error
**errp
)
946 Object
**child
= opaque
;
948 bool ambiguous
= false;
953 type
= object_property_get_type(obj
, name
, NULL
);
955 visit_type_str(v
, &path
, name
, errp
);
960 if (strcmp(path
, "") != 0) {
963 /* Go from link<FOO> to FOO. */
964 target_type
= g_strndup(&type
[5], strlen(type
) - 6);
965 target
= object_resolve_path_type(path
, target_type
, &ambiguous
);
968 error_set(errp
, QERR_AMBIGUOUS_PATH
, path
);
973 target
= object_resolve_path(path
, &ambiguous
);
974 if (target
|| ambiguous
) {
975 error_set(errp
, QERR_INVALID_PARAMETER_TYPE
, name
, target_type
);
977 error_set(errp
, QERR_DEVICE_NOT_FOUND
, path
);
985 if (old_target
!= NULL
) {
986 object_unref(old_target
);
990 void object_property_add_link(Object
*obj
, const char *name
,
991 const char *type
, Object
**child
,
996 full_type
= g_strdup_printf("link<%s>", type
);
998 object_property_add(obj
, name
, full_type
,
999 object_get_link_property
,
1000 object_set_link_property
,
1006 gchar
*object_get_canonical_path(Object
*obj
)
1008 Object
*root
= object_get_root();
1009 char *newpath
= NULL
, *path
= NULL
;
1011 if (object_is_type(obj
, type_interface
)) {
1012 obj
= INTERFACE(obj
)->obj
;
1015 while (obj
!= root
) {
1016 ObjectProperty
*prop
= NULL
;
1018 g_assert(obj
->parent
!= NULL
);
1020 QTAILQ_FOREACH(prop
, &obj
->parent
->properties
, node
) {
1021 if (!object_property_is_child(prop
)) {
1025 if (prop
->opaque
== obj
) {
1027 newpath
= g_strdup_printf("%s/%s", prop
->name
, path
);
1031 path
= g_strdup(prop
->name
);
1037 g_assert(prop
!= NULL
);
1042 newpath
= g_strdup_printf("/%s", path
);
1048 Object
*object_resolve_path_component(Object
*parent
, gchar
*part
)
1050 ObjectProperty
*prop
= object_property_find(parent
, part
);
1055 if (object_property_is_link(prop
)) {
1056 return *(Object
**)prop
->opaque
;
1057 } else if (object_property_is_child(prop
)) {
1058 return prop
->opaque
;
1064 static Object
*object_resolve_abs_path(Object
*parent
,
1066 const char *typename
,
1071 if (parts
[index
] == NULL
) {
1072 return object_dynamic_cast(parent
, typename
);
1075 if (strcmp(parts
[index
], "") == 0) {
1076 return object_resolve_abs_path(parent
, parts
, typename
, index
+ 1);
1079 child
= object_resolve_path_component(parent
, parts
[index
]);
1084 return object_resolve_abs_path(child
, parts
, typename
, index
+ 1);
1087 static Object
*object_resolve_partial_path(Object
*parent
,
1089 const char *typename
,
1093 ObjectProperty
*prop
;
1095 obj
= object_resolve_abs_path(parent
, parts
, typename
, 0);
1097 QTAILQ_FOREACH(prop
, &parent
->properties
, node
) {
1100 if (!object_property_is_child(prop
)) {
1104 found
= object_resolve_partial_path(prop
->opaque
, parts
,
1105 typename
, ambiguous
);
1116 if (ambiguous
&& *ambiguous
) {
1124 Object
*object_resolve_path_type(const char *path
, const char *typename
,
1127 bool partial_path
= true;
1131 parts
= g_strsplit(path
, "/", 0);
1132 if (parts
== NULL
|| parts
[0] == NULL
) {
1134 return object_get_root();
1137 if (strcmp(parts
[0], "") == 0) {
1138 partial_path
= false;
1145 obj
= object_resolve_partial_path(object_get_root(), parts
,
1146 typename
, ambiguous
);
1148 obj
= object_resolve_abs_path(object_get_root(), parts
, typename
, 1);
1156 Object
*object_resolve_path(const char *path
, bool *ambiguous
)
1158 return object_resolve_path_type(path
, TYPE_OBJECT
, ambiguous
);
1161 typedef struct StringProperty
1163 char *(*get
)(Object
*, Error
**);
1164 void (*set
)(Object
*, const char *, Error
**);
1167 static void property_get_str(Object
*obj
, Visitor
*v
, void *opaque
,
1168 const char *name
, Error
**errp
)
1170 StringProperty
*prop
= opaque
;
1173 value
= prop
->get(obj
, errp
);
1175 visit_type_str(v
, &value
, name
, errp
);
1180 static void property_set_str(Object
*obj
, Visitor
*v
, void *opaque
,
1181 const char *name
, Error
**errp
)
1183 StringProperty
*prop
= opaque
;
1185 Error
*local_err
= NULL
;
1187 visit_type_str(v
, &value
, name
, &local_err
);
1189 error_propagate(errp
, local_err
);
1193 prop
->set(obj
, value
, errp
);
1197 static void property_release_str(Object
*obj
, const char *name
,
1200 StringProperty
*prop
= opaque
;
1204 void object_property_add_str(Object
*obj
, const char *name
,
1205 char *(*get
)(Object
*, Error
**),
1206 void (*set
)(Object
*, const char *, Error
**),
1209 StringProperty
*prop
= g_malloc0(sizeof(*prop
));
1214 object_property_add(obj
, name
, "string",
1215 get
? property_get_str
: NULL
,
1216 set
? property_set_str
: NULL
,
1217 property_release_str
,