sl@0: // Copyright (c) 2006-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 the License "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: // e32test\power\d_lddpowerseqtest.cpp sl@0: // LDD for testing the power up and down sequence sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "d_lddpowerseqtest.h" sl@0: sl@0: sl@0: _LIT(KLitPower1,"PowerSeqTest1"); sl@0: _LIT(KLitPower2,"PowerSeqTest2"); sl@0: sl@0: // sl@0: // Variables to store asynchronous status request and time count user variables address. sl@0: // sl@0: TRequestStatus *aStatus_up1; sl@0: TRequestStatus *aStatus_up2; sl@0: TRequestStatus *aStatus_down1; sl@0: TRequestStatus *aStatus_down2; sl@0: TUint *time_power1down; sl@0: TUint *time_power2down; sl@0: TUint *time_power1up; sl@0: TUint *time_power2up; sl@0: TUint sleepTime; sl@0: sl@0: sl@0: class DTest1; sl@0: // sl@0: // Power handler1 sl@0: // sl@0: class DTest1PowerHandler : public DPowerHandler sl@0: { sl@0: public: sl@0: DTest1PowerHandler(); sl@0: sl@0: void PowerUp(); sl@0: void PowerDown(TPowerState); sl@0: }; sl@0: sl@0: // sl@0: // Power handler2 sl@0: // sl@0: class DTest2PowerHandler : public DPowerHandler sl@0: { sl@0: public: sl@0: DTest2PowerHandler(); sl@0: void PowerUp(); sl@0: void PowerDown(TPowerState); sl@0: }; sl@0: sl@0: class DTestFactory : public DLogicalDevice sl@0: // sl@0: // Test LDD factory sl@0: // sl@0: { sl@0: public: sl@0: DTestFactory(); sl@0: virtual TInt Install(); //overriding pure virtual sl@0: virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual sl@0: }; sl@0: sl@0: class DTest1 : public DLogicalChannelBase sl@0: // sl@0: // Test logical channel sl@0: // sl@0: { sl@0: public: sl@0: virtual ~DTest1(); sl@0: protected: sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); sl@0: DTest1PowerHandler power1; sl@0: DTest2PowerHandler power2; sl@0: }; sl@0: sl@0: sl@0: sl@0: DECLARE_STANDARD_LDD() sl@0: { sl@0: return new DTestFactory; sl@0: } sl@0: sl@0: // sl@0: // Constructor sl@0: // sl@0: DTestFactory::DTestFactory() sl@0: { sl@0: sl@0: } sl@0: sl@0: TInt DTestFactory::Create(DLogicalChannelBase*& aChannel) sl@0: { sl@0: // sl@0: // Create new channel sl@0: // sl@0: aChannel=new DTest1; sl@0: return aChannel?KErrNone:KErrNoMemory; sl@0: } sl@0: sl@0: TInt DTestFactory::Install() sl@0: // sl@0: // Install the LDD - overriding pure virtual sl@0: // sl@0: { sl@0: return SetName(&KLddName); sl@0: } sl@0: sl@0: void DTestFactory::GetCaps(TDes8& /*aDes*/) const sl@0: // sl@0: // Get capabilities - overriding pure virtual sl@0: // sl@0: { sl@0: } sl@0: sl@0: TInt DTest1::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) sl@0: // sl@0: // Create channel sl@0: // sl@0: { sl@0: //try to remove a handler that hasn't been added yet - should not cause any problems sl@0: power1.Remove(); sl@0: //Add power handlers sl@0: power2.Add(); sl@0: power1.Add(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: DTest1::~DTest1() sl@0: // sl@0: // Destructor sl@0: // sl@0: { sl@0: power1.Remove(); sl@0: power2.Remove(); sl@0: //try to remove a handler twice - should not cause any problems sl@0: power2.Remove(); sl@0: } sl@0: sl@0: TInt DTest1::Request(TInt aReqNo, TAny* a1, TAny* a2) sl@0: { sl@0: // sl@0: // Store status requests and time stamp variable for each power up and power down sl@0: // sl@0: sl@0: if(aReqNo<0) sl@0: { sl@0: // 'Request' functions... sl@0: TRequestStatus* s = (TRequestStatus*)a1; sl@0: TAny* args[2]; sl@0: kumemget32(args,a2,sizeof(args)); // get user side arguments sl@0: sl@0: switch(~aReqNo) sl@0: { sl@0: case RLddTest1::EPOWERDOWN_POWER1: sl@0: aStatus_down1 = s; sl@0: time_power1down = (TUint*)args[0]; sl@0: break; sl@0: sl@0: case RLddTest1::EPOWERDOWN_POWER2: sl@0: aStatus_down2 = s; sl@0: time_power2down = (TUint*)args[0]; sl@0: break; sl@0: sl@0: case RLddTest1::EPOWERUP_POWER1: sl@0: aStatus_up1 = s; sl@0: time_power1up = (TUint*)args[0]; sl@0: break; sl@0: sl@0: case RLddTest1::EPOWERUP_POWER2: sl@0: aStatus_up2 = s; sl@0: time_power2up = (TUint*)args[0]; sl@0: break; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // 'Control' functions... sl@0: switch(aReqNo) sl@0: { sl@0: // DoControl sl@0: case RLddTest1::ESET_SLEEPTIME: sl@0: sleepTime = (TUint)a1; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: DTest1PowerHandler::DTest1PowerHandler():DPowerHandler(KLitPower1) sl@0: { sl@0: // sl@0: // Power handler1 constructor sl@0: // sl@0: } sl@0: sl@0: DTest2PowerHandler::DTest2PowerHandler():DPowerHandler(KLitPower2) sl@0: { sl@0: // sl@0: // Power handler2 constructor sl@0: // sl@0: } sl@0: sl@0: sl@0: void DTest1PowerHandler::PowerUp() sl@0: { sl@0: // sl@0: // Sleep for sometime to get different tick counts for comparision. sl@0: // Copy the tick count to user variable and complete the request sl@0: // sl@0: NKern::Sleep(sleepTime); sl@0: sl@0: TUint temp = NKern::TickCount(); sl@0: kumemput(time_power1up, (const TUint *)&temp, sizeof(temp)); sl@0: sl@0: Kern::RequestComplete(aStatus_up1, KErrNone); sl@0: sl@0: PowerUpDone(); sl@0: sl@0: } sl@0: sl@0: void DTest2PowerHandler::PowerUp() sl@0: { sl@0: // sl@0: // Copy the tick count to user variable and complete the request sl@0: // sl@0: sl@0: TUint temp = NKern::TickCount(); sl@0: kumemput(time_power2up, (const TUint *)&temp, sizeof(temp)); sl@0: sl@0: Kern::RequestComplete(aStatus_up2, KErrNone); sl@0: sl@0: PowerUpDone(); sl@0: } sl@0: sl@0: void DTest1PowerHandler::PowerDown(TPowerState /*aState*/) sl@0: { sl@0: // sl@0: // Copy the tick count to user variable and complete the request sl@0: // sl@0: sl@0: TUint temp = NKern::TickCount(); sl@0: kumemput(time_power1down, (const TUint *)&temp, sizeof(temp)); sl@0: sl@0: Kern::RequestComplete(aStatus_down1, KErrNone); sl@0: sl@0: PowerDownDone(); sl@0: } sl@0: sl@0: void DTest2PowerHandler::PowerDown(TPowerState /*aState*/) sl@0: { sl@0: // sl@0: // Sleep for sometime to get different tick counts for comparision. sl@0: // Copy the tick count to user variable and complete the request sl@0: // sl@0: sl@0: NKern::Sleep(sleepTime); sl@0: sl@0: TUint temp = NKern::TickCount(); sl@0: kumemput(time_power2down, (const TUint *)&temp, sizeof(temp)); sl@0: sl@0: Kern::RequestComplete(aStatus_down2, KErrNone); sl@0: sl@0: PowerDownDone(); sl@0: }