qemu-devel
[Top][All Lists]
Advanced

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

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


From: Avi Kivity
Subject: Re: [Qemu-devel] [PATCH 07/18] qom: add link properties
Date: Thu, 01 Dec 2011 17:00:49 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0

On 12/01/2011 04:53 PM, Anthony Liguori wrote:
>
>>  What does the client code looks like for link<PCIDevice>?
>
> I'm not sure what you mean by client code,

This:

> 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);
> }

Issues:
- this is an object property, not a class property, so to get a list of
properties we need to instantiate an object.
- "UsbDevice" as the type is not type safe at compile time
- ditto for the cast

>
> 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.

Also, so we can have observers that trigger on changes.

-- 
error compiling committee.c: too many arguments to function




reply via email to

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