multimediacommsengine/tsrc/testdriver/testclient/watcher/src/CTcGrimreaper.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 23 Jun 2010 18:38:47 +0300
changeset 34 fc48eff9c76c
parent 0 1bce908db942
permissions -rw-r--r--
Revision: 201023 Kit: 2010125

/*
* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Implementation
*
*/

#include "CTcGrimreaper.h"
#include "WatcherConstants.h"
#include "debuglog.h"

CTcGrimreaper* CTcGrimreaper::NewL( const RThread& aClient, TInt aTimeout )
	{
	CTcGrimreaper* self = new( ELeave ) CTcGrimreaper( aTimeout );

	CleanupStack::PushL( self );
	self->ConstructL( aClient );
	CleanupStack::Pop();

	return self;
	}

CTcGrimreaper::~CTcGrimreaper()
	{
	Cancel();
	iTimer.Close();
	iClient.Close();
	}

CTcGrimreaper::CTcGrimreaper( TInt aTimeout )
	: CActive( EPriorityHigh ),
	  iTimeout( aTimeout )
	{
	CActiveScheduler::Add( this );
	}

void CTcGrimreaper::ConstructL( const RThread& aClient )
	{
	// Initialize local client thread handle
	User::LeaveIfError( iClient.Open( aClient.Id() ) );

	// Create and start timer
	User::LeaveIfError( iTimer.CreateLocal() );
	NotYet();
	}

void CTcGrimreaper::DoCancel()
	{
	iTimer.Cancel();
	}

void CTcGrimreaper::RunL()
	{
	// Fatal error occurred, report
	User::LeaveIfError( iStatus.Int() );

	// Go for the kill, time has ran out.
	iClient.Kill( KErrTimedOut );

	// Write log entry
	LOG( _L("[GRIMREAPER] Client did not report within timeout period. Killed.") );			
	}

void CTcGrimreaper::NotYet()
	{
	Cancel();
	iTimer.After( iStatus, iTimeout );
	SetActive();
	}