天天看點

BREW的基本機制小結

Mif編輯器:

        Mif 是相當于brew子產品上的容器,該容器可以裝載多個小程式。Mif上的每個小程式必須為它制定ID号,也即ClassID,其在本mif中具有唯一性。ClassID對應一個程式名。每個小程式會生成一個bid檔案。編輯mif的最後需要進行編譯,會生成mif、mfx檔案。

Resource編輯器:

       實際上,其包含編輯器,編譯器。編輯器内可以對字元串、檔案、對話框等等資源進行編輯。在編輯後儲存會生成中間檔案bri,經編譯後,會生成bar以及brh(一說是_res.h)檔案。

Emulator:

       其上可以選擇模拟器的裝置,以及需要模拟的最小程式目錄。

從HELLO WORLD看BREW的程式基本運作機制

AEEClsCreateInstance算是程式的入口函數。必須傳入classID去驗證。以下截取關鍵代碼分析。

int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)

{

 *ppObj = NULL;

 if( ClsId == AEECLSID_TEST1 )

 {

  // Create the applet and make room for the applet structure

  if( AEEApplet_New(sizeof(Test1),

                          ClsId,

                          pIShell,

                          po,

                          (IApplet**)ppObj,

                          (AEEHANDLER)Test1_HandleEvent,

                          (PFNFREEAPPDATA)Test1_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function

  {

   //Initialize applet data, this is called before sending EVT_APP_START

            // to the HandleEvent function

   if(Test1_InitAppData((Test1*)*ppObj))

   {

    //Data initialized successfully

    return(AEE_SUCCESS);

   }

   else

   {

    //Release the applet. This will free the memory allocated for the applet when

    // AEEApplet_New was called.

    IAPPLET_Release((IApplet*)*ppObj);

    return EFAILED;

   }

        } // end AEEApplet_New

    }

 return(EFAILED);

}

If即為檢驗classID。

AEEApplet_New()用于調用相應的程式,這裡Test1_HandleEvent()即為所調函數。Test1_InitAppData()初始化程式所用資料,IAPPLET_Release()用于在call了AEEApplet_New()後将applet釋放,Test1_FreeAppData()則是将資料釋放。

繼續閱讀