S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CLandmarksPositionRequest Class Reference

#include <LandmarksPositionRequest.h>

List of all members.

Public Member Functions

 ~CLandmarksPositionRequest ()
void FetchPositionInfoL (const TDesC &aMessage, TPositionInfo &aPositionInfo)
void DismissWaitNote ()
void DialogDismissedL (TInt aButtonId)
 Inherited from MProgressDialogCallback.

Static Public Member Functions

static CLandmarksPositionRequest * NewL (const TDesC &aAppName, MLandmarksOperationObserver *aObserver)

Protected Member Functions

void DoCancel ()
void RunL ()
TInt RunError (TInt aError)

Private Types

enum  TState { EIdle, EAcquiringDefaultLocation, EAcquiringLastKnownLocation, EDismissingDialog }

Private Member Functions

 CLandmarksPositionRequest (MLandmarksOperationObserver *aObserver)
void ConstructL (const TDesC &aAppName)
void ExecuteNextStep ()
void NotifyOperationCompleteL (TInt aError)
void InitializeL ()
void ShowErrorL (TInt aError)

Private Attributes

TPositionInfo * iPositionInfo
 Contains the location.
MLandmarksOperationObserver * iObserver
 The observer to callback when location retieval is ready.
RPositionServer iLocationServer
 Reference to the Location Server session.
RPositioner iPositioner
 Reference to the Location Server subsession.
TState iState
 The current state this object has entered.
CAknWaitDialog * iWaitNote
 The progress bar displayed when active.
HBufC * iAppName
 The name of this application.


Detailed Description

Provides an interface for retrieving the current location. It also manages a floating progress ball for indicating the progress of the location retrieval.

Definition at line 35 of file LandmarksPositionRequest.h.


Member Enumeration Documentation

enum CLandmarksPositionRequest::TState [private]
 

TState defines the different states this object may enter.

Definition at line 141 of file LandmarksPositionRequest.h.

00142             {
00143             EIdle,
00144             EAcquiringDefaultLocation,
00145             EAcquiringLastKnownLocation,
00146             EDismissingDialog
00147             };


Constructor & Destructor Documentation

CLandmarksPositionRequest::~CLandmarksPositionRequest (   ) 
 

Destructor.

Definition at line 75 of file LandmarksPositionRequest.cpp.

References DismissWaitNote(), iAppName, iLocationServer, and iPositioner.

00076     {
00077     Cancel();
00078     iPositioner.Close();
00079     iLocationServer.Close();
00080     DismissWaitNote();
00081     delete iAppName;
00082     }

CLandmarksPositionRequest::CLandmarksPositionRequest (  MLandmarksOperationObserver *  aObserver  )  [private]
 

C++ constructor.

Parameters:
aObserver observer to callback when locations are retrieved

Definition at line 36 of file LandmarksPositionRequest.cpp.

00038     : 
00039     CActive(CActive::EPriorityStandard), 
00040     iObserver(aObserver),
00041     iState(EIdle)
00042     {
00043     CActiveScheduler::Add(this);
00044     }


Member Function Documentation

CLandmarksPositionRequest * CLandmarksPositionRequest::NewL (  const TDesC &  aAppName,
MLandmarksOperationObserver *  aObserver
)  [static]
 

Two-phased constructor.

Parameters:
aAppName the name of this application
aObserver observer to callback when locations are retrieved

Definition at line 62 of file LandmarksPositionRequest.cpp.

References CLandmarksPositionRequest().

00065     {
00066     CLandmarksPositionRequest* self =
00067         new (ELeave) CLandmarksPositionRequest(aObserver);
00068     CleanupStack::PushL(self);
00069     self->ConstructL(aAppName);
00070     CleanupStack::Pop(self);
00071     return self;
00072     }

void CLandmarksPositionRequest::FetchPositionInfoL (  const TDesC &  aMessage,
TPositionInfo &  aPositionInfo
) 
 

Starts the fetching of a location. In the first place the default proxy is used for retrieving a location. If fetching default location fails the last known location is fetched. If fetching last known location fails, an error code is returned to the observer.

Parameters:
aMessage the message to present in the progress dialog.
aPositionInfo contains the fetched location

Definition at line 90 of file LandmarksPositionRequest.cpp.

References ExecuteNextStep(), iPositionInfo, iState, and iWaitNote.

00093     {
00094     Cancel();
00095     iPositionInfo = &aPositionInfo;
00096 
00097     // Initialize wait note
00098     CAknWaitDialog* waitNote = new (ELeave) CAknWaitDialog(
00099         reinterpret_cast <CEikDialog**> (&iWaitNote), ETrue); // show immedaitely
00100     CleanupStack::PushL(waitNote);
00101     waitNote->SetCallback(this);
00102     waitNote->SetTextL(aMessage);
00103     waitNote->PrepareLC(R_LMREFAPP_ACQUIRE_LOCATION_WAIT_NOTE);
00104     CleanupStack::Pop(waitNote); // waitNote will delete itself
00105     iWaitNote = waitNote;
00106 
00107     // Request location
00108     iState = EAcquiringDefaultLocation;
00109     ExecuteNextStep();
00110 
00111     // Launch wait note
00112     iWaitNote->RunLD();
00113     }

void CLandmarksPositionRequest::DismissWaitNote (   ) 
 

Dismisses the wait note.

Definition at line 121 of file LandmarksPositionRequest.cpp.

References iWaitNote.

00122     {
00123     if (iWaitNote)
00124         {
00125         TInt err;
00126         TRAP(err, iWaitNote->ProcessFinishedL());
00127         iWaitNote = NULL;
00128         }
00129     }

void CLandmarksPositionRequest::DoCancel (   )  [protected]
 

Implements cancellation of an outstanding request.

Definition at line 137 of file LandmarksPositionRequest.cpp.

References DismissWaitNote(), iPositioner, and iState.

00138     {
00139     // Cancel location request
00140     if (iState == EAcquiringDefaultLocation)
00141         {
00142         iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);
00143         }
00144     else if (iState == EAcquiringLastKnownLocation)
00145         {
00146         iPositioner.CancelRequest(EPositionerGetLastKnownPosition);
00147         }
00148     iState = EIdle;
00149     DismissWaitNote();
00150     }

void CLandmarksPositionRequest::RunL (   )  [protected]
 

Handles an active object’s request completion event.

Definition at line 158 of file LandmarksPositionRequest.cpp.

References ExecuteNextStep(), iState, and NotifyOperationCompleteL().

00159     {
00160     if (iStatus == KErrNone)
00161         {
00162         // Location retrieved. Operation finished.
00163         NotifyOperationCompleteL(KErrNone);
00164         }
00165     else // iStatus != KErrNone
00166         {
00167         if (iState == EAcquiringDefaultLocation)
00168             {
00169             // Fetching current location failed. Try last known location.
00170             iState = EAcquiringLastKnownLocation;
00171             ExecuteNextStep();
00172             }
00173         else if (iState == EAcquiringLastKnownLocation)
00174             {
00175             // Fetching last known location failed. 
00176             NotifyOperationCompleteL(iStatus.Int());
00177             }
00178         }
00179     }

TInt CLandmarksPositionRequest::RunError (  TInt  aError  )  [protected]
 

Handles a leave occurring in the request completion event handler RunL().

Returns:
KErrNone

Definition at line 187 of file LandmarksPositionRequest.cpp.

00188     {
00189     // Ignore possible errors.
00190     return KErrNone;
00191     }

void CLandmarksPositionRequest::ConstructL (  const TDesC &  aAppName  )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 51 of file LandmarksPositionRequest.cpp.

References iAppName, and InitializeL().

00052     {
00053     iAppName = aAppName.AllocL();
00054     InitializeL();
00055     }

void CLandmarksPositionRequest::ExecuteNextStep (   )  [private]
 

Executes the next step of the location retrieval.

Definition at line 233 of file LandmarksPositionRequest.cpp.

References iPositioner, iPositionInfo, iState, and LandmarksUtils::Panic().

00234     {
00235     iStatus = KRequestPending;
00236 
00237     switch (iState)
00238         {
00239         case EAcquiringDefaultLocation:
00240             iPositioner.NotifyPositionUpdate(*iPositionInfo, iStatus);
00241             break;
00242         case EAcquiringLastKnownLocation:
00243             iPositioner.GetLastKnownPosition(*iPositionInfo, iStatus);
00244             break;
00245         default:    
00246             // this case should never happen, see RunL
00247             LandmarksUtils::Panic(KErrGeneral);
00248             break;
00249         }
00250 
00251     SetActive();
00252     }

void CLandmarksPositionRequest::NotifyOperationCompleteL (  TInt  aError  )  [private]
 

Notifies the observer that the location retrieval is complete.

Parameters:
aError the status of the location retrieval

Definition at line 260 of file LandmarksPositionRequest.cpp.

References DismissWaitNote(), iObserver, iState, MLandmarksOperationObserver::NotifyOperationProgressL(), and ShowErrorL().

00261     {
00262     DismissWaitNote();
00263     iState = EIdle;
00264 
00265     // Notify user if location couldn't be fetched.
00266     if (aError) 
00267         {
00268         ShowErrorL(aError);
00269         }
00270 
00271     // Notify Observer
00272     iObserver->NotifyOperationProgressL(
00273         EAcquiringLocation, KOperationReady, aError);
00274     }

void CLandmarksPositionRequest::InitializeL (   )  [private]
 

Initializes the class to be ready for location acquisition.

Definition at line 282 of file LandmarksPositionRequest.cpp.

References iAppName, iLocationServer, and iPositioner.

00283     {
00284     // Connect to the location server
00285     User::LeaveIfError(iLocationServer.Connect());
00286 
00287     // Open the default positioner
00288     User::LeaveIfError(iPositioner.Open(iLocationServer));
00289 
00290     // Set this application as location requestor
00291     User::LeaveIfError(iPositioner.SetRequestor(
00292         CRequestor::ERequestorService,
00293         CRequestor::EFormatApplication,
00294         *iAppName));
00295 
00296     // Set maximum allowed time for a location request
00297     const TInt K30Seconds = 30000000;
00298     TTimeIntervalMicroSeconds timeOut(K30Seconds);
00299     TPositionUpdateOptions updateOptions;
00300     updateOptions.SetUpdateTimeOut(timeOut);
00301     User::LeaveIfError(iPositioner.SetUpdateOptions(updateOptions));
00302     }

void CLandmarksPositionRequest::ShowErrorL (  TInt  aError  )  [private]
 

Informs user about location request failure.

Definition at line 210 of file LandmarksPositionRequest.cpp.

00211     {
00212     HBufC* format = CCoeEnv::Static()->AllocReadResourceAsDes16LC(
00213         R_LMREFAPP_ACQUIRING_LOC_ERROR);
00214     
00215     // some extra characters needed for error code
00216     const TInt KErrorCodeTextLength = 10;
00217     HBufC* message = HBufC::NewLC(
00218         format->Length() + KErrorCodeTextLength);
00219     message->Des().Format(*format, aError);
00220 
00221     CAknInformationNote* informationNote = 
00222         new (ELeave) CAknInformationNote(ETrue);
00223     informationNote->ExecuteLD(*message);
00224     CleanupStack::PopAndDestroy(2, format);
00225     }


© Nokia 2006

Back to top