From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 2/6] qdev/prop: add 16bit integer type.
Date: Mon, 13 Jul 2009 11:36:01 +0200 [thread overview]
Message-ID: <1247477765-17026-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1247477765-17026-1-git-send-email-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/qdev-properties.c | 32 ++++++++++++++++++++++++++++++++
hw/qdev.h | 2 ++
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index cf1ad22..abd4b57 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -7,6 +7,33 @@ static void *prop_ptr(DeviceState *dev, Property *prop)
return ptr;
}
+/* --- 16bit integer --- */
+
+static int parse_uint16(DeviceState *dev, Property *prop, const char *str)
+{
+ uint16_t *ptr = prop_ptr(dev, prop);
+ const char *fmt;
+
+ /* accept both hex and decimal */
+ fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx16 : "%" PRIu16;
+ if (sscanf(str, fmt, ptr) != 1)
+ return -1;
+ return 0;
+}
+
+static int print_uint16(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ uint16_t *ptr = prop_ptr(dev, prop);
+ return snprintf(dest, len, "%" PRIu16, *ptr);
+}
+
+PropertyInfo qdev_prop_uint16 = {
+ .name = "uint16",
+ .size = sizeof(uint16_t),
+ .parse = parse_uint16,
+ .print = print_uint16,
+};
+
/* --- 32bit integer --- */
static int parse_uint32(DeviceState *dev, Property *prop, const char *str)
@@ -183,6 +210,11 @@ int qdev_prop_set(DeviceState *dev, const char *name, void *src, size_t size)
return 0;
}
+int qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
+{
+ return qdev_prop_set(dev, name, &value, sizeof(value));
+}
+
int qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
{
return qdev_prop_set(dev, name, &value, sizeof(value));
diff --git a/hw/qdev.h b/hw/qdev.h
index c61ef4a..d7f51fb 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -128,6 +128,7 @@ void do_info_qtree(Monitor *mon);
/*** qdev-properties.c ***/
+extern PropertyInfo qdev_prop_uint16;
extern PropertyInfo qdev_prop_uint32;
extern PropertyInfo qdev_prop_hex32;
extern PropertyInfo qdev_prop_ptr;
@@ -136,6 +137,7 @@ extern PropertyInfo qdev_prop_mac;
/* Set properties between creation and init. */
int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
int qdev_prop_set(DeviceState *dev, const char *name, void *src, size_t size);
+int qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
int qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
/* FIXME: Remove opaque pointer properties. */
int qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
--
1.6.2.5
next prev parent reply other threads:[~2009-07-13 9:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-13 9:35 [Qemu-devel] [PATCH 0/6] qdev: property fixups Gerd Hoffmann
2009-07-13 9:36 ` [Qemu-devel] [PATCH 1/6] qdev/prop: make uint32 accept both hex and decimal Gerd Hoffmann
2009-07-13 9:36 ` Gerd Hoffmann [this message]
2009-07-13 9:36 ` [Qemu-devel] [PATCH 3/6] qdev/prop: unstatic and rename prop_ptr() Gerd Hoffmann
2009-07-13 9:36 ` [Qemu-devel] [PATCH 4/6] qdev/prop: add property for target_phys_addr_t Gerd Hoffmann
2009-07-13 9:36 ` [Qemu-devel] [PATCH 5/6] qdev/prop: convert m48t59 Gerd Hoffmann
2009-07-13 9:36 ` [Qemu-devel] [PATCH 6/6] qdev/prop: convert tcx Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1247477765-17026-3-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).