120 likes | 246 Views
Python for Series 60 (i.e. Python on a Phone). Jukka Laurila EuroPython 2005. 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
E N D
Python for Series 60(i.e. Python on a Phone) Jukka Laurila EuroPython 2005
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
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)
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...
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
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
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 import appuifw appuifw.note(u’Hello World!’) Form Text widget Listbox & Tabs Popup menu Content handler Multifield query
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
Co-op multitasking and event handling the Symbian way 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” Thread AO RunL() { ...run code... run nested AS ...run more code... } AO AS RunL() { ...refresh UI widget... } AO RunL() { ...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
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:’)
Questions? For more information: http://www.forum.nokia.com/ http://discussion.forum.nokia.com/