First public contribution.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\d_medt2.cpp
23 #include <kernel/kernel.h>
24 const TInt KTestDriverBufferMaxSize=0x1000; // 4K
26 class DPhysicalDeviceMediaTest : public DPhysicalDeviceMedia
29 DPhysicalDeviceMediaTest();
30 virtual TInt Install();
31 virtual TInt Remove();
32 virtual void GetCaps(TDes8 &aDes) const;
33 virtual CBase *CreateL(TInt aDevice,const TDesC *anInfo,const TVersion &aVer);
34 virtual TInt Priority();
37 class DMediaDriverTest : public DMediaDriver
41 TInt DoCreate(TMediaDevice aMediaDevice);
42 void DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg);
43 void DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc);
44 void DoFormat(TInt64 &aPos,TInt aLength);
45 TInt Enlarge(TInt aLength);
46 TInt ReduceSize(TInt64 &aPos,TInt aLength);
48 TInt PartitionInfo(TPartitionInfo &anInfo);
49 void Caps(TDes8& aCapsBuf);
51 static void WriteCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
52 static void FormatCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
54 TUint8 iBuf[KTestDriverBufferMaxSize];
55 TTickLink iWriteTickLink;
56 TTickLink iFormatTickLink;
59 DPhysicalDeviceMediaTest::DPhysicalDeviceMediaTest()
64 iUnitsMask=0x1; // Support only one
65 iVersion=TVersion(KMediaDriverInterfaceMajorVersionNumber,KMediaDriverInterfaceMinorVersionNumber,KMediaDriverInterfaceBuildVersionNumber);
68 TInt DPhysicalDeviceMediaTest::Install()
70 // Install the test Media PDD.
74 TPtrC name=_L("Media.Tst2");
75 return(SetName(&name));
78 TInt DPhysicalDeviceMediaTest::Remove()
80 // Remove the test Media PDD.
86 void DPhysicalDeviceMediaTest::GetCaps(TDes8 &/* aDes */) const
88 // Return the media drivers capabilities.
93 CBase *DPhysicalDeviceMediaTest::CreateL(TInt aDevice,const TDesC * /* anInfo */,const TVersion &aVer)
95 // Create a test media driver.
98 if (User::QueryVersionSupported(iVersion,aVer)==EFalse)
99 User::Leave(KErrNotSupported);
100 DMediaDriverTest *mD=new(ELeave) DMediaDriverTest;
101 TInt ret=mD->DoCreate((TMediaDevice)aDevice);
110 TInt DPhysicalDeviceMediaTest::Priority()
112 // Return the priority of this media driver
116 return(KMediaDriverPriorityLow);
119 DMediaDriverTest::DMediaDriverTest()
125 // Mem::FillZ(&iBuf[0],sizeof(iBuf));
126 iFlags=KMediaDrvMultipleReqs;
129 TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice)
131 // Create the media driver.
135 if (!__IS_REMOVABLE(aMediaDevice))
136 return(KErrNotSupported);
137 SetTotalSizeInBytes(KTestDriverBufferMaxSize);
141 void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg)
143 // Read from specified area of media.
148 if (!aTrg.IsCurrentThread())
152 if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone)
154 TDes8 &t=*((TDes8*)aTrg.iPtr);
155 Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength);
156 t.SetLength(aLength+aTrg.iOffset);
159 Complete(KMediaDrvReadReq,ret);
162 const TInt KWriteAsyncTime=100000; // 100mS
163 void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc)
165 // Write to specifed area of media.
169 if (!aSrc.IsCurrentThread())
170 Complete(KMediaDrvWriteReq,KErrGeneral);
173 Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength);
174 iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this);
178 const TInt KFormatAsyncTime=5000000; // 5S
179 void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength)
181 // Format the specified area of the media.
185 Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF);
186 iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this);
189 TInt DMediaDriverTest::Enlarge(TInt /*aLength*/)
195 return(KErrNotSupported);
198 TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/)
200 // Reduce in size the drive
204 return(KErrNotSupported);
207 void DMediaDriverTest::Close()
209 // Close the media driver
213 iWriteTickLink.Cancel();
214 iFormatTickLink.Cancel();
217 TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo)
219 // Return partition information on the media.
223 anInfo.iPartitionCount=1;
224 anInfo.iEntry[0].iPartitionBaseAddr=0;
225 anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes();
229 void DMediaDriverTest::Caps(TDes8& aCapsBuf)
231 // Return the capabilities of the media
234 TLocalDriveCapsV2 caps;
235 caps.iType=EMediaFlash; // Pretend its a Flash device
236 caps.iConnectionBusType=EConnectionBusInternal;
237 caps.iDriveAtt=KDriveAttLocal|KDriveAttRemovable;
238 caps.iMediaAtt=KMediaAttFormattable;
239 caps.iFileSystemId=KDriveFileSysFAT;
240 caps.iHiddenSectors=0;
241 aCapsBuf.FillZ(aCapsBuf.MaxLength());
242 aCapsBuf.Copy((TUint8 *)&caps,Min(aCapsBuf.MaxLength(),sizeof(caps)));
245 void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
247 // Complete a write request
251 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
252 md.Complete(KMediaDrvWriteReq,KErrNone);
256 void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
258 // Complete a format request
262 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
263 md.Complete(KMediaDrvFormatReq,KErrNone);
267 DECLARE_STANDARD_PDD()
269 return new DPhysicalDeviceMediaTest;