Skip to content

Instantly share code, notes, and snippets.

@cwshu
Last active July 13, 2017 18:14
Show Gist options
  • Save cwshu/221cb9daf49937069a773ade567295cc to your computer and use it in GitHub Desktop.
Save cwshu/221cb9daf49937069a773ade567295cc to your computer and use it in GitHub Desktop.
qdev realize 的物件導向示意程式,以 c++ 為範例
class QDev {
private:
bool realized;
public:
void set_realized(bool value); // setter of realized
virtual void realize(void) = 0;
};
void QDev::set_realized(bool value){
if( value && !this->realized ){
this->realize();
}
this->realized = value;
}
void qdev_init_nofail(QDev *dev){
dev->set_realized(true)
}
// Intel E1000 ethernet device
class E1000 : QDev {
public:
virtual void realize(void);
}
void E1000::realize(void){
// initialization code
// ...
}
int main(int argc, char *argv[]){
E1000 net_device;
qdev_init_nofail(&net_device);
return 0;
}
@cwshu
Copy link
Author

cwshu commented Jul 13, 2017

真實的 QEMU code 還多一層 PCIDevice 的繼承,pci_create() 才呼叫 qdev_init_nofail()。
這邊有點懶了就沒有寫。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment