?? clocationexamplepositionrequestor.cpp
字號:
/*
* ============================================================================
* Name : clocationexamplepositionrequestor.cpp
* Part of : Location Example
* Created : 21.05.2007 by Forum Nokia
* Description:
* Version : 1.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include <Lbs.h>
#include <eikenv.h>
#include <locationexample.rsg>
#include "clocationexamplepositionrequestor.h"
#include "clocationexamplepositionlistener.h"
// CONSTANTS
const TInt KSecond = 1000000;
const TInt KMaxAge = KSecond;
const TInt KErrBuffer = 100;
//The name of the requestor
_LIT(KRequestor,"LocationExample");
//Error messages
_LIT(KLbsErrLocRequest, "Locatin req Error: %d.");
_LIT(KLbsErrAccess, "No Location access Error: %d.");
_LIT(KLbsErrPosServConn, "Location Server Error: %d.");
_LIT(KLbsErrOpenPos, "Location Server Error: %d.");
_LIT(KLbsErrSetRequestor, "Location req Error: %d.");
_LIT(KLbsErrSetUpOpt, "Location update Error: %d.");
_LIT(KLbsErrCanceled, "Location Cancelled.");
// -----------------------------------------------------------------------------
// CLocationExamplePositionRequestor::CLocationExamplePositionRequestor
// C++ default constructor can NOT contain any code, that
// might leave.
// -----------------------------------------------------------------------------
//
CLocationExamplePositionRequestor::CLocationExamplePositionRequestor(TInt aInterval, MPositionObserver& aPositionListener )
: CActive(CActive::EPriorityStandard),
iInterval(aInterval),
iPositionListener( aPositionListener ),
iPosInfoBase( &iPositionInfo ),
iGettingLastknownPosition( ETrue )
{
}
// -----------------------------------------------------------------------------
// CLocationExamplePositionRequestor::ConstructL
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CLocationExamplePositionRequestor::ConstructL()
{
// Set update interval to one second to receive one position data per second
iUpdateops.SetUpdateInterval(TTimeIntervalMicroSeconds(iInterval));
// If position server could not get position
// In two minutes it will terminate the position request
iUpdateops.SetUpdateTimeOut(TTimeIntervalMicroSeconds(iUpdateTimeout));
// Positions which have time stamp below KMaxAge can be reused
iUpdateops.SetMaxUpdateAge(TTimeIntervalMicroSeconds(KMaxAge));
// Enables location framework to send partial position data
iUpdateops.SetAcceptPartialUpdates(ETrue);
// Add this position requestor to the active scheduler
CActiveScheduler::Add( this );
// Initialise the position request sequence
DoInitialiseL();
}
// -----------------------------------------------------------------------------
// CLocationExamplePositionRequestor::NewL
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CLocationExamplePositionRequestor* CLocationExamplePositionRequestor::NewL(TInt aInterval,
MPositionObserver& aPositionListener )
{
//Create the object
CLocationExamplePositionRequestor* self = new( ELeave ) CLocationExamplePositionRequestor(
aInterval, aPositionListener);
//Push to the cleanup stack
CleanupStack::PushL( self );
//Construct the object
self->ConstructL();
//Remove from cleanup stack
CleanupStack::Pop( self );
//Return pointer to the created object
return self;
}
// -----------------------------------------------------------------------------
// CLocationExamplePositionRequestor::~CLocationExamplePositionRequestor
// Destructor
// -----------------------------------------------------------------------------
//
CLocationExamplePositionRequestor::~CLocationExamplePositionRequestor()
{
// Cancel active object
Cancel();
// Close the positioner
iPositioner.Close();
// Close the session to the position server
iPosServer.Close();
}
// -----------------------------------------------------------------------------
// DoCancel() implements CActive DoCancel()
// Implements the cancellation of an outstanding request.
// -----------------------------------------------------------------------------
//
void CLocationExamplePositionRequestor::DoCancel()
{
// When a client application wishes to close one of its connections to Location
// Server, there can be no outstanding requests on that particular connection
// If a client application attempts to close a connection before outstanding
// requests have been cancelled or completed, it is panicked
//If we are getting the last known position
if ( iGettingLastknownPosition )
{
//Cancel the last known position request
iPositioner.CancelRequest(EPositionerGetLastKnownPosition);
}
else
{
iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);
}
}
// -----------------------------------------------------------------------------
// RunL() implements CActive RunL()
// Handles an active object抯 request completion event.
// -----------------------------------------------------------------------------
//
void CLocationExamplePositionRequestor::RunL()
{
TBuf<KPositionMaxModuleName> buffer;
switch ( iStatus.Int() )
{
// The fix is valid
case KErrNone:
// The fix has only partially valid information.
// It is guaranteed to only have a valid timestamp
case KPositionPartialUpdate:
{
// Pre process the position information
PositionUpdatedL();
break;
}
// The data class used was not supported
case KErrArgument:
{
// Set info base to position info
iPosInfoBase = &iPositionInfo;
// Request next position
iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus );
// Set this object active
SetActive();
break;
}
// The position data could not be delivered
case KPositionQualityLoss:
{
// Send event to position listener
HBufC* text = CEikonEnv::Static()->AllocReadResourceAsDes16LC(R_POSITION_QUALITY_ERROR_TEXT);
iPositionListener.ErrorL(*text);
CleanupStack::PopAndDestroy(text);
if ( iGettingLastknownPosition )
{
//Change the data class type
iPosInfoBase = &iSatelliteInfo;
}
// Request position
iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus );
// Set this object active
SetActive();
break;
}
// Access is denied
case KErrAccessDenied:
{
// Send error to position listener
buffer.Format(KLbsErrAccess, iStatus.Int());
iPositionListener.ErrorL(buffer);
break;
}
// Request timed out
case KErrTimedOut:
{
// Send error to position listener
HBufC* text = CEikonEnv::Static()->AllocReadResourceAsDes16LC(R_POSITION_TIMEOUT_TEXT);
iPositionListener.ErrorL(*text);
CleanupStack::PopAndDestroy(text);
if ( iGettingLastknownPosition )
{
//Change the data class type
iPosInfoBase = &iSatelliteInfo;
}
// Request position
iPositioner.NotifyPositionUpdate( *iPosInfoBase, iStatus );
// Set this object active
SetActive();
break;
}
// The request was canceled
case KErrCancel:
{
// Send error to position listener
iPositionListener.ErrorL( KLbsErrCanceled );
break;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -