1 / 43

Programming mobile devices

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

yates
Télécharger la présentation

Programming mobile devices

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Content • The development environment • Tools • SDKs • IDEs • Simple example • Building and running

  3. Environment • XP, 2000 or NT • SDK for the device targeted • IDE • Device • Communication suite

  4. 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

  5. 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

  6. IDEs • MS Visual C++ • Metrowerks Code Warrior • Borland C++ Builder • Carbide.c++

  7. 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

  8. 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

  9. Application Components • Application • instantiates and starts the document class

  10. Hei Maailma (Hello World) • source code files: • HeiMaailma.cpp • HeiMaailmaApplication.cpp • HeiMaailmaAppUi.cpp • HeiMaailmaAppView.cpp • HeiMaailmaDocument.cpp

  11. 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

  12. 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)

  13. Build targets • ARM4 • 32 bit ARM instruction set • THUMB • 16 bit ARM instruction set • ARMI • ARM interchange format

  14. 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

  15. Emulators • WINS • Microsoft • WINSC • Code Warrior • WINSB • Borland

  16. 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 ); }

  17. HeiMaailmaApplication.cpp #include "HeiMaailmaDocument.h" #include "HeiMaailmaApplication.h" // ============================ MEMBER FUNCTIONS =========== // UID for the application; // this should correspond to the uid defined in the mmp file const 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 ) ) ); }

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

  19. 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; }

  20. 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; }

  21. 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 }

  22. 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 ) ); }

  23. 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 ) ); }

  24. 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!");

  25. HeiMaailmaAppUi.cpp // ----------------------------------------------------------------------------- // CHeiMaailmaAppUi::ConstructL() // Symbian 2nd phase constructor can leave. // ----------------------------------------------------------------------------- // void CHeiMaailmaAppUi::ConstructL() { // Initialise app UI with standard value. BaseConstructL(); // Create view object iAppView = CHeiMaailmaAppView::NewL( ClientRect() ); // Create a file to write the text to RFs fsSession; User::LeaveIfError(fsSession.Connect()); CleanupClosePushL( fsSession );

  26. HeiMaailmaAppUi.cpp TInt err = fsSession.MkDirAll(KFileName); if ( KErrNone != err ) { CleanupStack::PopAndDestroy(1); // fsSession return; } RFile file; err = file.Replace(fsSession, KFileName, EFileWrite ); CleanupClosePushL( file ); if ( KErrNone != err ) { CleanupStack::PopAndDestroy(2); // file, fsSession return; } RFileWriteStream outputFileStream( file ); CleanupClosePushL( outputFileStream ); outputFileStream << KText; CleanupStack::PopAndDestroy(3); // outputFileStream, file, fsSession }

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

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

  29. 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;

  30. 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 fileserver User::LeaveIfError(fsSession.Connect()); CleanupClosePushL(fsSession);

  31. HeiMaailmaAppUi.cpp //Open file where the stream text is User::LeaveIfError(rFile.Open(fsSession,KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText)); CleanupClosePushL(rFile); // copy stream from file to RFileStream object RFileReadStream 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);

  32. HeiMaailmaAppUi.cpp // Pop loaded resources from the cleanup stack CleanupStack::PopAndDestroy(4); // filedata, inputFileStream, rFile, fsSession fsSession.Close(); } break; default: Panic( EHeiMaailmaUi ); break; } }

  33. 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

  34. 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; }

  35. 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; }

  36. 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(); }

  37. 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 }

  38. 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 }

  39. 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 ); }

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

  41. Screen shots

  42. Screen shots

More Related