2014-01-16 20:34:38 +04:00
|
|
|
#ifndef OBJECT_INTERFACES_H
|
|
|
|
#define OBJECT_INTERFACES_H
|
|
|
|
|
|
|
|
#include "qom/object.h"
|
2021-02-17 14:06:20 +03:00
|
|
|
#include "qapi/qapi-types-qom.h"
|
2016-02-10 21:40:59 +03:00
|
|
|
#include "qapi/visitor.h"
|
2014-01-16 20:34:38 +04:00
|
|
|
|
|
|
|
#define TYPE_USER_CREATABLE "user-creatable"
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct UserCreatableClass UserCreatableClass;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_CLASS_CHECKERS(UserCreatableClass, USER_CREATABLE,
|
|
|
|
TYPE_USER_CREATABLE)
|
2014-01-16 20:34:38 +04:00
|
|
|
#define USER_CREATABLE(obj) \
|
|
|
|
INTERFACE_CHECK(UserCreatable, (obj), \
|
|
|
|
TYPE_USER_CREATABLE)
|
|
|
|
|
2018-12-04 17:20:06 +03:00
|
|
|
typedef struct UserCreatable UserCreatable;
|
2014-01-16 20:34:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UserCreatableClass:
|
|
|
|
* @parent_class: the base class
|
|
|
|
* @complete: callback to be called after @obj's properties are set.
|
2015-03-30 11:36:28 +03:00
|
|
|
* @can_be_deleted: callback to be called before an object is removed
|
|
|
|
* to check if @obj can be removed safely.
|
2014-01-16 20:34:38 +04:00
|
|
|
*
|
|
|
|
* Interface is designed to work with -object/object-add/object_add
|
|
|
|
* commands.
|
|
|
|
* Interface is mandatory for objects that are designed to be user
|
|
|
|
* creatable (i.e. -object/object-add/object_add, will accept only
|
|
|
|
* objects that inherit this interface).
|
|
|
|
*
|
|
|
|
* Interface also provides an optional ability to do the second
|
|
|
|
* stage * initialization of the object after its properties were
|
|
|
|
* set.
|
|
|
|
*
|
|
|
|
* For objects created without using -object/object-add/object_add,
|
|
|
|
* @user_creatable_complete() wrapper should be called manually if
|
|
|
|
* object's type implements USER_CREATABLE interface and needs
|
|
|
|
* complete() callback to be called.
|
|
|
|
*/
|
2020-09-03 23:43:22 +03:00
|
|
|
struct UserCreatableClass {
|
2014-01-16 20:34:38 +04:00
|
|
|
/* <private> */
|
|
|
|
InterfaceClass parent_class;
|
|
|
|
|
|
|
|
/* <public> */
|
|
|
|
void (*complete)(UserCreatable *uc, Error **errp);
|
2017-08-30 01:03:37 +03:00
|
|
|
bool (*can_be_deleted)(UserCreatable *uc);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2014-01-16 20:34:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* user_creatable_complete:
|
2018-12-04 17:20:07 +03:00
|
|
|
* @uc: the user-creatable object whose complete() method is called if defined
|
2014-01-16 20:34:38 +04:00
|
|
|
* @errp: if an error occurs, a pointer to an area to store the error
|
|
|
|
*
|
|
|
|
* Wrapper to call complete() method if one of types it's inherited
|
|
|
|
* from implements USER_CREATABLE interface, otherwise the call does
|
|
|
|
* nothing.
|
2020-07-07 19:05:55 +03:00
|
|
|
*
|
|
|
|
* Returns: %true on success, %false on failure.
|
2014-01-16 20:34:38 +04:00
|
|
|
*/
|
2020-07-07 19:05:55 +03:00
|
|
|
bool user_creatable_complete(UserCreatable *uc, Error **errp);
|
2015-03-30 11:36:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* user_creatable_can_be_deleted:
|
|
|
|
* @uc: the object whose can_be_deleted() method is called if implemented
|
|
|
|
*
|
|
|
|
* Wrapper to call can_be_deleted() method if one of types it's inherited
|
|
|
|
* from implements USER_CREATABLE interface.
|
|
|
|
*/
|
2017-08-30 01:03:37 +03:00
|
|
|
bool user_creatable_can_be_deleted(UserCreatable *uc);
|
2016-02-10 21:40:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* user_creatable_add_type:
|
|
|
|
* @type: the object type name
|
|
|
|
* @id: the unique ID for the object
|
|
|
|
* @qdict: the object properties
|
|
|
|
* @v: the visitor
|
|
|
|
* @errp: if an error occurs, a pointer to an area to store the error
|
|
|
|
*
|
|
|
|
* Create an instance of the user creatable object @type, placing
|
|
|
|
* it in the object composition tree with name @id, initializing
|
|
|
|
* it with properties from @qdict
|
|
|
|
*
|
|
|
|
* Returns: the newly created object or NULL on error
|
|
|
|
*/
|
|
|
|
Object *user_creatable_add_type(const char *type, const char *id,
|
|
|
|
const QDict *qdict,
|
|
|
|
Visitor *v, Error **errp);
|
|
|
|
|
2021-02-17 14:06:20 +03:00
|
|
|
/**
|
|
|
|
* user_creatable_add_qapi:
|
|
|
|
* @options: the object definition
|
|
|
|
* @errp: if an error occurs, a pointer to an area to store the error
|
|
|
|
*
|
|
|
|
* Create an instance of the user creatable object according to the
|
|
|
|
* options passed in @opts as described in the QAPI schema documentation.
|
|
|
|
*/
|
|
|
|
void user_creatable_add_qapi(ObjectOptions *options, Error **errp);
|
|
|
|
|
2021-02-19 20:14:01 +03:00
|
|
|
/**
|
|
|
|
* user_creatable_parse_str:
|
2023-10-04 15:00:11 +03:00
|
|
|
* @str: the object definition string as passed on the command line
|
2021-02-19 20:14:01 +03:00
|
|
|
* @errp: if an error occurs, a pointer to an area to store the error
|
|
|
|
*
|
|
|
|
* Parses the option for the user creatable object with a keyval parser and
|
|
|
|
* implicit key 'qom-type', converting the result to ObjectOptions.
|
|
|
|
*
|
|
|
|
* If a help option is given, print help instead.
|
|
|
|
*
|
|
|
|
* Returns: ObjectOptions on success, NULL when an error occurred (*errp is set
|
|
|
|
* then) or help was printed (*errp is not set).
|
|
|
|
*/
|
2023-10-04 15:00:11 +03:00
|
|
|
ObjectOptions *user_creatable_parse_str(const char *str, Error **errp);
|
2021-02-19 20:14:01 +03:00
|
|
|
|
2021-02-17 16:59:06 +03:00
|
|
|
/**
|
|
|
|
* user_creatable_add_from_str:
|
2023-10-04 15:00:11 +03:00
|
|
|
* @str: the object definition string as passed on the command line
|
2021-02-17 16:59:06 +03:00
|
|
|
* @errp: if an error occurs, a pointer to an area to store the error
|
|
|
|
*
|
2023-10-04 15:00:11 +03:00
|
|
|
* Create an instance of the user creatable object by parsing @str
|
2021-02-17 16:59:06 +03:00
|
|
|
* with a keyval parser and implicit key 'qom-type', converting the
|
|
|
|
* result to ObjectOptions and calling into qmp_object_add().
|
|
|
|
*
|
|
|
|
* If a help option is given, print help instead.
|
|
|
|
*
|
|
|
|
* Returns: true when an object was successfully created, false when an error
|
|
|
|
* occurred (*errp is set then) or help was printed (*errp is not set).
|
|
|
|
*/
|
2023-10-04 15:00:11 +03:00
|
|
|
bool user_creatable_add_from_str(const char *str, Error **errp);
|
2021-02-17 16:59:06 +03:00
|
|
|
|
2021-02-17 14:06:20 +03:00
|
|
|
/**
|
|
|
|
* user_creatable_process_cmdline:
|
2023-10-04 15:00:11 +03:00
|
|
|
* @cmdline: the object definition string as passed on the command line
|
2021-02-17 14:06:20 +03:00
|
|
|
*
|
2023-10-04 15:00:11 +03:00
|
|
|
* Create an instance of the user creatable object by parsing @cmdline
|
2021-02-17 14:06:20 +03:00
|
|
|
* with a keyval parser and implicit key 'qom-type', converting the
|
|
|
|
* result to ObjectOptions and calling into qmp_object_add().
|
|
|
|
*
|
|
|
|
* If a help option is given, print help instead and exit.
|
|
|
|
*
|
|
|
|
* This function is only meant to be called during command line parsing.
|
|
|
|
* It exits the process on failure or after printing help.
|
|
|
|
*/
|
2023-10-04 15:00:11 +03:00
|
|
|
void user_creatable_process_cmdline(const char *cmdline);
|
2021-02-17 14:06:20 +03:00
|
|
|
|
2019-10-11 20:20:12 +03:00
|
|
|
/**
|
|
|
|
* user_creatable_print_help:
|
|
|
|
* @type: the QOM type to be added
|
|
|
|
* @opts: options to create
|
|
|
|
*
|
2020-10-07 19:49:02 +03:00
|
|
|
* Prints help if requested in @type or @opts. Note that if @type is neither
|
|
|
|
* "help"/"?" nor a valid user creatable type, no help will be printed
|
|
|
|
* regardless of @opts.
|
2019-10-11 20:20:12 +03:00
|
|
|
*
|
2020-10-07 19:49:02 +03:00
|
|
|
* Returns: true if a help option was found and help was printed, false
|
|
|
|
* otherwise.
|
2019-10-11 20:20:12 +03:00
|
|
|
*/
|
|
|
|
bool user_creatable_print_help(const char *type, QemuOpts *opts);
|
|
|
|
|
2016-02-10 21:40:59 +03:00
|
|
|
/**
|
|
|
|
* user_creatable_del:
|
|
|
|
* @id: the unique ID for the object
|
|
|
|
* @errp: if an error occurs, a pointer to an area to store the error
|
|
|
|
*
|
|
|
|
* Delete an instance of the user creatable object identified
|
|
|
|
* by @id.
|
2020-07-07 19:05:55 +03:00
|
|
|
*
|
|
|
|
* Returns: %true on success, %false on failure.
|
2016-02-10 21:40:59 +03:00
|
|
|
*/
|
2020-07-07 19:05:55 +03:00
|
|
|
bool user_creatable_del(const char *id, Error **errp);
|
2016-02-10 21:40:59 +03:00
|
|
|
|
2017-08-24 22:23:13 +03:00
|
|
|
/**
|
|
|
|
* user_creatable_cleanup:
|
|
|
|
*
|
|
|
|
* Delete all user-creatable objects and the user-creatable
|
|
|
|
* objects container.
|
|
|
|
*/
|
|
|
|
void user_creatable_cleanup(void);
|
|
|
|
|
2014-01-16 20:34:38 +04:00
|
|
|
#endif
|