43
Programming mobile devices Part II Programming Symbian devices with Symbian C++ Environment and building applications

Programming mobile devices

  • Upload
    yates

  • View
    50

  • Download
    0

Embed Size (px)

DESCRIPTION

Programming mobile devices. Part II Programming Symbian devices with Symbian C++. Environment and building applications. Content. The development environment Tools SDKs IDEs Simple example Building and running. Environment. XP, 2000 or NT SDK for the device targeted IDE Device - PowerPoint PPT Presentation

Citation preview

Page 1: Programming mobile devices

Programming mobile devices

Part II

Programming Symbian devices with Symbian C++

Environment and building applications

Page 2: Programming mobile devices

Content

• The development environment

• Tools

• SDKs

• IDEs

• Simple example

• Building and running

Page 3: Programming mobile devices

Environment

• XP, 2000 or NT

• SDK for the device targeted

• IDE

• Device

• Communication suite

Page 4: Programming mobile devices

Tools

• An SDK for the targeted platform

• An IDE that is supported by the SDK

• Communicatio between the phone and the device– Communication suite– Communication media, such as BT or USB

cable

Page 5: Programming mobile devices

SDKs

• Manufactures site, e.g. forum.nokia.com

• symbian.com

• On this course, Series 60, 3rd edition

• Our targeted device will be the Nokia N91

• SDKs seem to be chubby dudes, the S60 3 ed. is almost 300 megas

Page 6: Programming mobile devices

IDEs

• MS Visual C++

• Metrowerks Code Warrior

• Borland C++ Builder

• Carbide.c++

Page 7: Programming mobile devices

Required components

• The setting I created was– S60 3 edition SDK– Carbide.c++ (forum.nokia.com)– Active State Active Perl

(www.activestate.com)

• Testing the setup– type "devices" on the command prompt

Page 8: Programming mobile devices

Application Components

• Application View– main window

• Application UI– instantiates the application view– command handler for GUI controls

• Application document– non-GUI data aspects– instantiates the UI class

Page 9: Programming mobile devices

Application Components

• Application – instantiates and starts the document class

Page 10: Programming mobile devices

Hei Maailma (Hello World)

• source code files:

• HeiMaailma.cpp

• HeiMaailmaApplication.cpp

• HeiMaailmaAppUi.cpp

• HeiMaailmaAppView.cpp

• HeiMaailmaDocument.cpp

Page 11: Programming mobile devices

Building

• To build from the command line:– bldmake BLDFILES– abld build wins– epoc

• Building from an IDE– depends on the IDE– we will use Carbide.c++– examples in demos

Page 12: Programming mobile devices

Build environment

• epoc32– include (common API classes)– build (intermediate build files)– tools (scripts, exes etc. windows tools)– gcc (compiler tools)– release (executables for supported platforms)– data/z (simulated z drive of the emulator)– wins (default location for other emulator

memory drives)

Page 13: Programming mobile devices

Build targets

• ARM4 – 32 bit ARM instruction set

• THUMB – 16 bit ARM instruction set

• ARMI – ARM interchange format

Page 14: Programming mobile devices

Build files

• Component description file (bld.inf)

• Project definition file (.mmp)

• source (.cpp files) in src folder

• header files (.h and .hrh files) in inc folder

Page 15: Programming mobile devices

Emulators

• WINS– Microsoft

• WINSC– Code Warrior

• WINSB– Borland

Page 16: Programming mobile devices

HeiMaailma.cpp// INCLUDE FILES#include <eikstart.h>#include "HeiMaailmaApplication.h"

LOCAL_C CApaApplication* NewApplication(){return new CHeiMaailmaApplication;}

GLDEF_C TInt E32Main(){return EikStart::RunApplication( NewApplication );}

Page 17: Programming mobile devices

HeiMaailmaApplication.cpp#include "HeiMaailmaDocument.h"#include "HeiMaailmaApplication.h"

// ============================ MEMBER FUNCTIONS ===========

// UID for the application;// this should correspond to the uid defined in the mmp fileconst TUid KUidHeiMaailmaApp = { 0x088C40EE };

// -----------------------------------------------------------------------------// CHeiMaailmaApplication::CreateDocumentL()// Creates CApaDocument object// -----------------------------------------------------------------------------//CApaDocument* CHeiMaailmaApplication::CreateDocumentL() { // Create an HeiMaailma document, and return a pointer to it return (static_cast<CApaDocument*> ( CHeiMaailmaDocument::NewL( *this ) ) ); }

Page 18: Programming mobile devices

HeiMaailmaApplication.cpp// -----------------------------------------------------------------------------// CHeiMaailmaApplication::AppDllUid()// Returns application UID// -----------------------------------------------------------------------------//TUid CHeiMaailmaApplication::AppDllUid() const { // Return the UID for the HeiMaailma application return KUidHeiMaailmaApp; }

// End of File

Page 19: Programming mobile devices

HeiMaailmaDocument.cpp// INCLUDE FILES#include "HeiMaailmaAppUi.h"#include "HeiMaailmaDocument.h"

// ============================ MEMBER FUNCTIONS============

// -----------------------------------------------------------------------------// CHeiMaailmaDocument::NewL()// Two-phased constructor.// -----------------------------------------------------------------------------//CHeiMaailmaDocument* CHeiMaailmaDocument::NewL( CEikApplication& aApp ) { CHeiMaailmaDocument* self = NewLC( aApp ); CleanupStack::Pop( self ); return self; }

Page 20: Programming mobile devices

HeiMaailmaDocument.cpp

// -----------------------------------------------------------------------------// CHeiMaailmaDocument::NewLC()// Two-phased constructor.// -----------------------------------------------------------------------------//CHeiMaailmaDocument* CHeiMaailmaDocument::NewLC( CEikApplication& aApp ) { CHeiMaailmaDocument* self = new ( ELeave ) CHeiMaailmaDocument( aApp );

CleanupStack::PushL( self ); self->ConstructL(); return self; }

Page 21: Programming mobile devices

HeiMaailmaDocument.cpp// -----------------------------------------------------------------------------// CHeiMaailmaDocument::ConstructL()// Symbian 2nd phase constructor can leave.// -----------------------------------------------------------------------------//void CHeiMaailmaDocument::ConstructL() { // No implementation required }// -----------------------------------------------------------------------------// CHeiMaailmaDocument::CHeiMaailmaDocument()// C++ default constructor can NOT contain any code, that might leave.// -----------------------------------------------------------------------------//CHeiMaailmaDocument::CHeiMaailmaDocument( CEikApplication& aApp ) : CAknDocument( aApp ) { // No implementation required }

Page 22: Programming mobile devices

HeiMaailmaDocument.cpp// CHeiMaailmaDocument::~CHeiMaailmaDocument() Destructor.// ---------------------------------------------------------------------------//CHeiMaailmaDocument::~CHeiMaailmaDocument() { // No implementation required }

// CHeiMaailmaDocument::CreateAppUiL()// Constructs CreateAppUi.// ---------------------------------------------------------------------------//CEikAppUi* CHeiMaailmaDocument::CreateAppUiL() { // Create the application user interface, and return a pointer to it; // the framework takes ownership of this object return ( static_cast <CEikAppUi*> ( new ( ELeave ) CHeiMaailmaAppUi ) ); }

Page 23: Programming mobile devices

HeiMaailmaDocument.cpp// CHeiMaailmaDocument::~CHeiMaailmaDocument() Destructor.// ---------------------------------------------------------------------------//CHeiMaailmaDocument::~CHeiMaailmaDocument() { // No implementation required }

// CHeiMaailmaDocument::CreateAppUiL()// Constructs CreateAppUi.// ---------------------------------------------------------------------------//CEikAppUi* CHeiMaailmaDocument::CreateAppUiL() { // Create the application user interface, and return a pointer to it; // the framework takes ownership of this object return ( static_cast <CEikAppUi*> ( new ( ELeave ) CHeiMaailmaAppUi ) ); }

Page 24: Programming mobile devices

HeiMaailmaAppUi.cpp

// INCLUDE FILES#include <avkon.hrh>#include <aknnotewrappers.h>#include <stringloader.h>#include <HeiMaailma.rsg>#include <f32file.h>#include <s32file.h>

#include "HeiMaailma.pan"#include "HeiMaailmaAppUi.h"#include "HeiMaailmaAppView.h"#include "HeiMaailma.hrh"

_LIT( KFileName, "C:\\private\\088C40EE\\HeiMaailma.txt" );_LIT( KText, "Hei Maailma!");

Page 25: Programming mobile devices

HeiMaailmaAppUi.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppUi::ConstructL()// Symbian 2nd phase constructor can leave.// -----------------------------------------------------------------------------//void CHeiMaailmaAppUi::ConstructL() { // Initialise app UI with standard value. BaseConstructL();

// Create view objectiAppView = CHeiMaailmaAppView::NewL( ClientRect() );

// Create a file to write the text toRFs fsSession;User::LeaveIfError(fsSession.Connect());CleanupClosePushL( fsSession );

Page 26: Programming mobile devices

HeiMaailmaAppUi.cppTInt err = fsSession.MkDirAll(KFileName);if ( KErrNone != err )

{CleanupStack::PopAndDestroy(1); // fsSessionreturn;}

RFile file;err = file.Replace(fsSession, KFileName, EFileWrite );CleanupClosePushL( file );if ( KErrNone != err )

{CleanupStack::PopAndDestroy(2); // file, fsSessionreturn;}

RFileWriteStream outputFileStream( file );CleanupClosePushL( outputFileStream );outputFileStream << KText;

CleanupStack::PopAndDestroy(3); // outputFileStream, file, fsSession}

Page 27: Programming mobile devices

HeiMaailmaAppUi.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppUi::CHeiMaailmaAppUi()// C++ default constructor can NOT contain any code, that might leave.// -----------------------------------------------------------------------------//CHeiMaailmaAppUi::CHeiMaailmaAppUi() { // No implementation required }

Page 28: Programming mobile devices

HeiMaailmaAppUi.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppUi::~CHeiMaailmaAppUi()// Destructor.// -----------------------------------------------------------------------------//CHeiMaailmaAppUi::~CHeiMaailmaAppUi() { if ( iAppView ) { delete iAppView; iAppView = NULL; }

}

Page 29: Programming mobile devices

HeiMaailmaAppUi.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppUi::HandleCommandL()// Takes care of command handling.// -----------------------------------------------------------------------------//void CHeiMaailmaAppUi::HandleCommandL( TInt aCommand ) { switch( aCommand ) { case EEikCmdExit: case EAknSoftkeyExit: Exit(); break;

case ECommand1: { // Load a string from the resource file and display it HBufC* textResource = StringLoader::LoadLC( R_COMMAND1_TEXT ); CAknInformationNote* informationNote;

Page 30: Programming mobile devices

HeiMaailmaAppUi.cpp informationNote = new ( ELeave ) CAknInformationNote;

// Show the information Note with // textResource loaded with StringLoader. informationNote->ExecuteLD( *textResource);

// Pop HBuf from CleanUpStack and Destroy it. CleanupStack::PopAndDestroy( textResource ); } break;

case ECommand2:{

RFs fsSession;RFile rFile;

// Connects a client process to the fileserverUser::LeaveIfError(fsSession.Connect());CleanupClosePushL(fsSession);

Page 31: Programming mobile devices

HeiMaailmaAppUi.cpp//Open file where the stream text isUser::LeaveIfError(rFile.Open(fsSession,KFileName,

EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));CleanupClosePushL(rFile);

// copy stream from file to RFileStream objectRFileReadStream inputFileStream(rFile);

CleanupClosePushL(inputFileStream); // HBufC descriptor is created from the RFileStream object. HBufC* fileData = HBufC::NewLC(inputFileStream, 32);

CAknInformationNote* informationNote;

informationNote = new ( ELeave ) CAknInformationNote; // Show the information Note informationNote->ExecuteLD( *fileData);

Page 32: Programming mobile devices

HeiMaailmaAppUi.cpp// Pop loaded resources from the cleanup stackCleanupStack::PopAndDestroy(4); // filedata,

inputFileStream, rFile, fsSessionfsSession.Close();}break;

default: Panic( EHeiMaailmaUi ); break; } }

Page 33: Programming mobile devices

HeiMaailmaAppUi.cpp// -----------------------------------------------------------------------------// Called by the framework when the application status pane// size is changed. Passes the new client rectangle to the// AppView// -----------------------------------------------------------------------------//void CHeiMaailmaAppUi::HandleStatusPaneSizeChange(){

iAppView->SetRect( ClientRect() );

}

// End of File

Page 34: Programming mobile devices

HeiMaailmaAppView.cpp// INCLUDE FILES#include <coemain.h>#include "HeiMaailmaAppView.h"

// ============================ MEMBER FUNCTIONS===========

// -----------------------------------------------------------------------------// CHeiMaailmaAppView::NewL()// Two-phased constructor.// -----------------------------------------------------------------------------//CHeiMaailmaAppView* CHeiMaailmaAppView::NewL( const TRect& aRect ) { CHeiMaailmaAppView* self = CHeiMaailmaAppView::NewLC( aRect ); CleanupStack::Pop( self ); return self; }

Page 35: Programming mobile devices

HeiMaailmaAppView.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppView::NewLC()// Two-phased constructor.// -----------------------------------------------------------------------------//CHeiMaailmaAppView* CHeiMaailmaAppView::NewLC( const TRect& aRect ) { CHeiMaailmaAppView* self = new ( ELeave ) CHeiMaailmaAppView; CleanupStack::PushL( self ); self->ConstructL( aRect ); return self; }

Page 36: Programming mobile devices

HeiMaailmaAppView.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppView::ConstructL()// Symbian 2nd phase constructor can leave.// -----------------------------------------------------------------------------//void CHeiMaailmaAppView::ConstructL( const TRect& aRect ) { // Create a window for this application view CreateWindowL();

// Set the windows size SetRect( aRect );

// Activate the window, which makes it ready to be drawn ActivateL(); }

Page 37: Programming mobile devices

HeiMaailmaAppView.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppView::CHeiMaailmaAppView()// C++ default constructor can NOT contain any code, that might leave.// -----------------------------------------------------------------------------//CHeiMaailmaAppView::CHeiMaailmaAppView() { // No implementation required }

// -----------------------------------------------------------------------------// CHeiMaailmaAppView::~CHeiMaailmaAppView()// Destructor.// -----------------------------------------------------------------------------//CHeiMaailmaAppView::~CHeiMaailmaAppView() { // No implementation required }

Page 38: Programming mobile devices

HeiMaailmaAppView.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppView::CHeiMaailmaAppView()// C++ default constructor can NOT contain any code, that might leave.// -----------------------------------------------------------------------------//CHeiMaailmaAppView::CHeiMaailmaAppView() { // No implementation required }

// -----------------------------------------------------------------------------// CHeiMaailmaAppView::~CHeiMaailmaAppView()// Destructor.// -----------------------------------------------------------------------------//CHeiMaailmaAppView::~CHeiMaailmaAppView() { // No implementation required }

Page 39: Programming mobile devices

HeiMaailmaAppView.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppView::Draw()// Draws the display.// -----------------------------------------------------------------------------//void CHeiMaailmaAppView::Draw( const TRect& /*aRect*/ ) const { // Get the standard graphics context CWindowGc& gc = SystemGc();

// Gets the control's extent TRect drawRect( Rect());

// Clears the screen gc.Clear( drawRect );

}

Page 40: Programming mobile devices

HeiMaailmaAppView.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppView::SizeChanged()// Called by framework when the view size is changed.// -----------------------------------------------------------------------------//void CHeiMaailmaAppView::SizeChanged() { DrawNow(); }// End of File

Page 41: Programming mobile devices

Screen shots

Page 42: Programming mobile devices

Screen shots

Page 43: Programming mobile devices