@@ -13,6 +13,7 @@
#include "sysemu/hostmem.h"
#include "sysemu/sysemu.h"
#include "qom/object_interfaces.h"
+#include "qom/property.h"
/* hostmem-file.c */
/**
@@ -16,6 +16,7 @@
#include "qapi/qmp/qerror.h"
#include "qemu/config-file.h"
#include "qom/object_interfaces.h"
+#include "qom/property.h"
#ifdef CONFIG_NUMA
#include <numaif.h>
@@ -14,6 +14,7 @@
#include "sysemu/char.h"
#include "qapi/qmp/qerror.h"
#include "hw/qdev.h" /* just for DEFINE_PROP_CHR */
+#include "qom/property.h"
#define TYPE_RNG_EGD "rng-egd"
#define RNG_EGD(obj) OBJECT_CHECK(RngEgd, (obj), TYPE_RNG_EGD)
@@ -14,6 +14,7 @@
#include "sysemu/rng.h"
#include "qapi/qmp/qerror.h"
#include "qemu/main-loop.h"
+#include "qom/property.h"
struct RndRandom
{
@@ -13,6 +13,7 @@
#include "sysemu/rng.h"
#include "qapi/qmp/qerror.h"
#include "qom/object_interfaces.h"
+#include "qom/property.h"
void rng_backend_request_entropy(RngBackend *s, size_t size,
EntropyReceiveFunc *receive_entropy,
@@ -17,6 +17,7 @@
#include "sysemu/tpm.h"
#include "qemu/thread.h"
#include "sysemu/tpm_backend_int.h"
+#include "qom/property.h"
enum TpmType tpm_backend_get_type(TPMBackend *s)
{
@@ -32,6 +32,7 @@
#include "hw/acpi/acpi.h"
#include "sysemu/kvm.h"
#include "exec/address-spaces.h"
+#include "qom/property.h"
#include "hw/i386/ich9.h"
#include "hw/mem/pc-dimm.h"
@@ -36,6 +36,7 @@
#include "exec/address-spaces.h"
#include "hw/pci/pci_bus.h"
#include "qom/qom-qobject.h"
+#include "qom/property.h"
#include "qapi/qmp/qint.h"
//#define DEBUG
@@ -36,6 +36,7 @@
#include "hw/mem/pc-dimm.h"
#include "hw/acpi/memory_hotplug.h"
#include "hw/acpi/acpi_dev_interface.h"
+#include "qom/property.h"
//#define DEBUG
@@ -12,6 +12,7 @@
#include "hw/boards.h"
#include "qapi/visitor.h"
+#include "qom/property.h"
static char *machine_get_accel(Object *obj, Error **errp)
{
@@ -35,6 +35,7 @@
#include "hw/hotplug.h"
#include "hw/boards.h"
#include "qapi-event.h"
+#include "qom/property.h"
int qdev_hotplug = 0;
static bool qdev_hot_added = false;
@@ -51,6 +51,7 @@
#include "qapi/qmp/qint.h"
#include "qom/qom-qobject.h"
+#include "qom/property.h"
typedef struct AcpiCpuInfo {
DECLARE_BITMAP(found_cpus, ACPI_CPU_HOTPLUG_ID_LIMIT);
@@ -45,6 +45,7 @@
#include "hw/pci/pci_bus.h"
#include "exec/address-spaces.h"
#include "sysemu/sysemu.h"
+#include "qom/property.h"
static int ich9_lpc_sci_irq(ICH9LPCState *lpc);
@@ -35,6 +35,7 @@
#include "kvm_ppc.h"
#include "mmu-hash64.h"
#include "qom/cpu.h"
+#include "qom/property.h"
#include "hw/boards.h"
#include "hw/ppc/ppc.h"
@@ -1170,91 +1170,6 @@ void object_property_add_link(Object *obj, const char *name,
Error **errp);
/**
- * object_property_add_str:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @get: the getter or NULL if the property is write-only. This function must
- * return a string to be freed by g_free().
- * @set: the setter or NULL if the property is read-only
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add a string property using getters/setters. This function will add a
- * property of type 'string'.
- */
-void object_property_add_str(Object *obj, const char *name,
- char *(*get)(Object *, Error **),
- void (*set)(Object *, const char *, Error **),
- Error **errp);
-
-/**
- * object_property_add_bool:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @get: the getter or NULL if the property is write-only.
- * @set: the setter or NULL if the property is read-only
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add a bool property using getters/setters. This function will add a
- * property of type 'bool'.
- */
-void object_property_add_bool(Object *obj, const char *name,
- bool (*get)(Object *, Error **),
- void (*set)(Object *, bool, Error **),
- Error **errp);
-
-/**
- * object_property_add_uint8_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory. This function will add a
- * property of type 'uint8'.
- */
-void object_property_add_uint8_ptr(Object *obj, const char *name,
- const uint8_t *v, Error **errp);
-
-/**
- * object_property_add_uint16_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory. This function will add a
- * property of type 'uint16'.
- */
-void object_property_add_uint16_ptr(Object *obj, const char *name,
- const uint16_t *v, Error **errp);
-
-/**
- * object_property_add_uint32_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory. This function will add a
- * property of type 'uint32'.
- */
-void object_property_add_uint32_ptr(Object *obj, const char *name,
- const uint32_t *v, Error **errp);
-
-/**
- * object_property_add_uint64_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory. This function will add a
- * property of type 'uint64'.
- */
-void object_property_add_uint64_ptr(Object *obj, const char *name,
- const uint64_t *v, Error **Errp);
-
-/**
* object_property_add_alias:
* @obj: the object to add a property to
* @name: the name of the property
new file mode 100644
@@ -0,0 +1,104 @@
+/*
+ * QEMU Object Model, property helpers
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_PROPERTY_H
+#define QEMU_PROPERTY_H
+
+#include "qom/object.h"
+
+/**
+ * object_property_add_str:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @get: the getter or NULL if the property is write-only. This function must
+ * return a string to be freed by g_free().
+ * @set: the setter or NULL if the property is read-only
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add a string property using getters/setters. This function will add a
+ * property of type 'string'.
+ */
+void object_property_add_str(Object *obj, const char *name,
+ char *(*get)(Object *, Error **),
+ void (*set)(Object *, const char *, Error **),
+ Error **errp);
+
+/**
+ * object_property_add_bool:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @get: the getter or NULL if the property is write-only.
+ * @set: the setter or NULL if the property is read-only
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add a bool property using getters/setters. This function will add a
+ * property of type 'bool'.
+ */
+void object_property_add_bool(Object *obj, const char *name,
+ bool (*get)(Object *, Error **),
+ void (*set)(Object *, bool, Error **),
+ Error **errp);
+
+/**
+ * object_property_add_uint8_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory. This function will add a
+ * property of type 'uint8'.
+ */
+void object_property_add_uint8_ptr(Object *obj, const char *name,
+ const uint8_t *v, Error **errp);
+
+/**
+ * object_property_add_uint16_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory. This function will add a
+ * property of type 'uint16'.
+ */
+void object_property_add_uint16_ptr(Object *obj, const char *name,
+ const uint16_t *v, Error **errp);
+
+/**
+ * object_property_add_uint32_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory. This function will add a
+ * property of type 'uint32'.
+ */
+void object_property_add_uint32_ptr(Object *obj, const char *name,
+ const uint32_t *v, Error **errp);
+
+/**
+ * object_property_add_uint64_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory. This function will add a
+ * property of type 'uint64'.
+ */
+void object_property_add_uint64_ptr(Object *obj, const char *name,
+ const uint64_t *v, Error **Errp);
+
+#endif /* !QEMU_PROPERTY_H */
@@ -19,6 +19,7 @@
#include "qapi/visitor.h"
#include "qemu/bitops.h"
#include "qom/object.h"
+#include "qom/property.h"
#include "trace.h"
#include <assert.h>
@@ -1,3 +1,3 @@
-common-obj-y = object.o container.o qom-qobject.o
+common-obj-y = object.o container.o qom-qobject.o property.o
common-obj-y += cpu.o
common-obj-y += object_interfaces.o
@@ -11,6 +11,7 @@
*/
#include "qom/object.h"
+#include "qom/property.h"
#include "qemu-common.h"
#include "qapi/visitor.h"
#include "qapi-visit.h"
@@ -1376,197 +1377,6 @@ Object *object_resolve_path(const char *path, bool *ambiguous)
return object_resolve_path_type(path, TYPE_OBJECT, ambiguous);
}
-typedef struct StringProperty
-{
- char *(*get)(Object *, Error **);
- void (*set)(Object *, const char *, Error **);
-} StringProperty;
-
-static void property_get_str(Object *obj, Visitor *v, void *opaque,
- const char *name, Error **errp)
-{
- StringProperty *prop = opaque;
- char *value;
-
- value = prop->get(obj, errp);
- if (value) {
- visit_type_str(v, &value, name, errp);
- g_free(value);
- }
-}
-
-static void property_set_str(Object *obj, Visitor *v, void *opaque,
- const char *name, Error **errp)
-{
- StringProperty *prop = opaque;
- char *value;
- Error *local_err = NULL;
-
- visit_type_str(v, &value, name, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
-
- prop->set(obj, value, errp);
- g_free(value);
-}
-
-static void property_release_str(Object *obj, const char *name,
- void *opaque)
-{
- StringProperty *prop = opaque;
- g_free(prop);
-}
-
-void object_property_add_str(Object *obj, const char *name,
- char *(*get)(Object *, Error **),
- void (*set)(Object *, const char *, Error **),
- Error **errp)
-{
- Error *local_err = NULL;
- StringProperty *prop = g_malloc0(sizeof(*prop));
-
- prop->get = get;
- prop->set = set;
-
- object_property_add(obj, name, "string",
- get ? property_get_str : NULL,
- set ? property_set_str : NULL,
- property_release_str,
- prop, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- g_free(prop);
- }
-}
-
-typedef struct BoolProperty
-{
- bool (*get)(Object *, Error **);
- void (*set)(Object *, bool, Error **);
-} BoolProperty;
-
-static void property_get_bool(Object *obj, Visitor *v, void *opaque,
- const char *name, Error **errp)
-{
- BoolProperty *prop = opaque;
- bool value;
-
- value = prop->get(obj, errp);
- visit_type_bool(v, &value, name, errp);
-}
-
-static void property_set_bool(Object *obj, Visitor *v, void *opaque,
- const char *name, Error **errp)
-{
- BoolProperty *prop = opaque;
- bool value;
- Error *local_err = NULL;
-
- visit_type_bool(v, &value, name, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
-
- prop->set(obj, value, errp);
-}
-
-static void property_release_bool(Object *obj, const char *name,
- void *opaque)
-{
- BoolProperty *prop = opaque;
- g_free(prop);
-}
-
-void object_property_add_bool(Object *obj, const char *name,
- bool (*get)(Object *, Error **),
- void (*set)(Object *, bool, Error **),
- Error **errp)
-{
- Error *local_err = NULL;
- BoolProperty *prop = g_malloc0(sizeof(*prop));
-
- prop->get = get;
- prop->set = set;
-
- object_property_add(obj, name, "bool",
- get ? property_get_bool : NULL,
- set ? property_set_bool : NULL,
- property_release_bool,
- prop, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- g_free(prop);
- }
-}
-
-static char *qdev_get_type(Object *obj, Error **errp)
-{
- return g_strdup(object_get_typename(obj));
-}
-
-static void property_get_uint8_ptr(Object *obj, Visitor *v,
- void *opaque, const char *name,
- Error **errp)
-{
- uint8_t value = *(uint8_t *)opaque;
- visit_type_uint8(v, &value, name, errp);
-}
-
-static void property_get_uint16_ptr(Object *obj, Visitor *v,
- void *opaque, const char *name,
- Error **errp)
-{
- uint16_t value = *(uint16_t *)opaque;
- visit_type_uint16(v, &value, name, errp);
-}
-
-static void property_get_uint32_ptr(Object *obj, Visitor *v,
- void *opaque, const char *name,
- Error **errp)
-{
- uint32_t value = *(uint32_t *)opaque;
- visit_type_uint32(v, &value, name, errp);
-}
-
-static void property_get_uint64_ptr(Object *obj, Visitor *v,
- void *opaque, const char *name,
- Error **errp)
-{
- uint64_t value = *(uint64_t *)opaque;
- visit_type_uint64(v, &value, name, errp);
-}
-
-void object_property_add_uint8_ptr(Object *obj, const char *name,
- const uint8_t *v, Error **errp)
-{
- object_property_add(obj, name, "uint8", property_get_uint8_ptr,
- NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint16_ptr(Object *obj, const char *name,
- const uint16_t *v, Error **errp)
-{
- object_property_add(obj, name, "uint16", property_get_uint16_ptr,
- NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint32_ptr(Object *obj, const char *name,
- const uint32_t *v, Error **errp)
-{
- object_property_add(obj, name, "uint32", property_get_uint32_ptr,
- NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint64_ptr(Object *obj, const char *name,
- const uint64_t *v, Error **errp)
-{
- object_property_add(obj, name, "uint64", property_get_uint64_ptr,
- NULL, NULL, (void *)v, errp);
-}
-
typedef struct {
Object *target_obj;
const char *target_name;
@@ -1638,6 +1448,11 @@ void object_property_add_alias(Object *obj, const char *name,
g_free(prop_type);
}
+static char *qdev_get_type(Object *obj, Error **errp)
+{
+ return g_strdup(object_get_typename(obj));
+}
+
static void object_instance_init(Object *obj)
{
object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
new file mode 100644
@@ -0,0 +1,212 @@
+/*
+ * QEMU Object Model, property helpers
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qom/property.h"
+#include "qemu-common.h"
+#include "qapi/visitor.h"
+#include "qapi-visit.h"
+#include "qapi/string-input-visitor.h"
+#include "qapi/string-output-visitor.h"
+#include "qapi/qmp/qerror.h"
+#include "trace.h"
+
+#include "qom/qom-qobject.h"
+#include "qapi/qmp/qobject.h"
+#include "qapi/qmp/qbool.h"
+#include "qapi/qmp/qint.h"
+#include "qapi/qmp/qstring.h"
+
+typedef struct StringProperty
+{
+ char *(*get)(Object *, Error **);
+ void (*set)(Object *, const char *, Error **);
+} StringProperty;
+
+static void property_get_str(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ StringProperty *prop = opaque;
+ char *value;
+
+ value = prop->get(obj, errp);
+ if (value) {
+ visit_type_str(v, &value, name, errp);
+ g_free(value);
+ }
+}
+
+static void property_set_str(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ StringProperty *prop = opaque;
+ char *value;
+ Error *local_err = NULL;
+
+ visit_type_str(v, &value, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ prop->set(obj, value, errp);
+ g_free(value);
+}
+
+static void property_release_str(Object *obj, const char *name,
+ void *opaque)
+{
+ StringProperty *prop = opaque;
+ g_free(prop);
+}
+
+void object_property_add_str(Object *obj, const char *name,
+ char *(*get)(Object *, Error **),
+ void (*set)(Object *, const char *, Error **),
+ Error **errp)
+{
+ Error *local_err = NULL;
+ StringProperty *prop = g_malloc0(sizeof(*prop));
+
+ prop->get = get;
+ prop->set = set;
+
+ object_property_add(obj, name, "string",
+ get ? property_get_str : NULL,
+ set ? property_set_str : NULL,
+ property_release_str,
+ prop, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ g_free(prop);
+ }
+}
+
+typedef struct BoolProperty
+{
+ bool (*get)(Object *, Error **);
+ void (*set)(Object *, bool, Error **);
+} BoolProperty;
+
+static void property_get_bool(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ BoolProperty *prop = opaque;
+ bool value;
+
+ value = prop->get(obj, errp);
+ visit_type_bool(v, &value, name, errp);
+}
+
+static void property_set_bool(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ BoolProperty *prop = opaque;
+ bool value;
+ Error *local_err = NULL;
+
+ visit_type_bool(v, &value, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ prop->set(obj, value, errp);
+}
+
+static void property_release_bool(Object *obj, const char *name,
+ void *opaque)
+{
+ BoolProperty *prop = opaque;
+ g_free(prop);
+}
+
+void object_property_add_bool(Object *obj, const char *name,
+ bool (*get)(Object *, Error **),
+ void (*set)(Object *, bool, Error **),
+ Error **errp)
+{
+ Error *local_err = NULL;
+ BoolProperty *prop = g_malloc0(sizeof(*prop));
+
+ prop->get = get;
+ prop->set = set;
+
+ object_property_add(obj, name, "bool",
+ get ? property_get_bool : NULL,
+ set ? property_set_bool : NULL,
+ property_release_bool,
+ prop, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ g_free(prop);
+ }
+}
+
+static void property_get_uint8_ptr(Object *obj, Visitor *v,
+ void *opaque, const char *name,
+ Error **errp)
+{
+ uint8_t value = *(uint8_t *)opaque;
+ visit_type_uint8(v, &value, name, errp);
+}
+
+static void property_get_uint16_ptr(Object *obj, Visitor *v,
+ void *opaque, const char *name,
+ Error **errp)
+{
+ uint16_t value = *(uint16_t *)opaque;
+ visit_type_uint16(v, &value, name, errp);
+}
+
+static void property_get_uint32_ptr(Object *obj, Visitor *v,
+ void *opaque, const char *name,
+ Error **errp)
+{
+ uint32_t value = *(uint32_t *)opaque;
+ visit_type_uint32(v, &value, name, errp);
+}
+
+static void property_get_uint64_ptr(Object *obj, Visitor *v,
+ void *opaque, const char *name,
+ Error **errp)
+{
+ uint64_t value = *(uint64_t *)opaque;
+ visit_type_uint64(v, &value, name, errp);
+}
+
+void object_property_add_uint8_ptr(Object *obj, const char *name,
+ const uint8_t *v, Error **errp)
+{
+ object_property_add(obj, name, "uint8", property_get_uint8_ptr,
+ NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint16_ptr(Object *obj, const char *name,
+ const uint16_t *v, Error **errp)
+{
+ object_property_add(obj, name, "uint16", property_get_uint16_ptr,
+ NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint32_ptr(Object *obj, const char *name,
+ const uint32_t *v, Error **errp)
+{
+ object_property_add(obj, name, "uint32", property_get_uint32_ptr,
+ NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint64_ptr(Object *obj, const char *name,
+ const uint64_t *v, Error **errp)
+{
+ object_property_add(obj, name, "uint64", property_get_uint64_ptr,
+ NULL, NULL, (void *)v, errp);
+}
@@ -43,6 +43,7 @@
#include "sysemu/sysemu.h"
#include "hw/qdev-properties.h"
+#include "qom/property.h"
#include "hw/cpu/icc_bus.h"
#ifndef CONFIG_USER_ONLY
#include "hw/xen/xen.h"
@@ -28,6 +28,7 @@
#include "qmp-commands.h"
#include "sysemu/char.h"
#include "trace.h"
+#include "qom/property.h"
#define DEFAULT_BACKSCROLL 512
#define CONSOLE_CURSOR_PERIOD 500
We have accumulated a number of friendly helpers that make registration of properties easier. However, their number is only increasing and they start to clutter the core object.c file. So let's move them into a separate C file and thus ensure that we have room to grow :). Signed-off-by: Alexander Graf <agraf@suse.de> --- backends/hostmem-file.c | 1 + backends/hostmem.c | 1 + backends/rng-egd.c | 1 + backends/rng-random.c | 1 + backends/rng.c | 1 + backends/tpm.c | 1 + hw/acpi/ich9.c | 1 + hw/acpi/pcihp.c | 1 + hw/acpi/piix4.c | 1 + hw/core/machine.c | 1 + hw/core/qdev.c | 1 + hw/i386/acpi-build.c | 1 + hw/isa/lpc_ich9.c | 1 + hw/ppc/spapr.c | 1 + include/qom/object.h | 85 ------------------- include/qom/property.h | 104 ++++++++++++++++++++++++ memory.c | 1 + qom/Makefile.objs | 2 +- qom/object.c | 197 ++------------------------------------------ qom/property.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++ target-i386/cpu.c | 1 + ui/console.c | 1 + 22 files changed, 340 insertions(+), 277 deletions(-) create mode 100644 include/qom/property.h create mode 100644 qom/property.c