From: Amit Shah <amit.shah@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 2/4] qdev: add string property.
Date: Tue, 22 Sep 2009 21:53:45 +0530 [thread overview]
Message-ID: <1253636627-12746-3-git-send-email-amit.shah@redhat.com> (raw)
In-Reply-To: <1253636627-12746-2-git-send-email-amit.shah@redhat.com>
From: Gerd Hoffmann <kraxel@redhat.com>
---
hw/qdev-properties.c | 28 ++++++++++++++++++++++++++++
hw/qdev.h | 4 ++++
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 2ecb58d..7e085f6 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -165,6 +165,34 @@ PropertyInfo qdev_prop_hex64 = {
.print = print_hex64,
};
+/* --- string --- */
+
+static int parse_string(DeviceState *dev, Property *prop, const char *str)
+{
+ char **ptr = qdev_get_prop_ptr(dev, prop);
+
+ if (*ptr)
+ qemu_free(*ptr);
+ *ptr = qemu_strdup(str);
+ return 0;
+}
+
+static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ char **ptr = qdev_get_prop_ptr(dev, prop);
+ if (!*ptr)
+ return snprintf(dest, len, "<null>");
+ return snprintf(dest, len, "\"%s\"", *ptr);
+}
+
+PropertyInfo qdev_prop_string = {
+ .name = "string",
+ .type = PROP_TYPE_STRING,
+ .size = sizeof(char*),
+ .parse = parse_string,
+ .print = print_string,
+};
+
/* --- drive --- */
static int parse_drive(DeviceState *dev, Property *prop, const char *str)
diff --git a/hw/qdev.h b/hw/qdev.h
index 623ded5..cd9da17 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -68,6 +68,7 @@ enum PropertyType {
PROP_TYPE_MACADDR,
PROP_TYPE_DRIVE,
PROP_TYPE_CHR,
+ PROP_TYPE_STRING,
PROP_TYPE_PTR,
};
@@ -161,6 +162,7 @@ extern PropertyInfo qdev_prop_int32;
extern PropertyInfo qdev_prop_uint64;
extern PropertyInfo qdev_prop_hex32;
extern PropertyInfo qdev_prop_hex64;
+extern PropertyInfo qdev_prop_string;
extern PropertyInfo qdev_prop_chr;
extern PropertyInfo qdev_prop_ptr;
extern PropertyInfo qdev_prop_macaddr;
@@ -200,6 +202,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
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_STRING(_n, _s, _f) \
+ DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
--
1.6.2.5
next prev parent reply other threads:[~2009-09-22 16:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-22 16:23 [Qemu-devel] Multiple port support for virtio-console Amit Shah
2009-09-22 16:23 ` [Qemu-devel] [PATCH 1/4] char: Emit 'OPENED' events on char device open Amit Shah
2009-09-22 16:23 ` Amit Shah [this message]
2009-09-22 16:23 ` [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication Amit Shah
2009-09-22 16:23 ` [Qemu-devel] [PATCH 4/4] virtio-console: Add a in-qemu api for open/read/write/close ports Amit Shah
2009-09-23 9:12 ` Gerd Hoffmann
2009-09-23 9:07 ` [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication Gerd Hoffmann
2009-09-23 9:43 ` Amit Shah
2009-09-23 11:20 ` Gerd Hoffmann
2009-09-23 11:50 ` Amit Shah
2009-09-23 12:30 ` Gerd Hoffmann
2009-09-23 12:40 ` Amit Shah
2009-09-23 13:04 ` Gerd Hoffmann
2009-09-23 13:17 ` Amit Shah
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=1253636627-12746-3-git-send-email-amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=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).