On 5 December 2011 14:36, Anthony Liguori <anth...@codemonkey.ws> wrote:
> On 12/05/2011 03:52 AM, Paolo Bonzini wrote:
> struct SCSIBus {
>   Interface parent;
>   void (*command_complete)(SCSIBus *bus, SCSIRequest *req);
> };
>
> TypeInfo scsi_bus_info = {
>   .name = TYPE_SCSI_BUS,
>   .parent = TYPE_INTERFACE,
> };
>
> type_register_static(&scsi_bus_info);
>
> --------
>
> struct LSIDevice {
>    PCIDevice parent;
> };
>
> static void lsi_command_complete(SCSIBus *bus, SCSIRequest *req)
> {
>   LSIDevice *dev = LSI_DEVICE(bus);
>   ...
> }

What is the LSI_DEVICE macro actually doing here? I assume
it's not just a cast...

> static void lsi_scsi_bus_initfn(Interface *iface)
> {
>   SCSIBus *bus = SCSI_BUS(iface);
>
>   bus->command_complete = lsi_command_complete;
> }
>
> TypeInfo lsi_device_info = {
>  .name = TYPE_LSI,
>  .parent = TYPE_PCI_DEVICE,
>  .interfaces = (Interface[]){
>     {
>        .name = TYPE_SCSI_BUS,
>        .interface_initfn = lsi_scsi_bus_initfn,
>     }, {
>     }
>  },
> };
>
> type_register_static(&lsi_device_info);
>
>
>>
>> Perhaps hidden with some macro that lets me just write
>> SCSI_BUS_INTERFACE(dev), but that's the idea; such a lookup function is
>> pretty much what all object models do. GObject has
>> G_TYPE_INSTANCE_GET_INTERFACE, COM/XPCOM has QueryInterface, etc.
>>
>> If I understood everything so far, then here is my question. Are
>> interfaces properties?
>
>
> No.  A device is-a interface.  Hopefully the above example will make it more
> clear.

Saying a device is-a interface doesn't match reality. Devices
have multiple interfaces with the rest of the world. (This is
one of the major reasons why SysBus exists: it provides a suboptimal
but usuable model of this for the two most common kinds of interface,
MMIO regions and random gpio.)

-- PMM

Reply via email to