landmarksui/engine/src/CLmkLocationService.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *     This file contains the methods which interface with Location Acquisition
       
    16 *     API for getting location information
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 // INCLUDE FILES
       
    27 
       
    28 #include <f32file.h>
       
    29 #include <sysutil.h>
       
    30 #include "LmkConsts.h"
       
    31 #include "MLmkLocationObserver.h"
       
    32 #include "CLmkLocationService.h"
       
    33 
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ==============================
       
    36 // ----------------------------------------------------------------------------
       
    37 // CLmkLocationService::CLmkLocationService
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CLmkLocationService::CLmkLocationService() : CActive(EPriorityStandard)
       
    43 	{
       
    44 	CActiveScheduler::Add( this );
       
    45 	}
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // CLmkLocationService::NewL
       
    49 // Two-phased constructor.
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C CLmkLocationService* CLmkLocationService::NewL(const TDesC& aSrvName)
       
    53 	{
       
    54 	CLmkLocationService* self = new ( ELeave ) CLmkLocationService;
       
    55 	CleanupStack::PushL( self );
       
    56 	self->ConstructL(aSrvName);
       
    57 	CleanupStack::Pop(); // self
       
    58 	return self;
       
    59 	}
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CLmkLocationService::ConstructL
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 void CLmkLocationService::ConstructL( const TDesC& aSrvName )
       
    66 	{
       
    67 	User::LeaveIfError(iServer.Connect());
       
    68 	User::LeaveIfError(iPositioner.Open( iServer ));
       
    69 
       
    70 	/*TPositionUpdateOptions updateOptions;
       
    71 	updateOptions.SetUpdateTimeOut( TTimeIntervalMicroSeconds(KLmkLRTimeOut));
       
    72 	User::LeaveIfError( iPositioner.SetUpdateOptions(updateOptions) );*/
       
    73 
       
    74 	User::LeaveIfError( iPositioner.SetRequestor(
       
    75 	                    CRequestor::ERequestorService,
       
    76 	                    CRequestor::EFormatApplication,
       
    77 	                    aSrvName ));
       
    78 	}
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CLmkLocationService::~CLmkLocationService
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CLmkLocationService::~CLmkLocationService()
       
    85 	{
       
    86 	Cancel();
       
    87 	iPositioner.Close();
       
    88 	iServer.Close();
       
    89 	}
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CLmkLocationService::SetObserver
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void CLmkLocationService::SetObserver(MLmkLocationObserver& aObserver)
       
    96 	{
       
    97 	iObserver = &aObserver;
       
    98 	}
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CLmkLocationService::RemoveModelObserver
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 EXPORT_C void CLmkLocationService::RemoveModelObserver()
       
   105     {
       
   106     iObserver = NULL;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CLmkLocationService::LocationRequestL
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 EXPORT_C void CLmkLocationService::LocationRequestL()
       
   114 	{
       
   115 	iPositioner.NotifyPositionUpdate( iPositionInfo, iStatus );
       
   116 	SetActive();
       
   117 	}
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CLmkLocationService::CurrentPosition
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 EXPORT_C TPosition& CLmkLocationService::CurrentPosition()
       
   124 	{
       
   125 	return iPosition;
       
   126 	}
       
   127 
       
   128 // ---------------------------------------------------------
       
   129 // CLmkLocationService::CancelRequest
       
   130 // ---------------------------------------------------------
       
   131 //
       
   132 EXPORT_C void CLmkLocationService::CancelRequest()
       
   133 	{
       
   134 	Cancel();
       
   135 	}
       
   136 
       
   137 // ---------------------------------------------------------
       
   138 // CLmkLocationService::RunL
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 void CLmkLocationService::RunL()
       
   142 	{
       
   143 	switch ( iStatus.Int() )
       
   144 		{
       
   145 		case KErrNone:
       
   146 		case KPositionPartialUpdate:
       
   147 			{
       
   148 			iPositionInfo.GetPosition( iPosition );
       
   149 			TReal32 altitude = iPosition.Altitude();
       
   150 			if (Math::IsNaN( altitude))
       
   151 				{
       
   152 				TRealX nan;
       
   153 				nan.SetNaN();
       
   154 				iPosition.SetVerticalAccuracy( nan );
       
   155 				}
       
   156 			iObserver->NotifyL( iStatus.Int() );
       
   157 			break;
       
   158 			}
       
   159 		case KErrAccessDenied:
       
   160 			{
       
   161 			User::Leave( KErrAccessDenied );
       
   162 			break;
       
   163 			}
       
   164 		case KPositionQualityLoss:
       
   165 		case KErrTimedOut:
       
   166 		case KErrNotFound: // No PSY selected.
       
   167 		case KErrUnknown:
       
   168 		case KErrCancel:
       
   169 		case KErrArgument:
       
   170 		default:
       
   171 			{
       
   172 			User::Leave( iStatus.Int() );
       
   173 			break;
       
   174 			}
       
   175 		}
       
   176 	}
       
   177 
       
   178 // ---------------------------------------------------------
       
   179 // CLmkLocationService::DoCancel
       
   180 // ---------------------------------------------------------
       
   181 //
       
   182 void CLmkLocationService::DoCancel()
       
   183     {
       
   184     iPositioner.CancelRequest( EPositionerNotifyPositionUpdate );
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------
       
   188 // CLmkLocationService::RunError
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 TInt CLmkLocationService::RunError(TInt aError)
       
   192     {
       
   193     if ( iObserver )
       
   194         {
       
   195         TRAPD( error, iObserver->NotifyErrorL( aError ) );
       
   196         if (error != KErrNone)
       
   197         {
       
   198         error = KErrNone;
       
   199         }
       
   200         }
       
   201     return KErrNone;
       
   202     }
       
   203 
       
   204 // End of File