phoneengine/PhoneCntFinder/ContactService/src/cphcntasynctosync.cpp
changeset 0 5f000ab63145
child 1 838b0a10d15b
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:  Converts asynchronous call to synchronous.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cphcntasynctosync.h"
       
    20 
       
    21 // ======== MEMBER FUNCTIONS ========
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // Constructor
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CPhCntAsyncToSync::CPhCntAsyncToSync()
       
    28     {
       
    29     }
       
    30 
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Second phase constructor.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 void CPhCntAsyncToSync::BaseConstructL()
       
    37     {
       
    38     iWait = new( ELeave )CActiveSchedulerWait();
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Destructor
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CPhCntAsyncToSync::~CPhCntAsyncToSync()
       
    46     {
       
    47     delete iWait;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // Converts asyncrhonous call to synchronous.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 TInt CPhCntAsyncToSync::MakeAsyncRequest()
       
    55     {
       
    56     iResponseReceived = EFalse;
       
    57     TRAPD( err, DoMakeAsyncRequestL() );
       
    58     if( !err )
       
    59         {
       
    60         // Check that response is not already received, we cannot 
       
    61         // start the scheduler if response is received, otherwise
       
    62         // scheduler waits forever.
       
    63         if( !iResponseReceived )
       
    64             {
       
    65             iWait->Start();
       
    66             }    
       
    67         err = iResponseError;
       
    68         }
       
    69     return err;
       
    70     }
       
    71     
       
    72 // ---------------------------------------------------------------------------
       
    73 // Indication that response has been received from async request.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CPhCntAsyncToSync::ResponseReceived( TInt aErrorCode )
       
    77     {
       
    78     iResponseReceived = ETrue;
       
    79     iResponseError = aErrorCode;
       
    80     if( iWait->IsStarted() )
       
    81         {
       
    82         iWait->AsyncStop();
       
    83         }
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Checks if there are pending asynchronous requests available.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 TBool CPhCntAsyncToSync::IsActive()
       
    91     {
       
    92     return iWait->IsStarted();
       
    93     }
       
    94