[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 07/18] qom: add link properties

From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 07/18] qom: add link properties
Date: Thu, 01 Dec 2011 08:53:19 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13

On 12/01/2011 08:03 AM, Avi Kivity wrote:
On 12/01/2011 03:44 PM, Anthony Liguori wrote:
So, links are equivalent to pointers?

Yup.  Once we have qom inheritance (next stage), we can have a
link<PCIDevice>  property and you'll be able to set it to an E1000State
with the appropriate casting and error checking taking place.

I really like this goal but can't help feeling that we're stretching C
beyond its limits here, so that the client code ends up
boilerplate-heavy.  Kind of like the issue with local_err elsewhere in
this thread, where you juggle things instead of a "throw

I understand and have been down every possible road here. It's tempting to look at C++ or another language and view it as a simplifying assumption that makes the whole effort tremendously easier.

But that's not been my experience. We just have to stretch C++ in different ways and you end up with that same icky feeling at the end of the day.

 What does the client code looks like for link<PCIDevice>?

I'm not sure what you mean by client code, but consider a device called UsbController that looks like:

struct UsbController
    DeviceState parent;

    UsbDevice *slave; // link property

To add this as a link, somewhere in the init function you would do:

static void usb_controller_initfn(UsbController *dev)
   qdev_property_add_link(DEVICE(dev), "slave", "UsbDevice",
                          (DeviceState **)&dev->slave, NULL);

If you want to set the property explicitly, you would just do:

  dev->slave = some_other_device

You don't need to use any special function to manipulate the link. Stylistically, I'd prefer that all devices exposed accessor functions and that you did these things through accessors so that we had clear rules about what's public and private.

In terms of QMP client code, you just do:

 qom-set /path/to/usb-controller.slave /some/other/device


Anthony Liguori

reply via email to

[Prev in Thread] Current Thread [Next in Thread]