datasourcemodules/gpspositioningmodule/lbsagpspsy/src/cagpsenvironment.cpp
changeset 0 9cfd9a3ee49c
child 48 81c9bee26a45
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @InternalComponent
       
    19 */
       
    20 
       
    21 #include "cagpsenvironment.h"
       
    22 #include "cpositionerq.h"
       
    23 #include "cagpsrequesthandler.h"
       
    24 #include "cagpsresponsehandler.h"
       
    25 #include "cagpsmodstatushandler.h"
       
    26 #include "lbsqualityprofile.h"
       
    27 #include "psylogging.h"
       
    28 #include "agpspsy.hrh"
       
    29 
       
    30 /**
       
    31  * Destructor
       
    32  */
       
    33 CAgpsEnvironment::~CAgpsEnvironment()
       
    34 	{
       
    35     Dll::SetTls(NULL);
       
    36     
       
    37     delete iPositionerQ;
       
    38     delete iRequestHandler;
       
    39     delete iResponseHandler;
       
    40     delete iModStatusHandler;
       
    41 	}
       
    42 
       
    43 /**
       
    44  * Constructor
       
    45  */
       
    46 CAgpsEnvironment::CAgpsEnvironment()
       
    47 	{
       
    48 	}
       
    49 
       
    50 /**
       
    51 Close the environment
       
    52 */
       
    53 void CAgpsEnvironment::CloseInstance()
       
    54 	{
       
    55 	CObject::Close();
       
    56 	}
       
    57 	
       
    58 /**
       
    59  * CAgpsEnvironment::RegisterPSYL
       
    60  * 
       
    61  * @param aPSY, the MPOsitioner instance to add to the queue.
       
    62  */
       
    63 void CAgpsEnvironment::RegisterPSYL(MPositioner* aPSY)
       
    64 	{
       
    65 	if(iPositionerQ)
       
    66 		{
       
    67 		iPositionerQ->RegisterPSYL(aPSY);
       
    68 		}
       
    69 	}
       
    70 
       
    71 /**
       
    72  * CAgpsEnvironment::UnregisterPSYL
       
    73  * 
       
    74  * @param aPSY, the MPositioner instance to remove from the queue.
       
    75  */
       
    76 void CAgpsEnvironment::UnregisterPSY(MPositioner* aPSY)
       
    77 	{
       
    78 	if(iPositionerQ)
       
    79 		{
       
    80 		iPositionerQ->UnregisterPSY(aPSY);
       
    81 		}
       
    82 	}
       
    83 
       
    84 
       
    85 /**
       
    86  * CPositionerQ::NewL Two-phased constructor.
       
    87  * Creates a new instance of a CAgpsEnvironment implementation.
       
    88  * 
       
    89  * @return the CPositionerEnvironment implementation.
       
    90  */
       
    91 CPositionerEnvironment* CAgpsEnvironment::NewL()
       
    92     {
       
    93 	// Have we loaded the environment already
       
    94     if ( !Dll::Tls() ) 
       
    95         {
       
    96         CAgpsEnvironment* self = new( ELeave ) CAgpsEnvironment();
       
    97         
       
    98         CleanupClosePushL(*self);
       
    99         self->ConstructL();
       
   100         CleanupStack::Pop();
       
   101 
       
   102         Dll::SetTls(self);
       
   103 		}
       
   104 	else
       
   105 		{
       
   106 		CPositionerEnvironment * theEnv = reinterpret_cast<CPositionerEnvironment*>(Dll::Tls());
       
   107 		theEnv->Open();
       
   108 		}
       
   109 
       
   110     return reinterpret_cast<CPositionerEnvironment*>(Dll::Tls());
       
   111     }
       
   112 
       
   113 void CAgpsEnvironment::ConstructL()
       
   114     {
       
   115     TRACESTRING("CAgpsEnvironment::ConstructL start");
       
   116     
       
   117 	// Do not change order of construction!
       
   118     CPositionerEnvironment::ConstructL();
       
   119 	iPositionerQ = CPositionerQ::NewL();
       
   120 	iRequestHandler = CAgpsRequestHandler::NewL(iPositionerQ);
       
   121 	iResponseHandler = CAgpsResponseHandler::NewL(iPositionerQ, iRequestHandler);
       
   122 	iModStatusHandler = CAgpsModStatusHandler::NewL(iPositionerQ);	
       
   123 	InitFinalNetPositionLagFromAdminProfile();
       
   124 	
       
   125     TRACESTRING("CAgpsEnvironment::ConstructL end");
       
   126     }
       
   127 
       
   128 /**
       
   129  * Returns the CAgpsRequestHandler instance
       
   130  *
       
   131  * @return the CAgpsRequestHandler
       
   132  */
       
   133 CRequestHandler* CAgpsEnvironment::GetRequestHandler()
       
   134 	{
       
   135     return iRequestHandler;
       
   136 	}
       
   137 	
       
   138 /**
       
   139  * Returns the CAgpsResponseHandler instance.
       
   140  *
       
   141  * @return the CAgpsResponseHandler
       
   142  */
       
   143 CResponseHandler* CAgpsEnvironment::GetResponseHandler()
       
   144 	{
       
   145     return iResponseHandler;
       
   146 	}
       
   147 
       
   148 /**
       
   149  * Returns the final network position lag value
       
   150  * 
       
   151  * @return iFinalNetPositionLag
       
   152  */
       
   153 TTimeIntervalMicroSeconds& CAgpsEnvironment::GetFinalNetPositionLag()
       
   154 	{
       
   155 	return iFinalNetPositionLag;
       
   156 	}
       
   157 
       
   158 /**
       
   159  * Called from ConstructL
       
   160  * to populate iFinalNetPositionLag
       
   161  **/
       
   162 void CAgpsEnvironment::InitFinalNetPositionLagFromAdminProfile()
       
   163 	{
       
   164 
       
   165 	// Get the profile Id for self locate requests
       
   166 	TLbsQualityProfileId profileId;
       
   167 	TInt err = Admin().Get(KLbsSettingQualityProfileSelfLocate, profileId);
       
   168 
       
   169 	if (err == KErrNone)
       
   170 		{
       
   171 		// Retrieve the quality profile that belongs to the given Id
       
   172 		TQualityProfile quality;
       
   173 		err = LbsQualityProfile::GetQualityProfileById(profileId, quality);
       
   174 		if (err == KErrNone)
       
   175 			{
       
   176 			iFinalNetPositionLag = quality.FinalNetPositionLag();
       
   177 			}
       
   178 		else
       
   179 			{
       
   180 			iFinalNetPositionLag = 0;
       
   181 			}
       
   182 		}
       
   183 	else
       
   184 		{
       
   185 		iFinalNetPositionLag = 0;
       
   186 		}
       
   187 	}
       
   188