1 #ifndef OBJECT_INTERFACES_H
2 #define OBJECT_INTERFACES_H
4 #include "qom/object.h"
5 #include "qapi/qmp/qdict.h"
6 #include "qapi/visitor.h"
8 #define TYPE_USER_CREATABLE "user-creatable"
10 #define USER_CREATABLE_CLASS(klass) \
11 OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
13 #define USER_CREATABLE_GET_CLASS(obj) \
14 OBJECT_GET_CLASS(UserCreatableClass, (obj), \
16 #define USER_CREATABLE(obj) \
17 INTERFACE_CHECK(UserCreatable, (obj), \
21 typedef struct UserCreatable
{
28 * @parent_class: the base class
29 * @complete: callback to be called after @obj's properties are set.
30 * @can_be_deleted: callback to be called before an object is removed
31 * to check if @obj can be removed safely.
33 * Interface is designed to work with -object/object-add/object_add
35 * Interface is mandatory for objects that are designed to be user
36 * creatable (i.e. -object/object-add/object_add, will accept only
37 * objects that inherit this interface).
39 * Interface also provides an optional ability to do the second
40 * stage * initialization of the object after its properties were
43 * For objects created without using -object/object-add/object_add,
44 * @user_creatable_complete() wrapper should be called manually if
45 * object's type implements USER_CREATABLE interface and needs
46 * complete() callback to be called.
48 typedef struct UserCreatableClass
{
50 InterfaceClass parent_class
;
53 void (*complete
)(UserCreatable
*uc
, Error
**errp
);
54 bool (*can_be_deleted
)(UserCreatable
*uc
, Error
**errp
);
58 * user_creatable_complete:
59 * @obj: the object whose complete() method is called if defined
60 * @errp: if an error occurs, a pointer to an area to store the error
62 * Wrapper to call complete() method if one of types it's inherited
63 * from implements USER_CREATABLE interface, otherwise the call does
66 void user_creatable_complete(Object
*obj
, Error
**errp
);
69 * user_creatable_can_be_deleted:
70 * @uc: the object whose can_be_deleted() method is called if implemented
71 * @errp: if an error occurs, a pointer to an area to store the error
73 * Wrapper to call can_be_deleted() method if one of types it's inherited
74 * from implements USER_CREATABLE interface.
76 bool user_creatable_can_be_deleted(UserCreatable
*uc
, Error
**errp
);
79 * user_creatable_add_type:
80 * @type: the object type name
81 * @id: the unique ID for the object
82 * @qdict: the object properties
84 * @errp: if an error occurs, a pointer to an area to store the error
86 * Create an instance of the user creatable object @type, placing
87 * it in the object composition tree with name @id, initializing
88 * it with properties from @qdict
90 * Returns: the newly created object or NULL on error
92 Object
*user_creatable_add_type(const char *type
, const char *id
,
94 Visitor
*v
, Error
**errp
);
97 * user_creatable_add_opts:
98 * @opts: the object definition
99 * @errp: if an error occurs, a pointer to an area to store the error
101 * Create an instance of the user creatable object whose type
102 * is defined in @opts by the 'qom-type' option, placing it
103 * in the object composition tree with name provided by the
104 * 'id' field. The remaining options in @opts are used to
105 * initialize the object properties.
107 * Returns: the newly created object or NULL on error
109 Object
*user_creatable_add_opts(QemuOpts
*opts
, Error
**errp
);
113 * user_creatable_add_opts_predicate:
114 * @type: the QOM type to be added
116 * A callback function to determine whether an object
117 * of type @type should be created. Instances of this
118 * callback should be passed to user_creatable_add_opts_foreach
120 typedef bool (*user_creatable_add_opts_predicate
)(const char *type
);
123 * user_creatable_add_opts_foreach:
124 * @opaque: a user_creatable_add_opts_predicate callback or NULL
125 * @opts: options to create
128 * An iterator callback to be used in conjunction with
129 * the qemu_opts_foreach() method for creating a list of
130 * objects from a set of QemuOpts
132 * The @opaque parameter can be passed a user_creatable_add_opts_predicate
133 * callback to filter which types of object are created during iteration.
134 * When it fails, report the error.
136 * Returns: 0 on success, -1 when an error was reported.
138 int user_creatable_add_opts_foreach(void *opaque
,
139 QemuOpts
*opts
, Error
**errp
);
142 * user_creatable_del:
143 * @id: the unique ID for the object
144 * @errp: if an error occurs, a pointer to an area to store the error
146 * Delete an instance of the user creatable object identified
149 void user_creatable_del(const char *id
, Error
**errp
);