> On 15 Jun 2015, at 01:36, Peter Crosthwaite <peter.crosthwa...@xilinx.com> > wrote: > > Liviu recently brought up a desire for arguments to QOM constructors. P8 > would probably be cleaner if this feature existed, as the number of CPUs > could be set as a constructor argument. There is no flexibility on when > this has to be set, it must be done immediately after construction so it > ideally should be part of construction.
as Peter mentioned in another thread, for some situations instance_init() is too early, realize() is to late. here is another one, from the implementation of my Cortex-M framework: DeviceState *mcu = qdev_alloc(NULL, TYPE_STM32F103RB); { STM32F103RB_GET_CLASS(mcu)->construct(OBJECT(mcu), machine); /* Set the board specific oscillator frequencies. */ qdev_prop_set_uint32(mcu, "hse-freq-hz", 8000000); /* 8.0 MHz */ qdev_prop_set_uint32(mcu, "lse-freq-hz", 32768); /* 32 KHz */ } qdev_realize(mcu); the two properties are in fact aliases to an internal object that handles clocks. doing the MCU construction in .instance_init() is not possible, because it depends on some data not available at that moment, and doing the construction at realize() is too late, because setting properties will no longer be possible after this point. my solution was to add a custom constructor to each class, and manually chain them up to the parent, as in any OO implementation. regards, Liviu