From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:41347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW88K-0007IP-4r for qemu-devel@nongnu.org; Thu, 01 Dec 2011 10:01:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RW88A-0007Td-5A for qemu-devel@nongnu.org; Thu, 01 Dec 2011 10:01:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61047) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW889-0007TB-Mp for qemu-devel@nongnu.org; Thu, 01 Dec 2011 10:00:57 -0500 Message-ID: <4ED796A1.4020403@redhat.com> Date: Thu, 01 Dec 2011 17:00:49 +0200 From: Avi Kivity 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> In-Reply-To: <4ED794DF.8090800@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 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: Anthony Liguori Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , Jan Kiszka , qemu-devel@nongnu.org, Markus Armbruster , Luiz Capitulino 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: - 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