Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

IFlip sample code, part 4

Definition and implementation of the c_iflipapp_InitAppData() function.

/*===========================================================================
FUNCTION c_iflipapp_InitAppData

DESCRIPTION
This function is called when your application is starting up 
and initialization of structure members and variables done here.

PROTOTYPE:
boolean c_iflipapp_InitAppData(c_iflipapp* pMe)

PARAMETERS:
pMe: Pointer to the c_iflipapp structure.

DEPENDENCIES
none

RETURN VALUE
TRUE: If intialization of structure members succeeds.
FALSE: If intialization of structure members failed.

SIDE EFFECTS
none
===========================================================================*/

boolean c_iflipapp_InitAppData(c_iflipapp* pMe)
{
   int i=0,nErr; AEERect rc;
   // 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);
	
   // The display and shell interfaces are always created by
   // default, so we'll asign them so that you can access
   // them via the standard "pMe->" without the "a."
   pMe->pIDisplay = pMe->a.m_pIDisplay;
   pMe->pIShell   = pMe->a.m_pIShell;

   // Sets the istatic dimensions
   rc.x  = 0;
   rc.y  = 0;
   rc.dx =  pMe->DeviceInfo.cxScreen;
   rc.dy =  pMe->DeviceInfo.cyScreen - SOFT_KEY_HEIGHT;
	
   // First screen is notice
   pMe->currentAppState = NOTICE_SCR;
   pMe->pIFlip    = NULL;
   pMe->pDispList = NULL;
   pMe->pIStatic  = NULL;
   pMe->pbuffer        = NULL;
   pMe->pOpenKeyList   = NULL;
   pMe->pCloseKeyList  = NULL;
   pMe->pIMedia        = NULL;
   pMe->pAckFromBGapp  = NULL;
   pMe->pFlipInfoList  = NULL;
   pMe->pFlipInfoListOnFlipEvents = NULL;
   pMe->nCurrentFlip   = 0;
   pMe->bIsFlip = FALSE;

   for( i=0 ;i < MAX_DISPLAY; i++)
   {
      pMe->pIDis[i] = NULL;
      pMe->pDispClassId[i] = 0;
   }

   // Creating the IFlip instance if failed then return .
   if(ISHELL_CreateInstance(pMe->a.m_pIShell, 
                            AEECLSID_FLIP, 
                            (void **)&pMe->pIFlip) != SUCCESS)
   {
      DBGPRINTF("Iflip instance creation failure");
      return FALSE;
   }

   // Create IStatic instance
   if (ISHELL_CreateInstance(pMe->a.m_pIShell, 
                             AEECLSID_STATIC, 
                             (void **)&(pMe->pIStatic)) != SUCCESS)
   {
      DBGPRINTF("IStatic instance creation failure");
      return FALSE;
   }
	
   // Memory allocation
   if((pMe->pbuffer = (char *) MALLOC(TEXT_BUFFER_SIZE)) == NULL) 
   {
      DBGPRINTF("pbuffer Malloc failed");
      return FALSE;
   }
	
   if((pMe->pOpenKeyList = (char *) MALLOC(TEXT_BUFFER_SIZE)) == NULL) 
   {
      DBGPRINTF("pOpenKeyList Malloc failed");
      return FALSE;
   }
	
   if((pMe->pCloseKeyList = (char *) MALLOC(TEXT_BUFFER_SIZE)) == NULL) 
   {
      DBGPRINTF("pCloseKeyList Malloc failed");
      return FALSE;
   }
	
   if((pMe->pAckFromBGapp = (char *) MALLOC(TEXT_BUFFER_SIZE)) == NULL) 
   {
      DBGPRINTF("pAckFromBGapp Malloc failed");
      return FALSE;
   }
	
   // Getting the number of flip in advance and allocate memory
   nErr=IFLIP_GetFlipIDList(pMe->pIFlip,0,&pMe->nNumberOfFlip); 
   DBGPRINTF("nErr=%d",nErr);
   DBGPRINTF("number of flips = %d", pMe->nNumberOfFlip);

   if((pMe->pFlipInfoList = 
            (AEEFlipInfo *)MALLOC(sizeof(AEEFlipInfo)*(pMe->nNumberOfFlip))) == NULL)
   {
      DBGPRINTF("pFlipInfoList Malloc failed");
	  return FALSE;
   }
   
   IFLIP_GetFlipIDList(pMe->pIFlip,pMe->pFlipInfoList,&pMe->nNumberOfFlip);

   // Start Background application and play audio to notify user that it started.

   if(SUCCESS == ISHELL_StartBackgroundApplet(pMe->pIShell,AEECLSID_C_BGAPP,NULL))
   {
      DBGPRINTF("BG app started");
	  c_iflipapp_PlayAudio(pMe, "media/bgstarted.qcp");
   }
   else
   {	
      DBGPRINTF("BG app failed to start");
      c_iflipapp_PlayAudio(pMe, "media/bgnotstarted.qcp");
   }

   if((pMe->pFlipInfoListOnFlipEvents = 
            (AEEFlipInfo *)MALLOC(sizeof(AEEFlipInfo)*(pMe->nNumberOfFlip))) == NULL)
   {
      DBGPRINTF("Malloc failed");
	  return FALSE;
   }

   IFLIP_GetFlipIDList(pMe->pIFlip,pMe->pFlipInfoListOnFlipEvents,&pMe->nNumberOfFlip);

	// Set Istatic properties		
   ISTATIC_SetRect(pMe->pIStatic, &rc); 
   ISTATIC_SetProperties(pMe->pIStatic, ST_ASCII|ST_MIDDLETEXT);
   // if there have been no failures up to this point then return success
   return TRUE;
}