S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CLbsPositionRequestor Class Reference

#include <LBSPositionRequestor.h>

List of all members.

Public Member Functions

virtual ~CLbsPositionRequestor ()

Static Public Member Functions

static CLbsPositionRequestor * NewL (MLbsPositionListener &aPositionListener)

Protected Member Functions

void DoCancel ()
void RunL ()

Private Member Functions

void ConstructL ()
 CLbsPositionRequestor (MLbsPositionListener &aPositionListener)
void DoInitialiseL ()
void GetModuleName (const TPositionModuleId &aModuleId)
void PositionUpdatedL ()

Private Attributes

TPositionModuleId iUsedPsy
RPositionServer iPosServer
RPositioner iPositioner
TPositionInfo iPositionInfo
TPositionSatelliteInfo iSatelliteInfo
MLbsPositionListener & iPositionListener
TBuf< KPositionMaxModuleName > iModuleName
TPositionUpdateOptions iUpdateops
TPositionInfoBase * iPosInfoBase
TBool iGettingLastknownPosition


Detailed Description

Position requestor. Request the position from the Location FW and handles the position requesting process

Definition at line 33 of file LBSPositionRequestor.h.


Constructor & Destructor Documentation

CLbsPositionRequestor::~CLbsPositionRequestor (   )  [virtual]
 

Destructor.

Definition at line 127 of file LBSPositionRequestor.cpp.

References iPositioner, and iPosServer.

00128     {
00129     // Cancel active object
00130     Cancel();
00131 
00132     // Close the positioner
00133     iPositioner.Close();
00134 
00135     // Close the session to the position server
00136     iPosServer.Close();
00137     }

CLbsPositionRequestor::CLbsPositionRequestor (  MLbsPositionListener &  aPositionListener  )  [private]
 

C++ default constructor.

Parameters:
aPositionListener Position listener to be registered

Definition at line 63 of file LBSPositionRequestor.cpp.

References iUpdateops.

00064     : CActive(CActive::EPriorityStandard),
00065     iPositionListener( aPositionListener ),
00066     iPosInfoBase( &iPositionInfo ),
00067     iGettingLastknownPosition( ETrue )
00068     {
00069     // Set update interval to one second to receive one position data per second
00070     iUpdateops.SetUpdateInterval(TTimeIntervalMicroSeconds(KUpdateInterval));
00071 
00072     // If position server could not get position
00073     // In two minutes it will terminate the position request
00074     iUpdateops.SetUpdateTimeOut(TTimeIntervalMicroSeconds(KUpdateTimeOut));
00075 
00076     // Positions which have time stamp below KMaxAge can be reused
00077     iUpdateops.SetMaxUpdateAge(TTimeIntervalMicroSeconds(KMaxAge));
00078 
00079     // Enables location framework to send partial position data
00080     iUpdateops.SetAcceptPartialUpdates(ETrue);
00081 
00082     // Add this position requestor to the active scheduler
00083     CActiveScheduler::Add( this );
00084     }


Member Function Documentation

CLbsPositionRequestor * CLbsPositionRequestor::NewL (  MLbsPositionListener &  aPositionListener  )  [static]
 

Creates a new instance of a CLbsPositionRequestor

Parameters:
aPositionListener Position listener to be registered
Returns:
The newly created CLbsPositionRequestor object

Definition at line 102 of file LBSPositionRequestor.cpp.

References CLbsPositionRequestor().

00104     {
00105     //Create the object
00106     CLbsPositionRequestor* self = new( ELeave ) CLbsPositionRequestor(
00107         aPositionListener);
00108 
00109     //Push to the cleanup stack
00110     CleanupStack::PushL( self );
00111 
00112     //Construct the object
00113     self->ConstructL();
00114 
00115     //Remove from cleanup stack
00116     CleanupStack::Pop( self );
00117 
00118     //Return pointer to the created object
00119     return self;
00120     }

void CLbsPositionRequestor::ConstructL (   )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 91 of file LBSPositionRequestor.cpp.

References DoInitialiseL().

00092     {
00093     // Initialise the position request sequence
00094     DoInitialiseL();
00095     }

void CLbsPositionRequestor::DoInitialiseL (   )  [private]
 

Starts a position requesting sequence

Definition at line 299 of file LBSPositionRequestor.cpp.

References iPosInfoBase, iPositioner, iPositionListener, iPosServer, iUpdateops, and MLbsPositionListener::ShowErrorL().

00300     {
00301     // Connect to the position server
00302     TInt error = iPosServer.Connect( );
00303     TBuf<100> buffer;
00304     
00305     // The connection failed
00306     if ( KErrNone != error )
00307         {
00308         // Show error to the user and leave
00309         buffer.Format(KLbsErrPosServConn, error);
00310         iPositionListener.ShowErrorL( buffer );
00311         return;
00312         }
00313 
00314     // Open subsession to the position server
00315     error = iPositioner.Open(iPosServer);
00316 
00317     // The opening of a subsession failed
00318     if ( KErrNone != error )
00319         {
00320         // Show error to the user and leave
00321         buffer.Format(KLbsErrOpenPos, error);
00322         iPositionListener.ShowErrorL( buffer );
00323         iPosServer.Close();
00324         return;
00325         }
00326 
00327     // Set position requestor
00328     error = iPositioner.SetRequestor( CRequestor::ERequestorService ,
00329          CRequestor::EFormatApplication , KRequestor );
00330 
00331     // The requestor could not be set
00332     if ( KErrNone != error )
00333         {
00334         // Show error to the user and leave
00335 
00336         buffer.Format(KLbsErrSetRequestor, error);
00337         iPositionListener.ShowErrorL( buffer );
00338         iPositioner.Close();
00339         iPosServer.Close();
00340         return;
00341         }
00342 
00343     // Set update options
00344     error =  iPositioner.SetUpdateOptions( iUpdateops );
00345 
00346     // The options could not be updated
00347     if ( KErrNone != error  )
00348         {
00349         // Show error to the user and leave
00350         buffer.Format(KLbsErrSetUpOpt, error);
00351         iPositionListener.ShowErrorL( buffer );
00352         iPositioner.Close();
00353         iPosServer.Close();
00354         return;
00355         }
00356 
00357     // Get last known position. The processing of the result
00358     // is done in RunL method
00359     iPositioner.GetLastKnownPosition(*iPosInfoBase,iStatus);
00360 
00361     // Set this active object active
00362     SetActive();
00363     }

void CLbsPositionRequestor::GetModuleName (  const TPositionModuleId &  aModuleId  )  [private]
 

Gets the name of the positioning module. If the name is not available the name will be an empty string

Parameters:
aModuleId The id of the module

Definition at line 370 of file LBSPositionRequestor.cpp.

References iModuleName, and iPosServer.

00371     {
00372     // Module information of the position module
00373     TPositionModuleInfo modInfo;
00374 
00375     // Get module info by module id
00376     TInt error = iPosServer.GetModuleInfoById( *&aModuleId, modInfo );
00377 
00378     // If error occured
00379     if ( KErrNone != error )
00380         {
00381         // Set the name of the module to 'Unknown'
00382         iModuleName = KUnknown;
00383         }
00384     else
00385         {
00386         // Get the name of the position module
00387         modInfo.GetModuleName(iModuleName);
00388         }
00389     }

void CLbsPositionRequestor::PositionUpdatedL (   )  [private]
 

Preprocess the position information

Definition at line 397 of file LBSPositionRequestor.cpp.

References GetModuleName(), iGettingLastknownPosition, iModuleName, iPosInfoBase, iPositioner, iPositionInfo, iPositionListener, iPosServer, iSatelliteInfo, iUsedPsy, and MLbsPositionListener::PositionInfoUpdatedL().

00398     {
00399     //If we are getting the last known position
00400     if ( iGettingLastknownPosition )
00401         {
00402         // Set the module name to 'Unknown' because last
00403         // known position has no module name
00404         iModuleName = KUnknown;
00405 
00406         // Send position information to registered listener
00407         iPositionListener.PositionInfoUpdatedL(*iPosInfoBase,iModuleName);
00408 
00409         //Change the data class type
00410         iPosInfoBase = &iSatelliteInfo;
00411 
00412         // Request next position
00413         iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus );
00414 
00415         // Set this object active
00416         SetActive();
00417         }
00418     else
00419         {
00420         // Check if the id of the used PSY is 0
00421         if ( 0 == iUsedPsy.iUid)
00422             {
00423             // Set the id of the currently used PSY
00424             iUsedPsy = iPosInfoBase->ModuleId();
00425             }
00426         // Check if the position module has changed
00427         else if ( iPosInfoBase->ModuleId() != iUsedPsy )
00428             {
00429             // Set the id of the currently used PSY
00430             iUsedPsy = iPosInfoBase->ModuleId();
00431 
00432             //Position module info of new module
00433             TPositionModuleInfo moduleInfo;
00434 
00435             // Get module info
00436             iPosServer.GetModuleInfoById(iUsedPsy,moduleInfo);
00437 
00438             // Get classes supported
00439             TInt32 moduleInfoFamily = moduleInfo.ClassesSupported(EPositionInfoFamily);
00440 
00441             iPosInfoBase = &iSatelliteInfo;
00442 
00443             // Check if the new module supports
00444             // TPositionSatelliteInfo class
00445             if ( EPositionSatelliteInfoClass & moduleInfoFamily )
00446                 {
00447                 // Set info base to satellite info
00448                 iPosInfoBase = &iSatelliteInfo;
00449                 }
00450             // The position module must support atleast
00451             // TPositionInfo class
00452             else
00453                 {
00454                 // Set info base to position info
00455                 iPosInfoBase = &iPositionInfo;
00456                 }
00457             }
00458 
00459         // Process the position information
00460         // and request next position
00461 
00462         // Get module name
00463         GetModuleName(iUsedPsy);
00464 
00465         // Send position information to registered listener
00466         iPositionListener.PositionInfoUpdatedL(*iPosInfoBase,iModuleName);
00467 
00468         // Request next position
00469         iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus );
00470 
00471         // Set this object active
00472         SetActive();
00473         }
00474     }


© Nokia 2006

Back to top