Wiley.Developing.Software.for.Symbian.OS.2nd.Edition.Dec.2007 (779887), страница 14
Текст из файла (страница 14)
Congratulations on creating and running your first SymbianOS C++ program on a smartphone!3Symbian OS ArchitectureThis chapter gives an overview of the architecture of Symbian OS – itsmain components and its underlying functionality.Much of the functionality described in this chapter is transparentfrom a typical Symbian OS application programming view; however,understanding the architectural details of an operating system can beuseful in developing software for it – especially for programming onhighly reliable, limited-resource devices such as smartphones.You can skim this chapter on a first read if you want, since anunderstanding of many of the subjects here is not absolutely essential todeveloping applications.
But if you are like me and prefer to dig into thedetails in order to gain deeper knowledge, then you will find this chapteruseful.3.1 Components in Symbian OSThere are usually many ways to slice a system up into pieces – thefollowing breakdown of the major parts of Symbian OS is suitable for thedetail covered in this chapter:1•KernelThe kernel is the central manager and arbiter of Symbian OS. Itmanages the system memory and schedules programs for execution. Italso allocates shared system resources and handles any functionalitythat requires privileged access to the CPU.•Base libraries: user library, file system, database manager1For more information about the components that comprise Symbian OS, I recommendyou consult the system model diagram available from the Symbian Developer Network(http://developer.symbian.com/main/oslibrary/sys models).64SYMBIAN OS ARCHITECTUREThe user library (euser.dll) contains APIs that provide functionalitysuch as string manipulation, linked lists, containers, math functions,error handling, and timers.
The user library also provides ‘user-side’access to kernel functions (e.g., thread control and client–servercommunications). This library is used not only by applications, butalso by the OS components.As you would expect, the file system library (efsrv.lib) providesthe functionality to manipulate files and directories, parse filenames,and perform file I/O.
The database manager (edbms.lib) provides aset of interfaces for relation database access.•Application services, engines, and protocolsApplication services, engines, and protocols provide access for programs to core application data, features, and services. An exampleis an engine to directly manipulate the data of built-in applicationsthat manage contacts, the calendar, and to-do lists. Other examplesinclude setting and handling alarms, and access to high-level communication features such as HTTP and HTTPS.•Application frameworkThe application framework implements the base functionality of thesmartphone’s graphical user interface applications.
This includes aframework for handling the GUI itself and an architecture frameworkfor handling non-GUI-related application functionality.•Communications architectureThe communications architecture consists of the APIs and frameworkthat implement data communications. This includes voice telephonyand TCP/IP over cellular radio as well as local communication protocols such as Bluetooth technology, IR, and USB. The messagingframework for support is also included, with SMS, MMS, and emailmessaging.•Middleware feature librariesThis is a catch-all category for the rest of the APIs and frameworks notcovered in the previous items. It includes components which provideservices for multimedia, security, and the POSIX-compliant librariesfor standard C.3.2 Multitasking in Symbian OSSymbian OS is a multitasking operating system – it can run multipleprograms at once. Although a smartphone’s screen is too small to displaymore than one application at a time (as desktop computers are able to),you can switch between running applications as needed.
Also, as withoperating systems such as Linux and Windows, Symbian OS providesSHARED CODE: LIBRARIES, DLLS, AND FRAMEWORKS65true multithreaded behavior in that it allows multiple execution threadsto execute in parallel, even in a single application.Here I’ll briefly introduce threads and processes in Symbian OS – theseform the basis of the multitasking capability in Symbian OS. Chapter 9covers threads and processes and inter-thread communication in moredetail.3.2.1 ThreadsThreads are streams of code execution that run in parallel with each other,based on their priorities.
The Symbian OS kernel supports pre-emptivemultithreading, which means that not only can threads run in parallel,but the kernel can switch execution from one thread to another withoutneeding any code in the running thread to explicitly relinquish control.A single Symbian OS program can have multiple threads, but as youwill see later, it’s best to avoid using them in your program directly, andinstead use the asynchronous framework. This framework provides anevent-driven cooperative multitasking model for your application, whichwill be introduced later in this chapter (and detailed in Chapter 8).3.2.2ProcessesA process is a running instance of a program that has its own independentdata space as well as one or more threads executing within it.
The codefor a process is contained in a file whose extension is .exe. The kernelcreates and starts a separate process for each invocation of an EXE file.Multiple processes can run at a time, and the kernel switches to a processwhenever one of the threads in that process becomes active.A process always contains a main thread, and can contain additionalthreads if needed. All threads within a process share its data space, and,therefore, can directly access its static data. For protection, Symbian OSdoes not allow a process to directly access memory in another process.3.3 Shared Code: Libraries, DLLs, and FrameworksShared code consists of packages of executable code that, as the namesuggests, can be shared by other executables; providing functions toall running programs for reuse.
These packages are usually known asdynamic link libraries (DLLs). This is more efficient than the traditionalstatically linked library, where each executable that uses the library’sfunctions links to a separate copy of its code. DLLs are used extensivelyin Symbian OS, and there are well over 100 of them on a typical phone.When a thread invokes a function within a DLL, that function runs within66SYMBIAN OS ARCHITECTUREthe context of the calling thread (and the corresponding process) and thusis able to directly access the data space of the calling process.Prior to Symbian OS v9, GUI applications were actually DLLs themselves; however, from Symbian OS v9 onwards, applications are implemented as fully independent executable processes.On Symbian OS, the most common types of shared binary are staticinterface libraries and polymorphic interface libraries.
They may alsosimply be referred to as DLLs when the context of the type of sharedbinary is established.3.3.1 Static Interface LibrariesStatic interface libraries are the traditional style of libraries, containinga collection of classes and functions that are made available to callingprograms through a series of exported functions, as Chapter 5 will discuss.The base operating system library (euser.dll), which, for example,provides string manipulation functions, is an example of a static interfacelibrary.
Static interface libraries typically end in .dll.3.3.2 Polymorphic DLLsPolymorphic interface libraries (most commonly known as ‘polymorphicDLLs’) are used as plug-ins to a framework, as opposed to simply providingclasses and functions as in static interface DLLs. They provide a concreteimplementation for some abstracted interface. A good example is a devicedriver, which is a polymorphic DLL that can be loaded or unloaded,kernel-side at runtime.Polymorphic DLLs, in a similar fashion to static interface DLLs, areloaded when needed and linked to at runtime. Unlike a static interfacelibrary, which supplies the implementation of an API that is fixed atcompile time and typically loaded by the system, a polymorphic DLL actsas a plug-in, and must be loaded by a framework or other client wishingto use it.A polymorphic DLL implements an abstract interface as a concrete C++class.
The first (and usually only) exported function of the polymorphicDLL just instantiates its concrete class and returns a pointer to it. Withpolymorphic DLLs, you can implement custom plug-ins that presentconsistent interfaces to applications.