Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008 (779888), страница 50
Текст из файла (страница 50)
Others, like P.I.P.S., are ‘mostly’ compliant by virtue of updates oradd-ons to the operating system. P.I.P.S. is not a Unix virtual machineand you can’t expect to just run all of your games all of a sudden – it’ssimply an extension to the standard operating system that supports ANSIC programming on Symbian OS.In practical terms, what this means to the development community isa set of headers, libraries and a tool update in your SDK.
And you can’tuse the P.I.P.S. libraries on the phones if they aren’t there, so there arealso signed SIS files to upgrade S60 and UIQ phones. On S60 3rd Edition,you can embed the P.I.P.S. runtime libraries into your own SIS file, byediting your package definition file as shown below:@"pips_s60_1_1.sis", (0x20009A80)And on UIQ 3:@"pips_uiq_1_1.sis", (0x20009A81)P.I.P.S is only available in Symbian OS v9.1 and later. From SymbianOS v9.3 onwards, the libraries will be included in the ROM, so builtdirectly into the phone handset, with no need for separate installationusing a SIS file.At time of writing, the last P.I.P.S.
release (version 1.1) was in July 2007.This provided P.I.P.S. for Symbian OS v9.1 but, as yet, there is nothingfor v9.2 (due to a difference in the low-level drivers), but the next P.I.P.S.release will work for Symbian OS v9.2. P.I.P.S. version 1.1 will thus onlywork with the S60 MR 3rd Edition SDK and the UIQ 3.0 SDK. It alsobreaks binary compatibility with the previous version of P.I.P.S., which,while a pain, was necessary, because in the earlier version Nokia andSymbian were using different UID ranges for the libraries (see section 7.2on Open C).There are four main P.I.P.S.
libraries:• libc – standard C and POSIX APIs (see below)• libm – mathematical APIs• libpthread – thread creation and synchronization mechanisms• libdl – standard C dynamic loading and symbol lookup APIs.By including the libc library, P.I.P.S. provides Symbian OS withstandard libraries including stdio, fileio and stdlib, as well asP.I.P.S.
IS POSIX ON SYMBIAN OS219string manipulation, searching, sorting and pattern matching functionality,locale and systems services, networking and socket APIs, and IPC mechanisms (pipe, FIFO, message queues and shared memory). It also includesprocess creation methods, such as popen, posix_spawn and system.At this point, you might be thinking of the standard library (STDLIB)that Symbian OS has included for ages (used originally to allow a JVM torun in Psion days). Well that’s now scheduled to be deprecated, so don’tuse it any more – it doesn’t support threading and it isn’t compatible withP.I.P.S.
anyway, as it was designed in a different time with a completelydifferent set of aims in mind.In terms of porting games across to Symbian OS using P.I.P.S., thereare a number of issues that need to be considered. To start with, noticethat there are no graphics libraries yet, so any game with a widget-basedGUI will need to have its interface completely re-written to use S60 orUIQ controls.
But as there’s no doubt a clean separation between UI andengine code in the existing C system, that won’t be a problem, right?Further, Symbian OS doesn’t support symbolic lookup in dynamiclibraries in any version prior to v9.3. Two new target types were createdin Symbian OS v9.3 to flag this standard usage (STDDLL and STDEXE)and set some MMP defaults (like enabling writable static data), but,more importantly, the loader was changed to support both ordinal andsymbolic lookup in DLLs.
This allows symbolic linking to be supportedfrom Symbian OS v9.3 in P.I.P.S. too. The workaround for versions earlierthan Symbian OS v9.3 is simply to find out the ordinal number for thefunction from the DEF file and pass it into the dlsym method from thelibdl library:// Instead ofdlsym(&handle, "CreateWanderingMonster");// If CreateWanderingMonster() has ordinal 3, usedlsym(&handle, "3");There are some additional considerations that arise because P.I.P.S.must obey the same rules of Symbian OS platform security as other nativeapplications.
For example, platform security prevents applications fromreading or writing to each other’s data caged areas without the AllFilescapability (which it’s unlikely a game should need or get). So a gamethat writes data to local temporary files needs to be aware that its defaultwill be its data caged area. Likewise, sharing a file descriptor betweenprocesses (used in POSIX for IPC) will fail without the correct capabilitiesfor the location of the file in question. Another example is the use ofsockets, which requires the NetworkServices capability.
For moreinformation about platform security, you should consult the Symbian OSlibrary documentation inside the SDK you’ve downloaded for the platformyou’re working on (UIQ or S60). There is also a comprehensive treatment220 C/C++ STANDARDS SUPPORT FOR GAMES DEVELOPERS ON SYMBIAN OSin the Symbian Press book called Symbian OS Platform Security, by CraigHeath, published in 2006.On POSIX-compliant systems, a process can use fork or exec tocreate, manage and communicate with child processes. However thereis no support for this on Symbian OS even with P.I.P.S., although thereare a number of situation-specific workarounds that can be used wherenecessary.
Depending on the game, this may or may not be a majorproblem.At the time of writing, P.I.P.S. doesn’t have any support for signals and,as a consequence, game code that is designed to operate with either signalor exception handlers should be removed. The main reason signals arenot supported at present is that P.I.P.S. implements many POSIX systemcalls using standard IPC mechanisms on Symbian OS. These methodsaren’t re-entrant, as they were never designed to be interrupted by signalsin the first place.A game port will also need to address any mechanisms that use signalsfor IPC by changing these to use pipes or FIFOs and would also needto move all asynchronous I/O (which also isn’t supported by P.I.P.S.because, in the absence of signals, all I/O must be synchronous) intoseparate threads in the same process.
Note, however, that this is within aP.I.P.S. context only – you can obviously still perform asynchronous I/Ousing native Symbian OS C++ calls, as and when required.With each subsequent release of P.I.P.S., Symbian OS is becomingcloser to being a fully POSIX compliant operating system as per the IEEEstandard. And hopefully as P.I.P.S. matures, we’ll see a wide range ofexciting game titles ported in the future.7.2 Open CThis is Nokia’s answer to the same problem addressed by P.I.P.S. – Nokiahas taken it further by adding another five standard C libraries on top ofthe four provided by P.I.P.S. Open C is only available for S60 3rd Editiondevices. On UIQ 3, only the four P.I.P.S. libraries (effectively a subset ofOpen C) are available.Symbian and Nokia have been working together very closely over thelast 18 months to keep both Open C and P.I.P.S.
in line with each other.Open C is available as a plug-in to the S60 3rd Edition SDK (MaintenanceRelease) from Forum Nokia (although you can also use S60 3rd EditionFP1, but you can’t target any handsets if you do). Installing the plug-inwill update your tool chain and add the necessary libraries and headersto your file system. You can use Carbide.c++ 1.1/1.2, CodeWarrior 3.1or Microsoft Visual Studio (with the Carbide.vs plug-in) for Open Cdevelopment, although you will need Carbide v1.2 if you wish to takeadvantage of the new target types defined for Symbian OS v9.3 (STDDLLand STDEXE).OPEN C221Table 7.1 Open C and P.I.P.S. libraries and their coverageStandard LibraryFunctionalityprovided by% Standard functionalityimplementedlibcP.I.P.S.
(UIQ and S60)47libmP.I.P.S. (UIQ and S60)42libpthreadP.I.P.S. (UIQ and S60)60libdlP.I.P.S. (UIQ and S60)100libzOpen C (S60 only)100libsslOpen C (S60 only)86libcryptOpen C (S60 only)100libcryptoOpen C (S60 only)77libglibOpen C (S60 only)77Since many functions in the standard C libraries are rarely used inpractice, not all of them have been included in the Open C versionsin the interests of keeping memory footprints as small as possible.Table 7.1 shows the relative coverage as well as showing the fiveextra libraries that differentiate Open C from P.I.P.S. These includelibraries for compression (libz), SSL and TLS (libssl), cryptography (libcrypt and libcrypto), and the general purpose utilitylibrary libglib, which provides string and file utilities, data types,and macros.Restrictions on intellectual property rights prevented the implementation of some cryptographic algorithms (such as Blowfish, MD4 etc.), and,since there is no parent-child relationship in process spawning, some ofthe APIs in libglib are not supported.Since Symbian smartphones to date haven’t had floating point processors, floating point operations have been emulated in software andconsequently floating point exceptions are not supported in Open C(although now there are several Nokia devices – including the NokiaN82, N93 and N95 – that do have floating point co-processors).As with P.I.P.S., library symbolic lookup is not supported becauseunder Symbian OS, DLL entry points are exported by ordinal only.
We’vealready seen how to deal with this when using the dlsym function fromlibdl, and the analogous case holds when you use g_module_symbolfrom libglib:222 C/C++ STANDARDS SUPPORT FOR GAMES DEVELOPERS ON SYMBIAN OS// instead ofret = g_module_symbol(module, "LaunchDrone",&ptr);// where LaunchDrone() has ordinal 22, useret = g_module_symbol(module, "22",&ptr);This is only necessary with the Open C SDK plug-in since Symbian OSv9.3 has added new target types (STDDLL and STDEXE), which introducesymbolic lookup support. This will be included in the release of the S603rd Edition SDK that is based on Symbian OS v9.3.It will also add other features such as automatically including theOpen C libraries during compilation, linking in euser.lib and defaultingthe contents of the MMP file so that you don’t have to specify the start uplibrary.