|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\pccd\d_medt2.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #if defined(_UNICODE) |
|
19 #if !defined(UNICODE) |
|
20 #define UNICODE |
|
21 #endif |
|
22 #endif |
|
23 #include <kernel/kernel.h> |
|
24 const TInt KTestDriverBufferMaxSize=0x1000; // 4K |
|
25 |
|
26 class DPhysicalDeviceMediaTest : public DPhysicalDeviceMedia |
|
27 { |
|
28 public: |
|
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(); |
|
35 }; |
|
36 |
|
37 class DMediaDriverTest : public DMediaDriver |
|
38 { |
|
39 public: |
|
40 DMediaDriverTest(); |
|
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); |
|
47 void Close(); |
|
48 TInt PartitionInfo(TPartitionInfo &anInfo); |
|
49 void Caps(TDes8& aCapsBuf); |
|
50 private: |
|
51 static void WriteCompleteCallBack(TAny *aMediaDriver,TInt aDelay); |
|
52 static void FormatCompleteCallBack(TAny *aMediaDriver,TInt aDelay); |
|
53 private: |
|
54 TUint8 iBuf[KTestDriverBufferMaxSize]; |
|
55 TTickLink iWriteTickLink; |
|
56 TTickLink iFormatTickLink; |
|
57 }; |
|
58 |
|
59 DPhysicalDeviceMediaTest::DPhysicalDeviceMediaTest() |
|
60 // |
|
61 // Constructor |
|
62 // |
|
63 { |
|
64 iUnitsMask=0x1; // Support only one |
|
65 iVersion=TVersion(KMediaDriverInterfaceMajorVersionNumber,KMediaDriverInterfaceMinorVersionNumber,KMediaDriverInterfaceBuildVersionNumber); |
|
66 } |
|
67 |
|
68 TInt DPhysicalDeviceMediaTest::Install() |
|
69 // |
|
70 // Install the test Media PDD. |
|
71 // |
|
72 { |
|
73 |
|
74 TPtrC name=_L("Media.Tst2"); |
|
75 return(SetName(&name)); |
|
76 } |
|
77 |
|
78 TInt DPhysicalDeviceMediaTest::Remove() |
|
79 // |
|
80 // Remove the test Media PDD. |
|
81 // |
|
82 { |
|
83 return(KErrNone); |
|
84 } |
|
85 |
|
86 void DPhysicalDeviceMediaTest::GetCaps(TDes8 &/* aDes */) const |
|
87 // |
|
88 // Return the media drivers capabilities. |
|
89 // |
|
90 { |
|
91 } |
|
92 |
|
93 CBase *DPhysicalDeviceMediaTest::CreateL(TInt aDevice,const TDesC * /* anInfo */,const TVersion &aVer) |
|
94 // |
|
95 // Create a test media driver. |
|
96 // |
|
97 { |
|
98 if (User::QueryVersionSupported(iVersion,aVer)==EFalse) |
|
99 User::Leave(KErrNotSupported); |
|
100 DMediaDriverTest *mD=new(ELeave) DMediaDriverTest; |
|
101 TInt ret=mD->DoCreate((TMediaDevice)aDevice); |
|
102 if (ret!=KErrNone) |
|
103 { |
|
104 delete mD; |
|
105 User::Leave(ret); |
|
106 } |
|
107 return(mD); |
|
108 } |
|
109 |
|
110 TInt DPhysicalDeviceMediaTest::Priority() |
|
111 // |
|
112 // Return the priority of this media driver |
|
113 // |
|
114 { |
|
115 |
|
116 return(KMediaDriverPriorityLow); |
|
117 } |
|
118 |
|
119 DMediaDriverTest::DMediaDriverTest() |
|
120 // |
|
121 // Constructor. |
|
122 // |
|
123 { |
|
124 |
|
125 // Mem::FillZ(&iBuf[0],sizeof(iBuf)); |
|
126 iFlags=KMediaDrvMultipleReqs; |
|
127 } |
|
128 |
|
129 TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice) |
|
130 // |
|
131 // Create the media driver. |
|
132 // |
|
133 { |
|
134 |
|
135 if (!__IS_REMOVABLE(aMediaDevice)) |
|
136 return(KErrNotSupported); |
|
137 SetTotalSizeInBytes(KTestDriverBufferMaxSize); |
|
138 return(KErrNone); |
|
139 } |
|
140 |
|
141 void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg) |
|
142 // |
|
143 // Read from specified area of media. |
|
144 // |
|
145 { |
|
146 |
|
147 TInt ret=KErrNone; |
|
148 if (!aTrg.IsCurrentThread()) |
|
149 ret=KErrGeneral; |
|
150 else |
|
151 { |
|
152 if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone) |
|
153 { |
|
154 TDes8 &t=*((TDes8*)aTrg.iPtr); |
|
155 Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength); |
|
156 t.SetLength(aLength+aTrg.iOffset); |
|
157 } |
|
158 } |
|
159 Complete(KMediaDrvReadReq,ret); |
|
160 } |
|
161 |
|
162 const TInt KWriteAsyncTime=100000; // 100mS |
|
163 void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc) |
|
164 // |
|
165 // Write to specifed area of media. |
|
166 // |
|
167 { |
|
168 |
|
169 if (!aSrc.IsCurrentThread()) |
|
170 Complete(KMediaDrvWriteReq,KErrGeneral); |
|
171 else |
|
172 { |
|
173 Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength); |
|
174 iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this); |
|
175 } |
|
176 } |
|
177 |
|
178 const TInt KFormatAsyncTime=5000000; // 5S |
|
179 void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength) |
|
180 // |
|
181 // Format the specified area of the media. |
|
182 // |
|
183 { |
|
184 |
|
185 Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF); |
|
186 iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this); |
|
187 } |
|
188 |
|
189 TInt DMediaDriverTest::Enlarge(TInt /*aLength*/) |
|
190 // |
|
191 // Enlarge the drive |
|
192 // |
|
193 { |
|
194 |
|
195 return(KErrNotSupported); |
|
196 } |
|
197 |
|
198 TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/) |
|
199 // |
|
200 // Reduce in size the drive |
|
201 // |
|
202 { |
|
203 |
|
204 return(KErrNotSupported); |
|
205 } |
|
206 |
|
207 void DMediaDriverTest::Close() |
|
208 // |
|
209 // Close the media driver |
|
210 // |
|
211 { |
|
212 |
|
213 iWriteTickLink.Cancel(); |
|
214 iFormatTickLink.Cancel(); |
|
215 } |
|
216 |
|
217 TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo) |
|
218 // |
|
219 // Return partition information on the media. |
|
220 // |
|
221 { |
|
222 |
|
223 anInfo.iPartitionCount=1; |
|
224 anInfo.iEntry[0].iPartitionBaseAddr=0; |
|
225 anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes(); |
|
226 return(KErrNone); |
|
227 } |
|
228 |
|
229 void DMediaDriverTest::Caps(TDes8& aCapsBuf) |
|
230 // |
|
231 // Return the capabilities of the media |
|
232 { |
|
233 |
|
234 TLocalDriveCapsV2 caps; |
|
235 caps.iType=EMediaFlash; // Pretend its a Flash device |
|
236 caps.iBattery=EBatNotSupported; |
|
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))); |
|
243 } |
|
244 |
|
245 void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/) |
|
246 // |
|
247 // Complete a write request |
|
248 // |
|
249 { |
|
250 |
|
251 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver; |
|
252 md.Complete(KMediaDrvWriteReq,KErrNone); |
|
253 return; |
|
254 } |
|
255 |
|
256 void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/) |
|
257 // |
|
258 // Complete a format request |
|
259 // |
|
260 { |
|
261 |
|
262 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver; |
|
263 md.Complete(KMediaDrvFormatReq,KErrNone); |
|
264 return; |
|
265 } |
|
266 |
|
267 DECLARE_STANDARD_PDD() |
|
268 { |
|
269 return new DPhysicalDeviceMediaTest; |
|
270 } |
|
271 |