1 © nokia europython_pythonforseries60.ppt / 2005-06-27 / jukka laurila python for series 60 (i.e....

12
1 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila Python for Series 60 (i.e. Python on a Phone) Jukka Laurila EuroPython 2005

Upload: audra-cross

Post on 17-Dec-2015

226 views

Category:

Documents


0 download

TRANSCRIPT

1 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Python for Series 60(i.e. Python on a Phone)

Jukka Laurila

EuroPython 2005

2 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

What is Series 60?

• 100-220 MHz ARM processor (and a separate processor for telephony functions)

• Typically 4 – 8 MB of free RAM• FAT formatted Flash as mass storage• Symbian OS• Series 60 software for UI, comms, applications

etc.• GSM, GPRS, UMTS, Bluetooth, IrDA, WLAN...• Display: 176x208 12-18 bpp LCD panel

(currently, N90 has 352x416)• Integrated camera (usually)• 20 million shipped by Nokia alone• In other words: A pretty capable computer

• ...with an always-on Internet connection• ...that’s with you all the time• ...that you can write your own software for• ...IF you spend enough effort

3 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Why port Python to a phone?

• Symbian C++ development is slow and hard

• Java has limited access to platform capabilities

• Easy to learn, clear syntax

• High productivity (See: Lutz Prechelt: An empirical comparison of seven programming languages, IEEE Computer 33(10):23-29, October 2000)

• Extending and embedding easy and efficient

• Popular

• Good standard library

• Reasonable memory footprint

• Ports to other “embedded” systems already existed at the time (PalmOS)

• Other choices: • ECMAScript• Perl (actually we did port Perl, too)

4 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Past and Future

• Stable 1.0 release Dec 2004

• 1.1.x pre-alpha series releases ongoing, soliciting feedback from external developers

• We need you!

• Stable 1.2 release coming later this year

• A standard component in future phones? Maybe.

• Source release? Working on it...

5 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Python for Series 60 1.1.5

• 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

changes• C modules need to be modified

6 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Bindings to Series 60 API’s

• appuifw: a simple S60 UI API• SMS sending• Native Symbian SQL database (e32db module), dbm (over e32db)• Location API (Cell ID)• Background “daemon” process support• New in 1.1 series:

• 2D graphics• Binding to Symbian GDI graphics• API partly similar to PIL• Image loading, saving, scaling, rotation, bitblit• Set of graphics primitives

• Raw key event handling• camera • contacts• calendar• telephony• audio: record and play samples, MIDI• sysinfo • miscellaneous improvements, like rich text support

7 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

appuifw

• Our own API for Series 60 GUI programming

• S60 UI made as simple as possible

• Just one widget allowed on screen at a time

Form Listbox & Tabs Text widget Popup menu Multifield queryContent handler

import appuifwappuifw.note(u’Hello World!’)

8 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Porting difficulties…

• No global writable data allowed in DLL’s• Globals moved to heap-allocated struct referenced via TLS

• No standard C++ exceptions• Instead TRAP/Leave (think setjmp/longjmp), Cleanup Stack

• Memory and disk space constraints• We can run out of memory at any time and should survive it

• C stdlib not quite complete• Locale-specific float formatting: 3.14 vs. 3,14

• Symbian and S60 API complexity

• Active Objects: co-op multitasking and event handling the Symbian way

9 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Co-op multitasking and event handling the Symbian way

Thread

AORunL() { ...run code... run nested AS ...run more code... }

Active Object: object that inherits from CActive, has a RunL method think “event handler” or “co-operative task”

Active Scheduler: a loop that runs RunL methods of AO’s in sequence think “event loop” or “co-operative multitasking engine”

AS AO RunL() { ...refresh UI widget... }

AORunL() { ...put data received from a socket to a buffer...}

lock=e32.Ao_lock()lock.wait() start a nested AS and run until the lock is .signal()ed e32.ao_yield() start a nested AS and run through it once

10 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Remaining problems

• unicode vs. str ugliness:

• Very little performance optimizations have been done yet, so there’s a lot of room for improvement

• Slow imports• Globals access using Thread Local Storage is a real killer

• Native Symbian resources aren’t threadsafe… at all.

• No gc support yet• Unfreed native resources cause an error message on exit• …which is nasty since reference cycles are easy to make

• Creating C extensions on Symbian is not as easy as it should be• Manual work required, no distutils, SWIG, SIP or any of that

magic (yet)

appuifw.note(u’foo’)appuifw.popup_menu([u’first’,u’second],u’Pick one:’)

11 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Demos!

12 © NOKIA EuroPython_PythonForSeries60.PPT / 2005-06-27 / Jukka Laurila

Questions?

For more information:

http://www.forum.nokia.com/http://discussion.forum.nokia.com/