multimediacommsengine/tsrc/testdriver/testclient/watcher/src/CTcGrimreaper.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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:  Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CTcGrimreaper.h"
       
    19 #include "WatcherConstants.h"
       
    20 #include "debuglog.h"
       
    21 
       
    22 CTcGrimreaper* CTcGrimreaper::NewL( const RThread& aClient, TInt aTimeout )
       
    23 	{
       
    24 	CTcGrimreaper* self = new( ELeave ) CTcGrimreaper( aTimeout );
       
    25 
       
    26 	CleanupStack::PushL( self );
       
    27 	self->ConstructL( aClient );
       
    28 	CleanupStack::Pop();
       
    29 
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CTcGrimreaper::~CTcGrimreaper()
       
    34 	{
       
    35 	Cancel();
       
    36 	iTimer.Close();
       
    37 	iClient.Close();
       
    38 	}
       
    39 
       
    40 CTcGrimreaper::CTcGrimreaper( TInt aTimeout )
       
    41 	: CActive( EPriorityHigh ),
       
    42 	  iTimeout( aTimeout )
       
    43 	{
       
    44 	CActiveScheduler::Add( this );
       
    45 	}
       
    46 
       
    47 void CTcGrimreaper::ConstructL( const RThread& aClient )
       
    48 	{
       
    49 	// Initialize local client thread handle
       
    50 	User::LeaveIfError( iClient.Open( aClient.Id() ) );
       
    51 
       
    52 	// Create and start timer
       
    53 	User::LeaveIfError( iTimer.CreateLocal() );
       
    54 	NotYet();
       
    55 	}
       
    56 
       
    57 void CTcGrimreaper::DoCancel()
       
    58 	{
       
    59 	iTimer.Cancel();
       
    60 	}
       
    61 
       
    62 void CTcGrimreaper::RunL()
       
    63 	{
       
    64 	// Fatal error occurred, report
       
    65 	User::LeaveIfError( iStatus.Int() );
       
    66 
       
    67 	// Go for the kill, time has ran out.
       
    68 	iClient.Kill( KErrTimedOut );
       
    69 
       
    70 	// Write log entry
       
    71 	LOG( _L("[GRIMREAPER] Client did not report within timeout period. Killed.") );			
       
    72 	}
       
    73 
       
    74 void CTcGrimreaper::NotYet()
       
    75 	{
       
    76 	Cancel();
       
    77 	iTimer.After( iStatus, iTimeout );
       
    78 	SetActive();
       
    79 	}