Wiley.Developing.Software.for.Symbian.OS.2nd.Edition.Dec.2007 (779887), страница 2
Текст из файла (страница 2)
This new edition ofthe book includes a chapter on platform security and application signing(Chapter 7), and a set of downloadable sample code for the major codeexamples in the book, for both UI platforms.The original book Developing Software for Symbian OS, publishedin 2005 for versions of Symbian OS pre-dating v9, has been a verypopular Symbian Press title.
It was a ground-breaking book because itwas our first aimed squarely at beginners. Readers appreciated Steve’spractical approach to the subject, and they report having learnt far morethan just the basics – it was a book packed with valuable and accessibleinformation.Based on the number of times we’ve seen the original book recommended on developer discussion forums, and our own belief in the qualityof the title, we decided to ask Steve to create a new edition for SymbianOS v9. This book is the result, and I believe it is a valuable contribution tothe Symbian Press series – our 23rd Symbian Press title. I anticipate it tobe a useful addition to the bookshelves of many developers as they learnhow to create more applications to help those millions of smartphoneusers to ‘do more with Symbian’.ForewordWarren DaySenior Technical Trainer, Symbian Software LtdWhy read this book?It has the best explanations I’ve read of the fundamental things wemust understand about Symbian OS, in that it covers the ‘what’ and the‘how’ of Symbian C++ software development.And there are several parts to the how.It is important to understand what facilities are provided (so we don’treinvent the wheel).
Just as importantly we should know both how tothink about these components and how to use them appropriately. A carisn’t meant to be driven in just first gear; doing so would quickly emptythe fuel tank and put great strain on the vehicle’s internal workings.As it is for a vehicle’s transmission system, so it is also true for a softwaresystem. Misusing software components can result in everything from shortbattery life (so phones need frequent recharging) to inappropriate or poorfunctionality, and phones that are difficult to use.
By having a clear insightinto the fundamentals (such as memory management, string classes andasynchronous events), your software will be more efficient, because itutilizes the underlying system as intended.We are living in exciting times. Society is evolving; being alwaysconnected to others and the Internet is standard for many. Now smartphones have the ability to make phone calls, access the Internet, capturevideo, as well as perform personal organizer, word processor and spreadsheet functionality, all from a small handset. However, smartphones arevery different from computers in one fundamental way, people have usedphones before! The telephone is easy to use and works correctly about100% of the time. Smartphones should be equally usable and reliable.This is the case with the other things a smartphone can do too, such asxiiFOREWORDtake photographs, play video and music.
People have equivalent experiences of reliability: the devices they are used to just work. Thus we nowhave raised standards for rich functionality, power efficiency and perhapsmost importantly, reliability.So, this book is a good ‘start writing and running programs from scratch’book. It covers similar material to Symbian’s OS Essentials training courseand shows you how to take your first steps to writing good qualityapplications for Symbian smartphones as they should be written.BiographySteve Babin works at IBM developing enterprise software for smartphonesbased on Symbian OS and Microsoft Windows Mobile.
He has a BSEEfrom Louisiana State University and over 20 years of software development and leadership experience on a variety of products – includingmedical devices, Java accelerators, avionics, Internet appliances, andsystem-on-chip silicon devices – using numerous operating systems. Steveis married to Sharon and has a daughter named Hillary. They live in Austin,TX. He is an Accredited Symbian Developer.Author AcknowledgmentsI would like to thank the people at Symbian Press for their interest in,and enthusiasm for, doing this update.
It was a pleasure working withthem again. I especially want to thank Jo Stichbury for her very thoroughreviews and edits, as well as her excellent suggestions and advice.Special thanks also go to Satu McNabb and all the technical reviewers,including Antony Pranata, Steve Rawlings, Howard Sykes, Laura Sykes,Matthew O’Donnell, Jehad Al-Ansari, Chris Notton, Douglas Feather,Neil Hepworth, Bruce Carney, Ricky Junday, Roderick Burns, and WarrenDay.
Updating the book for Symbian OS v9 was quite a challenge, butI was glad to have the help of such talented people. Thanks also go tothe people at John Wiley for their interest in this project, and their hardwork – I can only imagine what it takes to bring a book like this all theway through the process and into the reader’s hands. I also want to thankmy wife Sharon and my daughter Hillary, for putting up with me onthis – again.Symbian Press AcknowledgmentsSymbian Press would like to thank Steve Babin for resolutely revisinghis much-respected repository of knowledge.
Thank you Steve, for beingprofessional, reliable, and a pleasure to work with. We’d also like tothank each of the reviewers, and in particular Antony Pranata and SteveRawlings, who lent us the weight of their experience on each of theUI platforms at very short notice. Thanks must also go to the SymbianTechnical Training team for their feedback and support.We couldn’t have put this book together without the team at JohnWiley, and it’s thanks to Rosie Kemp that it happened so rapidly. PhilNortham came to the rescue in our darkest hour, and Jo has promised tobuy him and Satu lunch, in recognition and with gratitude.Symbian OS Code Conventionsand Notations Used in the BookFor you to get the most out of this book, let’s quickly run through thenotation we use.
The text is straightforward, and where we quote examplecode, resource files, or project definition files, they will be highlighted asfollows:This is example code;C++ code for Symbian OS uses an established naming convention.We encourage you to follow it in order for your own code to beunderstood most easily by other Symbian OS developers, and becausethe conventions have been chosen carefully to reflect object cleanupand ownership, and make code more comprehensible. An additionalbenefit to using the conventions is that your code can then be tested withautomatic code analysis tools, which can flag potential bugs or areas toreview.If they are unfamiliar, the best way to get used to the conventions is tolook at code examples in this book, and those provided with your chosenSDK.CapitalizationThe first letter of class names is capitalized:class TColor;xxSYMBIAN OS CODE CONVENTIONS AND NOTATIONS USED IN THE BOOKThe words making up variable, class, or function names are adjoining,with the first letter of each word capitalized.
Classes and functions havetheir initial letter capitalized while, in contrast, function parameters, local,global, and member variables have a lowercase first letter.Apart from the first letter of each word, the rest of each word is givenin lower case, including acronyms. For example:void CalculateScore(TInt aCorrectAnswers, TInt aQuestionsAnswered);class CActiveScheduler;TInt localVariable;CShape* iShape;class CBbc;//Acronyms are not usually written in upper casePrefixesMember variables are prefixed with a lowercase ‘i’, which stands for‘instance’.TInt iCount;CBackground* iBitmap;Parameters are prefixed with a lowercase ‘a’, which stands for ‘argument’.We do not use ‘an’ for arguments that start with a vowel.void ExampleFunction(TBool aExampleBool, const TDesC& aName);(Note: TBool aExampleBool rather than TBool anExampleBool).Local variables have no prefix:TInt localVariable;CMyClass* ptr = NULL;Class names should be prefixed with the letter appropriate to theirSymbian OS type (usually ‘C’, ‘R’, ‘T’, or ‘M’):classclassclassclassCActive;TParse;RFs;MCallback;Constants are prefixed with ‘K’:const TInt KMaxFilenameLength = 256;#define KMaxFilenameLength 256SYMBIAN OS CODE CONVENTIONS AND NOTATIONS USED IN THE BOOK xxiEnumerations are simple types, and so are prefixed with ‘T’.
Enumerationmembers are prefixed with ‘E’:enum TWeekdays {EMonday, ETuesday, ...};SuffixesA trailing ‘L’ on a function name indicates that the function may leave:void AllocL();A trailing ‘C’ on a function name indicates that the function returns apointer that has been pushed onto the cleanup stack:CCylon* NewLC();A trailing ‘D’ on a function name means that it will result in the deletionof the object referred to by the function:TInt ExecuteLD(TInt aResourceId);UnderscoresUnderscores are avoided in names except in macros (or resource files (MENU ITEM).ASSERT DEBUG)Code LayoutYou’ll notice that the curly bracket layout in Symbian OS code, usedthroughout this book, is to indent the bracket as well as the followingstatement:void CNotifyChange::StartFilesystemMonitor(){// Only allow one request to be submitted at a time// Caller must call Cancel() before submitting anotherif (IsActive()){_LIT(KAOExamplePanic, "CNotifyChange");User::Panic(KAOExamplePanic, KErrInUse);}iFs.NotifyChange(ENotifyAll, iStatus, *iPath);SetActive(); // Mark this object active}1Smartphones and Symbian OSSymbian OS is a full-featured, open, mobile operating system that powersmany of today’s smartphones.
As these smartphones become more powerful and popular, the demand for smartphone software has grown.Symbian smartphones are shipped with a variety of useful pre-loadedand targeted applications, which are selected by each phone’s manufacturer. Today, the average Symbian smartphone ships with over 30pieces of third-party software pre-installed.