/*===========================================================================
FILE: AEEModGen.c
SERVICES: Sample IModule implementation file
DESCRIPTION
This file contains sample implementation of the IModule interface
This file can be used for developing dynamic apps as well as static apps. Static
apps are the apps that will be statically linked with the phone image by the OEM.
To develop a static app, the following steps need to be done:
1. Provide a GetModInfo() function
2. Provide a Load() function
3. Provide a CreateInstance() function (which is identical to the AEEClsCreateInstance()
function that must be provided by a dynamic module.
PUBLIC CLASSES:
N/A
INITIALIZATION AND SEQUENCING REQUIREMENTS: N/A
Copyright � 1999-2002 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary/GTDR
========================================================================== */
/*==========================================================================
INCLUDES AND VARIABLE DEFINITIONS
========================================================================== */
#include "AEEHeap.h" // Memory allocation Routines
#include "AEEStdLib.h" // AEE Standard C library functions
#include "AEEModGen.h" // Contains Sample AEEModule declarations
#include "AEEAppGen.h"
/*==========================================================================
PUBLIC DATA DECLARATIONS
========================================================================== */
/*-------------------------------------------------------------------
Type Declarations
-------------------------------------------------------------------*/
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
/*
|| Functions to be provided by the module developers.
*/
static uint32 AEEMod_AddRef(IModule *po);
static uint32 AEEMod_Release(IModule *po);
static int AEEMod_CreateInstance(IModule *po,IShell *pIShell,
AEECLSID ClsId, void **ppObj);
static void AEEMod_FreeResources(IModule *po, IHeap *ph, IFileMgr *pfm);
/*-------------------------------------------------------------------
Global Constant Definitions
-------------------------------------------------------------------*/
/*-------------------------------------------------------------------
Global Data Definitions
-------------------------------------------------------------------*/
#ifdef AEE_SIMULATOR
// IMPORTANT NOTE: g_pvtAEEStdLibEntry global variable is defined for
// SDK ONLY! This variable should NOT BE:
//
// (1) overwritten
// (2) USED DIRECTLY by BREW SDK users.
//
// g_pvtAEEStdLibEntry is used as an entry point to AEEStdLib,
AEEHelperFuncs *g_pvtAEEStdLibEntry;
#endif
/*-------------------------------------------------------------------
Static variable Definitions
-------------------------------------------------------------------*/
/* =========================================================================
FUNCTION DEFINITIONS
========================================================================= */
/* =========================================================================
Function: AEEMod_Load()
Description:
This is the module load function. It is invoked when the module is being
loaded. It creates an instance of the AEEMod structure and initializes
the data members appropriately.
If running under the AEE Simulator, the function is prefixed with the tag
__declspec(dllexport) so that this function is exported by the App DLL.
This function shall be invoked from within the AEE.
Prototype:
boolean AEEMod_Load(IShell *pIShell, char *psz, IModule **ppMod)
Parameters:
piShell: Pointer to IShell interface
psz: String containing name of the resource file for module
ppMod: [ou]: On return, *ppMod contains a valid pointer to the AEEMod
structure
Return Value:
SUCCESS: If successful
Error code: IF failed
Comments:
This function must be the first function in the first module for
it to work on the handset!
Side Effects:
None
============================================================================*/
#ifdef AEE_SIMULATOR
__declspec(dllexport) int AEEMod_Load(IShell *pIShell, void *ph, IModule **ppMod)
#else
#if defined(BREW_MODULE) || defined(FLAT_BREW)
extern int module_main(IShell *pIShell, void *ph, IModule **ppMod);
int module_main(IShell *pIShell, void *ph, IModule **ppMod)
#else
int AEEMod_Load(IShell *pIShell, void *ph, IModule **ppMod)
#endif
#endif
{
// Invoke helper function to do the actual loading.
return AEEStaticMod_New(sizeof(AEEMod),pIShell,ph,ppMod,NULL,NULL);
}
/*===========================================================================
Function: AEEStaticMod_New()
Description:
This is the module load function for static modules. It is directly
invoked by static modules when the static module is being loaded.
It also serves as a helper function for dynamic modules.
It creates an instance of the AEEMod structure and initializes the data
members appropriately. The only difference between this function and the
one used for dynamic mods is that this function takes an additional
parameter that specifies the CreateInstance function of the static module.
Prototype:
boolean AEEStaticMod_New(int nSize, IShell *pIShell, void *ph,
IModule **ppMod,PFNMODCREATEINST pfn)
Parameters:
nSize: Specifies the size (in bytes) of the structure to be allocated for
the module. Typically, this is the size of the AEEMod structure
piShell: Pointer to IShell interface
ph: Not used on phone. In SDK, this is a pointer to the AEEHelperFuncs
structure.
ppMod: [ou]: On return, *ppMod contains a valid pointer to the AEEMod
structure
pfn: Pointer to the modules' CreateInstance() function
Return Value:
SUCCESS: If successful
Error code: IF failed
Comments: None
Side Effects: None
==============================================================================*/
int AEEStaticMod_New(int16 nSize, IShell *pIShell, void *ph, IModule **ppMod,
PFNMODCREATEINST pfnMC,PFNFREEMODDATA pfnMF)
{
AEEMod *pMe = NULL;
VTBL(IModule) *modFuncs;
if (!ppMod || !pIShell) {
return EFAILED;
}
*ppMod = NULL;
#ifdef AEE_SIMULATOR
// IMPORTANT NOTE: g_pvtAEEStdLibEntry global variable is defined for
// SDK ONLY! This variable should NOT BE:
//
// (1) overwritten
// (2) USED DIRECTLY by BREW SDK users.
//
// g_pvtAEEStdLibEntry is used as an entry point to AEEStdLib,
// DO NOT REMOVE the next five lines.
if (!ph) {
return EFAILED;
} else {
g_pvtAEEStdLibEntry = (AEEHelperFuncs *)ph;
}
#endif
//Allocate memory for the AEEMod object
if (nSize < sizeof(AEEMod)) {
nSize += sizeof(AEEMod);
}
if (NULL == (pMe = (AEEMod *)MALLOC(nSize + sizeof(IModuleVtbl)))) {
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 = (IModuleVtbl *)((byte *)pMe + nSize);
// Initialize individual entries in the VTBL
modFuncs->AddRef = AEEMod_AddRef;
modFuncs->Release = AEEMod_Release;
modFuncs->CreateInstance = AEEMod_CreateInstance;
modFuncs->FreeR