Login | Register
My pages Projects Community openCollabNet

Write your first C++ application



Table of Contents


  1. Write your first C++ application
    1. Table of Contents
    2. Prerequisite
    3. What is  the different
    4. Helloworld
    5. Compile the program
    6. The impact of speed and mod size

Prerequisite

Before building your first C++ application, please make sure that the lightblue C++ wrapper class has been properly configured and built. If it is not, please refer this document: How to configure and build lightblue library.

Following files exist in the lightblue directory:
include\brewpp_runtime\AEEimp.hpp
include\brewpp_runtime\brewpp.hpp
lib\vc\entryptr.obj            -- only  needed if you are using the vc compiler
lib\g++\entryptr.o            -- only needed if you are using the GNU ARM compiler
lib\rv22\entryptr.o           -- only needed if you are using the Realview ARM compiler 2.x

You have also have generated mif and bid files.


What is  the different

By using lightblue C++ wrapper library, you will find that the creation of your own application is  simplified, there is no need for AEEAppGen.c and implement the cleanup handler.
You just create a class which is inherited from IBrewApplet. You can then handle the event by override the HandleEvent() method of IBrewApplet. The cleanup handler is replaced with the C++ destructor.

Helloworld


Below is the whole source  code  of the helloworld application.

#include "brewpp_runtime/brewpp.hpp" 
#include "helloworld.bid"


class CHelloWorld:public CDefaultBrewApplet
{
public:
    enum{CLS_ID = AEECLSID_HELLOWORLD };
    CHelloWorld(CDefaultBrewModule* mdl):CDefaultBrewApplet(mdl){}
    virtual boolean  BREW_CALL_CONV HandleEvent( AEEEvent eCode,uint16 wParam, uint32 dwParam);
};

boolean BREW_CALL_CONV CHelloWorld::HandleEvent( AEEEvent eCode,uint16 wParam, uint32 dwParam)
{
    const AECHAR szText[] = {'H','e','l','l','o',' ','W','o', 'r', 'l', 'd', '\0'};
    switch (eCode)
    {
       
        case EVT_APP_START:                      
           m_pIDisplay->DrawText(AEE_FONT_BOLD,szText,-1, 0,0,NULL, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
           m_pIDisplay->Update(false);
            return(TRUE);

        case EVT_APP_STOP:  
           return(TRUE);

        default:  ;  // do nothing.
   }
   return(FALSE);
}

extern "C" int AEEClsCreateInstance(AEECLSID ClsId,CDefaultBrewModule *pMod, void **ppobj)
{
    *ppobj = NULL;
    if(ClsId == CHelloWorld::CLS_ID)
    {
        *ppobj = (void**)new CHelloWorld(pMod);
        return(AEE_SUCCESS);
    }
    return EFAILED;
}

Notes:
CDefaultBrewApplet is itself inherited from IBrewApplet. It implements AddRef() and Release() methods. The Release() method will call the destructor when the reference count becomes zero.

Compile the program

You can  Compile your lightblue application using command line or use the Visual Studio IDE.

You can copied an existing Visual studio project form the Example directory and fill it with your own files.


The impact of speed and mod size

I have to repeat this again: there is absolute no speed nor space penalties by using lightblue C++ wrapper library.  The generated C++ classes are declaration only, they will not add one byte to you final output file.