Last active
July 13, 2017 18:14
-
-
Save cwshu/221cb9daf49937069a773ade567295cc to your computer and use it in GitHub Desktop.
qdev realize 的物件導向示意程式,以 c++ 為範例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
真實的 QEMU code 還多一層 PCIDevice 的繼承,pci_create() 才呼叫 qdev_init_nofail()。
這邊有點懶了就沒有寫。