browserutilities/feedsengine/FeedsServer/Api/src/Waiter.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2008 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 the License "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:  Waits for request to complete
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "Waiter.h"
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 // CWaiter::NewL
       
    23 //
       
    24 // Two-phased constructor. 
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 CWaiter* CWaiter::NewL()
       
    28     {
       
    29     CWaiter* self = new (ELeave) CWaiter();
       
    30 
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop();
       
    34 
       
    35     return self;
       
    36     }
       
    37 // -----------------------------------------------------------------------------
       
    38 // CWaiter::CWaiter
       
    39 //
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CWaiter::CWaiter()
       
    45         :CActive( EPriorityStandard )
       
    46     {
       
    47     CActiveScheduler::Add( this );
       
    48     }
       
    49     
       
    50 // -----------------------------------------------------------------------------
       
    51 // CWaiter::ConstructL
       
    52 //
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CWaiter::ConstructL()
       
    57     {    
       
    58     }
       
    59     
       
    60 // -----------------------------------------------------------------------------
       
    61 // CWaiter::~CWaiter
       
    62 //
       
    63 // Deconstructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CWaiter::~CWaiter()
       
    67     {
       
    68     Cancel();
       
    69     }
       
    70     
       
    71 // -----------------------------------------------------------------------------
       
    72 // CWaiter::Wait
       
    73 //
       
    74 // Waits till request gets completed
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 TInt CWaiter::Wait()
       
    78     {
       
    79     iStatus = KRequestPending;
       
    80     iIsWaiting = ETrue;
       
    81     SetActive();
       
    82     iSyncWait.Start();
       
    83     return iStatus.Int();
       
    84     }
       
    85     
       
    86 // -----------------------------------------------------------------------------
       
    87 // CWaiter::RunL
       
    88 //
       
    89 // RunL
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CWaiter::RunL()
       
    93     {
       
    94     if( iSyncWait.IsStarted() )
       
    95         {
       
    96         iSyncWait.AsyncStop();
       
    97         }
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CWaiter::DoCancel
       
   102 //
       
   103 // DoCancel
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CWaiter::DoCancel()
       
   107     {
       
   108     RequestComplete(KErrCancel);
       
   109   	}
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CWaiter::RequestComplete
       
   113 //
       
   114 // RequestComplete
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TBool CWaiter::RequestComplete(TInt aStatus)
       
   118 {
       
   119 	if(iIsWaiting)
       
   120 	{
       
   121 		TRequestStatus  *status = &iStatus;
       
   122 		User::RequestComplete(status, aStatus);
       
   123 		iIsWaiting = EFalse;
       
   124 		return ETrue;
       
   125 	}
       
   126 	return EFalse;
       
   127 }