qdev/prop: add CharDriverState property.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Message-Id:
This commit is contained in:
Gerd Hoffmann 2009-08-03 17:35:18 +02:00 committed by Anthony Liguori
parent cf12b95bf5
commit 313feaabc6
2 changed files with 26 additions and 0 deletions

View File

@ -168,6 +168,21 @@ PropertyInfo qdev_prop_drive = {
.print = print_drive, .print = print_drive,
}; };
/* --- character device --- */
static int print_chr(DeviceState *dev, Property *prop, char *dest, size_t len)
{
CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
return snprintf(dest, len, "%s", (*ptr)->label);
}
PropertyInfo qdev_prop_chr = {
.name = "chr",
.type = PROP_TYPE_CHR,
.size = sizeof(CharDriverState*),
.print = print_chr,
};
/* --- pointer --- */ /* --- pointer --- */
static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len) static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
@ -357,6 +372,11 @@ void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value)
qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE); qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE);
} }
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
{
qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
}
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
{ {
qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); qdev_prop_set(dev, name, &value, PROP_TYPE_PTR);

View File

@ -4,6 +4,7 @@
#include "hw.h" #include "hw.h"
#include "sysemu.h" #include "sysemu.h"
#include "sys-queue.h" #include "sys-queue.h"
#include "qemu-char.h"
#include "qemu-option.h" #include "qemu-option.h"
typedef struct Property Property; typedef struct Property Property;
@ -65,6 +66,7 @@ enum PropertyType {
PROP_TYPE_TADDR, PROP_TYPE_TADDR,
PROP_TYPE_MACADDR, PROP_TYPE_MACADDR,
PROP_TYPE_DRIVE, PROP_TYPE_DRIVE,
PROP_TYPE_CHR,
PROP_TYPE_PTR, PROP_TYPE_PTR,
}; };
@ -155,6 +157,7 @@ extern PropertyInfo qdev_prop_uint32;
extern PropertyInfo qdev_prop_uint64; extern PropertyInfo qdev_prop_uint64;
extern PropertyInfo qdev_prop_hex32; extern PropertyInfo qdev_prop_hex32;
extern PropertyInfo qdev_prop_hex64; extern PropertyInfo qdev_prop_hex64;
extern PropertyInfo qdev_prop_chr;
extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_ptr;
extern PropertyInfo qdev_prop_macaddr; extern PropertyInfo qdev_prop_macaddr;
extern PropertyInfo qdev_prop_drive; extern PropertyInfo qdev_prop_drive;
@ -192,6 +195,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
#define DEFINE_PROP_PTR(_n, _s, _f) \ #define DEFINE_PROP_PTR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
#define DEFINE_PROP_CHR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
#define DEFINE_PROP_MACADDR(_n, _s, _f) \ #define DEFINE_PROP_MACADDR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6]) DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6])
@ -205,6 +210,7 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value); void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
/* FIXME: Remove opaque pointer properties. */ /* FIXME: Remove opaque pointer properties. */
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);