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

📄 cppapp.cpp

📁 封装了brew的最新多线程接口的类,对学习BREW程序的有很大帮助
💻 CPP
字号:
#include "cppapp.h"
#include "cppapp.bid"
#include <stdio.h>
#include <stdlib.h>
#include "BThread.h"


//-------------------------------------------------------------------------
// This application serves as a sample C++ application. The C++ capabilities
// being demonstrated are inheritance, operator overloading, function overloading, 
// new/delete overloading and polymorphism.
// CPPApp is the applet class that derives from AEEApplet. This class uses
// two helper classes, Writer and SmartWriter to display messages on device
// screen.
// Writer class writes messages on device screen using ITextCtl. SmartWriter
// extends Writer class and writes messages in bold using IStatic. Writer
// class provides WriteLine() method for writiting any message to device display.
// This method is specialised by derived class SmartWriter to write message
// in bold. Writer class has overloaded DisplayOutput() methods to support
// WriteLine() methods of base as well as derived class.
// Both of the classes have overloaded new, delete and stream out operators.
//-------------------------------------------------------------------------
// App specific constants
#define TEST1						100
#define TEST2						101
#define TEST3						102
#define TEST4						103
#define TEST5						104
#define TEST6						105
#define TEST7						106

#define APP_RES_FILE    "cppapp.bar"





//--------------------------------------------------------------------------
// All static functions of CPPApp class.
//--------------------------------------------------------------------------
extern "C" 
int AEEClsCreateInstance(AEECLSID clsID, IShell* pIShell, IModule* pIModule, void **ppobj)
{
	if(clsID == AEECLSID_CPPAPP)
	{
		// We want to load this App. So, invoke AEEApplet_New().To it, pass the
		// address of the app-specific handle event function.
		if(!AEEApplet_New(sizeof(CPPApp), clsID, pIShell, pIModule, (IApplet**)ppobj,(AEEHANDLER)CPPApp::HandleEvent,
			(PFNFREEAPPDATA)CPPApp::freeAppData))
			return EFAILED;

		// Allocate and initialize app specific data
		if (!CPPApp::InitAppData((IApplet *)*ppobj))
			return EFAILED;

		return SUCCESS;
	}
	return EFAILED;
}

boolean  CPPApp::InitAppData(IApplet *pIApplet)
{
	CPPApp* pCPPApp = (CPPApp*)pIApplet;
	pCPPApp->pos_ = 0;
	
	pCPPApp->writer_ = Writer(pCPPApp->m_pIShell);
	return pCPPApp->OnAppInitData();
}

void  CPPApp::freeAppData(CPPApp *pCPPApp)
{
	pCPPApp->OnAppfreeData();
}

boolean  CPPApp::HandleEvent(CPPApp *pCPPApp, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{   
	return pCPPApp->OnEvent(eCode, wParam, dwParam);
}

//--------------------------------------------------------------------------
// All member functions of CPPApp class.
//--------------------------------------------------------------------------
boolean CPPApp::OnAppInitData()
{
    m_pIMenuCtl = NULL;
	pool_=0;
	int err = ISHELL_CreateInstance(m_pIShell, AEECLSID_RSCPOOL, (void**)(&pool_));
    return TRUE;
}

void CPPApp::OnAppfreeData()
{
    if (m_pIMenuCtl)
        IMENUCTL_Release(m_pIMenuCtl);
	if (pool_)
	IRSCPOOL_Release(pool_);
}

boolean CPPApp::OnEvent(AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
	switch (eCode) 
	{
	    case EVT_APP_START:			
			// When this applet is started, try to create the main menu
			// that allows the user to select a usage example to execute.
			// If we cannot create an instance of the menu class, exit and
			// indicate that we have handled the event by returning TRUE
			if(ISHELL_CreateInstance(m_pIShell, AEECLSID_MENUCTL, 
				  (void **)&m_pIMenuCtl) != SUCCESS)
				return TRUE;

			// Succeeded in obtaining a menu instance pointer, so
			// construct the menu and display it on the screen
			BuildMainMenu();
			return(TRUE);

	    case EVT_KEY:
            IMENUCTL_SetActive(m_pIMenuCtl, TRUE);
            if (wParam == AVK_CLR)
                return TRUE;
			else 
                return IMENUCTL_HandleEvent(m_pIMenuCtl, EVT_KEY, wParam, dwParam);
		
	    case EVT_COMMAND:
            switch(wParam)
			{
				// The following commands are generated by user selections
				// from the main usage app menu.
			    case TEST1:
                case TEST2:
			    case TEST3:
                case TEST4:
                case TEST5:
                case TEST6:
                case TEST7:
				   IMENUCTL_SetActive(m_pIMenuCtl, FALSE);

				   // Execute the usage example the user has selected
                   CPPUsage (wParam);
			       return TRUE;
			    default:
				    return FALSE;
			}
		
	    case EVT_APP_STOP:
		    return(TRUE);
			
		case EVT_APP_NO_SLEEP:
			return TRUE;
	    default:
		    return(FALSE);	   
	}
}

bool CPPApp::CPPUsage(uint16 wParam)
{

    switch (wParam)
    {
        case TEST1:
        {
            test1();
            break;
        }
        case TEST2:
        {
           test2();
            break;
        }
        case TEST3:
        {
           test3();
            break;
        }
        case TEST4:
        {
           test4();
            break;
        }

        default:
            return FALSE;
    }

    return TRUE;
}

/*===========================================================================

FUNCTION: BuildMainMenu

DESCRIPTION
    This function constructs the menu control that allows the user to
	select a usage example to execute.  The command ID for each menu item
	is passed to the usage example function above when the user selects the
	menu item for that example.
    
PROTOTYPE:
    void CPPApp::BuildMainMenu()

PARAMETERS:
    None  

DEPENDENCIES
    None

RETURN VALUE
    None

SIDE EFFECTS
    None

===========================================================================*/
void CPPApp::BuildMainMenu()
{
	AEERect qrc;
	AEEDeviceInfo di;
    AECHAR* szBuf;
    char* charBuf;

	// Make sure the pointers we'll be using are valid
    if (m_pIShell == NULL || m_pIMenuCtl == NULL)
	   return;

    if ((szBuf = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
	   return;

    if ((charBuf = (char *) MALLOC(TEXT_BUFFER_SIZE/sizeof(AECHAR))) == NULL)
    {
       FREE(szBuf);
	    return;
    }

	// Set Title
    STRCPY(charBuf, "C++ Examples");
    STR_TO_WSTR(charBuf, szBuf, TEXT_BUFFER_SIZE);
	IMENUCTL_SetTitle(m_pIMenuCtl, NULL, 0, szBuf);

	//Set the Rectangle for the Menu
	ISHELL_GetDeviceInfo(m_pIShell,&di);
	qrc.x = 0;
	qrc.y = 0;
	qrc.dx = di.cxScreen;
	qrc.dy = di.cyScreen;
	IMENUCTL_SetRect(m_pIMenuCtl, &qrc);  

	//Add individual entries to the Menu

    // Add Base Class Usage to menu
    STRCPY(charBuf, "1. Cancel unsafe");
    STR_TO_WSTR(charBuf, szBuf, TEXT_BUFFER_SIZE);
	IMENUCTL_AddItem(m_pIMenuCtl, 0, 0, TEST1, szBuf, 0);


    STRCPY(charBuf, "2. Cancel safe");
    STR_TO_WSTR(charBuf, szBuf, TEXT_BUFFER_SIZE);
	IMENUCTL_AddItem(m_pIMenuCtl, 0, 0, TEST2, szBuf, 0);

/*	STRCPY(charBuf, "3. File Test");
    STR_TO_WSTR(charBuf, szBuf, TEXT_BUFFER_SIZE);
	IMENUCTL_AddItem(m_pIMenuCtl, 0, 0, TEST3, szBuf, 0);

	STRCPY(charBuf, "4. Generic resource");
    STR_TO_WSTR(charBuf, szBuf, TEXT_BUFFER_SIZE);
	IMENUCTL_AddItem(m_pIMenuCtl, 0, 0, TEST4, szBuf, 0);*/
	

    
    // Activate menu
	IMENUCTL_SetActive(m_pIMenuCtl,TRUE);

	FREE(szBuf);
    FREE(charBuf);
}






void CPPApp::test1()
{

	typedef BThread<RunnableImpl> BThr;
	BThr *t = BThr::createThread(m_pIShell,pool_);
	int err = t->start();
}



void CPPApp::test2()
{ 
	typedef BThread<RunnableImpl1> BThr1;
	BThr1 *t = BThr1::createThread(m_pIShell,pool_, &writer_);
	int err = t->start();
}

void CPPApp::test3()
{ 
	
}

void CPPApp::test4()
{}



⌨️ 快捷键说明

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