datasourcemodules/networkpositioningmodule/src/responsehandler/cnetresponsehandler.cpp
changeset 0 9cfd9a3ee49c
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 "cpositionerq.h"
       
    22 #include "cnetresponsehandler.h"
       
    23 #include "lbsdevloggermacros.h"
       
    24 #include "psypanic.h"
       
    25 #include "utilfunctions.h"
       
    26 #include "crequesthandler.h"
       
    27 #include "tpositionercall.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CNETResponseHandler::NewL
       
    31 // Two-phased constructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CNETResponseHandler* CNETResponseHandler::NewL(CPositionerQ* aPositionerQ, CRequestHandler* aRequestHandler)
       
    35     {
       
    36     CNETResponseHandler* self = new( ELeave ) CNETResponseHandler(aPositionerQ, aRequestHandler);
       
    37     
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41 
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CNETResponseHandler::CNETResponseHandler
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CNETResponseHandler::CNETResponseHandler(CPositionerQ* aPositionerQ, CRequestHandler* aRequestHandler)
       
    52     {
       
    53     iPositionerQ = aPositionerQ;
       
    54     iRequestHandler = aRequestHandler;
       
    55     }
       
    56 
       
    57 CNETResponseHandler::~CNETResponseHandler()
       
    58     {
       
    59     delete iNETDataBus;
       
    60     }
       
    61 
       
    62 /**
       
    63 * construct the data bus by module ID and set the data bus observer
       
    64 */
       
    65 void CNETResponseHandler::ConstructL()
       
    66 	{
       
    67 	iNETDataBus = CNETDataBus::NewL(static_cast<MDataBusObserver*>(this), KLbsNetLocManagerUid);
       
    68 	
       
    69 	Subscribe();
       
    70 	}
       
    71 	
       
    72 void CNETResponseHandler::Subscribe()
       
    73 	{
       
    74 	iNETDataBus->Subscribe();
       
    75 	}
       
    76 	
       
    77 /**
       
    78 Location update
       
    79 
       
    80 @param aPosition Position info from the data bus
       
    81 @param aStatus status of the bus
       
    82 @param aError error code
       
    83 @param aActualTime position update time
       
    84 */
       
    85 void CNETResponseHandler::DataUpdate(TPositionInfo& aPosition, TInt aStatus, TInt aError, TTime aActualTime, TUint /* aAttributes */, TUint /*aMode*/)
       
    86 	{
       
    87 	LBSLOG(ELogP1, "CNETResponseHandler::DataUpdate Start ");
       
    88 
       
    89 	Subscribe();
       
    90 	
       
    91 	if(aStatus==KErrNone)
       
    92 		{
       
    93 		if((KErrNone == aError))
       
    94 			{
       
    95 			LBSLOG(ELogP1, "CNETResponseHandler::DataUpdate Valid ");
       
    96 			
       
    97 			TLocationUpdate call(aPosition, aError, aActualTime, 0);
       
    98 			iPositionerQ->PositionerIterator(call);
       
    99 			iRequestHandler->NotifyRequestComplete();
       
   100 			}
       
   101 		else if (aError < 0)
       
   102 			{
       
   103 			LBSLOG2(ELogP1, "CNETResponseHandler::DataUpdate -  Error: %d", aError);
       
   104 			
       
   105 			TUpdateFailed call(aError);
       
   106 			iPositionerQ->PositionerIterator(call);
       
   107 			iRequestHandler->NotifyRequestComplete();
       
   108 			}
       
   109 		else
       
   110 			{
       
   111 			// 'Futile' is the only +ve error code we currently have, so this shouldn't happen
       
   112 			__ASSERT_DEBUG(EFalse, User::Panic(KAdaptationPanicCategory, EPanicUnknownUpdateError));
       
   113 			}
       
   114 		}
       
   115 	LBSLOG(ELogP1, "CNETResponseHandler::DataUpdate End ");
       
   116 	}
       
   117 
       
   118 /**
       
   119 GetLastPosition
       
   120 
       
   121 @param aPos	container for the position being returned (with KErrNone return)	
       
   122 @param aOldestValidTime	 the oldest valid time for a position being returned. If there is a valid position no older than this time, it should be returned.
       
   123 @param aAllowPartial	whether partial updates should be considered
       
   124 @return ETrue if the fix fulfills the requirements, 
       
   125 */
       
   126 TBool CNETResponseHandler::GetLastPosition(TPositionInfoBase& aPos, TTime aOldestValidTime, TBool aAllowPartial)
       
   127 	{
       
   128 	TBool ret = EFalse;
       
   129 
       
   130 	TTime actualTime;
       
   131 	TPositionInfo posInfo;
       
   132  	TPosition pos;	 	
       
   133  	TInt err;
       
   134 	
       
   135  	err = iNETDataBus->GetLastPositionInfo(posInfo, actualTime);
       
   136 	if( err == KErrNone && actualTime >= aOldestValidTime)	// got a recent enough position
       
   137 		{
       
   138 		posInfo.GetPosition(pos);
       
   139 		if(aAllowPartial || !Partial(pos))// complete enough
       
   140 			{
       
   141 			TRAPD(error, CopyPositionTypes(aPos, posInfo));
       
   142 			if(!error)
       
   143 				{
       
   144 				ret = ETrue;
       
   145 				}
       
   146 			else
       
   147 				{
       
   148 				LBSLOG(ELogP1, "CNetResponseHandler::GetLastPosition() failed to copy position ");
       
   149 				ret = EFalse;
       
   150 				}			
       
   151 			}
       
   152 		}	
       
   153 	return ret;
       
   154 	}