natplugins/natpnatfwsdpprovider/tsrc/testconsole/src/nsptestasyncservice.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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 "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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32base.h>
       
    20 #include "nsptestasyncservice.h"
       
    21 
       
    22 #define __PANIC( aError ) \
       
    23 	User::Panic( _L( "NSP Test console test async service" ), aError )
       
    24 
       
    25 const TTimeIntervalMicroSeconds32 KTimeoutInterval = 10000000; // 10s
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CNSPTestAsyncService::NewL
       
    29 // -----------------------------------------------------------------------------
       
    30 // 
       
    31 CNSPTestAsyncService* CNSPTestAsyncService::NewL( TInt& aTimerStatus )
       
    32     {
       
    33     CNSPTestAsyncService* self = CNSPTestAsyncService::NewLC( aTimerStatus );
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CNSPTestAsyncService::NewLC
       
    40 // -----------------------------------------------------------------------------
       
    41 // 
       
    42 CNSPTestAsyncService* CNSPTestAsyncService::NewLC( TInt& aTimerStatus )
       
    43     {
       
    44     CNSPTestAsyncService* self = new ( ELeave ) CNSPTestAsyncService( aTimerStatus );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     return self;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CNSPTestAsyncService::~CNSPTestAsyncService
       
    52 // -----------------------------------------------------------------------------
       
    53 // 
       
    54 CNSPTestAsyncService::~CNSPTestAsyncService()
       
    55     {
       
    56 	if ( iWait && iWait->IsStarted() )
       
    57 		{
       
    58 		iWait->AsyncStop();
       
    59 		}
       
    60 	
       
    61     delete iWait;
       
    62     iTimer.Close();
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CNSPTestAsyncService::CNSPTestAsyncService
       
    67 // -----------------------------------------------------------------------------
       
    68 // 
       
    69 CNSPTestAsyncService::CNSPTestAsyncService( TInt& aTimerStatus )
       
    70     : CActive( EPriorityStandard ),
       
    71       iTimerStatus( aTimerStatus )
       
    72     {
       
    73     CActiveScheduler::Add( this );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CNSPTestAsyncService::ConstructL
       
    78 // -----------------------------------------------------------------------------
       
    79 // 
       
    80 void CNSPTestAsyncService::ConstructL()
       
    81     {
       
    82 	User::LeaveIfError( iTimer.CreateLocal() );
       
    83     iWait = new (ELeave) CActiveSchedulerWait;
       
    84 	}
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CNSPTestAsyncService::StartScheduler
       
    88 // -----------------------------------------------------------------------------
       
    89 // 
       
    90 void CNSPTestAsyncService::RunL()
       
    91 	{
       
    92 	iTimerStatus = KErrTimedOut;
       
    93 	
       
    94 	if ( iWait && iWait->IsStarted() )
       
    95 		{
       
    96 		iWait->AsyncStop();	
       
    97 		}
       
    98 	}
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CNSPTestAsyncService::StartScheduler
       
   102 // -----------------------------------------------------------------------------
       
   103 // 
       
   104 void CNSPTestAsyncService::DoCancel()
       
   105 	{
       
   106 	iTimerStatus = KErrCancel;
       
   107 	iTimer.Cancel();
       
   108 	
       
   109 	if ( iWait && iWait->IsStarted() )
       
   110 		{
       
   111 		iWait->AsyncStop();	
       
   112 		}
       
   113 	}
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CNSPTestAsyncService::StartScheduler
       
   117 // -----------------------------------------------------------------------------
       
   118 // 
       
   119 void CNSPTestAsyncService::StartScheduler()
       
   120 	{
       
   121 	if ( IsActive() )
       
   122 		{
       
   123 		Cancel();
       
   124 		}
       
   125 	
       
   126     iTimer.After( iStatus, KTimeoutInterval );
       
   127 	SetActive();
       
   128 	iWait->Start();
       
   129 	}
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CNSPTestAsyncService::Stop
       
   133 // -----------------------------------------------------------------------------
       
   134 // 
       
   135 void CNSPTestAsyncService::Stop()
       
   136 	{
       
   137 	iTimerStatus = KErrNone;
       
   138 	iTimer.Cancel();
       
   139 	
       
   140 	if ( iWait && iWait->IsStarted() )
       
   141 		{
       
   142 		iWait->AsyncStop();	
       
   143 		}
       
   144 	}
       
   145