xref: /qemu/include/qom/object_interfaces.h (revision 72ac97cd)
1 #ifndef OBJECT_INTERFACES_H
2 #define OBJECT_INTERFACES_H
3 
4 #include "qom/object.h"
5 
6 #define TYPE_USER_CREATABLE "user-creatable"
7 
8 #define USER_CREATABLE_CLASS(klass) \
9      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
10                         TYPE_USER_CREATABLE)
11 #define USER_CREATABLE_GET_CLASS(obj) \
12      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
13                       TYPE_USER_CREATABLE)
14 #define USER_CREATABLE(obj) \
15      INTERFACE_CHECK(UserCreatable, (obj), \
16                      TYPE_USER_CREATABLE)
17 
18 
19 typedef struct UserCreatable {
20     /* <private> */
21     Object Parent;
22 } UserCreatable;
23 
24 /**
25  * UserCreatableClass:
26  * @parent_class: the base class
27  * @complete: callback to be called after @obj's properties are set.
28  *
29  * Interface is designed to work with -object/object-add/object_add
30  * commands.
31  * Interface is mandatory for objects that are designed to be user
32  * creatable (i.e. -object/object-add/object_add, will accept only
33  * objects that inherit this interface).
34  *
35  * Interface also provides an optional ability to do the second
36  * stage * initialization of the object after its properties were
37  * set.
38  *
39  * For objects created without using -object/object-add/object_add,
40  * @user_creatable_complete() wrapper should be called manually if
41  * object's type implements USER_CREATABLE interface and needs
42  * complete() callback to be called.
43  */
44 typedef struct UserCreatableClass {
45     /* <private> */
46     InterfaceClass parent_class;
47 
48     /* <public> */
49     void (*complete)(UserCreatable *uc, Error **errp);
50 } UserCreatableClass;
51 
52 /**
53  * user_creatable_complete:
54  * @obj: the object whose complete() method is called if defined
55  * @errp: if an error occurs, a pointer to an area to store the error
56  *
57  * Wrapper to call complete() method if one of types it's inherited
58  * from implements USER_CREATABLE interface, otherwise the call does
59  * nothing.
60  */
61 void user_creatable_complete(Object *obj, Error **errp);
62 #endif
63