ximpfw/tsrc/tsrcutils/testcaseutils/userafter.h
changeset 51 61fad867f68e
equal deleted inserted replaced
-1:000000000000 51:61fad867f68e
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Active object based wait.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CUSERAFTER_H__
       
    19 #define CUSERAFTER_H__
       
    20 
       
    21 // INCLUDES
       
    22 #include <E32base.h>
       
    23 
       
    24 
       
    25 // CLASS DESCRIPTION
       
    26 
       
    27 /**
       
    28  * Active object based wait.
       
    29  *
       
    30  * Similar like User::After() but doesn't block
       
    31  * whole thread, but current RunL() with
       
    32  * CActiveSchedulerWait.
       
    33  */
       
    34 class CUserAfter : public CTimer
       
    35     {
       
    36     public: //Construction
       
    37         static inline CUserAfter* NewL();
       
    38         static inline CUserAfter* NewLC();
       
    39        ~CUserAfter();
       
    40 
       
    41 
       
    42     public: //Wait support
       
    43 
       
    44         /**
       
    45          * Static "one shot" wait method.
       
    46          */
       
    47         static inline void AfterL( TInt aWaitTimeMicroSeconds );
       
    48         static inline void AfterSecondsL( TInt aWaitTimeSeconds );
       
    49 
       
    50         /**
       
    51          * Member wait method.
       
    52          */
       
    53         inline void After( TInt aWaitTimeMicroSeconds );
       
    54 
       
    55 
       
    56     private:
       
    57         CUserAfter();
       
    58 
       
    59         void RunL();
       
    60         void RunError();
       
    61         void DoCancel();
       
    62 
       
    63 
       
    64     private:    //data
       
    65         CActiveSchedulerWait iWait;
       
    66 
       
    67     };
       
    68 
       
    69 
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CUserAfter public functions
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 inline CUserAfter* CUserAfter::NewL()
       
    77     {
       
    78     CUserAfter* self = CUserAfter::NewLC();
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81     }
       
    82 
       
    83 inline CUserAfter* CUserAfter::NewLC()
       
    84     {
       
    85     CUserAfter* self = new (ELeave) CUserAfter();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     return self;
       
    89     }
       
    90 
       
    91 
       
    92 inline CUserAfter::~CUserAfter()
       
    93     {
       
    94     CTimer::Cancel();
       
    95     }
       
    96 
       
    97 inline void CUserAfter::After( TInt aWaitTimeMicroSeconds )
       
    98     {
       
    99     CTimer::After( aWaitTimeMicroSeconds );
       
   100     iWait.Start();
       
   101     }
       
   102 
       
   103 
       
   104 inline void CUserAfter::AfterL( TInt aWaitTimeMicroSeconds )
       
   105     {
       
   106     CUserAfter* after = CUserAfter::NewL();
       
   107     after->After( aWaitTimeMicroSeconds );
       
   108     delete after;
       
   109     }
       
   110 
       
   111 
       
   112 inline void CUserAfter::AfterSecondsL( TInt aWaitTimeSeconds )
       
   113     {
       
   114     CUserAfter* after = CUserAfter::NewL();
       
   115     after->After( aWaitTimeSeconds * 1000000 );
       
   116     delete after;
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CUserAfter private functions
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 inline CUserAfter::CUserAfter()
       
   125     : CTimer( CActive::EPriorityStandard )
       
   126     {
       
   127     CActiveScheduler::Add( this );
       
   128     }
       
   129 
       
   130 
       
   131 inline void CUserAfter::RunL()
       
   132     {
       
   133     iWait.AsyncStop();
       
   134     Cancel();
       
   135     }
       
   136 
       
   137 inline void CUserAfter::RunError()
       
   138     {
       
   139     }
       
   140 
       
   141 inline void CUserAfter::DoCancel()
       
   142     {
       
   143     iWait.AsyncStop();
       
   144     CTimer::DoCancel();
       
   145     }
       
   146 
       
   147 
       
   148 #endif // CUSERAFTER_H__
       
   149 
       
   150 // End of File
       
   151