Defining a Privacy Controller Observer Class

To write a Privacy Controller a licensee must define a Privacy Controller observer class derived from MLbsPrivacyObserver (or MLbsPrivacyObserver2 for a Privacy Controller that must be automatically shutdown by the LBS subsystem when all privacy requests have completed. This is required when the LBS subsystem is configured and built in the Standalone Privacy Mode configuration).

On startup the Privacy Controller must register itself with the LBS subsystem by calling CLbsPrivacyController::NewL(), passing a reference to its observer class as a parameter. This is explained in more detail in the code examples later in this document.

The code below shows an outline declaration of two Privacy Controller observer classes.

  • CMyLbsPrivacyControllerObserver implements MLbsPrivacyObserver.

  • CMyLbsPrivacyControllerObserver2 implements MLbsPrivacyObserver2 to receive a shutdown notification when the LBS subsystem is shutdown down in the Standalone Privacy Mode configuration.

Note: It is only necessary to create one observer class for the Privacy Controller and it is only necessary to derive from MLbsPrivacyObserver2 if the licensee Privacy Controller process lifecycle must be controlled by the LBS subsystem. This is only supported when the LBS subsystem is built in the Standalone Privacy Mode configuration.
/*
============================================================================
 Name		: MyLBSPrivacyController.h
 Description : Header file for example Privacy Controller
============================================================================
*/

#ifndef __MYLBSPRIVACYCONTROLLER_H__
#define __MYLBSPRIVACYCONTROLLER_H__


//  Include Files
#include <e32base.h>
#include <lbsloccommon.h>
#include <lbsprivacycontroller.h>

// Simple Privacy Controller class
class CMyLbsPrivacyControllerObserver : public CBase, MLbsPrivacyObserver
	{
	public:
		static CMyLbsPrivacyControllerObserver* NewL();
		~CMyLbsPrivacyControllerObserver();
	
	public:
		// From MLbsPrivacyObserver
		void ProcessNetworkLocationRequest(TUint aRequestId, const TLbsExternalRequestInfo& aRequestInfo,
                                     const TNotificationType& aNotifyType);
		void ProcessNetworkPositionUpdate(TUint aRequestId, const TPositionInfo& aPosInfo);
		void ProcessRequestComplete(TUint aRequestId, TInt aReason);
		
		// Functions to send privacy response or cancel a privacy request
		void SendResponse(TUint aRequestId, CLbsPrivacyController::TRequestVerificationResult aResult);
		void CancelRequest(TUint aRequestId);
		
	
	protected:
		CMyLbsPrivacyControllerObserver();
		void ConstructL();
		
	private:
		CLbsPrivacyController* iController;
	};


// Privacy Controller class that can receive shutdown notification from LBS Root
class CMyLbsPrivacyControllerObserver2 : public CMyLbsPrivacyControllerObserver, MLbsPrivacyObserver2
	{
	public:
		// From MLbsPrivacyObserver2
		void ProcessCloseDownNotification();
	};


#endif  // __MYLBSPRIVACYCONTROLLER_H__

Note that the observer class contains a member variable of class CLbsPrivacyController which is used to register the Privacy Controller with the LBS subsystem and to return privacy responses.

Registering the Privacy Controller with the LBS subsystem

The code below shows how a Privacy Controller can register itself with LBS in order to receive privacy requests. The ConstructL() method calls CLbsPrivacyController::NewL(), which registers the Privacy Controller with the LBS subsystem.

CMyLbsPrivacyControllerObserver* CMyLbsPrivacyControllerObserver::NewL()
	{
	CMyLbsPrivacyControllerObserver* self = new (ELeave) CMyLbsPrivacyControllerObserver();
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop();
	return self;
	}

// Register this observer class with the LBS subsystem
void CMyLbsPrivacyControllerObserver::ConstructL()
 {
 // Store a pointer to the LBS subsystem Privacy Controller handler
 // This is used by this observer to return privacy responses
 iController = CLbsPrivacyController::NewL(*this);
 }