From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:59815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW8Hq-0005C3-7a for qemu-devel@nongnu.org; Thu, 01 Dec 2011 10:11:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RW8Hk-0002le-9l for qemu-devel@nongnu.org; Thu, 01 Dec 2011 10:10:58 -0500 Received: from mail-gx0-f173.google.com ([209.85.161.173]:35741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW8Hk-0002lP-74 for qemu-devel@nongnu.org; Thu, 01 Dec 2011 10:10:52 -0500 Received: by ggnk1 with SMTP id k1so395444ggn.4 for ; Thu, 01 Dec 2011 07:10:51 -0800 (PST) Message-ID: <4ED798F9.4070200@codemonkey.ws> Date: Thu, 01 Dec 2011 09:10:49 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1322687028-29714-1-git-send-email-aliguori@us.ibm.com> <1322687028-29714-8-git-send-email-aliguori@us.ibm.com> <4ED76325.6080305@redhat.com> <4ED784B3.8060800@codemonkey.ws> <4ED7892A.1050502@redhat.com> <4ED794DF.8090800@us.ibm.com> <4ED796A1.4020403@redhat.com> In-Reply-To: <4ED796A1.4020403@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 07/18] qom: add link properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Kevin Wolf , Peter Maydell , Anthony Liguori , Stefan Hajnoczi , Jan Kiszka , qemu-devel@nongnu.org, Markus Armbruster , Luiz Capitulino On 12/01/2011 09:00 AM, Avi Kivity wrote: > On 12/01/2011 04:53 PM, Anthony Liguori wrote: >> >>> What does the client code looks like for link? >> >> 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: I have thought about all of these and have solutions but we have to take it one step at a time. > - this is an object property, not a class property, so to get a list of > properties we need to instantiate an object. Yes, but it will be safe to instantiate an object as object instantiation is side-effect free. Recall, QOM does not have constructor properties and construction is delayed to realize. In addition, we'll be moving all structures into header files and I imagine we'll have a doc syntax so that we can place documentation about the properties in the headers and exact it appropriately. > - "UsbDevice" as the type is not type safe at compile time It will become TYPE_USB_DEVICE once we get the next stage in. See some of my earlier QOM posts for examples. > - ditto for the cast The cast is unfortunate. I can't really figure a good solution to this. I could implement a macro to eliminate the cast but since this may be a NULL pointer when this function is called, I can't find a way to make this safer. > >> >> 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. Exactly. I don't think it's a hard requirement right now for any type of property. I think avoiding boiler plate is more important at the moment. Regards, Anthony Liguori