-- 2006.1.11
1. About aeeinterface.
Typedef struct _ isample;
Aeeinterface (isample)
{
Inherit_iqueryinterface (isample );
// Add your fun...
Void (* Fun) (isample * Po );
};
Struct isample
{
Const aeevtbl (isample) * PVT;
// Add your var...
Uint32 m_uref;
};
Macro inherit_iqueryinterface: inherits several key function pointers from the base interface IBASE addref, Rlease, and QueryInterface
In this way, an isample Interface Based on aeeinterface is constructed. You can add the required function pointer after the fun function pointer, add the member variable you need after m_uref, and then observe it with the object-oriented eyes. Then he is a class, although he previously put a struct.
Also, if you are diligent, or you want to imitate the database functions on the Brew platform, or you don't want others to know which members you actually use, you can use macros to define your member functions, just like the BREW Platform:
# Define isample_fun (p) aeegetpvtbl (p, isample)-> fun (p ))
In this way, is it cool, but it also has the function of adding a snake.
2. qinterface
In example, the source code of mediaplayer is classic, so take the iwindow in it as an example.
Typedef struct _ iwindow;
Qinterface (iwindow)
{
Void (* enable) (iwindow * Po, Boolean benable );
Void (* redraw) (iwindow * Po );
Boolean (* handleevent) (iwindow * Po, aeeevent ecode, uint16 wparam, uint32 dwparam );
Void (* Delete) (iwindow * Po );
// Add your fun in base struct
};
# Define inherit_cwindow (INAME )/
Declare_vtbl (INAME )/
Cmediaplayer * m_powner ;/
Ishell * m_pishell ;/
Idisplay * m_pidisplay ;/
Flg m_bactive: 1
// Add your VaR in base struct
Struct cwindow
{
Inherit_cwindow (iwindow );
};
Struct cmainwin
{
Inherit_cwindow (iwindow );
Iimage * m_plogo;
Aeerect m_rectlogo;
Imenuctl * m_pmainmenu;
Flg m_babout: 1;
// Add your VaR in sub struct
};
Iwindow is a struct, and all Members are function pointers. Therefore, it can also be called an interface. The macro inherit_cwindow is very important, and inheritance depends on it. You can add your data members and member functions to the base class in the area marked above. Then, when data members and member functions are merged, they form a cwindow base class. Obviously, cmainwin is derived from cwindow. If you 'd better add only data members, if you add a member function, data members at the same level as the member function will be exposed, the encapsulation will be reduced.
If you still want to imitate the Brew platform, you can write as follows:
# Define iwindow_handleevent (p, E, W, DW) get_pvtbl (p, iwindow)-> handleevent (p, E, W, DW)
In this application, pay attention to two macros: declare_vtbl and get_pvtbl.
You can also note that the iwindow_handleevent function corresponds to different xxx_handleevents for different cwindows, so different forms will reflect different behaviors.
This is probably so much, but in the end it is a simulation of the C language, it is difficult to achieve the perfection of the C ++ object-oriented, but for simple mobile application development, it is already competent, if you want to study more deeply, read the internal code of the Qualcomm platform.