From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:47437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaSdv-0007AT-BI for qemu-devel@nongnu.org; Tue, 13 Dec 2011 08:43:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaSdn-0001Hf-Jl for qemu-devel@nongnu.org; Tue, 13 Dec 2011 08:43:39 -0500 Received: from mail-yw0-f45.google.com ([209.85.213.45]:40655) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaSdn-0001HY-GB for qemu-devel@nongnu.org; Tue, 13 Dec 2011 08:43:31 -0500 Received: by yhgg71 with SMTP id g71so433836yhg.4 for ; Tue, 13 Dec 2011 05:43:30 -0800 (PST) Message-ID: <4EE7567E.3070702@codemonkey.ws> Date: Tue, 13 Dec 2011 07:43:26 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <4EE657AC.7080908@codemonkey.ws> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC] QEMU Object Model status/merge plan List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , Markus Armbruster , qemu-devel , Avi Kivity , Paolo Bonzini , Gerd Hoffmann On 12/13/2011 05:35 AM, Stefan Hajnoczi wrote: > On Mon, Dec 12, 2011 at 7:36 PM, Anthony Liguori wrote: >> I choose the serial device to showcase what we'll eventually be able to do. >> The three relevant files are: >> >> https://github.com/aliguori/qemu/blob/qom-next/hw/isa-serial.c >> >> https://github.com/aliguori/qemu/blob/qom-next/hw/mm-serial.c >> >> https://github.com/aliguori/qemu/blob/qom-next/hw/serial.c > > I'm not sure I understand how init functions are called for derived > classes. There are three types of init functions: class_init ========== This lives in (TypeInit) and is called when a class is first created for a type. It is only ever called once. Within this function, you should override any methods in your base classes and set default implementations for any methods you implement. instance_init ============= This is the constructor for a type. It is called when an object is created and chained such that the base class constructors are called first to initialize the object. DeviceState::init ================= This is the qdev initialize function. It is called sometime after properties are set and before the guest starts running for the first time. Long term, I plan to change this to "DeviceState::realize" and remove explicit calls to qdev_init() in favor of a propagated realize signal. But for now, I'm trying to avoid churn in the tree. > On one hand mm-serial.c calls its superclass init function, > on the other hand isa-bus.c:isa_qdev_init() calls an init function > that its child class must provide. One is calling its parent, the > other is calling its child. Is there a consistent way of doing this > and what did I miss :)? Yes, this is all DeviceState::init. This is what is called when you invoke qdev_init(). Right now, you have to do it explicitly and in the case of composition, since the device is creating another device, it must be the one that calls qdev_init() for that device. In the case of inheritance, we're just calling the superclass's init function because DeviceState::init is just a normal method so we have to explicitly chain it if we want that behavior. Regards, Anthony Liguori > > Stefan >