Sunday, February 7, 2010

Event Passing Between Brew apps

Thought to delve little more deeper into the event passing mechanism in Brew. In Brew SDK 1.1, there is one brew ishell usage example.

This app is having two class Id.
AEECLSID_SHELL_MAIN_APP - Main application class Id
AEECLSID_SHELL_SUPPORT_APP - Support application class id

The application sends events from AEECLSID_SHELL_MAIN_APP to AEECLSID_SHELL_SUPPORT_APP

the excerpt is given below.

ISHELL_SendEvent (pMe->a.m_pIShell, AEECLSID_SHELL_SUPPORT_APP,
EVT_USER, SEND_EVENT_16BITDATA, COMMON_32BIT_EVENT_DATA);

The following are the definitions of the constants in the above functions.

#define SEND_EVENT_16BITDATA 0
#define POST_EVENT_16BITDATA 1
#define HANDLE_EVENT_16BITDATA 2
#define COMMON_32BIT_EVENT_DATA 0

For testing purpose, altered the above data as

#define SEND_EVENT_16BITDATA 0
#define POST_EVENT_16BITDATA 1
#define COMMON_32BIT_EVENT_DATA "This is a sample data 32 bit"

and the receiving end, the loop is printed as

case EVT_USER:
{
switch (wParam)
{
case SEND_EVENT_16BITDATA:
DBGPRINTF("======= The Event Received in SendEvent is %s",dwParam);
ISHELL_StartApplet(pMe->a.m_pIShell,AEECLSID_SHELL_SUPPORT_APP);
return TRUE;
case POST_EVENT_16BITDATA:
DBGPRINTF("======= The Event Received in PostEvent is %s",dwParam);
ISHELL_StartApplet(pMe->a.m_pIShell,AEECLSID_SHELL_SUPPORT_APP);
return TRUE;
}
}

There is another event passing mechanism introduced in Brew 3.1 is ISHELL_SendURL and ISHELL_PostURL.

ISHELL_SendURL() posts asynchronous event EVT_APP_POST_URL to the applet associated with the URL scheme. The following are the signatures of the app.

boolean ISHELL_PostURL(IShell *po, const char * pszURL);
boolean ISHELL_SendURL(IShell *po, const char * pszURL);

A somewhat nice reference for this is available at the pdf