PECengine/AttributeLibrary2/SrcWVAttributes/CAsync2Sync.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Async to sync.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32Base.h>
       
    20 #include "CAsync2Sync.h"
       
    21 #include "PresenceDebugPrint.h"
       
    22 
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CAsync2Sync::NewLC()
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CAsync2Sync* CAsync2Sync::NewLC()
       
    29     {
       
    30     CAsync2Sync* self = new ( ELeave ) CAsync2Sync;
       
    31     CleanupStack::PushL( self );
       
    32     return self;
       
    33     }
       
    34 
       
    35 
       
    36 // Destructor
       
    37 CAsync2Sync::~CAsync2Sync()
       
    38     {
       
    39     Cancel();
       
    40     }
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CAsync2Sync::CAsync2Sync()
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CAsync2Sync::CAsync2Sync()
       
    50         : CActive( CActive::EPriorityStandard )
       
    51     {
       
    52     CActiveScheduler::Add( this );
       
    53     Prepare();
       
    54     }
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CAsync2Sync::Prepare()
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CAsync2Sync::Prepare()
       
    62     {
       
    63     Cancel();
       
    64     iStatus = KErrNone;
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CAsync2Sync::WaitToComplete()
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CAsync2Sync::WaitToComplete()
       
    73     {
       
    74     if ( iStatus == KRequestPending )
       
    75         {
       
    76         //some asynchronous operation really started
       
    77         //==> wait it to complete
       
    78         SetActive();
       
    79 
       
    80         PENG_DP( D_PENG_LIT( "CAsync2Sync::WaitToComplete() Waiting..." ) );
       
    81         iWait.Start();      // CSI: 10 #
       
    82         PENG_DP( D_PENG_LIT( "CAsync2Sync::WaitToComplete() Wait done [%d]" ), iStatus.Int() );
       
    83         }
       
    84     else
       
    85         {
       
    86         //No  request pending
       
    87         PENG_DP( D_PENG_LIT( "CAsync2Sync::WaitToComplete() No pending request to wait" ) );
       
    88         }
       
    89     }
       
    90 
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CAsync2Sync::RequestStatus()
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 TRequestStatus& CAsync2Sync::RequestStatus()
       
    97     {
       
    98     return iStatus;
       
    99     }
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CAsync2Sync::RunL()
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CAsync2Sync::RunL()
       
   107     {
       
   108     iWait.AsyncStop();
       
   109     }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CAsync2Sync::RunError()
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CAsync2Sync::RunError( TInt aError )
       
   117     {
       
   118     iWait.AsyncStop();
       
   119     iStatus = aError;
       
   120     return KErrNone;
       
   121     }
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CAsync2Sync::DoCancel()
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CAsync2Sync::DoCancel()
       
   129     {
       
   130     iStatus = KErrCancel;
       
   131     }
       
   132 
       
   133 
       
   134 // End of file.
       
   135 
       
   136