* NULL);
*
* if (!obj) {
- * g_printerr("Cannot create memory backend: %s\n",
- * error_get_pretty(err));
+ * error_reportf_err(err, "Cannot create memory backend: ");
* }
* </programlisting>
* </example>
Error **errp,
va_list vargs);
-void object_apply_global_props(Object *obj, const GPtrArray *props,
+bool object_apply_global_props(Object *obj, const GPtrArray *props,
Error **errp);
void object_set_machine_compat_props(GPtrArray *compat_props);
void object_set_accelerator_compat_props(GPtrArray *compat_props);
* Error *err = NULL;
* Object *obj = ...get / create object...;
*
- * obj = object_set_props(obj,
- * &err,
- * "share", "yes",
- * "mem-path", "/dev/shm/somefile",
- * "prealloc", "yes",
- * "size", "1048576",
- * NULL);
- *
- * if (!obj) {
- * g_printerr("Cannot set properties: %s\n",
- * error_get_pretty(err));
+ * if (!object_set_props(obj,
+ * &err,
+ * "share", "yes",
+ * "mem-path", "/dev/shm/somefile",
+ * "prealloc", "yes",
+ * "size", "1048576",
+ * NULL)) {
+ * error_reportf_err(err, "Cannot set properties: ");
* }
* </programlisting>
* </example>
* The returned object will have one stable reference maintained
* for as long as it is present in the object hierarchy.
*
- * Returns: -1 on error, 0 on success
+ * Returns: %true on success, %false on error.
*/
-int object_set_props(Object *obj,
- Error **errp,
- ...) QEMU_SENTINEL;
+bool object_set_props(Object *obj, Error **errp, ...) QEMU_SENTINEL;
/**
* object_set_propv:
*
* See object_set_props() for documentation.
*
- * Returns: -1 on error, 0 on success
+ * Returns: %true on success, %false on error.
*/
-int object_set_propv(Object *obj,
- Error **errp,
- va_list vargs);
+bool object_set_propv(Object *obj, Error **errp, va_list vargs);
/**
* object_initialize:
void object_initialize(void *obj, size_t size, const char *typename);
/**
- * object_initialize_child:
+ * object_initialize_child_with_props:
* @parentobj: The parent object to add a property to
* @propname: The name of the property
* @childobj: A pointer to the memory to be used for the object.
* strings. The propname of %NULL indicates the end of the property list.
* If the object implements the user creatable interface, the object will
* be marked complete once all the properties have been processed.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_initialize_child(Object *parentobj, const char *propname,
+bool object_initialize_child_with_props(Object *parentobj,
+ const char *propname,
void *childobj, size_t size, const char *type,
Error **errp, ...) QEMU_SENTINEL;
/**
- * object_initialize_childv:
+ * object_initialize_child_with_propsv:
* @parentobj: The parent object to add a property to
* @propname: The name of the property
* @childobj: A pointer to the memory to be used for the object.
* @vargs: list of property names and values
*
* See object_initialize_child() for documentation.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_initialize_childv(Object *parentobj, const char *propname,
+bool object_initialize_child_with_propsv(Object *parentobj,
+ const char *propname,
void *childobj, size_t size, const char *type,
Error **errp, va_list vargs);
+/**
+ * object_initialize_child:
+ * @parent: The parent object to add a property to
+ * @propname: The name of the property
+ * @child: A precisely typed pointer to the memory to be used for the
+ * object.
+ * @type: The name of the type of the object to instantiate.
+ *
+ * This is like
+ * object_initialize_child_with_props(parent, propname,
+ * child, sizeof(*child), type,
+ * &error_abort, NULL)
+ */
+#define object_initialize_child(parent, propname, child, type) \
+ object_initialize_child_internal((parent), (propname), \
+ (child), sizeof(*(child)), (type))
+void object_initialize_child_internal(Object *parent, const char *propname,
+ void *child, size_t size,
+ const char *type);
+
/**
* object_dynamic_cast:
* @obj: The object to cast.
*/
ObjectClass *object_class_by_name(const char *typename);
+/**
+ * module_object_class_by_name:
+ * @typename: The QOM typename to obtain the class for.
+ *
+ * For objects which might be provided by a module. Behaves like
+ * object_class_by_name, but additionally tries to load the module
+ * needed in case the class is not available.
+ *
+ * Returns: The class for @typename or %NULL if not found.
+ */
+ObjectClass *module_object_class_by_name(const char *typename);
+
void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
const char *implements_type, bool include_abstract,
void *opaque);
void object_unref(Object *obj);
/**
- * object_property_add:
+ * object_property_try_add:
* @obj: the object to add a property to
* @name: the name of the property. This can contain any character except for
* a forward slash. In general, you should use hyphens '-' instead of
* meant to allow a property to free its opaque upon object
* destruction. This may be NULL.
* @opaque: an opaque pointer to pass to the callbacks for the property
+ * @errp: pointer to error object
*
* Returns: The #ObjectProperty; this can be used to set the @resolve
* callback for child and link properties.
*/
+ObjectProperty *object_property_try_add(Object *obj, const char *name,
+ const char *type,
+ ObjectPropertyAccessor *get,
+ ObjectPropertyAccessor *set,
+ ObjectPropertyRelease *release,
+ void *opaque, Error **errp);
+
+/**
+ * object_property_add:
+ * Same as object_property_try_add() with @errp hardcoded to
+ * &error_abort.
+ */
ObjectProperty *object_property_add(Object *obj, const char *name,
const char *type,
ObjectPropertyAccessor *get,
/**
* object_property_get:
* @obj: the object
+ * @name: the name of the property
* @v: the visitor that will receive the property value. This should be an
* Output visitor and the data will be written with @name as the name.
- * @name: the name of the property
* @errp: returns an error if this function fails
*
* Reads a property from a object.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_property_get(Object *obj, Visitor *v, const char *name,
+bool object_property_get(Object *obj, const char *name, Visitor *v,
Error **errp);
/**
* object_property_set_str:
- * @value: the value to be written to the property
* @name: the name of the property
+ * @value: the value to be written to the property
* @errp: returns an error if this function fails
*
* Writes a string value to a property.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_property_set_str(Object *obj, const char *value,
- const char *name, Error **errp);
+bool object_property_set_str(Object *obj, const char *name,
+ const char *value, Error **errp);
/**
* object_property_get_str:
/**
* object_property_set_link:
- * @value: the value to be written to the property
* @name: the name of the property
+ * @value: the value to be written to the property
* @errp: returns an error if this function fails
*
* Writes an object's canonical path to a property.
* <code>OBJ_PROP_LINK_STRONG</code> bit, the old target object is
* unreferenced, and a reference is added to the new target object.
*
+ * Returns: %true on success, %false on failure.
*/
-void object_property_set_link(Object *obj, Object *value,
- const char *name, Error **errp);
+bool object_property_set_link(Object *obj, const char *name,
+ Object *value, Error **errp);
/**
* object_property_get_link:
/**
* object_property_set_bool:
- * @value: the value to be written to the property
* @name: the name of the property
+ * @value: the value to be written to the property
* @errp: returns an error if this function fails
*
* Writes a bool value to a property.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_property_set_bool(Object *obj, bool value,
- const char *name, Error **errp);
+bool object_property_set_bool(Object *obj, const char *name,
+ bool value, Error **errp);
/**
* object_property_get_bool:
/**
* object_property_set_int:
- * @value: the value to be written to the property
* @name: the name of the property
+ * @value: the value to be written to the property
* @errp: returns an error if this function fails
*
* Writes an integer value to a property.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_property_set_int(Object *obj, int64_t value,
- const char *name, Error **errp);
+bool object_property_set_int(Object *obj, const char *name,
+ int64_t value, Error **errp);
/**
* object_property_get_int:
/**
* object_property_set_uint:
- * @value: the value to be written to the property
* @name: the name of the property
+ * @value: the value to be written to the property
* @errp: returns an error if this function fails
*
* Writes an unsigned integer value to a property.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_property_set_uint(Object *obj, uint64_t value,
- const char *name, Error **errp);
+bool object_property_set_uint(Object *obj, const char *name,
+ uint64_t value, Error **errp);
/**
* object_property_get_uint:
/**
* object_property_set:
* @obj: the object
+ * @name: the name of the property
* @v: the visitor that will be used to write the property value. This should
* be an Input visitor and the data will be first read with @name as the
* name and then written as the property value.
- * @name: the name of the property
* @errp: returns an error if this function fails
*
* Writes a property to a object.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_property_set(Object *obj, Visitor *v, const char *name,
+bool object_property_set(Object *obj, const char *name, Visitor *v,
Error **errp);
/**
* object_property_parse:
* @obj: the object
- * @string: the string that will be used to parse the property value.
* @name: the name of the property
+ * @string: the string that will be used to parse the property value.
* @errp: returns an error if this function fails
*
* Parses a string and writes the result into a property of an object.
+ *
+ * Returns: %true on success, %false on failure.
*/
-void object_property_parse(Object *obj, const char *string,
- const char *name, Error **errp);
+bool object_property_parse(Object *obj, const char *name,
+ const char *string, Error **errp);
/**
* object_property_print:
* path is the path within the composition tree starting from the root.
* %NULL if the object doesn't have a parent (and thus a canonical path).
*/
-char *object_get_canonical_path_component(Object *obj);
+char *object_get_canonical_path_component(const Object *obj);
/**
* object_get_canonical_path:
* Returns: The canonical path for a object. This is the path within the
* composition tree starting from the root.
*/
-char *object_get_canonical_path(Object *obj);
+char *object_get_canonical_path(const Object *obj);
/**
* object_resolve_path:
Object *object_resolve_path_component(Object *parent, const char *part);
/**
- * object_property_add_child:
+ * object_property_try_add_child:
* @obj: the object to add a property to
* @name: the name of the property
* @child: the child object
+ * @errp: pointer to error object
*
* Child properties form the composition tree. All objects need to be a child
* of another object. Objects can only be a child of one object.
*
* Returns: The newly added property on success, or %NULL on failure.
*/
+ObjectProperty *object_property_try_add_child(Object *obj, const char *name,
+ Object *child, Error **errp);
+
+/**
+ * object_property_add_child:
+ * Same as object_property_try_add_child() with @errp hardcoded to
+ * &error_abort
+ */
ObjectProperty *object_property_add_child(Object *obj, const char *name,
Object *child);
*
* Set an object property's description.
*
+ * Returns: %true on success, %false on failure.
*/
void object_property_set_description(Object *obj, const char *name,
const char *description);