kerneltest/e32test/usbho/t_otgdi/src/testcasewd.cpp
changeset 0 a41df078684a
child 43 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // testengine.cpp
       
    15 // @internalComponent
       
    16 // Test Case watchdog implementation
       
    17 // 
       
    18 //
       
    19 
       
    20 #include <e32std.h>
       
    21 #include <e32std_private.h>
       
    22 #include <u32std.h> 	// unicode builds
       
    23 #include <e32base.h>
       
    24 #include <e32base_private.h>
       
    25 #include <e32cons.h>
       
    26 #include <e32Test.h>	// RTest headder
       
    27 #include "testcaseroot.h"
       
    28 #include "TestCasewd.h"
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 const TInt KMagicNumberWDogValid	= 0xF143F00D;
       
    34 _LIT(KMsgWatchdogPanicd, "Test Case watchdog error");
       
    35 
       
    36 //
       
    37 // CTestCaseWatchdog: Timer for any OTG event (async calls) time-outs
       
    38 //
       
    39 
       
    40 CTestCaseWatchdog::CTestCaseWatchdog()
       
    41     : CTimer(EPriorityUserInput)
       
    42     {
       
    43     }
       
    44     
       
    45 
       
    46 CTestCaseWatchdog::~CTestCaseWatchdog()
       
    47     {
       
    48 	Cancel();
       
    49 	iValidConstr = 0;
       
    50     }
       
    51     
       
    52 
       
    53 CTestCaseWatchdog* CTestCaseWatchdog::NewL()
       
    54     {
       
    55     CTestCaseWatchdog *self = new (ELeave) CTestCaseWatchdog();
       
    56     CleanupStack::PushL(self);
       
    57 	self->ConstructL();
       
    58 	CleanupStack::Pop();
       
    59     return self;
       
    60     }
       
    61     
       
    62 
       
    63 void CTestCaseWatchdog::ConstructL()
       
    64     {
       
    65 	iValidConstr = KMagicNumberWDogValid;
       
    66 	CTimer::ConstructL();
       
    67 	CActiveScheduler::Add(this);
       
    68     }
       
    69     
       
    70 
       
    71 void CTestCaseWatchdog::RunL()
       
    72 // Timer request has completed, so notify the timer's owner that we timed out
       
    73     {
       
    74 	LOG_FUNC
       
    75 	__ASSERT_ALWAYS(iCancelFriendFunc, User::Panic(KMsgWatchdogPanicd, EPanicWatchdogError));
       
    76 	__ASSERT_ALWAYS(iThisPointer, User::Panic(KMsgWatchdogPanicd, EPanicWatchdogError));
       
    77 	(*iCancelFriendFunc)(iThisPointer);
       
    78 	iCancelFriendFunc = NULL;
       
    79 	}
       
    80 	
       
    81 
       
    82 // call back setup
       
    83 void CTestCaseWatchdog::IssueRequest(TInt aWatchdogIntervalMS, 
       
    84 		CTestCaseRoot* pRoot, 
       
    85 		WDCancellerMethod cancelMethod)
       
    86 	{
       
    87 	LOG_VERBOSE2(_L("Watchdogging this step for %d ms\n"), aWatchdogIntervalMS);
       
    88 	if (IsValid())
       
    89 		{
       
    90 		Cancel();
       
    91 		
       
    92 		iThisPointer = pRoot;				// save caller instance data
       
    93 		iCancelFriendFunc = cancelMethod;	// save cancel handler
       
    94 		iMSRequested = aWatchdogIntervalMS;
       
    95 		After(aWatchdogIntervalMS * 1000);	// convert to uS
       
    96 		}
       
    97 	}
       
    98 	
       
    99 	
       
   100 /** IsValid
       
   101  A common mistake is to not new() this event source and start using it before instantiation
       
   102 */
       
   103 TBool CTestCaseWatchdog::IsValid()
       
   104 	{
       
   105 	// return ETrue if the object is validly constructed
       
   106 	// This is test code, or else we would ifdef this out
       
   107 	if (KMagicNumberWDogValid!= iValidConstr)
       
   108 		{
       
   109 		
       
   110 		test.Printf(_L("CTestCaseWatchdog obj not properly constructed!\n"));
       
   111 		return(EFalse);
       
   112 		}
       
   113 	return(ETrue);	
       
   114 	}
       
   115 
       
   116 
       
   117