sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @file
sl@0:  @test
sl@0:  @internalComponent
sl@0: */
sl@0: 
sl@0: #include "stresslet.h"
sl@0: #include "panic.h"
sl@0: 
sl@0: //
sl@0: // CStresslet::CRedrawHandler
sl@0: //
sl@0: 
sl@0: CStresslet::CRedrawHandler* CStresslet::CRedrawHandler::NewL(CStresslet& aStresslet)
sl@0: 	{
sl@0: 	CRedrawHandler * self = new (ELeave) CRedrawHandler(aStresslet);
sl@0: 	CleanupStack::PushL (self);
sl@0: 	self->ConstructL ();
sl@0: 	CleanupStack::Pop ();	
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: CStresslet::CRedrawHandler::~CRedrawHandler ()
sl@0: 	{
sl@0: 	Cancel ();
sl@0: 	}
sl@0: 
sl@0: CStresslet::CRedrawHandler::CRedrawHandler(CStresslet& aStresslet) :
sl@0: 	CActive(EPriorityNormal), iStresslet(aStresslet)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: void CStresslet::CRedrawHandler::ConstructL ()
sl@0: 	{
sl@0: 	CActiveScheduler::Add (this);
sl@0: 	iStresslet.Session().RedrawReady (&iStatus);
sl@0: 	SetActive ();
sl@0: 	}
sl@0: 
sl@0: void CStresslet::CRedrawHandler::RunL ()
sl@0: 	{
sl@0: 	iStresslet.Session().GetRedraw (iRedrawEvent);
sl@0: 
sl@0: 	if(iRedrawEvent.Handle () != 0)
sl@0: 		{
sl@0: 		iStresslet.HandleRedraw (iRedrawEvent);
sl@0: 		}
sl@0: 
sl@0: 	iStresslet.Session().RedrawReady (&iStatus); 
sl@0: 	SetActive ();								 
sl@0: 	}
sl@0: 
sl@0: void CStresslet::CRedrawHandler::DoCancel ()
sl@0: 	{
sl@0: 	iStresslet.Session().RedrawReadyCancel ();
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // CStresslet::CEventHandler
sl@0: //
sl@0: 
sl@0: CStresslet::CEventHandler* CStresslet::CEventHandler::NewL (CStresslet& aStresslet)
sl@0: 	{
sl@0: 	CEventHandler * self = new (ELeave) CEventHandler(aStresslet);
sl@0: 	CleanupStack::PushL (self);
sl@0: 	self->ConstructL ();
sl@0: 	CleanupStack::Pop (); 
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: CStresslet::CEventHandler::~CEventHandler ()
sl@0: 	{
sl@0: 	Cancel ();
sl@0: 	}
sl@0: 
sl@0: CStresslet::CEventHandler::CEventHandler (CStresslet& aStresslet) :
sl@0: 	CActive(EPriorityNormal), iStresslet(aStresslet)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: void CStresslet::CEventHandler::ConstructL ()
sl@0: 	{
sl@0: 	CActiveScheduler::Add (this);
sl@0: 	iStresslet.Session().EventReady (&iStatus);
sl@0: 	SetActive ();
sl@0: 	}
sl@0: 
sl@0: void CStresslet::CEventHandler::RunL ()
sl@0: 	{
sl@0: 	iStresslet.Session().GetEvent (iEvent);
sl@0: 
sl@0: 	iStresslet.HandleEvent (iEvent);
sl@0: 	
sl@0: 	iStresslet.Session().EventReady (&iStatus);		
sl@0: 	SetActive ();									
sl@0: 	
sl@0: 	}
sl@0: 
sl@0: void CStresslet::CEventHandler::DoCancel ()
sl@0: 	{
sl@0: 	iStresslet.Session().EventReadyCancel ();
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // CStresslet::CStresslet
sl@0: //
sl@0: 
sl@0: CStresslet::CStresslet (MTestStepReporter& aReporter) :
sl@0: 	iReporter(aReporter)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: MTestStepReporter& CStresslet::Reporter ()
sl@0: 	{
sl@0: 	return iReporter;
sl@0: 	}
sl@0: 
sl@0: void CStresslet::ConcludeNow (void)
sl@0: 	{
sl@0: 	CActiveScheduler::Stop ();
sl@0: 	}
sl@0: 
sl@0: void CStresslet::LaunchL (CStresslet* aStresslet)
sl@0: 	{
sl@0: 	CStresslet* obj = aStresslet;
sl@0: 
sl@0: 	CActiveScheduler* runner = new (ELeave) CActiveScheduler;
sl@0: 	CleanupStack::PushL (runner);
sl@0: 	CActiveScheduler::Install (runner);
sl@0: 
sl@0: 	obj->ConstructL();
sl@0: 	
sl@0: 	CActiveScheduler::Start (); //runner
sl@0: 
sl@0: 	delete obj;
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy (runner);
sl@0: 	}
sl@0: 
sl@0: void CStresslet::ConstructL()
sl@0: 	{
sl@0: 	User::LeaveIfError(iWs.Connect());
sl@0: 	iRedrawHandler = CRedrawHandler::NewL (*this);
sl@0: 	iEventHandler = CEventHandler::NewL (*this);
sl@0: 	iScreenDevice = new (ELeave)CWsScreenDevice(iWs);
sl@0: 	User::LeaveIfError(iScreenDevice->Construct ());
sl@0: 	User::LeaveIfError(iScreenDevice->CreateContext (iGc));
sl@0: 	StartL ();
sl@0: 	}
sl@0: 
sl@0: CStresslet::~CStresslet ()
sl@0: 	{
sl@0: 	delete iRedrawHandler;
sl@0: 	delete iEventHandler;
sl@0: 	iWs.Close ();
sl@0: 	}
sl@0: 
sl@0: RWsSession& CStresslet::Session ()
sl@0: 	{
sl@0: 	return iWs;
sl@0: 	}
sl@0: 
sl@0: CWindowGc& CStresslet::WindowGc()
sl@0: 	{
sl@0: 	__ASSERT_ALWAYS(iGc, Panic(EPanic1));
sl@0: 	return *iGc;
sl@0: 	}