phoneengine/PhoneCntFinder/ContactService/src/CPhCntService.cpp
changeset 0 5f000ab63145
child 9 8871b09be73b
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 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:  Aiw service wrapper.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPhCntService.h"
       
    20 #include <AiwServiceHandler.h>
       
    21 #include <AiwGenericParam.hrh>
       
    22 #include <AiwCommon.hrh>
       
    23 #include <AiwContactSelectionDataTypes.h>
       
    24 #include "mphcntservicerequestparam.h"
       
    25 #include "mphcntserviceresult.h"
       
    26 
       
    27 _LIT8( KContentType ,EGenericParamContactItemStr );
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Static constructor
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CPhCntService* CPhCntService::NewL() 
       
    34 	{
       
    35 	CPhCntService* self = 
       
    36 	    new( ELeave )CPhCntService();
       
    37 	CleanupStack::PushL( self );
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop( self );
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Destructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //	
       
    47 CPhCntService::~CPhCntService() 
       
    48 	{
       
    49 	CancelRequest();
       
    50 	if( iAiwService ) 
       
    51 	    {
       
    52         iAiwService->Reset();	    
       
    53 	    }
       
    54 	iCriteriaArray.ResetAndDestroy();
       
    55 	iCriteriaArray.Close();
       
    56 	
       
    57 	delete iAiwService;
       
    58 	}
       
    59 	
       
    60 // ---------------------------------------------------------------------------
       
    61 // Attach AIW criterias
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CPhCntService::AttachCriteriasL() 
       
    65 	{
       
    66 	// Note take array to member variable and detach from aiw when destructing.
       
    67 	CAiwCriteriaItem* selectCriteria = 
       
    68 		CAiwCriteriaItem::NewLC( KAiwCmdSelect, KAiwCmdSelect, KContentType ); 
       
    69     TUid uid;
       
    70 	uid.iUid = KAiwClassBase;
       
    71 	selectCriteria->SetServiceClass( uid );
       
    72 	selectCriteria->SetMaxProviders( 1 );
       
    73 	iCriteriaArray.AppendL( selectCriteria );
       
    74 	CleanupStack::Pop( selectCriteria );
       
    75 		
       
    76     CAiwCriteriaItem* assignCriteria = 
       
    77         CAiwCriteriaItem::NewLC( KAiwCmdAssign, KAiwCmdAssign, KContentType );
       
    78 	
       
    79 	uid.iUid = KAiwClassMenu;
       
    80 	assignCriteria->SetServiceClass( uid );
       
    81 	assignCriteria->SetMaxProviders( 1 );
       
    82 	
       
    83 	
       
    84 	iCriteriaArray.AppendL( assignCriteria  );
       
    85 	iAiwService->AttachL( iCriteriaArray ); 
       
    86 	CleanupStack::Pop( assignCriteria );
       
    87 	}
       
    88 
       
    89         
       
    90 // ---------------------------------------------------------------------------
       
    91 // Cancels request if request is outstanding.
       
    92 // ---------------------------------------------------------------------------
       
    93 //    
       
    94 TInt CPhCntService::CancelRequest()
       
    95     {
       
    96     TInt err( KErrNone );
       
    97     if ( iParams )
       
    98     	{
       
    99     	if( iClientCanceledRequest )
       
   100     	    {
       
   101     	    *iClientCanceledRequest = ETrue;
       
   102     	    }
       
   103     	// Cancel old requests
       
   104 	    iCommandOptions |= KAiwOptCancel;
       
   105 	    // Cancel is synchronous and we have request ongoing so
       
   106 	    // do not use base class MakeAsyncRequest, because it uses
       
   107 	    // CActiveSchedulerWait to make synchronisation and the 
       
   108 	    // wait scheduler is already waiting. If we would call the 
       
   109 	    // wait scheduler again, it would crash.
       
   110     	TRAP( err, DoMakeAsyncRequestL() );
       
   111         iCommandOptions = 0; // Reset the command options
       
   112     	}
       
   113     return err;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // From MPhCntService
       
   118 // Executes AIW service rewuest.
       
   119 // ---------------------------------------------------------------------------
       
   120 //	
       
   121 void CPhCntService::ExecuteRequestL( 
       
   122     MPhCntServiceRequestParam& aParams,
       
   123     MPhCntServiceResult& aResult )
       
   124     {
       
   125     if( !IsActive() )
       
   126         {
       
   127         // Destructor can indicate canceling of request using 
       
   128         // iClientCanceledRequest.
       
   129         TBool requestCanceledByClient = EFalse;
       
   130         iClientCanceledRequest = &requestCanceledByClient;
       
   131         
       
   132         SetRequestAndResult( aParams, aResult );
       
   133         TInt err( KErrNone );
       
   134         TRAPD( applicationShuttingdown, err = MakeAsyncRequest() );
       
   135         // If application using phonecntfinder is ended from task switcher, then
       
   136         // underlying CActiveSchedulerWait::Wait leaves. This needs to be
       
   137         // trapped because we are using clients aParams and aResult, which 
       
   138         // are stack based objects. 
       
   139         if( applicationShuttingdown )
       
   140             {
       
   141             // Cancel possible outstanding request
       
   142            	    CancelRequest();
       
   143            	    iResult = NULL;
       
   144                 iParams = NULL;
       
   145            	    User::Leave( applicationShuttingdown );
       
   146            	    }
       
   147            
       
   148             if( !requestCanceledByClient )
       
   149                 {
       
   150                 iResult = NULL;
       
   151                 iParams = NULL;
       
   152                 }
       
   153             else
       
   154                 {
       
   155                 err = KErrCancel;
       
   156                 }
       
   157     
       
   158         User::LeaveIfError( err );
       
   159         }
       
   160     }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // From MPhCntAiwServiceCompleteObserver
       
   165 // Notifies link fetch observer that links are fetched.
       
   166 // ---------------------------------------------------------------------------
       
   167 //    
       
   168 void CPhCntService::ServiceRequestComplete( TInt aError )
       
   169     {
       
   170     ResponseReceived( aError );
       
   171     }
       
   172 	
       
   173 void CPhCntService::ConstructL() 
       
   174 	{
       
   175     BaseConstructL();
       
   176 	iAiwService = CAiwServiceHandler::NewL();
       
   177 	AttachCriteriasL();
       
   178 
       
   179 	}
       
   180 	
       
   181 CPhCntService::CPhCntService() : 
       
   182     iAiwServiceObserver( *this )
       
   183 	{
       
   184 	}
       
   185 	
       
   186 // ---------------------------------------------------------------------------
       
   187 // From CPhCntAsyncToSync
       
   188 // Makes the actual aiw request.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CPhCntService::DoMakeAsyncRequestL()  
       
   192     {
       
   193     iAiwService->ExecuteServiceCmdL( 
       
   194         iParams->Command(), 
       
   195         iParams->InParamList(), 
       
   196         iAiwService->OutParamListL(), 
       
   197         iCommandOptions, 
       
   198         &iAiwServiceObserver );
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // Sets variables
       
   203 // ---------------------------------------------------------------------------
       
   204 //    
       
   205 void CPhCntService::SetRequestAndResult( 
       
   206     MPhCntServiceRequestParam& aServiceRequestParams, 
       
   207     MPhCntServiceResult& aResult )
       
   208     {
       
   209     iResult = &aResult;
       
   210    	iParams = &aServiceRequestParams;
       
   211    	iAiwServiceObserver.SetRequestAndResult( iParams, iResult );
       
   212     }
       
   213