From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTH5K-0001bI-BJ for qemu-devel@nongnu.org; Tue, 21 Jul 2009 11:16:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTH5F-0001Yn-Qt for qemu-devel@nongnu.org; Tue, 21 Jul 2009 11:16:54 -0400 Received: from [199.232.76.173] (port=41016 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTH5F-0001Yf-9X for qemu-devel@nongnu.org; Tue, 21 Jul 2009 11:16:49 -0400 Received: from mx2.redhat.com ([66.187.237.31]:33380) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MTH5E-0003Xx-Lk for qemu-devel@nongnu.org; Tue, 21 Jul 2009 11:16:49 -0400 Message-ID: <4A65DB59.7020401@redhat.com> Date: Tue, 21 Jul 2009 17:14:33 +0200 From: Gerd Hoffmann MIME-Version: 1.0 References: <1247841685-18495-1-git-send-email-aliguori@us.ibm.com> <1247841685-18495-2-git-send-email-aliguori@us.ibm.com> <4A65D4DD.1040603@redhat.com> <4A65D676.9050406@us.ibm.com> <4A65D8CA.20004@redhat.com> In-Reply-To: <4A65D8CA.20004@redhat.com> Content-Type: multipart/mixed; boundary="------------010005010107030706070709" Subject: [Qemu-devel] Re: [PATCH 1/2] Introduce CharDriverState qdev property type List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, Paul Brook This is a multi-part message in MIME format. --------------010005010107030706070709 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 07/21/09 17:03, Gerd Hoffmann wrote: > Yes. Same for drives and others. A generic string property should do I > think. Something like the attached patch. Compiles, but not tested yet. I'm not fully sure the dynamic allocation is actually a good idea though as it makes the string property a special case. Commments? cheers, Gerd --------------010005010107030706070709 Content-Type: text/plain; name="fix" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix" diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 76699b0..51cb8b3 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -145,6 +145,31 @@ PropertyInfo qdev_prop_macaddr = { .print = print_mac, }; +/* --- string --- */ + +static int parse_str(DeviceState *dev, Property *prop, const char *str) +{ + char **ptr = qdev_get_prop_ptr(dev, prop); + + qemu_free(*ptr); + *ptr = qemu_strdup(str); + return 0; +} + +static int print_str(DeviceState *dev, Property *prop, char *dest, size_t len) +{ + char **ptr = qdev_get_prop_ptr(dev, prop); + return snprintf(dest, len, "%s", *ptr); +} + +PropertyInfo qdev_prop_str = { + .name = "string", + .type = PROP_TYPE_STRING, + .size = sizeof(char*), + .parse = parse_str, + .print = print_str, +}; + /* --- public helpers --- */ static Property *qdev_prop_walk(Property *props, const char *name) @@ -229,6 +254,12 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); } +void qdev_prop_set_str(DeviceState *dev, const char *name, char *str) +{ + char *value = qemu_strdup(str); + qdev_prop_set(dev, name, &value, PROP_TYPE_STRING); +} + void qdev_prop_set_defaults(DeviceState *dev, Property *props) { char *dst; diff --git a/hw/qdev.h b/hw/qdev.h index 59ac8dc..ec38a37 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -61,6 +61,7 @@ enum PropertyType { PROP_TYPE_TADDR, PROP_TYPE_MACADDR, PROP_TYPE_PTR, + PROP_TYPE_STRING, }; struct PropertyInfo { @@ -148,6 +149,7 @@ extern PropertyInfo qdev_prop_uint32; extern PropertyInfo qdev_prop_hex32; extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_macaddr; +extern PropertyInfo qdev_prop_str; /* Set properties between creation and init. */ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); @@ -157,6 +159,7 @@ 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); /* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); +void qdev_prop_set_str(DeviceState *dev, const char *name, char *value); void qdev_prop_set_defaults(DeviceState *dev, Property *props); void qdev_prop_register_compat(CompatProperty *props); --------------010005010107030706070709--