Title: Symbian programming
1Symbian programming
- Part III
- Programming Symbian devices with Symbian C
Environment and building applications
2Content
- Simple example
- Symbian application source code files
- Some details about the source files
- Building and running
- Deployment (OTA)
3Application 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
4Application Components
- Application
- instantiates and starts the document class
5Hei Maailma (Hello World)
- source code files
- HeiMaailma.cpp
- HeiMaailmaApplication.cpp
- HeiMaailmaAppUi.cpp
- HeiMaailmaAppView.cpp
- HeiMaailmaDocument.cpp
6HeiMaailma.cpp
// INCLUDE FILES include lteikstart.hgt include
"HeiMaailmaApplication.h" LOCAL_C
CApaApplication NewApplication() return new
CHeiMaailmaApplication GLDEF_C TInt
E32Main() return EikStartRunApplication(
NewApplication )
7HeiMaailmaApplication.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 //
--------------------------------------------------
--------------------------- // CHeiMaailmaApplicat
ionCreateDocumentL() // Creates CApaDocument
object // ----------------------------------------
------------------------------------- // CApaDocum
ent CHeiMaailmaApplicationCreateDocumentL()
// Create an HeiMaailma document, and
return a pointer to it return
(static_castltCApaDocumentgt (
CHeiMaailmaDocumentNewL( this ) ) )
8HeiMaailmaApplication.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaApplicationAppDllUid() // Returns
application UID // -------------------------------
---------------------------------------------- //
TUid CHeiMaailmaApplicationAppDllUid() const
// Return the UID for the HeiMaailma
application return KUidHeiMaailmaApp
// End of File
9HeiMaailmaDocument.cpp
// INCLUDE FILES include "HeiMaailmaAppUi.h" inc
lude "HeiMaailmaDocument.h" //
MEMBER
FUNCTIONS // ------------------------
--------------------------------------------------
--- // CHeiMaailmaDocumentNewL() // Two-phased
constructor. // ----------------------------------
------------------------------------------- // CHe
iMaailmaDocument CHeiMaailmaDocumentNewL(
CEikApplication
aApp )
CHeiMaailmaDocument self NewLC( aApp )
CleanupStackPop( self ) return self
10HeiMaailmaDocument.cpp
// ---------------------------------------------
-------------------------------- //
CHeiMaailmaDocumentNewLC() // Two-phased
constructor. // ----------------------------------
------------------------------------------- // CHe
iMaailmaDocument CHeiMaailmaDocumentNewLC(
CEikApplication
aApp )
CHeiMaailmaDocument self new ( ELeave
) CHeiMaailmaDocument( aApp )
CleanupStackPushL( self )
self-gtConstructL() return self
11HeiMaailmaDocument.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaDocumentConstructL() // Symbian 2nd
phase constructor can leave. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaDocumentConstructL() // No
implementation required //
--------------------------------------------------
--------------------------- // CHeiMaailmaDocument
CHeiMaailmaDocument() // C default
constructor can NOT contain any code, that might
leave. // ----------------------------------------
------------------------------------- // CHeiMaail
maDocumentCHeiMaailmaDocument( CEikApplication
aApp ) CAknDocument( aApp ) // No
implementation required
12HeiMaailmaDocument.cpp
// CHeiMaailmaDocumentCHeiMaailmaDocument()
Destructor. // -----------------------------------
---------------------------------------- // CHeiMa
ailmaDocumentCHeiMaailmaDocument()
// No implementation required //
CHeiMaailmaDocumentCreateAppUiL() // Constructs
CreateAppUi. // ----------------------------------
----------------------------------------- // CEikA
ppUi CHeiMaailmaDocumentCreateAppUiL()
// Create the application user interface, and
return a pointer to it // the framework
takes ownership of this object return (
static_cast ltCEikAppUigt ( new ( ELeave )
CHeiMaailmaAppUi
) )
13HeiMaailmaAppUi.cpp
// INCLUDE FILES include ltavkon.hrhgt include
ltaknnotewrappers.hgt include ltstringloader.hgt inc
lude ltHeiMaailma.rsggt include ltf32file.hgt includ
e lts32file.hgt include "HeiMaailma.pan" include
"HeiMaailmaAppUi.h" include "HeiMaailmaAppView.h"
include "HeiMaailma.hrh" _LIT( KFileName,
"C\\private\\088C40EE\\HeiMaailma.txt" ) _LIT(
KText, "Hei Maailma!")
14_LIT macro
- The _LIT macro declares a string literal as a
descriptor - A descriptor is an object that
- contains both the data and the length of the data
- is derived from the TDescC class
15TDesC
- functions
- Ptr()
- Length()
- Size()
- Compare()
- ...
16HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppUiConstructL() // Symbian 2nd
phase constructor can leave. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaAppUiConstructL() //
Initialise app UI with standard value.
BaseConstructL() // Create view
object iAppView CHeiMaailmaAppViewNewL(
ClientRect() ) // Create a file to write the
text to RFs fsSession UserLeaveIfError(fsSess
ion.Connect()) CleanupClosePushL( fsSession )
17HeiMaailmaAppUi.cpp
TInt err fsSession.MkDirAll(KFileName) if (
KErrNone ! err ) CleanupStackPopAndDestro
y(1) // fsSession return RFile
file err file.Replace(fsSession, KFileName,
EFileWrite ) CleanupClosePushL( file ) if (
KErrNone ! err ) CleanupStackPopAndDestro
y(2) // file, fsSession return
RFileWriteStream outputFileStream( file
) CleanupClosePushL( outputFileStream
) outputFileStream ltlt KText CleanupStackPop
AndDestroy(3) // outputFileStream, file,
fsSession
18HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppUiCHeiMaailmaAppUi() // C
default constructor can NOT contain any code,
that might leave. // -----------------------------
------------------------------------------------ /
/ CHeiMaailmaAppUiCHeiMaailmaAppUi()
// No implementation required
19HeiMaailmaAppUi.cpp
// ----------------------------------------------
------------------------------- //
CHeiMaailmaAppUiCHeiMaailmaAppUi() //
Destructor. // -----------------------------------
------------------------------------------ // CHei
MaailmaAppUiCHeiMaailmaAppUi() if (
iAppView ) delete iAppView
iAppView NULL
20HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppUiHandleCommandL() // Takes care
of command handling. // --------------------------
--------------------------------------------------
- // void CHeiMaailmaAppUiHandleCommandL( TInt
aCommand ) switch( aCommand )
case EEikCmdExit case
EAknSoftkeyExit Exit()
break case ECommand1
// Load a string from the
resource file and display it HBufC
textResource StringLoaderLoadLC(
R_COMMAND1_TEXT ) CAknInformationNote
informationNote
21HeiMaailmaAppUi.cpp
informationNote new ( ELeave )
CAknInformationNote // Show the
information Note with // textResource
loaded with StringLoader.
informationNote-gtExecuteLD( textResource)
// Pop HBuf from CleanUpStack and Destroy
it. CleanupStackPopAndDestroy(
textResource )
break case ECommand2 RFs
fsSession RFile rFile // Connects a
client process to the fileserver UserLeaveIfE
rror(fsSession.Connect()) CleanupClosePushL(fs
Session)
22HeiMaailmaAppUi.cpp
//Open file where the stream text
is UserLeaveIfError(rFile.Open(fsSession,KFil
eName, 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
HBufCNewLC(inputFileStream, 32)
CAknInformationNote informationNote
informationNote new ( ELeave )
CAknInformationNote // Show the
information Note informationNote-gtExec
uteLD( fileData)
23HeiMaailmaAppUi.cpp
// Pop loaded resources from the cleanup
stack CleanupStackPopAndDestroy(4) //
filedata, inputFileStream, rFile,
fsSession fsSession.Close() break
default Panic( EHeiMaailmaUi
) break
24HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ // Called by the
framework when the application status pane //
size is changed. Passes the new client rectangle
to the // AppView // ----------------------------
-------------------------------------------------
// void CHeiMaailmaAppUiHandleStatusPaneSizeChan
ge() iAppView-gtSetRect( ClientRect() )
// End of File
25HeiMaailmaAppView.cpp
// INCLUDE FILES include ltcoemain.hgt include
"HeiMaailmaAppView.h" //
MEMBER FUNCTIONS //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
NewL() // Two-phased constructor. //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
CHeiMaailmaAppViewNewL( const TRect aRect )
CHeiMaailmaAppView self
CHeiMaailmaAppViewNewLC( aRect )
CleanupStackPop( self ) return self
26HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewNewLC() // Two-phased
constructor. // ----------------------------------
------------------------------------------- // CHe
iMaailmaAppView CHeiMaailmaAppViewNewLC( const
TRect aRect ) CHeiMaailmaAppView self
new ( ELeave ) CHeiMaailmaAppView
CleanupStackPushL( self )
self-gtConstructL( aRect ) return self
27HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewConstructL() // Symbian 2nd
phase constructor can leave. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaAppViewConstructL( 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()
28HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewCHeiMaailmaAppView() // C
default constructor can NOT contain any code,
that might leave. // -----------------------------
------------------------------------------------ /
/ CHeiMaailmaAppViewCHeiMaailmaAppView()
// No implementation required //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
CHeiMaailmaAppView() // Destructor. //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
CHeiMaailmaAppView() // No
implementation required
29HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewDraw() // Draws the
display. // --------------------------------------
--------------------------------------- // void
CHeiMaailmaAppViewDraw( 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 )
30HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewSizeChanged() // Called by
framework when the view size is changed. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaAppViewSizeChanged()
DrawNow() // End of File
31Screen shots
32Screen shots
33(No Transcript)
34The application development
A problem
Design
Implementation
Testing
Deployment
35OTA
- Over-The-Air
- User downloads the application from internet
using e.g. GPRS - The device knows how to handle the packet
- SIS for Symbian
- JAR for Java
- CAB for Windows
- MIME type associated with the application