quick_recipes (779892), страница 57
Текст из файла (страница 57)
Since allsuch classes should inherit from TPositionInfo, the client gets theextended information simultaneously with the general data in one request.However, you have to be careful and verify that the current modulesupports the particular position information class before issuing a request,otherwise it will fail.As the code snippet is much the same as for the previous recipe, letus just mention here how to ensure that the given positioning modulesupports the required capabilities. You can verify the data from thepositioning module information or apply appropriate selection criteriawhen you open the subsession to RPositioner. The latter case isillustrated below:#include <lbs.h>void SetCriteriaL(TPositionCriteria& aCriteria){// Set required capabilities for satellite and course info...aCriteria.AddRequiredCapabilities(TPositionModuleInfo:: ECapabilitySatellite |TPositionModuleInfo:: ECapabilitySpeed |TPositionModuleInfo:: ECapabilityDirection);// Later on you can use RPositioner::Open(server, criteria)// to allow selecting suitable module}When the NotifyPositionUpdate() request is completed successfully, the position information structure is filled in by requestedLOCATION-BASED SERVICES317information.
For example, if the TPositionSatelliteInfo objectwas passed to the request, you can enumerate available satellites andrequest the TSatelliteData object by calling the GetSatelliteData() method:void SatelliteInfoL(){TPositionSatelliteInfo satInfo;...// Assume that the location info request was issued// and completed successfully...// Now we can iterate through all detected satellites and// get some additional infoTInt numSatellites = satInfo.NumSatellitesInView();TInt err = KErrNone;for (int i = 0; i < numSatellites; i++){// Get the satellite dataTSatelliteData satData;err = satInfo.GetSatelliteData(i,satData);if ( err != KErrNone ){continue;}// Get some infoTReal32 azimuth = satData.Azimuth();TInt satSignalStrength = satData.SignalStrength();}// Now get the course infoTCourse course;satInfo.GetCourse(course);TReal32 heading = course.Heading();TReal32 speed = course.Speed();}The location acquisition API can be extended by defining new positioning data classes by deriving new classes from TPositionInfoBaseor any of its descendants, such as the HPositionGenericInfo classfound in S60.
This has to be supported by an appropriate positioningmodule.5Next Level DevelopmentThis chapter gives you a glimpse of some advanced features of SymbianOS. If you want to take full advantage of these features, you will probablyneed to use some additional resources, such as the Symbian DeveloperLibrary, Symbian Press books or technical papers available on SymbianC++ developer community websites.5.1 Advanced Technologies5.1.1 Publish and Subscribe: System-wide PropertiesYou can find a full introduction to the Publish and Subscribe API atdeveloper.symbian.com/main/downloads/papers/publishandsubscribe/PublishAndSubscribe v1.0.pdf.The Publish and Subscribe API in Symbian OS is basically a kernelside hashtable that can only contain one value per key.
The key of thehashtable should be a UID that you allocated. The value of the hashtableis a TInt or a TDesC (binary data or text, limited to 512 bytes).Your code accesses the hashtable through the RProperty class. TheAPI is fairly basic: add/remove key, get/set value. You can also receivenotification if a value changes using RProperty::Subscribe(),which is an asynchronous request. Only one such request is allowedper RProperty instance at any given time.Each property belongs to a category, identified by yet another UID.The category UID defaults to the secure identifier of the current process.It can be useful to you as a developer to have a look at all the propertiesin the KUidSystemCategoryValue category.The main issue with the system category is to find all the propertykeys that belong to it.
They are scattered across many technologies,like Bluetooth, Backup and Restore and the Software Installer. Looking320NEXT LEVEL DEVELOPMENTfor KUidXyzPropertyKey or KPropertyKeyXyz in . . . \epoc32\include\ is a good first step. When looking into the documentation fora specific technology, be on the lookout for public property keys, andsearch the developer forums.Read and write access to properties is controlled through securitypolicies based on the secure ID for the process, the application’s VendorID and platform security capabilities, using the TSecurityPolicy class.For other data-sharing mechanisms used on Symbian OS, such as messagequeues, the central repository or DBMS, you should also consult the DataSharing Tips booklet published at developer.symbian.com/booklets.5.1.2 Creating a Server Process: File SharingMost developers know that not all executables need a graphical userinterface (GUI).
In Symbian OS, you can develop a program designed torun in the background, with no GUI and accessible by other applicationsvia Inter Process Communication (IPC). You have had occasion to useseveral such server processes already: the window server, the font andbitmap server and the file server, to name a few.If all you want to do is monitor the state of another process, you canuse the RProcess class.
It allows you to launch a new process, react toa process terminating or rendezvous with another process. What is moreuseful is to be able to create your own server process so that several otherapplications can use it at the same time.The example we have chosen to demonstrate is very important becauseof the data caging feature of platform security in Symbian OS. You willfind that you may want some files that are private to your server process tobe shared only with the applications using this server process. Developingyour own simple file server is a common solution to this problem.The source code for this example is in \Advanced\FileSharingServer and \Advanced\FileSharingClient.The following RFile member methods support file handle sharingbetween processes:• RFile::TransferToClient()• RFile::AdoptFromClient()• RFile::TransferToServer()• RFile::AdoptFromServer()• RFile::TransferToProcess()• RFile::AdoptFromCreator().The TranferToXyz() methods are used to transfer the file handleto another process, which includes another server or client.
The AdoptADVANCED TECHNOLOGIES321FromXyz() methods are used to read the file handle that is shared byanother process.The example shows how to transfer a handle that allow access to atext file, from the data cage of the process that owns it, FileSharingServer.exe, to another process, FileSharingClient.exe.The main classes that are always used when implementing a serverare CServer2, CSession2, RMessage2, TSecurityPolicy andCPolicyServer on the server side and RSessionBase and TIpcArgson the client side.
In most cases, it is useful to define a subclass ofRSubSessionBase.You should definitely have a look at the IPC examples in your SDK andconsult the transient server example template code available from theSymbian Developer Network (developer.symbian.com/main/oslibrary/cpp papers/advanced.jsp).Since we are talking about starting an active scheduler from scratch inyour own process, you cannot use the Symbian OS application frameworkand you will instead need to start with an E32Main() method. Create aCActiveScheduler, install it, create your CServer2 object, add it tothe active scheduler, start it, then start the active scheduler. The examplecode illustrates how to do this.RMessage2 encapsulates a single IPC request.
IPC requests can be synchronous, but the asynchronous version is usually preferred. TIpcArgsis used to create and populate the IPC request. An IPC request is triggeredfrom the client side by a call to RSessionBase::SendReceive().Since TIpcArgs can only contain integers, you will need to use pointers when sending buffers across processes. The RMessage2::ReadL()methods allow you to make a server-side copy of client-side descriptors.The RMessage2::WriteL() methods allow you to send data back tothe client process.The important thing to realize about CServer2 is that it is actuallyan active object. The main particularity is that you should not overwriteits RunL(), DoCancel() or RunError() methods, but instead defineyour own CSession2::ServiceL() method where the IPC requestwill be processed.When the server-side processing is complete, the server needs tonotify the client side with RMessage2::Complete(), which has asimilar effect as User::RequestComplete() but over IPC.Error handling and multi-threading inside your own process can helpyou restart the server, but you need to realize that a system panic will befatal.5.1.3 Advanced Platform-Specific User InterfaceBoth the S60 and UIQ platforms have their own set of publicly availablecontrols that can be used in the GUI of your application.322NEXT LEVEL DEVELOPMENTS60 3rd Edition• On S60 3rd Edition, you can access full-featured GUI controls anddialogs for the contact application using all the CPbkXyz, TPbkXyzand MPbkXyz classes.
We recommend particularly CPbkContactEditorDlg and the subclasses of CPbkAddressSelect, as those arethe ones you are most likely to want to use.• You can make the handset vibrate using the CHWRMVibra class.• You can give the user access to the handset time and date usingCClkDateTimeView.• You can embed the view of a remote web page using CBrCtlInterface.• You can modify the way predictive input works in your text fields byusing the Predictive Input Engine API: CPtiEngine.• You can lock the phone’s keypad with RAknKeyLock.• You can let the user manipulate files using AknCommonDialogs.We recommend that you read all the S60 Platform Avkon UI Resourcesdocuments that you will find on the Forum Nokia website at www.forum.nokia.com.UIQ 3The application management in UIQ 3 is fairly unusual and that has animpact on user interface development.If the ‘back’ command is going to work properly, the system has tonot only consider applications but also each of these applications’ singleview separately.
The framework that allows view-based GUI switches iscalled Dynamic Navigation Links (DNL).There is a very nice side-effect to this. When a third-party applicationimplements a self-contained functionality in a single view and makesthat view available to DNL (like most applications preloaded on yourhandset), you can use it from your own code – very much like a simplemethod call – and benefit from the functionality, including its full-fledgedGUI. CCoeAppUi::ActivateViewL() is the main method used forDNL.With DNL, letting the user look at his scheduled meetings is simplicityitself thanks to the TAgnDnlXyz classes, manipulating contacts caneasily be achieved thanks to the TCntDnlXyz classes and messagingfunctionality comes from the TQMappDnlXyz classes.The UIQ platform also provides you with simple controls and dialogsthat you can reuse: CQBTUISelectDialog lets the user select BluetoothADVANCED TECHNOLOGIES323devices, CQikCameraCaptureDlg allows the user to take a picture andCContactUiFindDialog is pretty self-explanatory by now.You can let the user select a date with CEikCalendar but youwill probably prefer CQikDateEditor.