|
1 // Copyright (c) 2006-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 "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 // |
|
15 |
|
16 #include <mtp/tmtptyperequest.h> |
|
17 #include <mtp/mmtpdataproviderframework.h> |
|
18 #include <mtp/mmtpobjectmgr.h> |
|
19 #include <mtp/cmtptypestorageinfo.h> |
|
20 #include <mtp/cmtptypestring.h> |
|
21 |
|
22 #include "cmtpgetstorageinfo.h" |
|
23 #include "cmtpstoragemgr.h" |
|
24 #include "mtpdevicedpconst.h" |
|
25 #include "mtpdevdppanic.h" |
|
26 #include "rmtpdevicedpsingletons.h" |
|
27 #include "cmtpdevicedpconfigmgr.h" |
|
28 |
|
29 // Class constants. |
|
30 __FLOG_STMT(_LIT8(KComponent,"GetStorageInfo");) |
|
31 |
|
32 /** |
|
33 Verification data for GetStorageInfo request |
|
34 */ |
|
35 const TMTPRequestElementInfo KMTPGetStorageInfoPolicy[] = |
|
36 { |
|
37 {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeStorageId, EMTPElementAttrNone, 0, 0, 0} |
|
38 }; |
|
39 |
|
40 /** |
|
41 Two-phase construction method |
|
42 @param aPlugin The data provider plugin |
|
43 @param aFramework The data provider framework |
|
44 @param aConnection The connection from which the request comes |
|
45 @return a pointer to the created request processor object |
|
46 */ |
|
47 MMTPRequestProcessor* CMTPGetStorageInfo::NewL( |
|
48 MMTPDataProviderFramework& aFramework, |
|
49 MMTPConnection& aConnection) |
|
50 { |
|
51 CMTPGetStorageInfo* self = new (ELeave) CMTPGetStorageInfo(aFramework, aConnection); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 /** |
|
59 Destructor |
|
60 */ |
|
61 CMTPGetStorageInfo::~CMTPGetStorageInfo() |
|
62 { |
|
63 delete iStorageInfo; |
|
64 iSingletons.Close(); |
|
65 __FLOG_CLOSE; |
|
66 } |
|
67 |
|
68 /** |
|
69 Standard c++ constructor |
|
70 */ |
|
71 CMTPGetStorageInfo::CMTPGetStorageInfo( |
|
72 MMTPDataProviderFramework& aFramework, |
|
73 MMTPConnection& aConnection) |
|
74 :CMTPRequestProcessor(aFramework, aConnection,sizeof(KMTPGetStorageInfoPolicy)/sizeof(TMTPRequestElementInfo), KMTPGetStorageInfoPolicy) |
|
75 { |
|
76 } |
|
77 |
|
78 /** |
|
79 GetStorageInfo request handler |
|
80 Build storage info data set and send the data to the initiator |
|
81 */ |
|
82 void CMTPGetStorageInfo::ServiceL() |
|
83 { |
|
84 TUint32 storageId = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
85 |
|
86 if ( iSingletons.StorageMgr().LogicalStorageId(storageId) ) |
|
87 { |
|
88 if ( iSingletons.StorageMgr().LogicalStorageOwner(storageId) == iFramework.DataProviderId() ) |
|
89 { |
|
90 BuildStorageInfoL(); |
|
91 SendDataL(*iStorageInfo); |
|
92 } |
|
93 else |
|
94 { |
|
95 SendResponseL(EMTPRespCodeStoreNotAvailable); |
|
96 } |
|
97 } |
|
98 else if ( iSingletons.StorageMgr().PhysicalStorageId(storageId) ) |
|
99 { |
|
100 if ( iSingletons.StorageMgr().PhysicalStorageOwner(storageId) == iFramework.DataProviderId() ) |
|
101 { |
|
102 BuildStorageInfoL(); |
|
103 SendDataL(*iStorageInfo); |
|
104 } |
|
105 else |
|
106 { |
|
107 SendResponseL(EMTPRespCodeStoreNotAvailable); |
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 // Storage Id is not valid |
|
113 SendResponseL(EMTPRespCodeInvalidStorageID); |
|
114 } |
|
115 } |
|
116 |
|
117 /** |
|
118 Second-phase construction |
|
119 */ |
|
120 void CMTPGetStorageInfo::ConstructL() |
|
121 { |
|
122 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
123 iStorageInfo = CMTPTypeStorageInfo::NewL(); |
|
124 iSingletons.OpenL(); |
|
125 } |
|
126 |
|
127 /** |
|
128 Populate the storage info data set |
|
129 */ |
|
130 void CMTPGetStorageInfo::BuildStorageInfoL() |
|
131 { |
|
132 SetupDriveVolumeInfoL(); |
|
133 SetStorageTypeL(); |
|
134 SetFileSystemTypeL(); |
|
135 SetAccessCapabilityL(); |
|
136 SetMaxCapacityL(); |
|
137 SetFreeSpaceInBytesL(); |
|
138 SetFreeSpaceInObjectsL(); |
|
139 SetStorageDescriptionL(); |
|
140 SetVolumeIdentifierL(); |
|
141 } |
|
142 |
|
143 /** |
|
144 Set the drive volume info in the storage info data set |
|
145 */ |
|
146 void CMTPGetStorageInfo::SetupDriveVolumeInfoL() |
|
147 { |
|
148 TUint32 storageId = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
149 TInt driveNo(iFramework.StorageMgr().DriveNumber(storageId)); |
|
150 User::LeaveIfError(driveNo); |
|
151 RFs& fs = iFramework.Fs(); |
|
152 User::LeaveIfError(fs.Drive(iDriveInfo, driveNo)); |
|
153 User::LeaveIfError(fs.Volume(iVolumeInfo, driveNo)); |
|
154 } |
|
155 |
|
156 /** |
|
157 Set the storage type in the storage info data set |
|
158 */ |
|
159 void CMTPGetStorageInfo::SetStorageTypeL() |
|
160 { |
|
161 TUint16 storageType = EMTPStorageUndefined; |
|
162 switch(iDriveInfo.iType) |
|
163 { |
|
164 case EMediaNotPresent: |
|
165 User::Leave(KErrDisMounted); |
|
166 break; |
|
167 case EMediaUnknown: |
|
168 break; |
|
169 |
|
170 case EMediaCdRom: |
|
171 storageType = EMTPStorageRemovableROM; |
|
172 break; |
|
173 case EMediaRam: |
|
174 case EMediaNANDFlash: |
|
175 storageType = EMTPStorageFixedRAM; |
|
176 break; |
|
177 case EMediaRom: |
|
178 storageType = EMTPStorageFixedROM; |
|
179 break; |
|
180 case EMediaHardDisk: |
|
181 case EMediaFlash: |
|
182 case EMediaRemote: |
|
183 case EMediaFloppy: |
|
184 storageType = EMTPStorageRemovableRAM; |
|
185 break; |
|
186 default: |
|
187 break; |
|
188 } |
|
189 TMTPTypeUint16 mtpStorageType(storageType); |
|
190 iStorageInfo->SetL(CMTPTypeStorageInfo::EStorageType, mtpStorageType); |
|
191 } |
|
192 |
|
193 /** |
|
194 Set the file system type in the storage info data set |
|
195 */ |
|
196 void CMTPGetStorageInfo::SetFileSystemTypeL() |
|
197 { |
|
198 TMTPTypeUint16 mtpFileSystemType(EMTPFileSystemGenericHierarchical); |
|
199 iStorageInfo->SetL(CMTPTypeStorageInfo::EFileSystemType, mtpFileSystemType); |
|
200 } |
|
201 |
|
202 |
|
203 /** |
|
204 Set the access capability in the storage info data set |
|
205 */ |
|
206 void CMTPGetStorageInfo::SetAccessCapabilityL() |
|
207 { |
|
208 TMTPTypeUint16 mtpStorageType; |
|
209 iStorageInfo->GetL(CMTPTypeStorageInfo::EStorageType, mtpStorageType); |
|
210 TUint16 storageType = mtpStorageType.Value(); |
|
211 TInt accessCapability = EAccessCapabilityReadWrite; |
|
212 if(storageType == EMTPStorageFixedROM || storageType == EMTPStorageRemovableROM) |
|
213 { |
|
214 accessCapability = EAccessCapabilityReadOnlyWithoutDeletion; |
|
215 } |
|
216 TMTPTypeUint16 mtpAccessCapability(accessCapability); |
|
217 iStorageInfo->SetL(CMTPTypeStorageInfo::EAccessCapability, mtpAccessCapability); |
|
218 } |
|
219 |
|
220 /** |
|
221 Set the max capacity in the storage info data set |
|
222 */ |
|
223 void CMTPGetStorageInfo::SetMaxCapacityL() |
|
224 { |
|
225 TMTPTypeUint64 mtpMaxCapacity(iVolumeInfo.iSize); |
|
226 iStorageInfo->SetL(CMTPTypeStorageInfo::EMaxCapacity, mtpMaxCapacity); |
|
227 } |
|
228 |
|
229 /** |
|
230 Set the free space of the drive in the storage info data set |
|
231 */ |
|
232 void CMTPGetStorageInfo::SetFreeSpaceInBytesL() |
|
233 { |
|
234 TMTPTypeUint64 mtpFreeSpace(iVolumeInfo.iFree); |
|
235 iStorageInfo->SetL(CMTPTypeStorageInfo::EFreeSpaceInBytes, mtpFreeSpace); |
|
236 } |
|
237 |
|
238 /** |
|
239 Set the free space of in objects in the storage info data set |
|
240 */ |
|
241 void CMTPGetStorageInfo::SetFreeSpaceInObjectsL() |
|
242 { |
|
243 TMTPTypeUint32 mtpFreeSpaceInObj(0xFFFFFFFF); //we don't support this property |
|
244 iStorageInfo->SetL(CMTPTypeStorageInfo::EFreeSpaceInObjects, mtpFreeSpaceInObj); |
|
245 } |
|
246 |
|
247 /** |
|
248 Set the storage description (volume name) of the drive in the storage info data set |
|
249 */ |
|
250 void CMTPGetStorageInfo::SetStorageDescriptionL() |
|
251 { |
|
252 __FLOG(_L8("SetStorageDescriptionL - Entry")); |
|
253 TUint32 storage(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
254 TInt driveNumber = iFramework.StorageMgr().DriveNumber(storage); |
|
255 RBuf volumeName; |
|
256 volumeName.CreateL(KMaxFileName); |
|
257 volumeName.CleanupClosePushL(); |
|
258 RMTPDeviceDpSingletons devSingletons; |
|
259 devSingletons.OpenL(iFramework); |
|
260 CleanupClosePushL(devSingletons); |
|
261 TRAPD(resError, devSingletons.ConfigMgr().GetFriendlyVolumeNameL(driveNumber, volumeName)); |
|
262 if ((KErrNone == resError) && (0 < volumeName.Length())) |
|
263 { |
|
264 __FLOG(_L8("Using volume name from resource file")); |
|
265 CMTPTypeString* mtpDescription = CMTPTypeString::NewLC(volumeName); |
|
266 iStorageInfo->SetL(CMTPTypeStorageInfo::EStorageDescription, *mtpDescription); |
|
267 CleanupStack::PopAndDestroy(mtpDescription); |
|
268 } |
|
269 else if (0 < iVolumeInfo.iName.Length()) |
|
270 { |
|
271 __FLOG(_L8("Using standard volume name")); |
|
272 CMTPTypeString* mtpDescription = CMTPTypeString::NewLC(iVolumeInfo.iName); |
|
273 iStorageInfo->SetL(CMTPTypeStorageInfo::EStorageDescription, *mtpDescription); |
|
274 CleanupStack::PopAndDestroy(mtpDescription); |
|
275 } |
|
276 |
|
277 CleanupStack::PopAndDestroy(&devSingletons); |
|
278 CleanupStack::PopAndDestroy(&volumeName); |
|
279 __FLOG(_L8("SetStorageDescriptionL - Exit")); |
|
280 } |
|
281 |
|
282 /** |
|
283 Set the volume identifier of the drive in the storage info data set |
|
284 */ |
|
285 void CMTPGetStorageInfo::SetVolumeIdentifierL() |
|
286 { |
|
287 // Retrieve the StorageID. |
|
288 TUint32 storage(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
289 |
|
290 // Retrieve the volume info. |
|
291 TVolumeInfo volInfo; |
|
292 iFramework.Fs().Volume(volInfo, iFramework.StorageMgr().DriveNumber(storage)); |
|
293 |
|
294 // Construct the suffix string. |
|
295 RBuf16 suffix; |
|
296 CleanupClosePushL(suffix); |
|
297 suffix.CreateMaxL(KMTPMaxStringCharactersLength); |
|
298 suffix.Format(_L("%08X"), volInfo.iUniqueID); |
|
299 |
|
300 if (volInfo.iName.Length() != 0) |
|
301 { |
|
302 // Append the separator and volume label, truncating if necessary. |
|
303 suffix.Append(_L("-")); |
|
304 suffix.Append(volInfo.iName.Left(KMTPMaxStringCharactersLength - suffix.Length())); |
|
305 } |
|
306 |
|
307 // Generate the volume ID string. |
|
308 CMTPTypeString* volId(iFramework.StorageMgr().VolumeIdL(iFramework.DataProviderId(), storage, suffix)); |
|
309 CleanupStack::PopAndDestroy(&suffix); |
|
310 CleanupStack::PushL(volId); |
|
311 iStorageInfo->SetL(CMTPTypeStorageInfo::EVolumeIdentifier, *volId); |
|
312 CleanupStack::PopAndDestroy(volId); |
|
313 } |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |