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
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
• Communication suite
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
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
IDEs
• MS Visual C++
• Metrowerks Code Warrior
• Borland C++ Builder
• Carbide.c++
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
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
Application Components
• Application – instantiates and starts the document class
Hei Maailma (Hello World)
• source code files:
• HeiMaailma.cpp
• HeiMaailmaApplication.cpp
• HeiMaailmaAppUi.cpp
• HeiMaailmaAppView.cpp
• HeiMaailmaDocument.cpp
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
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)
Build targets
• ARM4 – 32 bit ARM instruction set
• THUMB – 16 bit ARM instruction set
• ARMI – ARM interchange format
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
Emulators
• WINS– Microsoft
• WINSC– Code Warrior
• WINSB– Borland
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 );}
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 ) ) ); }
HeiMaailmaApplication.cpp// -----------------------------------------------------------------------------// CHeiMaailmaApplication::AppDllUid()// Returns application UID// -----------------------------------------------------------------------------//TUid CHeiMaailmaApplication::AppDllUid() const { // Return the UID for the HeiMaailma application return KUidHeiMaailmaApp; }
// End of File
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; }
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; }
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 }
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 ) ); }
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 ) ); }
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!");
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 );
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}
HeiMaailmaAppUi.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppUi::CHeiMaailmaAppUi()// C++ default constructor can NOT contain any code, that might leave.// -----------------------------------------------------------------------------//CHeiMaailmaAppUi::CHeiMaailmaAppUi() { // No implementation required }
HeiMaailmaAppUi.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppUi::~CHeiMaailmaAppUi()// Destructor.// -----------------------------------------------------------------------------//CHeiMaailmaAppUi::~CHeiMaailmaAppUi() { if ( iAppView ) { delete iAppView; iAppView = NULL; }
}
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;
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);
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);
HeiMaailmaAppUi.cpp// Pop loaded resources from the cleanup stackCleanupStack::PopAndDestroy(4); // filedata,
inputFileStream, rFile, fsSessionfsSession.Close();}break;
default: Panic( EHeiMaailmaUi ); break; } }
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
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; }
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; }
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(); }
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 }
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 }
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 );
}
HeiMaailmaAppView.cpp// -----------------------------------------------------------------------------// CHeiMaailmaAppView::SizeChanged()// Called by framework when the view size is changed.// -----------------------------------------------------------------------------//void CHeiMaailmaAppView::SizeChanged() { DrawNow(); }// End of File
Screen shots
Screen shots