BREW 学习笔记

1BREW平台可以做到开机就自启动BREW 应用,这需要在MIF中做如下设置: 
MIF Editor/applets/Notifications,flags,settings/ 
进入后再选
notifications/Notifier: AEECLSID_SHELL 
notifications/Mask: NMASK_SHELL_INIT 

这相当于手机在开机后即注册了SHELL_INIT notification消息, 即相当于应用管理器在开机后自动运行了下面的代码: 
ISHELL_RegisterNotify (pIShell, AEECLSID, MyAppCls, NMASK_SHELL_INIT); 
可以把ISHELL_RegisterNotify (pIShell, AEECLSID, MyAppCls, NMASK_SHELL_INIT);加在类似RootApp的根应用里面的初始化函数里
如若应用想将自己启动起来,则需要处理此notification消息,如下: 

    case EVT_NOTIFY: 
      { 
          AEENotify* pNotify = (AEENotify*) dwParam; 
          if (pNotify && (pNotify->cls == AEECLSID_SHELL))  // event sender 
          { 
              if ((pNotify->dwMask & NMASK_SHELL_INIT) == NMASK_SHELL_INIT) 
              { 
                  // AEECLSID_MYAPP 
为指定应用程序ID 
                    ISHELL_StartApplet(pMe->a.m_pIShell, AEECLSID_MYAPP); 
              } 
          } 
      }

 

 

2

BREWUI里的callBack机制:

当要连续调用某一功能,但是又不能独占CPU,不能影响到MMI界面刷新时,最好使用BREW自带的AEECallback机制

例:

 

//开始

#define CALLBACK_Init(pcb,pcf,pcx) /

   do { /

      (pcb)->pfnNotify = (CallbackNotifyFunc*)(pcf); /

      (pcb)->pNotifyData = (pcx); /

   } while (0);

 

//启动

ISHELL_Resume(pme->a.m_pIShell,&pme->m_cb);

 

//结束

#define CALLBACK_Cancel(pcb) /

   do { /

      if (0 != (pcb)->pfnCancel) { /

         (pcb)->pfnCancel(pcb); /

      } /

   } while (0)

 

每调用一次CALLBACK_Init,都要对应一个ISHELL_Resume(pme->a.m_pIShell,&pme->m_cb);它们每调用一次,只跑一次,如果想持续地调用,则需要不停地同时调用CALLBACK_InitISHELL_Resume(或AEE_ResumeCallback)。最后不再调用它时,须调用CALLBACK_Cancel来结束它

 

FM自动搜一次台为例:

AEECallback               pICBAutoSearchChannel;

 

CALLBACK_Init(&(pThis->pICBAutoSearchChannel),

          (PFNNOTIFY) FmUI_AutoSearchChannel,

          (void *)pThis); 

 ISHELL_Resume(pThis->pIShell,&pThis->pICBAutoSearchChannel);

 

CALLBACK_Cancel(&(pThis->pICBAutoSearchChannel));

 

 

 

 

BREW上下文处理函数

=======================================================================
Function: AEE_EnterAppContext()

Description:
  This function is used to set the application context, asserting
  permissions and marking the application context as running.

Prototype:
  ACONTEXT *AEE_EnterAppContext(ACONTEXT * pc);

Parameters:
  pc: pointer to the new application context

Return Value:
  The previous application context to later be passed to
  AEE_LeaveAppContext()

Comments:
  You must use AEE_LeaveAppContext() to undo and restore the
  previous ACONTEXT.

Side Effects:
  None

See Also:
  AEE_GetAppContext(), AEE_LeaveAppContext()

=======================================================================
Function: AEE_LeaveAppContext()

Description:
  This function is used to de-assert an application context and
  to restore the *previously* asserted ACONTEXT.

Prototype:
  void AEE_LeaveAppContext(ACONTEXT *pacRestore)

Parameters:
  pacRestore: the application context to return to

Return Value:
  None

Comments:
  pacRestore should be the return value of a matching call to
  AEE_EnterAppContext().

Side Effects:
  None

See Also:
  AEE_GetAppContext(), AEE_EnterAppContext()

=======================================================================
Function: AEE_GetAppContext()

Description:
  This function is used to get the current application context.

Prototype:
  void * AEE_GetAppContext(void);

Parameters:
  None

Return Value:
  Pointer to the current application context

Comments:
  None

Side Effects:
  None

See Also:
  AEE_GetLastAppContext(),AEE_EnterAppContext(), AEE_LeaveAppContext()

=======================================================================
Function: AEE_GetLastAppContext()

Description:
  This function is used to get the most recently running, non-system app context (if any).
  For ex: While App A is executing, if it switches temporariy to system context (for
  privilege purposes), this API can be used to determine the class ID of the app (A) that is
  running while A has switched to system context.  
    
  When A has switched to system context, calling the function AEE_GetAppContext()
  will not yield the app context of A since that function returns the current app-context. This
  function AEE_GetLastAppContext() has to be used for that purpose.
    
  After obtaining the AppContext, the function AEE_GetAppContextCls() can then be used to  
  obtain the actual ClassID of the app is running. If that returns AEECLSID_SHELL, it indicates  
  that the system context is currently running and there is no non-system app  
  executing currently.

Prototype:
  void * AEE_GetLastAppContext(void);

Parameters:
  None

Return Value:
  Pointer to the current application context.  

Comments:
  None

Side Effects:
  None

See Also:
  AEE_GetAppContext(),AEE_GetAppContextCls

 

 

 

打印内存信息

BREW4.0里,如果想在退出applet时打印内存信息,以便查看是否有内存泄露,可以在AEEAppGen.c里的AEEApplet_Release函数里,加上

       uint32 id = AEE_GetMemGroup();

       AEEHeap_DumpGroup(id);

就可以了。例如:

static uint32 AEEApplet_Release(IApplet * po)

{

   IShell * pIShell = NULL;

 

   AEEApplet * pme = (AEEApplet *)po;

 

   if (--pme->m_nRefs)

      return(pme->m_nRefs);

 

   // Invoke the APP's FreeAppData function. This gives them a chance to

   // free-up any data they may have allocated when the app was created.

 

   if(pme->pFreeAppData)

      pme->pFreeAppData(po);

 

   // Release the interfaces created in AEEApplet_New()

   if (pme->m_pIDisplay)

      IDISPLAY_Release(pme->m_pIDisplay);  

 

 

   IMODULE_Release(pme->m_pIModule);

 

   pIShell = pme->m_pIShell;

 

   // delete this AEEApplet object

   FREE_VTBL(pme, IApplet);

   FREE(pme);  

  

   ISHELL_Release(pIShell);   // Release the Shell

   {

       uint32 id = AEE_GetMemGroup();

       AEEHeap_DumpGroup(id);

   }

   return 0;

}

 

BREW里的静态和全局变量

    BREW静态应用里,是可以随便用静态变量和全局变量的,因为静态应用是在编程BIN文件时一起变进去的,所以静态和全局变量存放的位置都是和其他应用一起的,在系统的ROM里。

    BREW动态应用里,不能使用全局的静态变量,因为动态应用是单独编译出来的mod,再动态地加载到手机里去的,它们和手机里其他应用的变量存放地址不一致,所以不能使用静态和全局变量

 

ISHELL_RegisterNotify()

1. ISHELL_RegisterNotify()注册需要指定发送方、接收方和事

件屏蔽位三元组:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值