sl@0: // Copyright (c) 1998-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\pccd\d_medt2.cpp sl@0: // sl@0: // sl@0: sl@0: #if defined(_UNICODE) sl@0: #if !defined(UNICODE) sl@0: #define UNICODE sl@0: #endif sl@0: #endif sl@0: #include <kernel/kernel.h> sl@0: const TInt KTestDriverBufferMaxSize=0x1000; // 4K sl@0: sl@0: class DPhysicalDeviceMediaTest : public DPhysicalDeviceMedia sl@0: { sl@0: public: sl@0: DPhysicalDeviceMediaTest(); sl@0: virtual TInt Install(); sl@0: virtual TInt Remove(); sl@0: virtual void GetCaps(TDes8 &aDes) const; sl@0: virtual CBase *CreateL(TInt aDevice,const TDesC *anInfo,const TVersion &aVer); sl@0: virtual TInt Priority(); sl@0: }; sl@0: sl@0: class DMediaDriverTest : public DMediaDriver sl@0: { sl@0: public: sl@0: DMediaDriverTest(); sl@0: TInt DoCreate(TMediaDevice aMediaDevice); sl@0: void DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg); sl@0: void DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc); sl@0: void DoFormat(TInt64 &aPos,TInt aLength); sl@0: TInt Enlarge(TInt aLength); sl@0: TInt ReduceSize(TInt64 &aPos,TInt aLength); sl@0: void Close(); sl@0: TInt PartitionInfo(TPartitionInfo &anInfo); sl@0: void Caps(TDes8& aCapsBuf); sl@0: private: sl@0: static void WriteCompleteCallBack(TAny *aMediaDriver,TInt aDelay); sl@0: static void FormatCompleteCallBack(TAny *aMediaDriver,TInt aDelay); sl@0: private: sl@0: TUint8 iBuf[KTestDriverBufferMaxSize]; sl@0: TTickLink iWriteTickLink; sl@0: TTickLink iFormatTickLink; sl@0: }; sl@0: sl@0: DPhysicalDeviceMediaTest::DPhysicalDeviceMediaTest() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: iUnitsMask=0x1; // Support only one sl@0: iVersion=TVersion(KMediaDriverInterfaceMajorVersionNumber,KMediaDriverInterfaceMinorVersionNumber,KMediaDriverInterfaceBuildVersionNumber); sl@0: } sl@0: sl@0: TInt DPhysicalDeviceMediaTest::Install() sl@0: // sl@0: // Install the test Media PDD. sl@0: // sl@0: { sl@0: sl@0: TPtrC name=_L("Media.Tst2"); sl@0: return(SetName(&name)); sl@0: } sl@0: sl@0: TInt DPhysicalDeviceMediaTest::Remove() sl@0: // sl@0: // Remove the test Media PDD. sl@0: // sl@0: { sl@0: return(KErrNone); sl@0: } sl@0: sl@0: void DPhysicalDeviceMediaTest::GetCaps(TDes8 &/* aDes */) const sl@0: // sl@0: // Return the media drivers capabilities. sl@0: // sl@0: { sl@0: } sl@0: sl@0: CBase *DPhysicalDeviceMediaTest::CreateL(TInt aDevice,const TDesC * /* anInfo */,const TVersion &aVer) sl@0: // sl@0: // Create a test media driver. sl@0: // sl@0: { sl@0: if (User::QueryVersionSupported(iVersion,aVer)==EFalse) sl@0: User::Leave(KErrNotSupported); sl@0: DMediaDriverTest *mD=new(ELeave) DMediaDriverTest; sl@0: TInt ret=mD->DoCreate((TMediaDevice)aDevice); sl@0: if (ret!=KErrNone) sl@0: { sl@0: delete mD; sl@0: User::Leave(ret); sl@0: } sl@0: return(mD); sl@0: } sl@0: sl@0: TInt DPhysicalDeviceMediaTest::Priority() sl@0: // sl@0: // Return the priority of this media driver sl@0: // sl@0: { sl@0: sl@0: return(KMediaDriverPriorityLow); sl@0: } sl@0: sl@0: DMediaDriverTest::DMediaDriverTest() sl@0: // sl@0: // Constructor. sl@0: // sl@0: { sl@0: sl@0: // Mem::FillZ(&iBuf[0],sizeof(iBuf)); sl@0: iFlags=KMediaDrvMultipleReqs; sl@0: } sl@0: sl@0: TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice) sl@0: // sl@0: // Create the media driver. sl@0: // sl@0: { sl@0: sl@0: if (!__IS_REMOVABLE(aMediaDevice)) sl@0: return(KErrNotSupported); sl@0: SetTotalSizeInBytes(KTestDriverBufferMaxSize); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg) sl@0: // sl@0: // Read from specified area of media. sl@0: // sl@0: { sl@0: sl@0: TInt ret=KErrNone; sl@0: if (!aTrg.IsCurrentThread()) sl@0: ret=KErrGeneral; sl@0: else sl@0: { sl@0: if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone) sl@0: { sl@0: TDes8 &t=*((TDes8*)aTrg.iPtr); sl@0: Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength); sl@0: t.SetLength(aLength+aTrg.iOffset); sl@0: } sl@0: } sl@0: Complete(KMediaDrvReadReq,ret); sl@0: } sl@0: sl@0: const TInt KWriteAsyncTime=100000; // 100mS sl@0: void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc) sl@0: // sl@0: // Write to specifed area of media. sl@0: // sl@0: { sl@0: sl@0: if (!aSrc.IsCurrentThread()) sl@0: Complete(KMediaDrvWriteReq,KErrGeneral); sl@0: else sl@0: { sl@0: Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength); sl@0: iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this); sl@0: } sl@0: } sl@0: sl@0: const TInt KFormatAsyncTime=5000000; // 5S sl@0: void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength) sl@0: // sl@0: // Format the specified area of the media. sl@0: // sl@0: { sl@0: sl@0: Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF); sl@0: iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this); sl@0: } sl@0: sl@0: TInt DMediaDriverTest::Enlarge(TInt /*aLength*/) sl@0: // sl@0: // Enlarge the drive sl@0: // sl@0: { sl@0: sl@0: return(KErrNotSupported); sl@0: } sl@0: sl@0: TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/) sl@0: // sl@0: // Reduce in size the drive sl@0: // sl@0: { sl@0: sl@0: return(KErrNotSupported); sl@0: } sl@0: sl@0: void DMediaDriverTest::Close() sl@0: // sl@0: // Close the media driver sl@0: // sl@0: { sl@0: sl@0: iWriteTickLink.Cancel(); sl@0: iFormatTickLink.Cancel(); sl@0: } sl@0: sl@0: TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo) sl@0: // sl@0: // Return partition information on the media. sl@0: // sl@0: { sl@0: sl@0: anInfo.iPartitionCount=1; sl@0: anInfo.iEntry[0].iPartitionBaseAddr=0; sl@0: anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: void DMediaDriverTest::Caps(TDes8& aCapsBuf) sl@0: // sl@0: // Return the capabilities of the media sl@0: { sl@0: sl@0: TLocalDriveCapsV2 caps; sl@0: caps.iType=EMediaFlash; // Pretend its a Flash device sl@0: caps.iConnectionBusType=EConnectionBusInternal; sl@0: caps.iDriveAtt=KDriveAttLocal|KDriveAttRemovable; sl@0: caps.iMediaAtt=KMediaAttFormattable; sl@0: caps.iFileSystemId=KDriveFileSysFAT; sl@0: caps.iHiddenSectors=0; sl@0: aCapsBuf.FillZ(aCapsBuf.MaxLength()); sl@0: aCapsBuf.Copy((TUint8 *)&caps,Min(aCapsBuf.MaxLength(),sizeof(caps))); sl@0: } sl@0: sl@0: void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/) sl@0: // sl@0: // Complete a write request sl@0: // sl@0: { sl@0: sl@0: DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver; sl@0: md.Complete(KMediaDrvWriteReq,KErrNone); sl@0: return; sl@0: } sl@0: sl@0: void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/) sl@0: // sl@0: // Complete a format request sl@0: // sl@0: { sl@0: sl@0: DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver; sl@0: md.Complete(KMediaDrvFormatReq,KErrNone); sl@0: return; sl@0: } sl@0: sl@0: DECLARE_STANDARD_PDD() sl@0: { sl@0: return new DPhysicalDeviceMediaTest; sl@0: } sl@0: