15
Common Design Patterns for Symbian OS The Foundations of Smartphone Software Lead Author Adrian Issott With Nicholas Addo, Toby Gray, David Harper, Craig Heath, Guruprasad Kini, Ian McDowall, Ben Morris, John Roe, Dale Self, James Steele, Jo Stichbury, Oliver Stuart, Viki Turner, Hamish Willee Reviewed by Sandip Ahluwalia, Matthew Allen, Sorin Basca, David Caabiero, Iain Campbell, Douglas Feather, Ryan Gilmour, Martin Hardman, Richard Harrison, Tim Howes, Mark Jacobs, Martin Jakl, Sian James, Antti Juustila, Simon Mellor, Sihem Merah, Will Palmer, Subhasis Panigrahi, Lucian Piros, Mark Shackman, Adrian Taylor, Paul Todd, Gabor Torok, Charles Weir, Alex Wilbur, Tim Williams Head of Symbian Press Freddie Gjertsen Managing Editor Satu McNabb A John Wiley and Sons, Ltd., Publication

Common Design Patterns for Symbian OS - Buch.de Design Patterns for Symbian OS The Foundations of Smartphone ... Milton, Queensland 4064, Australia John Wiley & Sons (Asia) ... Sony

  • Upload
    vodan

  • View
    218

  • Download
    4

Embed Size (px)

Citation preview

  • Common Design Patternsfor Symbian OSThe Foundations of SmartphoneSoftware

    Lead AuthorAdrian Issott

    WithNicholas Addo, Toby Gray, David Harper, Craig Heath,Guruprasad Kini, Ian McDowall, Ben Morris, John Roe,Dale Self, James Steele, Jo Stichbury, Oliver Stuart, Viki Turner,Hamish Willee

    Reviewed bySandip Ahluwalia, Matthew Allen, Sorin Basca, David Caabiero,Iain Campbell, Douglas Feather, Ryan Gilmour,Martin Hardman, Richard Harrison, Tim Howes, Mark Jacobs,Martin Jakl, Sian James, Antti Juustila, Simon Mellor,Sihem Merah, Will Palmer, Subhasis Panigrahi, Lucian Piros,Mark Shackman, Adrian Taylor, Paul Todd, Gabor Torok,Charles Weir, Alex Wilbur, Tim Williams

    Head of Symbian PressFreddie Gjertsen

    Managing EditorSatu McNabb

    A John Wiley and Sons, Ltd., Publication

    ayyappan9780470713778.jpg

  • Common Design Patternsfor Symbian OS

    The Foundations of Smartphone Software

  • Common Design Patternsfor Symbian OSThe Foundations of SmartphoneSoftware

    Lead AuthorAdrian Issott

    WithNicholas Addo, Toby Gray, David Harper, Craig Heath,Guruprasad Kini, Ian McDowall, Ben Morris, John Roe,Dale Self, James Steele, Jo Stichbury, Oliver Stuart, Viki Turner,Hamish Willee

    Reviewed bySandip Ahluwalia, Matthew Allen, Sorin Basca, David Caabiero,Iain Campbell, Douglas Feather, Ryan Gilmour,Martin Hardman, Richard Harrison, Tim Howes, Mark Jacobs,Martin Jakl, Sian James, Antti Juustila, Simon Mellor,Sihem Merah, Will Palmer, Subhasis Panigrahi, Lucian Piros,Mark Shackman, Adrian Taylor, Paul Todd, Gabor Torok,Charles Weir, Alex Wilbur, Tim Williams

    Head of Symbian PressFreddie Gjertsen

    Managing EditorSatu McNabb

    A John Wiley and Sons, Ltd., Publication

  • Copyright 2008 John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester,West Sussex PO19 8SQ, England

    Telephone (+44) 1243 779777Email (for orders and customer service enquiries): [email protected] our Home Page on www.wileyeurope.com or www.wiley.com

    All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system ortransmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning orotherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms ofa licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London W1T 4LP,UK, without the permission in writing of the Publisher. Requests to the Publisher should be addressed tothe Permissions Department, John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, WestSussex PO19 8SQ, England, or emailed to [email protected], or faxed to (+44) 1243 770620.Designations used by companies to distinguish their products are often claimed as trademarks. Allbrand names and product names used in this book are trade names, service marks, trademarks orregistered trademarks of their respective owners. The Publisher is not associated with any product orvendor mentioned in this book.

    This publication is designed to provide accurate and authoritative information in regard to the subjectmatter covered. It is sold on the understanding that the Publisher is not engaged in renderingprofessional services. If professional advice or other expert assistance is required, the services of acompetent professional should be sought.

    Other Wiley Editorial Offices

    John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA

    Jossey-Bass, 989 Market Street, San Francisco, CA 94103-1741, USA

    Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany

    John Wiley & Sons Australia Ltd, 42 McDougall Street, Milton, Queensland 4064, Australia

    John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809

    John Wiley & Sons Canada Ltd, 6045 Freemont Blvd, Mississauga, Ontario, L5R 4J3, Canada

    Wiley also publishes its books in a variety of electronic formats. Some content that appearsin print may not be available in electronic books.

    British Library Cataloguing in Publication Data

    A catalogue record for this book is available from the British Library

    ISBN 978-0-470-51635-5

    Typeset in 10/12 Optima by Laserwords Private Limited, Chennai, IndiaPrinted and bound in Great Britain by Bell & Bain, GlasgowThis book is printed on acid-free paper responsibly manufactured from sustainable forestryin which at least two trees are planted for each one used for paper production.

    www.wiley.com

  • Dedicated to Kat and to Mike

  • Contents

    Author Biographies ix

    Authors Acknowledgments xv

    Foreword xvii

    Glossary xix

    1 Introduction 11.1 About this Book 11.2 Who this Book Is For 11.3 Which Version of Symbian OS this Book Is For 21.4 General Design Patterns 21.5 Symbian OS Patterns 41.6 Design Pattern Template 101.7 Structure of this Book 121.8 Conventions 131.9 Other Sources of Information 13

    2 Error-Handling Strategies 15Fail Fast 17Escalate Errors 32

    3 Resource Lifetimes 49Immortal 53

  • viii CONTENTS

    Lazy Allocation 63Lazy De-allocation 73

    4 Event-Driven Programming 87Event Mixin 93Request Completion 104Publish and Subscribe 114

    5 Cooperative Multitasking 131Active Objects 133Asynchronous Controller 148

    6 Providing Services 165Client-Thread Service 171ClientServer 182Coordinator 211

    7 Security 233Secure Agent 240Buckle 252Quarantine 260Cradle 273

    8 Optimizing Execution Time 287Episodes 289Data Press 309

    9 Mapping Well-Known Patterns onto Symbian OS 331ModelViewController 332Singleton 346Adapter 372HandleBody 385

    Appendix: Impact Analysis of RecurringConsequences 397

    References 403

    Index 407

  • Author Biographies

    Nicholas Addo

    Nicholas has worked on Symbian OS for six years. He first joined theBrowser Technology group in Symbian, developing a generic frameworkfor content handling. He then moved to the Personal Information Man-agement group to work on Enterprise Group Scheduling technology.From there, he joined the Multi-technology development group to workon cross-technology and process-improvement projects. This included astint in product management defining a Component Technology productstrategy for Symbian OS and an ongoing involvement in improvementinitiatives for Symbian OS core idioms.

    Nicholas started his career as an apprentice Electronics Engineer in the1980s, developing semiconductor devices for telecommunications. Hemoved into a solely software development career in the 1990s. This wasinitially in real-time embedded systems and later Windows-based userinterfaces for image scanners, writers, and print register and color controldevices for the printing and pre-press industry.

    Toby Gray

    Toby has worked with Symbian OS since joining the System Managementgroup of Symbian in 2005. Since then, he has worked on topics rangingfrom optimizing system characteristics (e.g. speed, RAM usage and ROMusage) to management of system start-up and from development ofdiagnostic tools to ARM assembler optimization. He holds a BA inComputer Science from the University of Cambridge.

  • x AUTHOR BIOGRAPHIES

    David Harper

    David has worked at Psion Software and Symbian for over 10 years.During that time he has developed an in-depth knowledge of HTTP,Internet technologies, ECom and Platform Security. He now works inIntegration Management, specializing in Technology Integration. Davidholds an MSc in Artificial Intelligence from Queen Mary and WestfieldCollege.

    Craig Heath

    Craig has been working in IT security since 1988, with The Santa CruzOperation as security architect for SCO UNIX, then at Lutris Technologiesas security architect for their Java Enterprise Application Server. Hejoined Symbian in 2002, working in product management and strategy.He has contributed to several published industry standards and hasa long association with The Open Group Security Forum, includingco-authorship of the Open Group Technical Guide to Security DesignPatterns. Craig is lead author of Symbian OS Platform Security.

    Adrian Issott

    Adrian joined Symbians Shortlink team in 2004 working first on devel-oping support for Bluetooth stereo headsets and then on enhancing theBluetooth HAI. In 2006, he moved on to become an architect focusingon system characteristics such as performance, RAM usage, reliabilityand security. His time is currently spent either working on long-termarchitectural improvements in areas such as system start-up and trace oron urgent projects helping device manufacturers optimize their devicesand get the best out of Symbian OS. Adrian graduated from Jesus College,Oxford with a first class honors degree in Mathematics.

    Guruprasad Kini

    Guru has been working with Symbian for the last three and a half years,most of which he spent in the Remote Management Team. He is nowa part of the Systems Engineering Team. Design patterns, cryptographyand data security have been his primary professional interests. Guru isbased near Bangalore and holds a BE in Computer Science from ManipalInstitute of Technology, Karnataka. He hopes to retire early and do whathe always wanted to do teach mathematics in schools. And . . . oh yes,he is also very bad at writing bios.

  • AUTHOR BIOGRAPHIES xi

    Ian McDowall

    Ian joined Symbian in 2001, has worked in a range of teams withinSymbian and is currently a Technology Architect responsible for Short-link technologies. He has previously filled roles ranging from developerthrough project manager to technical manager. He has an MA in Com-puter Sciences from Cambridge University and an MBA from WarwickUniversity. As a software engineer for over 25 years, he has workedfor a number of software companies and has worked on more than 15operating systems, developing software ranging from enterprise systemsto embedded software. He is married to Lorraine and they have twochildren, Kelly and Ross, and a number of pets.

    Ben Morris

    Ben joined Psion Software in October 1997, working in the softwaredevelopment kit team on the production of the first C++ and Java SDKsfor what was at that time still the EPOC32 operating system. He led thesmall team that produced the SDKs for the ER5 release of EPOC32 and,when Psion Software became Symbian, he took over responsibility forexpanding and leading the companys system documentation team. In2002, he joined the newly formed System Management Group in theSoftware Engineering organization of Symbian, with a brief to definethe system. He devised the original system model for Symbian OS andcurrently leads the team responsible for its maintenance and evolution.He can be found on the Internet at www.benmorris.eu.

    John Roe

    John has an MA in Engineering from Cambridge University and hasworked with Symbian for well over 10 years. For the past nine years, hehas been in Symbians Customer Engineering group as the S60 TechnicalLead. He has worked on S60 since its inception and on many S60 phonesranging from the Nokia 7650 to present-day devices. He divides his timebetween supporting Symbians licensees and using his product realizationexperience to develop the architecture of Symbian OS.

    Dale Self

    Dale is soon to celebrate 10 years of working for Symbian, where heworked first in the Messaging team on IMAP and later in the Shortlink

  • xii AUTHOR BIOGRAPHIES

    team on Bluetooth and OBEX. Most recently, he has been working onUSB architecture and standardization. In his spare time, he enjoys music,photography and writing fiction as well as non-fiction. He hopes that hiscontribution to this book falls into the latter category.

    James Steele

    James joined Symbian after graduating from university in 2004. Heattended the University of Cambridge (Fitzwilliam College) where heread Computer Science. Since starting his career at Symbian as a memberof the Shortlink team he has been involved with the development ofnumerous protocol stacks, including Bluetooth, USB and IrDA.

    In his free time, James enjoys taking part in friendly poker matcheswith friends and colleagues, and pretending to be a film critic. He playsvarious sports, including basketball, badminton and squash. In the winter,you will probably find him skiing somewhere in the French Alps.

    Jo Stichbury

    Jo is Senior Technical Editor with Symbian Press. She has worked withinthe Symbian ecosystem since 1997 in the Base, Connectivity and Securityteams of Symbian, as well as for Advansys, Sony Ericsson and Nokia. Jois the author of Symbian OS Explained: Effective C++ programming forsmartphones, published by Symbian Press in 2004. She also coauthoredThe Accredited Symbian Developer Primer: Fundamentals of SymbianOS with Mark Jacobs, in 2006. Her most recent book is Games onSymbian OS: A handbook for mobile development, published in early2008.

    Oliver Stuart

    Oliver is a recent convert to Symbian and joined the companys Commsteam in 2007. Thrown in at the deep end, he has enjoyed the challengingwork of developing for a powerful mobile operating system. He previouslyworked in the field of biological digital imaging at Improvision Ltd andhas interests in object-oriented programming, concurrency, networkingand multimedia. He holds a BSc with Hons in Computer Science/SoftwareEngineering from the University of Birmingham in the UK. He has carefullytried to hide his past as a Windows developer from his new colleagues toavoid derision.

  • AUTHOR BIOGRAPHIES xiii

    Viki Turner

    Viki is the Comms Chief Technology Architect at Symbian. She has workedwith communications technologies at Symbian since joining in 2001,when she helped the third Symbian phone to ship successfully. In earlierengineering roles, she also developed communications middleware first with an interesting but short-lived startup, developing a networkedmultimedia distribution platform, and then working in the City of Londonon data feed products. Viki trained in computing at Imperial College, aftera few years pursuing a career as a classical soprano . . . but thats anotherstory.

    Hamish Willee

    Hamish joined Symbian in late 1998 and is looking forward to the10 year celebrations! Most of those years were spent in developer supportroles he still gets a kick out of improving third-party development onSymbian OS. The last few years he has worked remotely from Melbourne,Australia, continuing to provide technical assistance to Symbians globaldeveloper ecosystem. Outside work, Hamish loves to spend time with hisfamily: Jen, Oscar, Sam and Leo.