Patchwork [01/10,v2] qdev: add qdev property for bool type

login
register
mail settings
Submitter Igor Mammedov
Date March 7, 2013, 4:16 p.m.
Message ID <1362672978-19701-1-git-send-email-imammedo@redhat.com>
Download mbox | patch
Permalink /patch/225882/
State New
Headers show

Comments

Igor Mammedov - March 7, 2013, 4:16 p.m.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  - fixed indentation
  - replaced error message. Suggested-By: Andreas Färber <afaerber@suse.de>
---
 hw/qdev-properties.c |   33 +++++++++++++++++++++++++++++++++
 hw/qdev-properties.h |   10 ++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)
Andreas Färber - April 9, 2013, 1:56 p.m.
Am 07.03.2013 17:16, schrieb Igor Mammedov:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v2:
>   - fixed indentation
>   - replaced error message. Suggested-By: Andreas Färber <afaerber@suse.de>

Thanks, rebased onto PMM's array properties and applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas
Igor Mammedov - April 9, 2013, 2:13 p.m.
On Tue, 09 Apr 2013 15:56:57 +0200
Andreas Färber <afaerber@suse.de> wrote:

> Am 07.03.2013 17:16, schrieb Igor Mammedov:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > v2:
> >   - fixed indentation
> >   - replaced error message. Suggested-By: Andreas Färber
> > <afaerber@suse.de>
> 
> Thanks, rebased onto PMM's array properties and applied to qom-cpu:
> https://github.com/afaerber/qemu-cpu/commits/qom-cpu
> 
> Andreas
> 

Thanks,

one more note could you fixup setter like Peter did in b000dfbd4,
or would you like me send a patch?
Andreas Färber - April 9, 2013, 2:25 p.m.
Am 09.04.2013 16:13, schrieb Igor Mammedov:
> On Tue, 09 Apr 2013 15:56:57 +0200
> Andreas Färber <afaerber@suse.de> wrote:
> 
>> Am 07.03.2013 17:16, schrieb Igor Mammedov:
>>> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
>>> ---
>>> v2:
>>>   - fixed indentation
>>>   - replaced error message. Suggested-By: Andreas Färber
>>> <afaerber@suse.de>
>>
>> Thanks, rebased onto PMM's array properties and applied to qom-cpu:
>> https://github.com/afaerber/qemu-cpu/commits/qom-cpu
>>
>> Andreas
>>
> 
> Thanks,
> 
> one more note could you fixup setter like Peter did in b000dfbd4,
> or would you like me send a patch?

Thanks for pointing that out! Updated to use
qdev_prop_set_after_realized() and pushed.

Andreas

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index a8a31f5..b0f2333 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -106,6 +106,39 @@  PropertyInfo qdev_prop_bit = {
     .set   = set_bit,
 };
 
+/* --- bool --- */
+
+static void get_bool(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+static void set_bool(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (dev->realized) {
+        error_setg(errp, "Property '%s' cannot be changed once realized", name);
+        return;
+    }
+
+    visit_type_bool(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_bool = {
+    .name  = "boolean",
+    .get   = get_bool,
+    .set   = set_bool,
+};
+
 /* --- 8bit integer --- */
 
 static void get_uint8(Object *obj, Visitor *v, void *opaque,
diff --git a/hw/qdev-properties.h b/hw/qdev-properties.h
index 20c67f3..3915f7c 100644
--- a/hw/qdev-properties.h
+++ b/hw/qdev-properties.h
@@ -6,6 +6,7 @@ 
 /*** qdev-properties.c ***/
 
 extern PropertyInfo qdev_prop_bit;
+extern PropertyInfo qdev_prop_bool;
 extern PropertyInfo qdev_prop_uint8;
 extern PropertyInfo qdev_prop_uint16;
 extern PropertyInfo qdev_prop_uint32;
@@ -51,6 +52,15 @@  extern PropertyInfo qdev_prop_pci_host_devaddr;
         .defval    = (bool)_defval,                              \
         }
 
+#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
+        .name      = (_name),                                    \
+        .info      = &(qdev_prop_bool),                          \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(bool, typeof_field(_state, _field)),    \
+        .qtype     = QTYPE_QBOOL,                                \
+        .defval    = (bool)_defval,                              \
+        }
+
 #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
     DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
 #define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \