Skip to contentSkip to conversation

About object oriented programming in qemu

Qemu-devel Li Qiang 2 participants 2 messages Oct 30, 2018

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

Hello all,

Today I read the BusClass’ definition.

The comment
/* FIXME first arg should be BusState */
remind me that OOP in qemu is not very OOP.

Maybe we should take the first arg as the Object pointer, just as the cpp’s this pointer.

For example, we can define the BusClass function as this

void (*print_dev)(BusState*, Monitor *mon, DeviceState *dev, int indent); char *(*get_dev_path)(BusState*, DeviceState *dev);
char *(*get_fw_dev_path)(BusState*, DeviceState *dev);

So we don’t need get the BusState in the callback function, such as ‘usb_bus_dev_print’.

I want to know do do you think it make senses?
If not I will not spend time to write the patch.

Thanks,
Li Qiang

#1 lore raw
Quoted 6 lines · Li Qiang

Hello all,

Today I read the BusClass’ definition.

Quoted 7 lines

The comment

/* FIXME first arg should be BusState */

remind me that OOP in qemu is not very OOP.

It is not "not very OOP", it is not language-supported and so it can take a few more liberties.

Perhaps these functions should be moved to DeviceClass instead. That would make sense, I think.

Paolo

Quoted 24 lines

Maybe we should take the first arg as the Object pointer, just as the cpp’s this pointer.

For example, we can define the BusClass function as this

void (*print_dev)(BusState*, Monitor *mon, DeviceState *dev, int indent); char *(*get_dev_path)(BusState*,  DeviceState *dev);
char *(*get_fw_dev_path)(BusState*, DeviceState *dev);

So we don’t need get the BusState in the callback function, such as ‘usb_bus_dev_print’.

I want to know do do you think it make senses?

If not I will not spend time to write the patch.

Thanks,

Li Qiang