Mobile Software Technologies (SW8) -...
Transcript of Mobile Software Technologies (SW8) -...
Hua LuDepartment of Computer Science
Aalborg UniversitySpring 2008
Mobile Software Technologies(SW8)Symbian
2
Symbian• Introduction• Symbian OS Based Mobile Phones• Symbian OS and Symbian C++
Software Developing on Symbian OSFundamentals
• Python for S60
3
Smartphone Operating Systems
• Data from Canalys report “Worldwide smart mobile device market, Canalys Q2 2007”
Symbian (72.4%)
Linux (13.3%)
Windows Mobile (6.1%)
RIM BlackBerry (5.3%)
Palm (1.6%)
OS X (1.3%)
4
http://www.symbian.com
• Operating system for mobile devices• Produced by Symbian Ltd• Runs exclusively on ARM processors
ARM family accounts for ~75% of all embedded 32-bit RISC CPUs
• Symbian is currently owned by multiple mobile phonemanufacturers
Symbian OS
5
Brief History of Symbian• 1980 Psion Ltd. founded
In 1980s produced Psion Organizer I and II PDAs• 1991-1998 Psion Series 3 devices
EPOC16 OS (from word epoch)Robust, reliable, and flexibleSeparated the kernel from the interface to support different form factors (clamshell, palmtop, etc)
• 1997 Psion Series 5 devicesEPOC32 OS, based on 32bit C++
• 1998 Symbian Ltd. founded by Nokia, Ericsson, Matsushita (Panasonic), Motorola and the Psion OS development team
To avoid Microsoft dominance a la desktopTo cope with Palm’s potential threatSmbian OS name started its fame
6
Symbian OS Versions• EPOC Release 5 a.k.a. Symbian OS 5 (before 2000)
Ericsson R380 using ER5u (‘u’ for Unicode) in 2000
• Symbian OS 6.0 and 6.1, or ER6First ‘open’ Symbian OS phone, Nokia 9210 Communicator in 2001
• Symbian OS 7.0 and 7.0s (2003)1 million Symbian OS phones were shipped in Q1 2003Symbian OS 7.0s was a special version for backwards compatibility with OS 6.xThe first worm for mobile phone developed in Symbian OS
• Symbian OS 8.0 (2004)New APIs for 3G, enhanced multimedia
• Symbian OS 9.x (v9.5 in March 2007)A complete binary break from previous versions
7
Symbian• Introduction• Symbian OS Based Mobile Phones• Symbian OS and Symbian C++
Software Developing on Symbian OSFundamentals
• Python for S60
8
The First Symbian OS Phone• Ericsson R380 Smartphone shipped in Nov. 2000
WAP, SMS and E-mailSddress book, calendar, notepadSupport for synchronization with industry-leading PC applications
9
Nokia 9210 Communicator • The first open Symbian phone, shipped on June 19, 2001
Software can be installed on itSMS, Email, FaxWAP, HTMLJava supportVideo playerOffice: Word, Spreadsheet and Presentation viewer
10
Symbian Licenses
• As of 30 September 200720.4 million Symbian smartphones shipped in Q3 ‘07, up 56% from Q3 ‘06 165 million cumulative Symbian smartphones shipped since the formation of Symbian
11
Symbian OS Phones 2000 - 2005
2000 – 2002 – 6 products 2003 – 10 products
2004 – 20 products
20051H – 17 products
12
Motorola MOTO Z10• A most recent release, 7 Jan 2008
3.2 Megapixel cameraHigh quality video 30 frames/sec3G
13
Symbian• Introduction• Symbian OS Based Mobile Phones• Symbian OS and Symbian C++
Software Developing on Symbian OSFundamentals
• Python for S60
15
Characteristics of Symbian OS• Integrated multimode mobile telephony
Multiple cellular technologies are supported
• Open application environmentMake phones a platform for various applications and services
• Open standards and interoperabilityFully object-oriented and component basedClassification of APIs
• Multi-tasking kernelClient-server architecture framework for resources and services
• Flexible user interface designOffer choices for device manufacturers, carriers and end-users
• RobustnessGuaranteed exception handling (similar to Java), no memory leak
16
Classification of Symbian APIs• Symbian OS has four categories for its APIs used by the
licensees on their phones
• Common SymbianCore OS, every licensee implementation must include these
• Common ReplaceableLow-level hardware-specific components that must be present but are expected to be replaced by licensees
• Optional SymbianOptional for all phones, but if implemented must maintain the standard public API
• Optional ReplaceableInclusion is optional. Licensees can introduce their own APIs
17
Symbian• Introduction• Symbian OS Based Mobile Phones• Symbian OS and Symbian C++
Software Developing on Symbian OSFundamentals
• Python for S60
18
Sybmian OS Based Platforms• S60: Series 60 User Interface
Strongly supported by Nokia. Most popularLenovo, LG, Panasonic and SamsungDifferent from Nokia Series 40, 80, 90
Series 40 is not based on Symbian OSCompatibility is not ensured
• UIQ: User Interface QuartzPrincipally backed by Sony EricssonMotorola, BenQ and Arima
• MOAP: Mobile Oriented Applications Platform Intended for NTT DoCoMo's 3G FOMA service Well supported by Fujitsu, Nokia, Mitsubishi, Sharp, etc.NOT an open development platform
19
Developing on Symbian OS• Native language of Symbian OS is C++
Not a standard implementation
• Platforms with SDK for application developersUIQ
http://www.uiq.comS60
http://www.s60.com
• Individual device products or families provide SDKs, which contain
DocumentationHeader files and library filesWindows based emulatorA cross-compiler (GCC based)
20
Prog. Languages on Symbian OS• Symbian C++
Symbian OS’s flavor of C++ is very specialised.
• OPLAn entry-level development tool for rapid development.
• PythonScripts for both UIQ and Nokia S60 phones (more popular)
• Visual Basic, VB.NET, C#Requires AppForge Crossfire, a plugin for MS Visual Studio
• Perl• Java
Java MEPersonalJava
21
Symbian• Introduction• Symbian OS Based Mobile Phones• Symbian OS and Symbian C++
Software Developing on Symbian OSFundamentals
• Python for S60
22
Symbian Fundamentals• Naming Conventions• Descriptors• Exception Handling• Cleanup Stack• Two-Phase Object Construction
• Client/Server Framework• Event Handling and Active Object
Closely related to Symbian C++
Special OS design
25
Descriptors• Descriptors are often seen as Symbian OS “Strings”• Actually, they are containers for both texts and binary
data. Base class is TDesCTwo variants
8bit: TDesC8 (explicitly use this when dealing with binary data)16bit: TDesC16 (=TDesC. supports Unicode character set)
• CharacteristicsTexts and binary are treated in the same wayNo null termination (no end mark like ’\0’)Runtime bounds checkingAPI for buffer modificationModifiable and non-modifiable
• Used extensively in Symbian OS APIs• Confusing but provide very safe and efficient APIs
28
Exception Handling• Reliability of continuous running resource constrained
devicesUse memory efficiently and safelyRelease resources as early as possibleCope with out-of-memory and other errors and roll back to a consistent state when they occur
• Symbian’s own variant of C++ try, catch, throwC++ throw -> Symbian User::Leave()C++ try, catch -> Symbian TRAP and TRAPD macros
29
Exception Handling Terms• Exception
Runtime error that is NOT the programmer’s fault
• Panicprogrammatic error that IS the programmer’s fault
• LeaveExecution leaves the method and jumps up the call stack to the closest exception handler. An error code for the leaving cause is carried to the handler.A leaving function
Calls another leaving function, orCalls the system function User::Leave()
• Trap / trap harnessException handlers
30
Leave and Trap Harness• void DoExampleL()
{CExample* example = new CExample;if (example == NULL) {
User::Leave(KErrNoMemory);}// do something with exampledelete example;
}
• TInt r = 0; // leave variableTRAP(r, DoExampleL());if (r != KErrNone) {// handle error }
• TRAPD(r, DoExampleL()) without defining r• Nest trap harness is supported
L indicates that method may leave (naming convention)
throw exceptionwith reason code
trap harness will catch a leave in DoExampleL.Control returns to the trap harness from DoExampleL.
31
Overload of Operator new()• Allocating memory using the operator new() many fail due
to “out-of-memory” reason.• Necessary check is needed
CExample* ptr = new CExample;if (ptr == NULL) {
User::Leave(KErrNoMemory);}
• A global overload of the operator new() in Symbian C++It takes a parameter ELeave. It will leave with KErrNoMemory if fails to allocate memory.
• The above code lines becomeCExample* ptr = new (ELeave) CExample;
32
Cleanup Stack: Avoid Memory Leaks
• When control returns to the trap harness due to a leave, all automatic variables on the stack are destroyed
Memory leaks if the they are pointers to memory on the heap
• Cleanup stackIt can freeheap memory
HeapHeap contains orphaned memory
Stack frame lost due to leave
Stack contains pointers to memory on the heap
Heap
Cleanup stackStack frame lost due to leave
33
Cleanup Stack Example• void DoExampleL()
{CObject* ptr1 = new (ELeave) CObject;CObject* ptr2 = new (ELeave) CObject; // out-of-memory failure// …delete ptr1;delete ptr2;
}
• void DoExampleL(){
CObject* ptr1 = new (ELeave) CObject;CleanupStack::PushL(ptr1);CObject* ptr2 = new (ELeave) CObject;CleanupStack::PushL(ptr2);// …CleanupStack::PopAndDestroy(2); // Pops and delete two pointers
}
34
Problem with Compound Objects• Compound objects are those creates inner objects as their member
variables.• Such member variables should be destroyed in the compound object’s
destructor.• They are NEVER supposed to be pushed onto the cleanup stack,
otherwise double deletion error will happen.
• class CExample : public CBase {CExample();CElement* iElementPtr;
};• CExample is a compound object• We cannot push iElementPtr into cleanup stack
• This is closely related to Two-phase construction in Symbian C++
35
Two-Phase Construction (1)• Constructing member variable objects in the constructor will cause
problem
• Class definitionclass CExample : public CBase {
CExample();CElement* iElementPtr;
};
CExample::CExample() {iElementPtr = new (ELeave) CElement();
}
• Class useCExample* examplePtr = new (ELeave) CExample();
1. Memory is allocated for CExample2. The constructor of CExample is called3. Memory is allocated for CElement and
its constructor is called4. A pointer to CElement is stored in
iElementPtr5. Constructor is complete
If step 3 fails, the trap harness will get the control and we have no way to destroy the partially created CExample object, because examplePtr pointer is lost
36
Two-Phase Construction (2)• Construct member variable objects in a 2nd-phase
• Class definitionclass CExample : public CBase {
CExample() {iElement = NULL; // CBase takes care of zero-initialization
}void ConstructL() {
iElement = new (ELeave) CElement();}
CElement* iElement;}
• Class useCExample* examplePtr = new (ELeave) CExample();CleanupStack::PushL(example);example->ConstructL();CleanupStack::Pop();
can be hidden inside a static factory method: NewL or NewLC
37
Two-Phase Construction of Objects (3)• Static factory method NewL()
• Class definitionclass CExample : public CBase {
CExample() { iElement = NULL; }void ConstructL() {
iElement = new (ELeave) CElement();}
static void NewL() {CExample* self = new (ELeave) CExample();CleanupStack::PushL(self);self->ConstructL();CleanupStack::Pop();
}
CElement* iElement;}
• Class useCExample* examplePtr = CExample::NewL();
38
Client-Server Framework• Symbian OS uses a micro kernel architecture• Most system functionality is accessed through servers
39
Multitasking in Symbian OS• Asynchronous service request
Return immediately while the service provider runs in backgroundImplemented using preemptive multitasking on most desktop systems
A new thread is spawned to handle an asynchronous requestHowever, thread switching is too expensive on resource constrained devices Symbian OS intended for
• Active object frameworkEnables non-preemptive multitasking within one threadActive objects are used to encapsulate asynchronous service requestsDefine your own Active Object class by inheriting CActiveSymbian OS provides an Active Scheduler
40
Service Request in Symbian
ActiveObject
SystemServer
Process or thread boundary
Call Active Objecthandler function Wait for new result
Step1: Issue request
Step2: Completion signal
Step3: Handle completion
Active Schedulermessage loop
42
Symbian• Introduction• Symbian OS Based Mobile Phones• Symbian OS and Symbian C++
Software Developing on Symbian OSFundamentals
• Python for S60
43
Python for S60• Python 2.2.2 as a Symbian DLL• Extensible and embeddable with the Python/C API• Standard library
socket (TCP/IP, SSL, Bluetooth serial connections), urllib, httplib, nntplib, thread, math, re, sre, marshal, anydbm, whichdbm etc...File system access Many modules written in Python work unchanged or with minor changesC modules need to be modified
44
Python Phone-Specific Modules• appuifw• graphics• e32• messaging• location• sysinfo• camera• audio• telephone• calendar• contacts
45
appuifw Module• API for S60 GUI programming• S60 UI made as simple as possible• Just one widget allowed on screen at a time• Three different screen types:Normal/Large/Full• Variety of user interactions
Form Listbox & Tabs Text widget Popup menu Multifield queryContent handler
import appuifwappuifw.note(u’Hello World!’)
47
Single Field Dialog As Query• You can input
Text, code, number, date, time, query
• User interaction requestedretrievedtext = appuifw.query(u“text", "text")