|
注意事项
|
详细描述
|
|
执行空指针检查
|
关于这一条有如下两个方面:
1、在使用ISHELL_CreateInstance()或其他接口函数创建接口实例后,一定要进行接口指针有效性的检查,如果指针异常,则不能够使用这个接口
2、检查全部的指针以确认指针有效性,包括传入的、使用BREW方法创建的和分配内存后的。不可用的指针将引起系统的致命错误。
|
|
避免堆栈溢出
|
由于系统分配给BREW运行环境的堆栈空间是有限的,因此不要在堆栈中分配大数组,也就是说,不要再一个函数的局部变量中声明大数组。如果确实在程序中需要这样的数组,那么,请使用分配内存的方式。
|
|
不要使用大的循环
|
当一个循环运行的时间足够长时,将引起BREW设备的复位。基于这样的原因,不能在一个BREW事件里进行耗时很长的处理。
|
|
尽可能的使应用程序成为设备独立的
|
为了使我们的应用程序可以独立于设备的内存大小、键盘数量、颜色深度和屏幕尺寸等因素而独立运行,请使用ISHELL_GetDeviceInfo()方法来获得设备的规格,从而根据不同的规格处理不同的应用程序。
|
|
使用资源文件
|
使用资源文件存储指定语言的字符串、对话框和图片。这样可以方便的进行不同语言版本的开发,而不影响代码本身。
|
|
释放内存
|
由于在BREW设备上的可用内存是有限的,因此清理不使用的内存就十分重要了。有如下两种情况:
1、必须释放全部创建的实例
2、应用程序终止时必须释放全部分配的内存
推荐在内存不再使用的时候就释放掉。
|
|
不要使用全局或静态变量
|
由于全局和局部变量在BREW动态应用程序中无法处理,因此基于这样的BREW架构不支持全局和静态变量,而且全局和静态变量也会引起BREW设备环境下的链接错误。请在应用程序的结构体中声明这些数据。
|
|
不要在定义的时候初始化一个结构体
|
与上面不能使用全局和静态变量一样,在定义的时候初始化一个结构体也会引起BREW设备环境下的一个链接错误。
|
|
不要直接使用C语言的浮点运算
|
BREW平台不支持浮点运算。虽然这些运算在模拟器中运行良好,那时因为在Windows环境下,在BREW设备环境下,通常不支持浮点运算。如果确实需要使用的话,请用BREW提供的助手函数进行运算。
|
|
使用BREW支持的标准库函数
|
为了可以让我们的程序所占的空间最小,请不要使用目标设备的库函数,而是使用BREW提供相应的助手函数。
|
|
避免类型转换错误
|
由于目标设备的编译器对于类型的检查要严格,因此,请明确声明变量转换的类型,以防止从Windows环境移植到BREW设备环境下产生错误。
|
|
检查返回值
|
如果我们调用的BREW API含有返回值,建议处理这些返回值,这样可以让我们所写的程序更加健壮。
|
|
helloworld.c
|
|
/*====================================================================
FILE: helloworld.c
====================================================================*/
/*====================================================================
INCLUDES AND VARIABLE DEFINITIONS
====================================================================*/
#include "AEEModGen.h"
// Module interface definitions
#include "AEEAppGen.h"
// Applet interface definitions
#include "AEEShell.h"
// Shell interface definitions
#include "helloworld.bid"
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _helloworld {
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
// add your own variables here...
} helloworld;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean helloworld_HandleEvent( helloworld* pMe,
AEEEvent eCode, uint16 wParam,
uint32 dwParam);
boolean helloworld_InitAppData(helloworld* pMe);
void
helloworld_FreeAppData(helloworld* pMe);
/*====================================================================
FUNCTION DEFINITIONS
==================================================================== */
/*====================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
====================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
*ppObj = NULL;
if( ClsId == AEECLSID_HELLOWORLD )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(helloworld),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)helloworld_HandleEvent,
(PFNFREEAPPDATA)helloworld_FreeAppData) )
{
//Initialize applet data, this is called before sending EVT_APP_START
// to the HandleEvent function
if(helloworld_InitAppData((helloworld*)*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);
}
/*====================================================================
FUNCTION SampleAppWizard_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.
PROTOTYPE:
boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
====================================================================*/
static boolean helloworld_HandleEvent(helloworld* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
AECHAR szBuf[] = {'H','e','l','l','o',' ',
'W','o','r','l','d','/0'};
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
// Add your code here...
// Clear the display.
IDISPLAY_ClearScreen( pMe->a.m_pIDisplay );
// Display string on the screen
IDISPLAY_DrawText( pMe->a.m_pIDisplay, // What
AEE_FONT_BOLD, // What font
szBuf, // How many chars
-1, 0, 0, 0, // Where & clip
IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE );
// Redraw the display to show the drawn text
IDISPLAY_Update (pMe->a.m_pIDisplay);
return(TRUE);
// App is told it is exiting
case EVT_APP_STOP:
// Add your code here...
return(TRUE);
// App is being suspended
case EVT_APP_SUSPEND:
// Add your code here...
return(TRUE);
// App is being resumed
case EVT_APP_RESUME:
// Add your code here...
return(TRUE);
// A key was pressed. Look at the wParam above to see which key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
case EVT_KEY:
// Add your code here...
return(TRUE);
// If nothing fits up to this point then we'll just break out
default:
break;
}
return FALSE;
}
// this function is called when your application is starting up
boolean helloworld_InitAppData(helloworld* pMe)
{
// Get the device information for this handset.
// Reference all the data by looking at the pMe->DeviceInfo structure
// Check the API reference guide for all the handy device info you can get
pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
// Insert your code here for initializing or allocating resources...
// if there have been no failures up to this point then return success
return TRUE;
}
// this function is called when your application is exiting
void helloworld_FreeAppData(helloworld* pMe)
{
// insert your code here for freeing any resources you have allocated...
}
|
|
struct _AEEApplet
{
//
// NOTE: These 3 fields must be declared in this order!
//
DECLARE_VTBL(IApplet)
AEECLSID clsID;
uint32 m_nRefs; // Applet reference counter
IShell * m_pIShell; // pointer to IShell
IModule * m_pIModule; // pointer to IModule
IDisplay * m_pIDisplay; // pointer to IDisplay
//Pointer to Handle Event Function
AEEHANDLER pAppHandleEvent;
// Pointer to FreeAppData function. This will be invoked when the
// reference count of the App goes to zero. This function is supplied
// by the app developer.
// NOTE: Apps should NOT directly call their FreeAppData function.
PFNFREEAPPDATA pFreeAppData;
};
|
|
int AEEClsCreateInstance( AEECLSID clsID,
IShell * pIShell,
IModule * po,
void ** ppObj )
{
boolean result;
*ppObj = NULL;
// 如果Class ID符合我的应用程序...
if( clsID == AEECLSID_MYCLASSID )
{
// 使用BREW助手函数创建应用程序实例
result = AEEApplet_New( sizeof( AEEApplet ),
clsID,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER) HandleEvent,
NULL );
}
return result ? AEE_SUCCESS : EFAILED;
}
|
|
事件名称
|
所属类型
|
描述
|
|
EVT_APP_START
|
系统事件
|
启动应用程序的事件,dwParam = ( AEEAppStart * )
|
|
EVT_APP_STOP
|
系统事件
|
应用程序停止,无参数
|
|
EVT_APP_SUSPEND
|
系统事件
|
应用程序挂起,无参数
|
|
EVT_APP_RESUME
|
系统事件
|
应用程序恢复,dwParam = ( AEEAppStart * )
|
|
EVT_APP_CONFIG
|
系统事件
|
切换应用程序,显示配置界面
|
|
EVT_APP_HIDDEN_CONFIG
|
系统事件
|
切换应用程序,显示隐藏配置界面
|
|
EVT_APP_BROWSE_URL
|
系统事件
|
在EVT_APP_START之后调用,dwParam = (const AECHAR * pURL)
|
|
EVT_APP_BROWSE_FILE
|
系统事件
|
在 EVT_APP_START 之后调用,dwParam = (const AECHAR * pszFileName)
|
|
EVT_APP_MESSAGE
|
系统事件
|
文本消息,wParam = AEESMSEncoding,dwParam取决于 wParam 值的字符串格式
|
|
EVT_APP_TERMINATE
|
系统事件
|
EVT_APP_STOP的强制版本。小程序将被释放。
|
|
EVT_EXIT
|
系统事件
|
在BREW终止时发送给所有已加载的小程序
|
|
EVT_APP_NO_CLOSE
|
系统事件
|
应用程序不应关闭
|
|
EVT_APP_NO_SLEEP
|
系统事件
|
应用程序正在运行 - 运行应用程序很长时间之后调用
|
|
EVT_KEY
|
按键事件
|
按键事件,wParam = 按键代码
|
|
EVT_KEY_PRESS
|
按键事件
|
按键按下事件,wParam = 按键代码,发生在EVT_KEY事件之前
|
|
EVT_KEY_RELEASE
|
按键事件
|
按键抬起事件,wParam = 按键代码,发生在EVT_KEY事件之后
|
|
EVT_CHAR
|
按键事件
|
字符事件,wParam表示发生事件的宽字符
|
|
EVT_UPDATECHAR
|
按键事件
|
字符更新事件,wParam表示发生事件的宽字符
|
|
EVT_COMMAND
|
控件事件
|
自定义控件的事件,wParam表示发生事件的Item ID值。如菜单按下时发生此事件。
|
|
EVT_CTL_TAB
|
控件事件
|
控件焦点切换事件,dwParam = 控件;wParam = 0-向左顺序切换,1-向右顺序切换
|
|
EVT_CTL_SET_TITLE
|
控件事件
|
设置标题的消息接口,wParam = ID;dwParam = 资源文件(如果 ID != 0)或文本
|
|
EVT_CTL_SET_TEXT
|
控件事件
|
设置文本的消息接口, wParam = ID;dwParam = 资源文件(如果 ID != 0)或文本
|
|
EVT_DIALOG_INIT
|
对话框事件
|
对话框初始化事件,创建控件,预初始化值、标记和其它项,wParam = ID;dwParam = IDialog *
|
|
EVT_DIALOG_START
|
对话框事件
|
对话框打开事件,wParam = ID;dwParam = IDialog *
|
|
EVT_DIALOG_END
|
对话框事件
|
对话框正常结束事件,wParam = ID;dwParam = IDialog *
|
|
EVT_COPYRIGHT_END
|
对话框事件
|
版权对话框结束事件
|
|
EVT_ALARM
|
Shell事件
|
闹钟事件,wParam表示闹钟序号
|
|
EVT_NOTIFY
|
Shell事件
|
通知事件,dwParam = AEENotify *
|
|
EVT_BUSY
|
Shell事件
|
发送到应用程序以确定是否可以中止或停止该应用程序。
|
|
EVT_FLIP
|
设备事件
|
设备翻盖事件,wParam = TRUE(打开);FALSE(关闭)
|
|
EVT_KEYGUARD
|
设备事件
|
键盘锁事件,wParam = TRUE(键盘锁定打开)
|
|
EVT_HEADSET
|
设备事件
|
耳机事件,wParam == TRUE(已插入耳机,否则为 FALSE)
|
|
EVT_PEN_DOWN
|
设备事件
|
触摸笔按下事件,dwParam = 点笔的位置: 高16位表示x坐标,低16位表示y坐标
|
|
EVT_PEN_MOVE
|
设备事件
|
触摸笔移动事件,dwParam = 点笔的位置: 高16位表示x坐标,低16位表示y坐标
|
|
EVT_PEN_UP
|
设备事件
|
触摸笔抬起事件,dwParam = 点笔的位置: 高16位表示x坐标,低16位表示y坐标
|
|
EVT_PEN_STALE_MOVE
|
设备事件
|
触摸笔事件过多时发送,应用程序通常忽略这个事件。dwParam = 点笔的位置: 高16位表示x坐标,低16位表示y坐标
|
|
EVT_USER
|
用户事件
|
用户定义事件(应用程序私有)
|
|
static boolean HandleEvent( IApplet *pi,
AEEEvent eCode,
uint16 wParam,
uint32 dwParam )
{
MyAppTyp * pMe = (AEEApplet*)pi;
// 决定如何处理收到的事件
switch (eCode){
// 应用程序启动
case EVT_APP_START:
// 进行相关的初始化操作
return TRUE;
// 挂起应用程序
case EVT_APP_SUSPEND:
// 保存数据用于恢复应用程序
return TRUE;
// 恢复应用程序到运行状态
case EVT_APP_RESUME:
// 恢复挂起时的应用程序状态
return TRUE;
// 应用程序关闭
case EVT_APP_STOP:
// 释放资源
return TRUE;
default:
break;
}
return FALSE;
}
|
|
typedef struct _MyAppTyp
{
AEEApplet a; // 应用程序信息结构体
uint32 m_launchTime, m_nEvents; // 应用程序指定的数据
} MyAppTyp;
int AEEClsCreateInstance( AEECLSID clsID,
IShell * pIShell,
IModule * po,
void ** ppObj )
{
boolean result;
*ppObj = NULL;
// 如果Class ID符合我的应用程序...
if( clsID == AEECLSID_MYCLASSID )
{
// 使用BREW助手函数创建应用程序实例
result = AEEApplet_New( sizeof(MyAppTyp),
clsID,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER) HandleEvent,
NULL );
}
return result ? AEE_SUCCESS : EFAILED;
}
static boolean HandleEvent( IApplet *pi,
AEEEvent eCode,
uint16 wParam,
uint32 dwParam )
{
MyAppTyp *pMe = (MyAppTyp )pi;
pMe->m_nEvents++;
// 决定如何处理收到的事件
switch (eCode){
// 应用程序启动
case EVT_APP_START:
pMe->m_launchTime = GETTIMESECONDS();
pMe->m_nEvents = 1;
return TRUE;
// 挂起应用程序
case EVT_APP_SUSPEND:
return TRUE;
// 恢复应用程序到运行状态
case EVT_APP_RESUME:
return TRUE;
// 应用程序关闭
case EVT_APP_STOP:
DBGPRINTF( "Application ran for %ld seconds.",
GETTIMESECONDS() - pMe->m_launchTime );
DBGPRINTF( "Application received %ld events.",
pMe->m_nEvents );
return TRUE;
default:
break;
}
return FALSE;
}
|
|
ISHELL_CreateInstance( pIShell,
AEECLSID_DISPLAY,
(void **) &pme->m_pIDisplay);
|
|
BREW助手函数
|
C语言标准库
|
|
ATOI
|
atoi
|
|
DBGPRINTF
|
printf
|
|
FREE
|
free
|
|
MALLOC
|
malloc
|
|
MEMCMP
|
memcmp
|
|
MEMCPY
|
memcpy
|
|
MEMMOVE
|
memmove
|
|
MEMSET
|
memset
|
|
REALLOC
|
realloc
|
|
SPRINTF
|
sprintf
|
|
STRCAT
|
strcat
|
|
STRCHR
|
strchr
|
|
STRCMP
|
strcmp
|
|
STRCPY
|
strcpy
|
|
STRDUP
|
strdup
|
|
STRLEN
|
strlen
|
|
STRNCPY
|
strncpy
|
|
STRSTR
|
strstr
|
|
路径名
|
描述
|
|
fs:/mif
|
存储MIF文件的文件夹
|
|
fs:/sys
|
存储BREW系统文件的地方,如系统配置文件、系统资源文件等
|
|
fs:/mod
|
存储应用程序文件夹及文件的地方。在这个文件夹中,使以各个MIF文件名相同名称的文件夹以及MOD文件和签名文件等
|
|
fs:/shared
|
存储公共文件的地方
|
|
标志
|
描述
|
|
Popup
|
此项标志描述当载入应用程序时不清空设备屏幕。如果没有选中此选项,那么当载入应用程序时将首先清空当前的屏幕。如果我们的应用程序在启动时出现白屏,那么可以选择此项解决问题。
|
|
Screensaver
|
此项表示当前的应用程序属于一个屏幕保护的应用程序,这将导致此应用程序出现在屏幕保护程序的列表中。
|
|
Phone
|
此标志表示将BREW设定的关闭全部应用程序的按键事件(通常是End键)像其他正常的按键一样传递给此应用程序(仅在此应用程序处于激活状态时)。此标志只有在应用程序具有系统级别的访问权限时才有效。
|
|
Show On Config Menu
|
此选项表示是否将此应用程序在BREW设置菜单中显示,显示的内容是在下面的“Menu string”输入框中输入的内容。
|
|
Show On Hidden Config Menu
|
此选项表示是否将此应用程序在BREW隐藏设置菜单中显示,显示的内容是在下面的“Menu string”输入框中输入的内容。
|
|
名称
|
描述
|
|
File
|
IFile、IDBMgr、IDatabase和IDBRecord接口的文件和数据库函数。
|
|
Network
|
INetwork和ISocket接口的网络和套接字函数,用以设置TCP和UDP套接字。
|
|
Web Access
|
访问IWeb接口。
|
|
TAPI
|
ITAPI接口中的TAPI函数。
|
|
Position Location
|
IPOSDET_SetGPSConfig、IPOSDET_GetGPSConfig 和 IPOSDET_Get GPSInfo 函数,提供基于GPS的定位信息。ISHELL_GetPosition 函数,提供对设备定位功能的访问。
|
|
Access To Ringer Directory
|
BREW SDK 和手持设备上存储音质文件的目录的写入权限。 在运行 IRINGER_Create() 函数时,将自动创建该目录。
|
|
Write Access To Shared Directory
|
BREW SDK 和手持设备上 <BREW/sdk/examples/Shared> 目录的写入权限。
|
|
Access To Sector Information
|
访问从 IPOSDET_GetSectorInfo API 获取的扇区信息。
|
|
Access To Address Book
|
访问IAddrBook接口
|
303




被折叠的 条评论
为什么被折叠?



