[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/2] qdev: add string and binary properties.
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PATCH 1/2] qdev: add string and binary properties. |
Date: |
Fri, 29 May 2009 00:44:38 +0200 |
Signed-off-by: Gerd Hoffmann <address@hidden>
---
hw/qdev.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 5 +++++
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index f271b7f..d723b3e 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -35,12 +35,17 @@ struct DeviceProperty {
const char *name;
enum {
PROP_INT,
+ PROP_STR,
+ PROP_BIN,
PROP_PTR,
} type;
union {
uint64_t i;
+ char *str;
+ uint8_t *bin;
void *ptr;
} value;
+ size_t len;
DeviceProperty *next;
};
@@ -146,6 +151,26 @@ void qdev_set_prop_int(DeviceState *dev, const char *name,
uint64_t value)
prop->value.i = value;
}
+void qdev_set_prop_str(DeviceState *dev, const char *name, const char *str)
+{
+ DeviceProperty *prop;
+
+ prop = create_prop(dev, name);
+ prop->type = PROP_STR;
+ prop->value.str = qemu_strdup(str);
+}
+
+void qdev_set_prop_bin(DeviceState *dev, const char *name, const uint8_t *bin,
size_t len)
+{
+ DeviceProperty *prop;
+
+ prop = create_prop(dev, name);
+ prop->type = PROP_BIN;
+ prop->value.bin = qemu_malloc(len);
+ prop->len = len;
+ memcpy(prop->value.bin, bin, len);
+}
+
void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value)
{
DeviceProperty *prop;
@@ -203,6 +228,30 @@ uint64_t qdev_get_prop_int(DeviceState *dev, const char
*name, uint64_t def)
return prop->value.i;
}
+const char *qdev_get_prop_str(DeviceState *dev, const char *name, const char
*def)
+{
+ DeviceProperty *prop;
+
+ prop = find_prop(dev, name);
+ if (!prop || prop->type != PROP_STR)
+ return def;
+
+ return prop->value.str;
+}
+
+int qdev_get_prop_bin(DeviceState *dev, const char *name, uint8_t *dest,
size_t size)
+{
+ DeviceProperty *prop;
+
+ prop = find_prop(dev, name);
+ if (!prop || prop->type != PROP_BIN)
+ return -1;
+ if (size < prop->len)
+ return -1;
+ memcpy(dest, prop->value.bin, prop->len);
+ return 0;
+}
+
void *qdev_get_prop_ptr(DeviceState *dev, const char *name)
{
DeviceProperty *prop;
@@ -326,6 +375,7 @@ void qbus_print(Monitor *mon, BusState *bus, int indent)
struct DeviceState *dev;
struct BusState *child;
struct DeviceProperty *prop;
+ int i;
monitor_printf(mon, "%*sbus: name %s, type %d\n", indent, "",
bus->name, bus->type);
@@ -336,6 +386,17 @@ void qbus_print(Monitor *mon, BusState *bus, int indent)
case PROP_INT:
monitor_printf(mon, ", %s=%" PRId64, prop->name,
prop->value.i);
break;
+ case PROP_STR:
+ monitor_printf(mon, ", %s=\"%s\"", prop->name,
prop->value.str);
+ break;
+ case PROP_BIN:
+ monitor_printf(mon, ", %s=", prop->name);
+ for (i = 0; i < prop->len && i < 8; i++) {
+ monitor_printf(mon, "%s%02x", 0 == i ? "" : ",",
+ prop->value.bin[i]);
+ }
+ monitor_printf(mon, "%s", i == prop->len ? "" : ",...");
+ break;
case PROP_PTR:
monitor_printf(mon, ", %s=%p", prop->name, prop->value.ptr);
break;
diff --git a/hw/qdev.h b/hw/qdev.h
index ab670de..2f5d9dc 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -50,6 +50,9 @@ void qdev_free(DeviceState *dev);
/* Set properties between creation and init. */
void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value);
+void qdev_set_prop_str(DeviceState *dev, const char *name, const char *str);
+void qdev_set_prop_bin(DeviceState *dev, const char *name, const uint8_t *bin,
+ size_t len);
void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
@@ -84,6 +87,8 @@ CharDriverState *qdev_init_chardev(DeviceState *dev);
BusState *qdev_get_parent_bus(DeviceState *dev);
uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
+const char *qdev_get_prop_str(DeviceState *dev, const char *name, const char
*def);
+int qdev_get_prop_bin(DeviceState *dev, const char *name, uint8_t *dest,
size_t size);
void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
/* Convery from a base type to a parent type, with compile time checking. */
--
1.6.2.2
- [Qemu-devel] [PATCH 1/2] qdev: add string and binary properties.,
Gerd Hoffmann <=