posmsgpluginreferenceimpl/src/epos_comasuplpossession.cpp
changeset 0 0ce1b5ce9557
equal deleted inserted replaced
-1:000000000000 0:0ce1b5ce9557
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Provides the reference implementation for POS message plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <ecom/ecom.h>
       
    21 #include <lbs/epos_eomasuplposerrors.h>
       
    22 #include <lbs/epos_comasuplpospayload.h>
       
    23 #include <lbs/epos_momasuplobserver.h>
       
    24 #include "epos_comasuplpossession.h"
       
    25 #include "epos_tomasuplposutility.h"
       
    26 
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // COMASuplPosSession::NewL
       
    30 // Factory function to instantiate an object of COMASuplPosSession
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 COMASuplPosSessionBase* COMASuplPosSession::NewL(
       
    34                             MOMASuplObserver* aSuplObserver )
       
    35     {
       
    36     return new ( ELeave ) COMASuplPosSession( aSuplObserver );
       
    37     }
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // COMASuplPosSession::~COMASuplPosSession
       
    42 // Destructor. Removes the object from the active scheduler's list
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 COMASuplPosSession::~COMASuplPosSession()
       
    46     {
       
    47     delete iPosPayload;
       
    48     Deque();
       
    49     }
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // COMASuplPosSession::COMASuplPosSession
       
    54 // Constructor
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 COMASuplPosSession::COMASuplPosSession( MOMASuplObserver* aSuplObserver ):
       
    58                         CActive( EPriorityStandard )
       
    59                         , COMASuplPosSessionBase( aSuplObserver )
       
    60     {
       
    61     iIsInitialized = EFalse;
       
    62     iRequestID = 0;
       
    63     CActiveScheduler::Add( this );
       
    64     }
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // COMASuplPosSession::InitializeL
       
    69 // Initializes the instance of COMASuplPosSession
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void COMASuplPosSession::InitializeL( const TInt aRequestID, 
       
    73                         TRequestStatus& aStatus )
       
    74     {
       
    75     aStatus = KRequestPending;
       
    76     iRequestID = aRequestID;
       
    77     iClientStatus = &aStatus;
       
    78     iState = EInitialize;
       
    79     if ( iPosPayload )
       
    80         {
       
    81         delete iPosPayload;
       
    82         iPosPayload = NULL;
       
    83         }
       
    84     IdleComplete();
       
    85     }
       
    86     
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // COMASuplPosSession::CancelInitialize
       
    90 // Cancels an outstanding request to initialize
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void COMASuplPosSession::CancelInitialize()
       
    94     {
       
    95     iIsInitialized = EFalse;
       
    96     CancelRequest();
       
    97     }
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // COMASuplPosSession::HandleSuplPosMessageL
       
   102 // Handles SUPL POS payload 
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void COMASuplPosSession::HandleSuplPosMessageL( 
       
   106                         const COMASuplPosPayload* aPosPayload )
       
   107     {
       
   108     __ASSERT_ALWAYS( iIsInitialized, User::Leave( KErrOMASuplPosInActive ) );
       
   109     
       
   110     // Delete any existing memory
       
   111     if ( iPosPayload )
       
   112         {
       
   113         delete iPosPayload;
       
   114         iPosPayload = NULL;
       
   115         }
       
   116 
       
   117     iPosPayload = static_cast<COMASuplPosPayload*>( aPosPayload->CloneL() );
       
   118     }
       
   119         
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // COMASuplPosSession::GetSuplInfoL
       
   123 // Provides different POS parameters to the SUPL FW
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void COMASuplPosSession::GetSuplInfoL( 
       
   127                         COMASuplInfoRequestList* aInfoRequestList,
       
   128                         TRequestStatus& aStatus )
       
   129     {
       
   130     TRequestStatus* status = &aStatus;
       
   131     if(!iIsInitialized)
       
   132     	{
       
   133     	User::RequestComplete(status, KErrOMASuplPosInActive );
       
   134     	return;
       
   135     	}
       
   136     aStatus = KRequestPending;
       
   137     iClientStatus = &aStatus;
       
   138     iSuplInfoReqList = aInfoRequestList;
       
   139     iState = EGetSuplInfo;
       
   140     IdleComplete();
       
   141     }
       
   142     						  
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // COMASuplPosSession::CancelSuplInfoRequest
       
   146 // Cancels an outstanding request to GetSuplInfoL
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void COMASuplPosSession::CancelSuplInfoRequest()
       
   150     {
       
   151     CancelRequest();
       
   152     }
       
   153         
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // COMASuplPosSession::GetPositionL
       
   157 // Provides position estimates to the SUPL FW
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void COMASuplPosSession::GetPositionL( TRequestStatus& aStatus, 
       
   161                         COMASuplPosition* aPosition )
       
   162     {
       
   163     TRequestStatus* status = &aStatus;
       
   164     if(!iIsInitialized)
       
   165     	{
       
   166     	User::RequestComplete(status, KErrOMASuplPosInActive );
       
   167     	return;
       
   168     	}
       
   169     aStatus = KRequestPending;
       
   170     iClientStatus = &aStatus;
       
   171     iPosition = aPosition;
       
   172     iState = EGetPosition;
       
   173     IdleComplete();
       
   174     }
       
   175         
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // COMASuplPosSession::CancelGetPosition
       
   179 // Cancels an outstanding request to GetPositionL
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void COMASuplPosSession::CancelGetPosition()
       
   183     {
       
   184     CancelRequest();
       
   185     }
       
   186         
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // COMASuplPosSession::SessionEnd
       
   190 // Terminates a SUPL POS Session
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void COMASuplPosSession::SessionEnd()
       
   194     {
       
   195     CancelRequest();
       
   196     iIsInitialized = EFalse;
       
   197     }
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // COMASuplPosSession::RunL
       
   202 // Inherited from CActive - called when object is active.
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void COMASuplPosSession::RunL()
       
   206     {
       
   207     switch( iState )
       
   208         {
       
   209         case EInitialize:
       
   210             iIsInitialized = ETrue;
       
   211             User::RequestComplete( iClientStatus, KErrNone );
       
   212             // CActiveScheduler::Stop();
       
   213             break;
       
   214             
       
   215         case EGetSuplInfo:
       
   216             TOmaSuplPosUtility::GetPosParametersL( iSuplInfoReqList );
       
   217             User::RequestComplete( iClientStatus, KErrNone );
       
   218             // CActiveScheduler::Stop();
       
   219             break;
       
   220             
       
   221         case EGetPosition:
       
   222             TOmaSuplPosUtility::GetPositionEstimatesL( iPosition );
       
   223             User::RequestComplete( iClientStatus, KErrNone );
       
   224             // CActiveScheduler::Stop();
       
   225             break;
       
   226             
       
   227         default:
       
   228             break;
       
   229         }
       
   230     }
       
   231     
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // COMASuplPosSession::DoCancel
       
   235 // Inherited from CActive - called to cancel outanding requests
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void COMASuplPosSession::DoCancel()
       
   239     {
       
   240     // Cancel any outstanding requests to asynchronous service providers
       
   241     TBool isActive = IsActive();
       
   242     if ( isActive )
       
   243         {
       
   244         User::RequestComplete( iClientStatus, KErrCancel );
       
   245         }
       
   246     }
       
   247 
       
   248 TInt COMASuplPosSession::RunError(TInt /*aError*/)
       
   249 	{
       
   250 	return KErrNone;
       
   251 	}
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // COMASuplPosSession::IdleComplete
       
   255 // Completes an asynchronous request with KErrNone
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void COMASuplPosSession::IdleComplete()
       
   259     {
       
   260     TRequestStatus* pS = &iStatus;
       
   261     User::RequestComplete( pS, KErrNone );
       
   262     if ( !IsActive() )
       
   263         {
       
   264         SetActive();
       
   265         }
       
   266     }
       
   267 
       
   268     
       
   269 // -----------------------------------------------------------------------------
       
   270 // COMASuplPosSession::CancelRequest
       
   271 // Cancels an outstanding request if any with KErrCancel
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void COMASuplPosSession::CancelRequest()
       
   275     {
       
   276     Cancel();
       
   277     }