/*===========================================================================
                              OEMAppFuncs.c

  OEM REFERENCE APPLICATION CONTROL ROUTINES
  
  This file contains a reference implementation of a standard AEE application
  control interfaces.
    
        Copyright ?1999-2002 QUALCOMM Incorporated.
               All Rights Reserved.
            QUALCOMM Proprietary/GTDR
============================================================================*/

#include "OEMFeatures.h"


#if defined(OEMAPPFUNCS)

#include "OEMConfig.h"
#include "OEMNotify.h"
#include "bridle_oemsvc.h"

#include "AEE_OEM.h"
#include "AEE_OEMDispatch.h"
#include "AEE_OEMDownload.h"
#include "AEEDownload.h"
#include "AEEStdLib.h"
#ifdef FEATURE_PROVISION
#include "OEMProvisionItems.h"
#endif // FEATURE_PROVISION

  

static AEECallback   gCBReset;   
static boolean       gbReset = FALSE;
static AEECallback   gCBStartCoreOEMApp;

/*==================================================================
Function: OEM_AuthorizeDownload

Description: 

 This function is called before each download.  The OEM must fire the callback before the IDOWNLOAD_Acquire 
 operation will be completed.  The OEM can use the IDownload instance class instance and the item/price IDs
 to query information about the item if desired.  In addition, the IDownload pointer can be used to 
 set the HTTP headers sent to the ADS.  This is performed via the IDOWNLOAD_SetHeaders method.

 pUser - User data to be passed to the callback.
 iID - Item ID
 iPrice - Item Price Handle
 pItem - Pointer to information structure for the item
 nErr - Error code.  If non-zero, the download will abort and this error will be reported.

Prototype:
   void OEM_AuthorizeDownload(IDownload * pd, DLITEMID iID, DLPRICEID iPrice,PFNCHECKDLCB pfn, void * pUser);

Parameter(s):

Return Value:  None
Comments:      None
Side Effects:  None
See Also:      None

==================================================================*/
void OEM_AuthorizeDownload(IDownload * pd, DLITEMID iID, DLPRICEID iPrice,DLItem * pItem,PFNCHECKDLCB pfn, void * pUser)
{
   pfn(pUser,iID,iPrice,0);
}


/*==================================================================
Function: OEM_SimpleBeep

Description:
   This function plays a standard OEM beep tone and vibration given
the duration, and returns TRUE if successful.

Prototype:
   boolean OEM_SimpleBeep(BeepType nBeepType, boolean bLoud);

Parameters:
   nBeepType: beep type which can be one of the following:
      - BEEP_OFF: stop playback of the current beep or vibration
      - BEEP_ALERT: alert beep tone
      - BEEP_REMINDER: reminder beep tone
      - BEEP_MSG: message beep tone
      - BEEP_ERROR: error beep tone
      - BEEP_VIBRATE_ALERT: alert vibration
      - BEEP_VIBRATE_REMIND: reminder vibration
   bLoud: boolean flag that sets the playback volume high or low

Return Value:
   TRUE if successfuly played or stopped the tone or vibration;
   FALSE otherwise/unsupported.

Comments:
   None

Side Effects:
   None

See Also:
   None
==================================================================*/
boolean OEM_SimpleBeep(BeepType nBeepType, boolean bLoud)
{
   return packbridle_OEM_SVCSimpleBeep(nBeepType, bLoud);
}

/*==============================================================
==============================================================*/
static void WakeReset(void * pUnused)
{
   AEE_SafeExit();
   AEEOS_ResetDevice(" Resetting...", 0);
}

/*==============================================================
Function: WakeCoreOEMApp

Description: Starts OEM's core BREW app that represents the idle state.
             This is useful when the device UI etc. are BREW apps.
==============================================================*/
static void WakeCoreOEMApp( void *pUnused )
{
   ISHELL_StartApplet( AEE_GetShell(), AEECLSID_CORE_OEMAPP );
}
/*==============================================================
Function: OEM_Notify

Description: Notification to the device

==============================================================*/
int OEM_Notify(OEMNotifyEvent evt, uint32 dw)
{
   OEMAppEvent * pae = (OEMAppEvent *)dw;

   switch(evt){
      case OEMNTF_IDLE:
         if(gbReset){
            gbReset = FALSE;
            CALLBACK_Init(&gCBReset, WakeReset, NULL);
            AEE_ResumeCallback(&gCBReset,0);
         }
         else {
            CALLBACK_Init(&gCBStartCoreOEMApp, WakeCoreOEMApp, NULL);
            AEE_ResumeCallback(&gCBStartCoreOEMApp,0);
         }
         break;

      case OEMNTF_RESET:
//         if(ISHELL_ActiveApplet(AEE_GetShell())){
//            gbReset = TRUE;
//            ISHELL_CloseApplet(AEE_GetShell(),TRUE);
//         }
//         else{
            CALLBACK_Init(&gCBReset, WakeReset, NULL);
            AEE_ResumeCallback(&gCBReset,0);
//         }
         break;
      case OEMNTF_APP_EVENT:
         if( pae->evt == EVT_APP_START   ||
             pae->evt == EVT_APP_STOP    ||
             pae->evt == EVT_APP_SUSPEND ||
             pae->evt == EVT_APP_RESUME ){
            DBGEVENT( pae->evt, pae->cls );
         }
         break;

      default:
         break;
   }
   return(0);
}

/*==============================================================
Function: OEM_IsClsOKInSafeMode

Description: The OEMs can maintain a list of class IDs for apps
             that they do not want to throttle when in Safe mode.
             For example, the OEM will not throttle the UI app.
             in devices where the UI is implemented using BREW.

==============================================================*/
boolean OEM_IsClsOKInSafeMode(uint32 clsid)
{
   return FALSE;
}

#endif

