sl@0: // Copyright (c) 2007-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 sl@0: #include "t_app1eng.h" sl@0: #include "t_inidata.h" sl@0: #include "t_wservconsts.h" sl@0: sl@0: sl@0: _LIT(KTApp1ScrMode, "KTApp1ScrMode%d"); sl@0: _LIT(KTApp1Rotation, "KTApp1Rotation%d"); sl@0: _LIT(KTApp1PanicTxt, "t_app1.exe"); sl@0: sl@0: // sl@0: // class CTApp1Eng sl@0: // sl@0: CTApp1Eng::CTApp1Eng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow) sl@0: : CTimer(CActive::EPriorityLow), sl@0: iClient(aClient), sl@0: iWindow(aWindow), sl@0: iScreenDevice(aScreenDevice), sl@0: iDrawing(EFalse), sl@0: iRotationFlag(EFalse) sl@0: { sl@0: } sl@0: sl@0: CTApp1Eng* CTApp1Eng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow) sl@0: { sl@0: CTApp1Eng* self = new (ELeave) CTApp1Eng(aClient, aScreenDevice, aWindow); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); // self; sl@0: return self; sl@0: } sl@0: sl@0: CTApp1Eng::~CTApp1Eng() sl@0: { sl@0: if(IsActive()) sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: iRotationList.Close(); sl@0: iScrModeList.Close(); sl@0: iSemaphore.Close(); sl@0: } sl@0: sl@0: void CTApp1Eng::ConstructL() sl@0: { sl@0: CTimer::ConstructL(); sl@0: User::LeaveIfError(iScreenDevice.CreateContext(iGc)); sl@0: sl@0: HBufC* rotFlag = NULL; sl@0: READ_STR(KTApp1RotationFlag, KWServTApp1ConfigFile, rotFlag); sl@0: sl@0: // check to see if instead of the default behaviour of drawing to sl@0: // window with alternate frames of red/blue, that the app is to sl@0: // periodically cause the screen to rotate, which is all defined sl@0: // in the configuration file created by the test step sl@0: if (rotFlag!=NULL && rotFlag->Des().Compare(_L("ETrue")) == KErrNone) sl@0: { sl@0: delete rotFlag; sl@0: iRotationFlag=ETrue; sl@0: sl@0: // setup rotation and screen mode lists sl@0: TBool moreData=ETrue; sl@0: TInt index=0; sl@0: TBuf<255> tempStore; sl@0: CIniData * iniData = CIniData::NewL(KWServTApp1ConfigFile); sl@0: CleanupStack::PushL(iniData); sl@0: sl@0: // read in rotations to be performed sl@0: while (moreData) sl@0: { sl@0: TInt scrMode; sl@0: tempStore.Format(KTApp1ScrMode, ++index); sl@0: moreData = iniData->FindVar(KDefaultSectionName, tempStore, scrMode); sl@0: if (moreData) sl@0: { sl@0: TInt rotation; sl@0: tempStore.Format(KTApp1Rotation, index); sl@0: moreData = iniData->FindVar(KDefaultSectionName, tempStore, rotation); sl@0: if (moreData) sl@0: { sl@0: RDebug::Print(_L("CTApp1Eng::ConstructL - Screen Mode: %d, Rotation: %d"),scrMode,rotation); sl@0: iRotationList.AppendL(rotation); sl@0: iScrModeList.AppendL(scrMode); sl@0: } sl@0: else sl@0: { sl@0: User::Panic(KTApp1PanicTxt(), KErrNotFound); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: moreData=EFalse; sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(iniData); sl@0: sl@0: // setup the number of frames to be counted between each sl@0: // screen rotation sl@0: TInt iters = 0; sl@0: READ_INT(KTApp1Iterations, KWServTApp1ConfigFile, iters); sl@0: iRotationTimer = iters/(iRotationList.Count()+1); sl@0: RDebug::Print(_L("CTApp1Eng::ConstructL - Rotation Timer: %d"), iRotationTimer); sl@0: sl@0: if (iRotationList.Count()==0) sl@0: { sl@0: User::Panic(KTApp1PanicTxt(), KErrNotFound); sl@0: } sl@0: } sl@0: User::LeaveIfError(iSemaphore.OpenGlobal(KWservDsaSemaphoreName)); sl@0: sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CTApp1Eng::StartDrawing() sl@0: { sl@0: if (iDrawing) sl@0: { sl@0: User::Panic(KTApp1PanicTxt(), TApp1EngAlreadyStarted); sl@0: } sl@0: sl@0: iDrawing=ETrue; sl@0: sl@0: After(TTimeIntervalMicroSeconds32(0)); sl@0: } sl@0: sl@0: void CTApp1Eng::StopDrawing() sl@0: { sl@0: if (!iDrawing) sl@0: { sl@0: User::Panic(KTApp1PanicTxt(), TApp1EngAlreadyStopped); sl@0: } sl@0: sl@0: // Cancel timer and display sl@0: Cancel(); sl@0: iDrawing = EFalse; sl@0: } sl@0: sl@0: sl@0: // Timer's RunL() sl@0: void CTApp1Eng::RunL() sl@0: { sl@0: iFrameCount++; sl@0: sl@0: if (iFrameCount==1) sl@0: { sl@0: RDebug::Print(_L("CTApp1Eng::RunL - Rotation Flag: %d"), iRotationFlag); sl@0: } sl@0: sl@0: // just draw to window, with alternate frames of red and blue sl@0: if (iRotationFlag==EFalse) sl@0: { sl@0: iGc->Activate(iWindow); sl@0: TRect myRect(iWindow.Size()); sl@0: TRgb color(0,0,255); sl@0: sl@0: if (iFrameCount%2) sl@0: { sl@0: color.SetRed(255); sl@0: color.SetBlue(0); sl@0: } sl@0: sl@0: iGc->SetBrushColor(color); sl@0: iWindow.SetBackgroundColor(color); sl@0: iGc->SetPenColor(color); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: iGc->DrawRect(myRect); sl@0: iGc->Deactivate(); sl@0: sl@0: iDrawing=EFalse; sl@0: iWindow.Invalidate(); sl@0: } sl@0: // else rotate screen sl@0: else sl@0: { sl@0: if (iFrameCount==iRotationTimer) sl@0: { sl@0: iSemaphore.Signal(); sl@0: iFrameCount=0; sl@0: sl@0: if (iRotationCount