#ifndef AEEMODULEDEFS_H
#define AEEMODULEDEFS_H
/*===========================================================================
HEADER     AEEModuleDefs.h                 
 
ABSTRACT   AEE Module Support services for dynamically loaded modules

DESCRIPTION
   Provides services to dynamically loaded modules that allow them to
   initialize themselves and provide transparent library services.

PUBLIC CLASSES
   Not Applicable

INITIALIZATION AND SEQUENCING REQUIREMENTS
   Not Applicable


        Copyright © 1999-2002 QUALCOMM Incorporated.
               All Rights Reserved.
            QUALCOMM Proprietary/GTDR
===========================================================================*/

/*=============================================================================
// INCLUDES AND VARIABLE DEFINITIONS
=============================================================================*/

#ifdef __cplusplus
extern "C" {
#endif

/*---------------------------------------------------------------------------*
// Defines
 *---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*
// Include Files
 *---------------------------------------------------------------------------*/
#include "AEEComdef.h"

/*---------------------------------------------------------------------------*
// Type Declarations
 *---------------------------------------------------------------------------*/

typedef uint32 (*ProcPtr)();
typedef uint32 (*ModProcPtr)();

typedef struct AEEGlobalFunctionTable {
   void *(*gfMalloc)(uint32 size);
   void (*gfFree)(void *ptr);
   void *(*gfCalloc)(uint32 el_count, uint32 el_size);
   void *(*gfRealloc)(void *oldptr, uint32 newsize);
   void *(*gfGlueVtbl)(const void *vtbl, uint32 numEntries);
   void (*gfGlueAddRef)(void *gluevtbl);
   void (*gfGlueDelRef)(void *gluevtbl);
   uint32 (*gfGlueGetRefs)(const void *gluevtbl);
   ModProcPtr (*gfNewProcPtr)(ProcPtr localProc);
   void (*gfDisposeProcPtr)(ModProcPtr globalProc);
} AEEGlobalFunctionTable;

typedef struct AEEModuleSupportInfo {
   uint32   version;
   uint32   oldestVersion;
   uint32   gfuncCount;
   const AEEGlobalFunctionTable *gftbl;
   void     **sbStackPtrPtr;
} AEEModuleSupportInfo;

/*---------------------------------------------------------------------------*
// Global Constant Declarations
 *---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*
// Global Data Declarations
 *---------------------------------------------------------------------------*/

extern AEEGlobalFunctionTable *gftbl;

/*=============================================================================
// FUNCTION DECLARATIONS and INLINE FUNCTION DEFINITIONS
=============================================================================*/

/*---------------------------------------------------------------------------*
// Interface Definitions - C Style
 *---------------------------------------------------------------------------*/

#ifdef FLAT_BREW

//TAB(doesn't seem to exist) extern uint32 AEEModule_SetSB(void);
//TAB(doesn't seem to exist) extern void AEEModule_RestoreSB(uint32);

#else

#define AEEModule_SetSB() 0
#define AEEModule_RestoreSB(x)

#endif

#ifdef BREW_MODULE

/* Note that sb MUST have the correct value for localProc when
** AEEModule_NewProcPtr is called.  Normally you call this
** from the same module as localProc so it's not a problem.
*/
/*extern ModProcPtr AEEModule_NewProcPtr(ProcPtr localProc);*/
#define AEEModule_NewProcPtr(localProc) ((*gftbl->gfNewProcPtr)(localProc))

/*extern void AEEModule_DisposeProcPtr(ModProcPtr);*/
#define AEEModule_DisposeProcPtr(globalProc) ((*gftbl->gfDisposeProcPtr)(globalProc))

#else

#define AEEModule_NewProcPtr(localProc) ((ModProcPtr)(localProc))
#define AEEModule_DisposeProcPtr(globalProc)

#endif

#ifdef __cplusplus
}
#endif

#endif   /* AEEMODULEDEFS_H */

