natfw/tsrc/natfwtestconsoles/natfwtestconsole/src/natfwtestconsolestubs.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2009 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 
       
    19 //*******************************************************************************
       
    20 // Method      : 
       
    21 // Purpose     : Working as a stub for NAT Connectivity FW tests
       
    22 // Parameters  : 
       
    23 // Return Value: 
       
    24 //*******************************************************************************
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <e32debug.h>
       
    28 #include <e32cons.h>
       
    29 
       
    30 #include "natfwtestconsolestubs.h"
       
    31 #include "mmccnetworksettings.h"
       
    32 #include "natfwcandidate.h"
       
    33 #include "timeouttimer.h"
       
    34 
       
    35 //NATFWConnectivityEvents
       
    36 _LIT16( KESessionCreated, "ESessionCreated" );
       
    37 _LIT16( KELocalCandidateFound, "ELocalCandidateFound" );
       
    38 _LIT16( KEFetchingCompleted, "EFetchingCompleted" );
       
    39 _LIT16( KEReceivingActivated, "EReceivingActivated" );
       
    40 _LIT16( KEReceivingDeactivated, "EReceivingDeactivated" );
       
    41 _LIT16( KESendingActivated, "ESendingActivated" );
       
    42 _LIT16( KESendingDeactivated, "ESendingDeactivated" );
       
    43 _LIT16( KECandidatePairFound, "ECandidatePairFound" );
       
    44 _LIT16( KEConnChecksCompleted, "EConnChecksCompleted" );
       
    45 _LIT16( KEGeneralError, "EGeneralError" );
       
    46 _LIT16( KAllEvents, "EAllEvents" );
       
    47     
       
    48 CNATConnFWTestConsoleStubs* CNATConnFWTestConsoleStubs::NewL( CConsoleBase& aConsole )
       
    49     {
       
    50     CNATConnFWTestConsoleStubs* self = new (ELeave) CNATConnFWTestConsoleStubs( aConsole );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56     
       
    57 void CNATConnFWTestConsoleStubs::ConstructL()
       
    58     {
       
    59     iTimer = CTimeOutTimer::NewL( CActive::EPriorityStandard, *this );
       
    60     }
       
    61 
       
    62 CNATConnFWTestConsoleStubs::CNATConnFWTestConsoleStubs( CConsoleBase& aConsole ) :
       
    63     iTimedExpired( EFalse ), iConsole( aConsole )
       
    64     {
       
    65     }
       
    66     
       
    67 CNATConnFWTestConsoleStubs::~CNATConnFWTestConsoleStubs()
       
    68     {
       
    69     iTimer->Cancel();
       
    70     delete iTimer;
       
    71     delete iLocalCandidate;
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CMediaTestStubs::LocalCandidateL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CNATFWCandidate& CNATConnFWTestConsoleStubs::LocalCandidateL()
       
    80     {
       
    81     RDebug::Print(
       
    82         _L( "TEST PRINT: CNATConnFWTestConsoleStubs::LocalCandidateL" ) );
       
    83     if ( NULL == iLocalCandidate )
       
    84         {
       
    85         User::Leave( KErrNotFound );
       
    86         }
       
    87     return *iLocalCandidate;
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CNATConnFWTestConsoleStubs::StartActiveSchedulerL
       
    93 // ---------------------------------------------------------------------------
       
    94 //    
       
    95 TInt CNATConnFWTestConsoleStubs::StartActiveSchedulerL( TUint aRunningTime )
       
    96     {
       
    97     RDebug::Print( _L( "TEST PRINT: CNATConnFWTestConsoleStubs::StartActiveSchedulerL" ) );
       
    98     iActive = ETrue;
       
    99     if ( aRunningTime )
       
   100         {
       
   101         iTimer->After( aRunningTime );
       
   102         }
       
   103     CActiveScheduler::Start();
       
   104 
       
   105     if ( iTimedExpired )
       
   106         {
       
   107         iTimedExpired = EFalse;
       
   108         return KErrTimedOut;
       
   109         }
       
   110     return KErrNone;
       
   111     }
       
   112  
       
   113  
       
   114 // ---------------------------------------------------------------------------
       
   115 // CNATConnFWTestConsoleStubs::StopActiveScheduler
       
   116 // ---------------------------------------------------------------------------
       
   117 //       
       
   118 void CNATConnFWTestConsoleStubs::StopActiveScheduler()
       
   119     {
       
   120     RDebug::Print( _L(
       
   121         "TEST PRINT: CNATConnFWTestConsoleStubs::StopActiveScheduler" ) );
       
   122     iTimer->Cancel();
       
   123     CActiveScheduler::Stop();
       
   124     iActive = EFalse;
       
   125     }
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CNATConnFWTestConsoleStubs::SetFailureTest
       
   130 // ---------------------------------------------------------------------------
       
   131 //       
       
   132 void CNATConnFWTestConsoleStubs::SetFailureTest( TBool aFailureTest )
       
   133     {
       
   134     iFailureTest = aFailureTest;
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // From class MNATFWConnectivityObserver
       
   140 // CNATConnFWTestConsoleStubs::EventOccured
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CNATConnFWTestConsoleStubs::EventOccured( TUint aSessionId, TUint aStreamId,
       
   144     TNATFWConnectivityEvent aEvent, TInt aError, TAny* aEventData )
       
   145     {
       
   146     _LIT16( KNotify, "TEST PRINT: CNATConnFWTestConsoleStubs::EventOccured, SessionId: %d, StreamId: %d, Event: %S, Error: %d");
       
   147     RDebug::Print(
       
   148         KNotify, aSessionId, aStreamId, &EventDesc( aEvent ), aError );
       
   149         
       
   150     if ( KErrNone != aError && !iFailureTest )
       
   151         {
       
   152         iConsole.Printf( _L( "\n Notify, Event: %S Error: %d\n" ),
       
   153             &EventDesc( aEvent ), aError );
       
   154         }
       
   155      
       
   156    if ( iActive && ( ESessionCreated == aEvent ||
       
   157         EReceivingActivated == aEvent ||
       
   158         EReceivingDeactivated == aEvent ||
       
   159         ESendingActivated == aEvent ||
       
   160         ESendingDeactivated == aEvent ||
       
   161         EFetchingCompleted == aEvent ) ) 
       
   162         {
       
   163         StopActiveScheduler();
       
   164         }
       
   165     if ( iActive && ( ELocalCandidateFound == aEvent ) )
       
   166         {
       
   167         delete iLocalCandidate;
       
   168         iLocalCandidate = NULL;
       
   169         iLocalCandidate = static_cast<CNATFWCandidate*>( aEventData );
       
   170         RDebug::Print( _L( "TEST PRINT: LocalCandidateFound" ) );
       
   171         }
       
   172     }
       
   173 
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CNATConnFWTestConsoleStubs::EventOccured
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 const TDesC16& CNATConnFWTestConsoleStubs::EventDesc( TUint16 aEventVal )
       
   180     {
       
   181     TPtrC16 desc; 
       
   182     switch( aEventVal )
       
   183         {
       
   184         case ESessionCreated:
       
   185             return KESessionCreated();
       
   186         case ELocalCandidateFound:
       
   187             return KELocalCandidateFound();
       
   188         case EFetchingCompleted:
       
   189             return KEFetchingCompleted();
       
   190         case EReceivingActivated:
       
   191             return KEReceivingActivated();
       
   192         case EReceivingDeactivated:
       
   193             return KEReceivingDeactivated();
       
   194         case ESendingActivated:
       
   195             return KESendingActivated();
       
   196         case ESendingDeactivated:
       
   197             return KESendingDeactivated();
       
   198         case ECandidatePairFound:
       
   199             return KECandidatePairFound();
       
   200         case EConnChecksCompleted:
       
   201             return KEConnChecksCompleted();
       
   202         case EGeneralError:
       
   203             return KEGeneralError();
       
   204         case EAllEvents:
       
   205             return KAllEvents();
       
   206         }
       
   207     return KEGeneralError();
       
   208     }
       
   209 
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // From class MTimeoutNotifier
       
   213 // CNATConnFWTestConsoleStubs::TimerExpired
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CNATConnFWTestConsoleStubs::TimerExpired()
       
   217     {
       
   218     _LIT16( KTimerExpired, "TEST PRINT: CNATConnFWTestConsoleStubs::TimerExpired" );
       
   219     RDebug::Print( KTimerExpired );
       
   220         
       
   221     CActiveScheduler::Stop();
       
   222     iActive = EFalse;
       
   223     iTimedExpired = ETrue;
       
   224     }