⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extentest.c

📁 brew平台关于扩展编写的一个简单的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================

FILE: extentest.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "UIExtension.h"
#include "DatExtension.h"

#include "DatApplet.bid"
#include "UIApplet.bid"

/*macro*/
#define BUFFER_SIZE 64
#define DISPLY_SETP 8

/*******************************************************************
*Applet structure
********************************************************************/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.

/*1.UIApplet*/
typedef struct _UIApplet 
{
	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...
	IUIExtension   *m_pUiExtension;


} UIApplet;

/*2.DatApplet*/
typedef struct _DatApplet 
{
	AEEApplet      a ;	       // First element of this structure must be AEEApplet
    AEEDeviceInfo  DeviceInfo; // always have access to the hardware device information

	IDatExtension *m_pDatExtension;
    // add your own variables here...
	
} DatApplet;

/*******************************************************************
* extension structure
********************************************************************/

/*3.UIextension structure*/
typedef struct _UIExtensionCls
{
	// Declare our VTable
	// by doing so, we have placed function pointers
	// in the begininng of this structure
	DECLARE_VTBL(IUIExtension)
		
	// Class member variables
	uint32		m_nRefs;				// References to us
	IShell      *m_pIShell;				// copy of Shell pointer
	IDisplay    *m_pIDisplay;			// Display interface pointer
	IModule     *m_pIModule;			// IModule interface pointer
	
	
	AEECallback *m_pCB;			// Callback function pointer for the caller
	char*	m_pBuf;					// Application status code for the caller
	
	AEECLSID	m_iCaller;			
	
}UIExtensionCls;

/*4.Dat Extension structure*/
typedef struct _DatExtensionCls
{
	// Declare our VTable
	// by doing so, we have placed function pointers
	// in the begininng of this structure
	DECLARE_VTBL(IDatExtension)
		
	// Class member variables
	uint32		m_nRefs;				// References to us
	IShell      *m_pIShell;				// copy of Shell pointer
	IDisplay    *m_pIDisplay;			// Display interface pointer
	IModule     *m_pIModule;			// IModule interface pointer
	
	
	AEECallback *m_pCB;			// Callback function pointer for the caller
	char*	m_pBuf;					// Application status code for the caller
	
	AEECLSID	m_iCaller;	
	int iLoop;		      /*count*/
	PFNNOTIFY m_fnTimeCb; /*Timer Callback*/
	
}DatExtensionCls;

/********************************************************************
Function Prototypes
*********************************************************************/
/*1.UI applet*/
static  boolean UIApplet_HandleEvent(UIApplet* pMe, AEEEvent eCode, 
                                             uint16 wParam, uint32 dwParam);
boolean UIApplet_InitAppData(UIApplet* pMe);
void    UIApplet_FreeAppData(UIApplet* pMe);

/*2.dat applet*/
static  boolean DatApplet_HandleEvent(DatApplet* pMe, AEEEvent eCode, 
									 uint16 wParam, uint32 dwParam);
boolean DatApplet_InitAppData(DatApplet* pMe);
void    DatApplet_FreeAppData(DatApplet* pMe);

/*3.UI extension*/
static uint32 UIExtensionCls_AddRef(IUIExtension * po);
static uint32 UIExtensionCls_Release(IUIExtension* po);
static void UIExtensionCls_Show(IUIExtension* po,char* pBuffer,int len);


/*4.dat extension*/
static uint32 DatExtensionCls_AddRef(IDatExtension * po);
static uint32 DatExtensionCls_Release(IDatExtension* po);
static char*  DatExtensionCls_GetData(IDatExtension* po,int item);
static void  DatExtensionCls_SendData(IDatExtension* po,PFNNOTIFY pfn);
static void  TimeNotify(void * pData);/*timer callback*/

/*******************************************************************************
FUNCTION DEFINITIONS
********************************************************************************/
/*1.Dat Extension*/
/*for initial*/
int DatExtensionCls_New(int16 nSize, IShell *pIShell, IModule* pIModule, IDatExtension ** ppMod)
{
	DatExtensionCls *			pMe = NULL;
	VTBL(IDatExtension) *	modFuncs;
	int iLoop = 0;
	
	if( !ppMod || !pIShell || !pIModule )
		return EFAILED;
	
	*ppMod = NULL;
	
	// Allocate memory for the MyExtension object
	if( nSize < sizeof(DatExtensionCls) )
		nSize += sizeof(DatExtensionCls);
	
	if( (pMe = (DatExtensionCls*)MALLOC(nSize + sizeof(IDatExtensionVtbl))) == NULL )
		return ENOMEMORY;
	
	// Allocate the vtbl and initialize it. Note that the modules and apps must not
	// have any static data. Hence, we need to allocate the vtbl as well.
	modFuncs = (IDatExtensionVtbl *)((byte *)pMe + nSize);
	//Initialize individual entries in the VTBL
	modFuncs->AddRef			= DatExtensionCls_AddRef;
	modFuncs->Release			= DatExtensionCls_Release;
	modFuncs->GetData           = DatExtensionCls_GetData;
	modFuncs->SendData          = DatExtensionCls_SendData;
	// initialize the vtable
	INIT_VTBL(pMe, IDatExtension, *modFuncs);
	
	// initialize the data members
	pMe->m_pBuf = (char*)MALLOC(BUFFER_SIZE);
	for(iLoop = 0;iLoop < BUFFER_SIZE;iLoop++)
	{
		pMe->m_pBuf[iLoop] = iLoop + 0x21;/*ascII code to display*/
	}
	pMe->m_nRefs      = 1;
	
	// init all data members
	pMe->m_iCaller = 0;		
	pMe->iLoop = 0;
//	pMe->m_fnTimeCb = TimeNotify;

	pMe->m_pIShell = pIShell;
	ISHELL_AddRef(pIShell);	
	
	// Set the pointer in the parameter
	*ppMod = (IDatExtension*)pMe;
	
	return AEE_SUCCESS;
	
}

static uint32 DatExtensionCls_AddRef(IDatExtension * po)
{
	return (++((DatExtensionCls *)po)->m_nRefs);
}


static uint32 DatExtensionCls_Release(IDatExtension * po)
{
	DatExtensionCls *		pMe = (DatExtensionCls *)po;
	
	if( --pMe->m_nRefs != 0 )
		return pMe->m_nRefs;
	
	// Ref count is zero. So, release memory associated with this object.
	
	//Free the object itself
	if(pMe->m_pBuf)
		FREE(pMe->m_pBuf);

	ISHELL_Release(pMe->m_pIShell);	
	
	/*cancel timer*/
	ISHELL_CancelTimer(pMe->m_pIShell,pMe->m_fnTimeCb,(void*)pMe);	
	
	FREE_VTBL(pMe, IDatExtension);
	FREE( pMe );
	
	return 0;
}

/*get data point*/
static char* DatExtensionCls_GetData(IDatExtension* po,int item)
{
	DatExtensionCls * pMe = (DatExtensionCls *)po;
	return(pMe->m_pBuf + item);

}
static void  DatExtensionCls_SendData(IDatExtension* po,PFNNOTIFY pfn)
{
	DatExtensionCls *pMe = (DatExtensionCls*)po;
	pMe->m_fnTimeCb = pfn;
	ISHELL_SetTimer(pMe->m_pIShell,2,pfn,(void*)pMe);				
		
}

static void TimeNotify(void * pData)
{

	DatExtensionCls *po = (DatExtensionCls*)pData;
	/*Get Buffer point */
	char *pBuf 	= IDatExtension_GetData((IDatExtension*)po,po->iLoop);
	/*send event to notify UI applet*/
	ISHELL_SendEvent(po->m_pIShell,AEECLSID_UIAPPLET,EVT_DATA_UPDATE,0,(uint32)(pBuf));
	/*cancel timer*/
	ISHELL_CancelTimer(po->m_pIShell,po->m_fnTimeCb,(void*)po);

	po->iLoop = (po->iLoop+DISPLY_SETP) % BUFFER_SIZE;
	/*reset timer*/
	ISHELL_SetTimer(po->m_pIShell,2000,TimeNotify,(void*)po);			
	
}


/*2.UIExtension*/
//initial
int UIExtensionCls_New(int16 nSize, IShell *pIShell, IModule* pIModule, IUIExtension ** ppMod)
{
	UIExtensionCls *			pMe = NULL;
	VTBL(IUIExtension) *	modFuncs;
	
	if( !ppMod || !pIShell || !pIModule )
		return EFAILED;
	
	*ppMod = NULL;
	
	// Allocate memory for the MyExtension object
	if( nSize < sizeof(UIExtensionCls) )
		nSize += sizeof(UIExtensionCls);
	
	if( (pMe = (UIExtensionCls*)MALLOC(nSize + sizeof(IUIExtensionVtbl))) == NULL )
		return ENOMEMORY;
	
	// Allocate the vtbl and initialize it. Note that the modules and apps must not
	// have any static data. Hence, we need to allocate the vtbl as well.
	modFuncs = (IUIExtensionVtbl *)((byte *)pMe + nSize);
	//Initialize individual entries in the VTBL
	modFuncs->AddRef			= UIExtensionCls_AddRef;
	modFuncs->Release			= UIExtensionCls_Release;
	modFuncs->Show				= UIExtensionCls_Show;
		
	// initialize the vtable
	INIT_VTBL(pMe, IUIExtension, *modFuncs);
	
	// initialize the data members
	pMe->m_nRefs      = 1;
	
	// init all data members
	pMe->m_iCaller = 0;	
	
	if( ISHELL_CreateInstance(pIShell, 
		                      AEECLSID_DISPLAY, 
		                      (void **)&(pMe->m_pIDisplay)) != SUCCESS )
		return EFAILED;	
	
	// Set the pointer in the parameter
	*ppMod = (IUIExtension*)pMe;
	
	return AEE_SUCCESS;
}


static uint32 UIExtensionCls_AddRef(IUIExtension * po)
{
	return (++((UIExtensionCls *)po)->m_nRefs);
}


static uint32 UIExtensionCls_Release(IUIExtension * po)
{
	UIExtensionCls *		pMe = (UIExtensionCls *)po;
	
	if( --pMe->m_nRefs != 0 )
		return pMe->m_nRefs;
	
	// Ref count is zero. So, release memory associated with this object.
		
	//Free the object itself
	if( pMe->m_pIDisplay )
		IDISPLAY_Release(pMe->m_pIDisplay);	
	FREE_VTBL(pMe, IUIExtension);
	FREE( pMe );
	
	return 0;
}

static void UIExtensionCls_Show(IUIExtension* po,char* pBuffer,int len)
{
	UIExtensionCls *		pMe = (UIExtensionCls *)po;
	char *acTemp = (char*)MALLOC(len+1);
	AECHAR *acBuffer = (AECHAR*)MALLOC((len+1)*sizeof(AECHAR));
	MEMSET(acTemp,0,(len+1)*sizeof(char));
	MEMSET(acBuffer,0,(len+1)*sizeof(AECHAR));
	
	MEMCPY(acTemp,pBuffer,len);
	acTemp[len] = '\0';

	STRTOWSTR(acTemp,acBuffer,(len+1)*sizeof(AECHAR));

	IDISPLAY_DrawText(pMe->m_pIDisplay,    // Display instance
		AEE_FONT_BOLD,       // Use BOLD font
		acBuffer,              // Text - Normally comes from resource
		-1,                  // -1 = Use full string length
		0,                   // Ignored - IDF_ALIGN_CENTER
		0,                   // Ignored - IDF_ALIGN_MIDDLE
		NULL,                // No clipping
		IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
				
	IDISPLAY_Update (pMe->m_pIDisplay);
	FREE(acTemp);
	FREE(acBuffer);				

}

/*===========================================================================
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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -