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

📄 myringer.step4

📁 高通 BREW 培训 实用例子
💻 STEP4
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================

FILE: myringer.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEFile.h"			// File interface definitions
#include "AEEStdLib.h"
#include "AEEMenu.h"
#include "AEERinger.h"

#include "myringer.bid"

const char * FormatList[] = { "UNKNOWN\n", "MIDI\n", "MP3\n", "LAST\n" };

/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _myringer {
	AEEApplet      a ;	       // First element of this structure must be AEEApplet
    AEEDeviceInfo  DeviceInfo; // always have access to the hardware device information
    IDisplay      *pIDisplay;  // give a standard way to access the Display interface
    IShell        *pIShell;    // give a standard way to access the Shell interface

	IFileMgr	  *m_pIFileMgr;	// File Manager
	IFile		  *m_pIFile;		// File Object
	IMenuCtl	  *m_pIMainMenu;	// Main Menu
	IMenuCtl	  *m_pISoftMenu;	// Soft-Key Menu
	IRingerMgr    *m_pIRingerMgr;
	IMemAStream   *m_pMemStream;
	IStatic		  *m_pIStatic;
	AECHAR		  *m_pszText;
	byte		  *m_pBuff;
	AECHAR		   m_szTitle[20];

} myringer;


#define RT_CREATE			100
#define RT_ENUMCATEGORY		101
#define RT_ENUMRINGER		102
#define RT_RINGERFORMAT		103
#define RT_PLAY				104
#define RT_SETRINGER		105
#define RT_REMOVE			106

#define RINGER_NAME_PREFIX	"rt"
#define SetRingerName(name) 	RINGER_NAME_PREFIX#name

#define SOFTMENU_BACK		400

#define TEXT_BUFFER_SIZE (1024 * sizeof(AECHAR))
#define BOTTOM_TEXT_HEIGHT			15


/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static  boolean myringer_HandleEvent(myringer* pMe, 
                                                   AEEEvent eCode, uint16 wParam, 
                                                   uint32 dwParam);
boolean myringer_InitAppData(myringer* pMe);
void    myringer_FreeAppData(myringer* pMe);

static void DisplayText(myringer* pMe);
static void BuildMainMenu(myringer* pMe);
static boolean CreateRinger(myringer* pMe, const char * ringername, 
						const char * inputfile, AEESoundPlayerFile format);
static void CleanUp(myringer* pMe);

static AEERingerID GetFirstRingerID(myringer* pMe);


/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */

/*===========================================================================
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
   example, a generic structure is provided so that app developers need not change app specific
   initialization section every time except for a call to IDisplay_InitAppData(). 
   This is done as follows: InitAppData() is called to initialize AppletData 
   instance. It is app developers responsibility to fill-in app data initialization 
   code of InitAppData(). App developer is also responsible to release memory 
   allocated for data contained in AppletData -- this can be done in 
   IDisplay_FreeAppData().

PROTOTYPE:
   int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)

PARAMETERS:
	clsID: [in]: Specifies the ClassID of the applet which is being loaded

	pIShell: [in]: Contains pointer to the IShell object. 

	pIModule: pin]: Contains pointer to the IModule object to the current module to which
	this app belongs

	ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
	of memory for this structure and initializing the base data members is done by AEEApplet_New().

DEPENDENCIES
  none

RETURN VALUE
  AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
     successful
  EFAILED: If the app does not need to be loaded or if errors occurred in 
     AEEApplet_New(). If this function returns FALSE, the app will not be loaded.

SIDE EFFECTS
  none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
	*ppObj = NULL;

	if( ClsId == AEECLSID_MYRINGER )
	{
		// Create the applet and make room for the applet structure
		if( AEEApplet_New(sizeof(myringer),
                          ClsId,
                          pIShell,
                          po,
                          (IApplet**)ppObj,
                          (AEEHANDLER)myringer_HandleEvent,
                          (PFNFREEAPPDATA)myringer_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
                          
		{
			//Initialize applet data, this is called before sending EVT_APP_START
            // to the HandleEvent function
			if(myringer_InitAppData((myringer*)*ppObj))
			{
				//Data initialized successfully
				return(AEE_SUCCESS);
			}
			else
			{
				//Release the applet. This will free the memory allocated for the applet when
				// AEEApplet_New was called.
				IAPPLET_Release((IApplet*)*ppObj);
				return EFAILED;
			}

        } // end AEEApplet_New

    }

	return(EFAILED);
}


/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent

DESCRIPTION
	This is the EventHandler for this app. All events to this app are handled in this
	function. All APPs must supply an Event Handler.

PROTOTYPE:
	boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
	pi: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AEEClsCreateInstance() function.

	ecode: Specifies the Event sent to this applet

   wParam, dwParam: Event specific data.

DEPENDENCIES
  none

RETURN VALUE
  TRUE: If the app has processed the event
  FALSE: If the app did not process the event

SIDE EFFECTS
  none
===========================================================================*/
static boolean myringer_HandleEvent(myringer* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  

	char szBuf[100];

    switch (eCode) 
	{
        // App is told it is starting up
        case EVT_APP_START:                        
		    BuildMainMenu(pMe);
            return(TRUE);


        // App is told it is exiting
        case EVT_APP_STOP:
            // Add your code here...

      		return(TRUE);


        // App is being suspended 
        case EVT_APP_SUSPEND:
		    // Add your code here...

      		return(TRUE);


        // App is being resumed
        case EVT_APP_RESUME:
		    // Add your code here...

      		return(TRUE);


        // An SMS message has arrived for this app. Message is in the dwParam above as (char *)
        // sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
        case EVT_APP_MESSAGE:
		    // Add your code here...

      		return(TRUE);

        // A key was pressed. Look at the wParam above to see which key was pressed. The key
        // codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
        case EVT_KEY:
		    //If Main Menu is Active let it handle the event
			if(pMe->m_pIMainMenu && IMENUCTL_IsActive(pMe->m_pIMainMenu))
			{
				CleanUp(pMe);
				return IMENUCTL_HandleEvent(pMe->m_pIMainMenu, EVT_KEY, wParam, 0);
			}

			//If Soft Menu is Active let it handle the event
			if(pMe->m_pISoftMenu && IMENUCTL_IsActive(pMe->m_pISoftMenu))
			{
				switch(wParam)
				{
				case AVK_CLR:
					// Go back to the mainmenu
					ISTATIC_Release (pMe->m_pIStatic);
					pMe->m_pIStatic = NULL;

					IMENUCTL_SetActive(pMe->m_pISoftMenu, FALSE);
					IMENUCTL_SetActive(pMe->m_pIMainMenu, TRUE);
					IDISPLAY_ClearScreen(pMe->pIDisplay);
					IMENUCTL_Redraw(pMe->m_pIMainMenu);
					return TRUE;

				default:
					return IMENUCTL_HandleEvent(pMe->m_pISoftMenu, EVT_KEY, wParam, 0);
				}
			}

      		return(TRUE);
		case EVT_COMMAND:
			switch (wParam)
			{
			case RT_CREATE:
				STRTOWSTR("Create", pMe->m_szTitle, sizeof(pMe->m_szTitle));

				if (TRUE != CreateRinger(pMe, SetRingerName(0), "ringer0.mid", AEE_SOUNDPLAYER_FILE_MIDI))
				{
					DBGPRINTF("Create ring0 failed!");
					STRCPY(szBuf, "Create ring0 failed!\n");
				}
				else
				{
					DBGPRINTF("Create ring0 successfully!");
					STRCPY(szBuf, "Create ring0 successfully!\n");
				}
				
				STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
				IDISPLAY_ClearScreen(pMe->pIDisplay);
				DisplayText(pMe);

				return TRUE;
				
			case RT_ENUMCATEGORY:
				{
					AEERingerCat catinfo;
					AECHAR szFormat[30], szText[70];

					STRTOWSTR("EnumCategory", pMe->m_szTitle, sizeof(pMe->m_szTitle));
					
					//lab 2
					ISHELL_CreateInstance(pMe->pIShell, AEECLSID_RINGERMGR, (void **)&pMe->m_pIRingerMgr); 
					//end of lab 2
					
					if(pMe->m_pIRingerMgr == NULL)
					{
						DBGPRINTF("Create RingerMgr failed!");
						STRCPY(szBuf, "Create RingerMgr failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->pIDisplay);
						DisplayText(pMe);
						return TRUE;
					}

					//lab 2
					if(SUCCESS != IRINGERMGR_EnumCategoryInit(pMe->m_pIRingerMgr))
					{
						DBGPRINTF("EnumCTG failed!");
						CleanUp(pMe);
						STRCPY(szBuf, "EnumCateInit failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->pIDisplay);
						DisplayText(pMe);

						return TRUE;
					}
					//end of lab 2
				 
					DBGPRINTF("EnumCTG Begin:");
					MEMSET(pMe->m_pszText, 0, TEXT_BUFFER_SIZE);
					
					//lab 2
					while(IRINGERMGR_EnumNextCategory(pMe->m_pIRingerMgr,&catinfo))
					{
						DBGPRINTF("CATEGORY ID: %u", catinfo.id);
						DBGPRINTF("RINGER ID: %u", catinfo.idRinger);
						DBGPRINTF("NAME: %S", catinfo.szName);
						STRTOWSTR("CATEGORY NAME: %s \n", szFormat, sizeof(szFormat));
						WSPRINTF(szText, sizeof(szText), szFormat, catinfo.szName);
						WSTRCAT(pMe->m_pszText, szText);
					}
					//end of lab 2
				}
				
				CleanUp(pMe);
				IDISPLAY_ClearScreen(pMe->pIDisplay);
				DisplayText(pMe);
				
				return TRUE;
				
			case RT_ENUMRINGER:
				{
				  
					AEERingerInfo ringerinfo;
					AECHAR szFormat[30], szText[70];

					STRTOWSTR("EnumRinger", pMe->m_szTitle, sizeof(pMe->m_szTitle));
					
					//lab 3
					ISHELL_CreateInstance(pMe->pIShell, AEECLSID_RINGERMGR, (void **)&pMe->m_pIRingerMgr); 
					//end of lab 3
					
					if(pMe->m_pIRingerMgr == NULL)
					{
						DBGPRINTF("Create RingerMgr failed!");
						STRCPY(szBuf, "Create RingerMgr failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->pIDisplay);
						DisplayText(pMe);
						return TRUE;
					}
					
					//lab 3
					if (SUCCESS != IRINGERMGR_EnumRingerInit(pMe->m_pIRingerMgr))
					{
						DBGPRINTF("EnumRing failed!");
						CleanUp(pMe);
						STRCPY(szBuf, "EnumRinger failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->pIDisplay);
						DisplayText(pMe);
						return TRUE;
					}
					//end of lab 3
					
					MEMSET(pMe->m_pszText, 0, TEXT_BUFFER_SIZE);
					
					//lab 3
					while(IRINGERMGR_EnumNextRinger(pMe->m_pIRingerMgr, &ringerinfo))
					{
						DBGPRINTF("RINGER ID: %u", ringerinfo.id);
						DBGPRINTF("FORMAT: %u", ringerinfo.format);
						DBGPRINTF("NAME: %s", ringerinfo.szName);
						if (ringerinfo.szFile) // can be NULL if read only
						{
							DBGPRINTF("FILE: %s", ringerinfo.szFile);
						}
						STRTOWSTR("NAME: %s \n", szFormat, sizeof(szFormat));
						WSPRINTF(szText, sizeof(szText), szFormat, ringerinfo.szName);
						WSTRCAT(pMe->m_pszText, szText);
					}
					//end of lab 3
				}
				CleanUp(pMe);

				IDISPLAY_ClearScreen(pMe->pIDisplay);
				DisplayText(pMe);
				return TRUE;

			case RT_RINGERFORMAT:
				{
					AEESoundPlayerFile pwFormats[4];
					int NumberOfFormats = -1, i;
					
					STRTOWSTR("RingerFormat", pMe->m_szTitle, sizeof(pMe->m_szTitle));
					//lab 4
					ISHELL_CreateInstance(pMe->pIShell, AEECLSID_RINGERMGR, (void **)&pMe->m_pIRingerMgr); 
					//end of lab 4
					if(pMe->m_pIRingerMgr == NULL)
					{
						DBGPRINTF("Create RingerMgr failed!");

⌨️ 快捷键说明

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