现在的位置: 首页 > 综合 > 正文

BREW的事件机制,BREW中的设计模式

2013年09月15日 ⁄ 综合 ⁄ 共 2122字 ⁄ 字号 评论关闭

BREW的事件机制
2007/03/08 10:47 A.M.

 

  Brew中的handle event函数都是boolean返回类型的,这是为了实现事件处理的层次机制,当该层上的handle event没有处理该事件时,应该返回false,以便上层对该事件感兴趣的handle event来处理。如果处理了,应该返回TRUE,说明该事件已被处理,无需其他层再处理。

 

下面给出完整的BREW环境下消息分发和处理的流程。

 

  首先BREW存在于一个task中,尽管允许brew运行于一个单独的task中,但是实际oem中都是将其运行于现有的一个task中,比如ui task。当brew运行后,首先ui task中捕捉到各种事件,此时ui task通过aee_dispatch将事件分发至brew环境中,brew环境再通过aee_sentevent具体分发事件至目的地。接着在两种不同的情况下将走不同的流程。

 

  如果当前没有active dialog,则紧接着IAPPLET_Handleevent被brew自动调用来处理事件,而此时调用的IAPPLET_Handleevent其实就是用户注册的自己的applet_handleevent。从而实现了允许用户app捕捉到事件并处理的机制。在用户的app handleevent中,用户可以将事件继续下发,比如通过调用IMENU_handleevent等将事件下发给各种控件处理。

 

  如果当前有active dialog,则紧接着Adialog_event被brew自动调用,从而使得事件被dialog最先截获,而dialog之后的处理是检查包含的控件中哪个处于focus,并将事件下发给它的handleevent来处理,同时根据其返回值来判断其是否已经处理了该事件,当其返回False后,dialog将该事件继续转发至该dialog注册的handleevent(如果有的话),如果该handleevent仍然返回false,brew继续将该事件转发至app handleevent。这种机制使得当以dialog方式来创建应用时,各种event被自动的处理,从而简化了代码量,但也使得事件流程更加晦涩,用户的程序不能直接的控制它。

Handling SUSPEND and RESUME events

 

  It is important to include the EVT_APP_SUSPEND and EVT_APP_RESUME events withinyour application’s HandleEvent function so that your application knows how to handle eventsthat might interrupt its operation. For example, when an SMS message or an incoming phonecall is received, you application needs to know whether it should resume where it left off at theend of the call or if it should start over.

 

  When BREW suspends an applet, it sends the EVT_APP_SUSPEND event. Depending onthe type of application you are developing, you have a couple of options on how BREWshouldhandle the event, as follows:

 

  You can set the applet to return TRUE to the event, indicating that the applet has processed the Suspend and

has not been unloaded from memory. This is howMyFirstApp works.

 

  You can also have the applet return FALSE to the event, indicating that you do notwant the applet to process the Suspend. When this occurs, BREW sends anEVT_APP_STOP event and the applet is removed from memory.

 

BREW中的设计模式

 

工厂模式
1. 工厂模式介绍
2. BREW中的IShell_CreateInstance

 

SingleTon模式
1. SingleTon模式
2. BREW中SingleTon的不同实现方式和注意事项
3. SingleTon/Multi-Instance的使用场合
4. SingleTon中如何存储应用关联的非共享数据
5. Multi-Instance中如何进行局部共享

 

Facade模式
1. Facade模式介绍
2. BREW是手机软件的Facade

 

Proxy模式
1. Proxy模式介绍
2. BMP中的Stub/skelecton

 

Observer模式
1. Observer模式介绍
2. BREW中的Model-Listener
3. BREW中的Notifier

【上篇】
【下篇】

抱歉!评论已关闭.