|
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_medt1.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.Tst1"); |
|
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 } |
|
127 |
|
128 TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice) |
|
129 // |
|
130 // Create the media driver. |
|
131 // |
|
132 { |
|
133 |
|
134 if (!__IS_REMOVABLE(aMediaDevice)) |
|
135 return(KErrNotSupported); |
|
136 SetTotalSizeInBytes(KTestDriverBufferMaxSize); |
|
137 return(KErrNone); |
|
138 } |
|
139 |
|
140 void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg) |
|
141 // |
|
142 // Read from specified area of media. |
|
143 // |
|
144 { |
|
145 |
|
146 TInt ret=KErrNone; |
|
147 if (!aTrg.IsCurrentThread()) |
|
148 ret=KErrGeneral; |
|
149 else |
|
150 { |
|
151 if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone) |
|
152 { |
|
153 TDes8 &t=*((TDes8*)aTrg.iPtr); |
|
154 Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength); |
|
155 t.SetLength(aLength+aTrg.iOffset); |
|
156 } |
|
157 } |
|
158 Complete(KMediaDrvReadReq,ret); |
|
159 } |
|
160 |
|
161 const TInt KWriteAsyncTime=100000; // 100mS |
|
162 void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc) |
|
163 // |
|
164 // Write to specifed area of media. |
|
165 // |
|
166 { |
|
167 |
|
168 if (!aSrc.IsCurrentThread()) |
|
169 Complete(KMediaDrvWriteReq,KErrGeneral); |
|
170 else |
|
171 { |
|
172 Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength); |
|
173 iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this); |
|
174 } |
|
175 } |
|
176 |
|
177 const TInt KFormatAsyncTime=5000000; // 5S |
|
178 void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength) |
|
179 // |
|
180 // Format the specified area of the media. |
|
181 // |
|
182 { |
|
183 |
|
184 Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF); |
|
185 iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this); |
|
186 } |
|
187 |
|
188 TInt DMediaDriverTest::Enlarge(TInt /*aLength*/) |
|
189 // |
|
190 // Enlarge the drive |
|
191 // |
|
192 { |
|
193 |
|
194 return(KErrNotSupported); |
|
195 } |
|
196 |
|
197 TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/) |
|
198 // |
|
199 // Reduce in size the drive |
|
200 // |
|
201 { |
|
202 |
|
203 return(KErrNotSupported); |
|
204 } |
|
205 |
|
206 void DMediaDriverTest::Close() |
|
207 // |
|
208 // Close the media driver |
|
209 // |
|
210 {} |
|
211 |
|
212 TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo) |
|
213 // |
|
214 // Return partition information on the media. |
|
215 // |
|
216 { |
|
217 |
|
218 anInfo.iPartitionCount=1; |
|
219 anInfo.iEntry[0].iPartitionBaseAddr=0; |
|
220 anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes(); |
|
221 return(KErrNone); |
|
222 } |
|
223 |
|
224 void DMediaDriverTest::Caps(TDes8& aCapsBuf) |
|
225 // |
|
226 // Return the capabilities of the media |
|
227 { |
|
228 |
|
229 TLocalDriveCapsV2 caps; |
|
230 caps.iType=EMediaRam; |
|
231 caps.iBattery=EBatNotSupported; |
|
232 caps.iDriveAtt=KDriveAttLocal|KDriveAttRemovable; |
|
233 caps.iMediaAtt=KMediaAttFormattable; |
|
234 caps.iFileSystemId=KDriveFileSysFAT; |
|
235 caps.iHiddenSectors=0; |
|
236 aCapsBuf.FillZ(aCapsBuf.MaxLength()); |
|
237 aCapsBuf.Copy((TUint8 *)&caps,Min(aCapsBuf.MaxLength(),sizeof(caps))); |
|
238 } |
|
239 |
|
240 void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/) |
|
241 // |
|
242 // Complete a write request |
|
243 // |
|
244 { |
|
245 |
|
246 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver; |
|
247 md.Complete(KMediaDrvWriteReq,KErrNone); |
|
248 return; |
|
249 } |
|
250 |
|
251 void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/) |
|
252 // |
|
253 // Complete a format request |
|
254 // |
|
255 { |
|
256 |
|
257 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver; |
|
258 md.Complete(KMediaDrvFormatReq,KErrNone); |
|
259 return; |
|
260 } |
|
261 |
|
262 DECLARE_STANDARD_PDD() |
|
263 { |
|
264 return(new DPhysicalDeviceMediaTest); |
|
265 } |
|
266 |