|
1 // Copyright (c) 2008-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 // mw/remoteconn/mtpfws/mtpfw/dataproviders/dputility/src/cmtpknowledgehandler.cpp |
|
15 |
|
16 #include <bautils.h> |
|
17 #include <centralrepository.h> |
|
18 #include <mtp/cmtptypestring.h> |
|
19 #include <mtp/cmtpobjectmetadata.h> |
|
20 #include <mtp/cmtptypeobjectinfo.h> |
|
21 #include <mtp/cmtptypeobjectproplist.h> |
|
22 #include <mtp/mmtpdataproviderframework.h> |
|
23 #include <mtp/mmtpobjectmgr.h> |
|
24 #include <mtp/cmtptypefile.h> |
|
25 #include <mtp/mtpdatatypeconstants.h> |
|
26 |
|
27 #include "cmtpknowledgehandler.h" |
|
28 |
|
29 // Class constants. |
|
30 __FLOG_STMT(_LIT8(KComponent,"KwgObjHdler");) |
|
31 |
|
32 const TInt KDateTimeMaxLength = 22; |
|
33 const TInt KNameMaxLength = 255; |
|
34 |
|
35 _LIT16(KEmptyContent16, ""); |
|
36 _LIT(KMTPKnowledgeObjDriveLocation, "c:"); |
|
37 _LIT(KMTPNoBackupFolder, "nobackup\\"); |
|
38 _LIT(KMTPSlash, "\\"); |
|
39 _LIT(KMTPKnowledgeObjFileName, "mtp_knowledgeobj.dat"); |
|
40 _LIT(KMTPKnowledgeObjSwpFileName, "mtp_knowledgeobj.swp"); |
|
41 |
|
42 EXPORT_C CMTPKnowledgeHandler* CMTPKnowledgeHandler::NewL(MMTPDataProviderFramework& aFramework, TUint16 aFormatCode, |
|
43 CRepository& aReposotry, const TDesC& aKwgSuid) |
|
44 { |
|
45 CMTPKnowledgeHandler *self = new (ELeave) CMTPKnowledgeHandler(aFramework, aFormatCode, aReposotry, aKwgSuid); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 EXPORT_C CMTPKnowledgeHandler::~CMTPKnowledgeHandler() |
|
53 { |
|
54 __FLOG(_L8("~CMTPKnowledgeHandler - Entry")); |
|
55 delete iDateModified; |
|
56 delete iName; |
|
57 delete iKnowledgeObj; |
|
58 delete iKnowledgeSwpBuffer; |
|
59 __FLOG(_L8("~CMTPKnowledgeHandler - Exit")); |
|
60 __FLOG_CLOSE; |
|
61 } |
|
62 |
|
63 CMTPKnowledgeHandler::CMTPKnowledgeHandler(MMTPDataProviderFramework& aFramework, TUint16 aFormatCode, |
|
64 CRepository& aReposotry, const TDesC& aKwgSuid) : |
|
65 iFramework(aFramework), iRepository(aReposotry), iKnowledgeFormatCode(aFormatCode), |
|
66 iKnowledgeObjectSize(KObjectSizeNotAvaiable), iCacheStatus(EOK), iSuid(aKwgSuid) |
|
67 { |
|
68 } |
|
69 |
|
70 void CMTPKnowledgeHandler::ConstructL() |
|
71 { |
|
72 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
73 __FLOG(_L8("Construct - Entry")); |
|
74 |
|
75 iFramework.Fs().PrivatePath(iKnowObjFileName); |
|
76 iKnowObjFileName.Insert(0, KMTPKnowledgeObjDriveLocation); |
|
77 iKnowObjFileName.Append(KMTPNoBackupFolder); |
|
78 iKnowObjFileName.Append(iSuid); |
|
79 iKnowObjFileName.Append(KMTPSlash); |
|
80 |
|
81 iKnowObjSwpFileName.Append(iKnowObjFileName); |
|
82 iKnowObjSwpFileName.Append(KMTPKnowledgeObjSwpFileName); |
|
83 |
|
84 iKnowObjFileName.Append(KMTPKnowledgeObjFileName); |
|
85 |
|
86 // Create knowledge object file directory if not exist. |
|
87 BaflUtils::EnsurePathExistsL(iFramework.Fs(), iKnowObjFileName); |
|
88 |
|
89 // Recover for previous failed transaction |
|
90 if(BaflUtils::FileExists(iFramework.Fs(), iKnowObjSwpFileName)) |
|
91 { |
|
92 // In case DP received some object content |
|
93 User::LeaveIfError(iFramework.Fs().Delete(iKnowObjSwpFileName)); |
|
94 } |
|
95 |
|
96 LoadKnowledgeObjPropertiesL(); |
|
97 __FLOG(_L8("ConstructL - Exit")); |
|
98 } |
|
99 |
|
100 EXPORT_C void CMTPKnowledgeHandler::SetStorageId(TUint32 aStorageId) |
|
101 { |
|
102 iStorageID = aStorageId; |
|
103 } |
|
104 |
|
105 void CMTPKnowledgeHandler::CommitL() |
|
106 { |
|
107 __FLOG(_L8("CommitL - Entry")); |
|
108 |
|
109 User::LeaveIfError(iRepository.StartTransaction(CRepository::EReadWriteTransaction)); |
|
110 iRepository.CleanupCancelTransactionPushL(); |
|
111 if(iKnowledgeObjectSize != KObjectSizeNotAvaiable) |
|
112 { |
|
113 User::LeaveIfError(iRepository.Set(ESize, (TInt)iKnowledgeObjectSize)); |
|
114 } |
|
115 if(iDateModified) |
|
116 { |
|
117 User::LeaveIfError(iRepository.Set(EDateModified, *iDateModified)); |
|
118 } |
|
119 if(iName) |
|
120 { |
|
121 User::LeaveIfError(iRepository.Set(EName, *iName)); |
|
122 } |
|
123 |
|
124 if (EMTPRespCodeOK != SetColumnType128Value(ELastAuthorProxyID, iLastAuthorProxyID)) |
|
125 { |
|
126 User::Leave(KErrGeneral); |
|
127 } |
|
128 // Close all knowledge file and reset pointer. |
|
129 if (iKnowledgeObj) |
|
130 { |
|
131 delete iKnowledgeObj; |
|
132 iKnowledgeObj = NULL; |
|
133 } |
|
134 |
|
135 if (iKnowledgeSwpBuffer) |
|
136 { |
|
137 delete iKnowledgeSwpBuffer; |
|
138 iKnowledgeSwpBuffer = NULL; |
|
139 } |
|
140 |
|
141 if(BaflUtils::FileExists(iFramework.Fs(), iKnowObjSwpFileName)) |
|
142 { |
|
143 // In case DP received some object content |
|
144 User::LeaveIfError(iFramework.Fs().Replace(iKnowObjSwpFileName, iKnowObjFileName)); |
|
145 } |
|
146 // If swp file isn't exsited, that means 0 sized object received, need do nothing. |
|
147 |
|
148 TUint32 keyInfo; |
|
149 User::LeaveIfError(iRepository.CommitTransaction(keyInfo)); |
|
150 CleanupStack::Pop(&iRepository); |
|
151 __FLOG(_L8("CommitL - Exit")); |
|
152 } |
|
153 |
|
154 void CMTPKnowledgeHandler::CommitForNewObjectL(TDes& aSuid) |
|
155 { |
|
156 aSuid = iSuid; |
|
157 CommitL(); |
|
158 } |
|
159 |
|
160 void CMTPKnowledgeHandler::RollBack() |
|
161 { |
|
162 __FLOG(_L8("Rollback - Entry")); |
|
163 TRAP_IGNORE(LoadKnowledgeObjPropertiesL()); |
|
164 __FLOG(_L8("Rollback - Exit")); |
|
165 } |
|
166 |
|
167 EXPORT_C void CMTPKnowledgeHandler::GetObjectSuidL(TDes& aSuid) const |
|
168 { |
|
169 __FLOG(_L8("GetObjectSuidL - Entry")); |
|
170 if(iKnowledgeObjectSize != KObjectSizeNotAvaiable) |
|
171 { |
|
172 aSuid.Append(iSuid); |
|
173 } |
|
174 __FLOG(_L8("GetObjectSuidL - Exit")); |
|
175 } |
|
176 |
|
177 void CMTPKnowledgeHandler::LoadKnowledgeObjPropertiesL() |
|
178 { |
|
179 __FLOG(_L8("LoadKnowledgeObjPropertiesL - Entry")); |
|
180 iCacheStatus = EOK; |
|
181 iCacheStatusFlag = EDirty; |
|
182 TCleanupItem cacheDroper(DropCacheWrapper, this); |
|
183 CleanupStack::PushL(cacheDroper); |
|
184 TInt objSize; |
|
185 User::LeaveIfError(iRepository.Get(ESize, objSize)); |
|
186 iKnowledgeObjectSize = objSize; |
|
187 |
|
188 // Load DateModify |
|
189 delete iDateModified; |
|
190 iDateModified = NULL; |
|
191 iDateModified = HBufC::NewL(KDateTimeMaxLength); |
|
192 TPtr ptrDate(iDateModified->Des()); |
|
193 User::LeaveIfError(iRepository.Get(EDateModified, ptrDate)); |
|
194 |
|
195 // Load Name |
|
196 delete iName; |
|
197 iName = NULL; |
|
198 iName = HBufC::NewL(KNameMaxLength); |
|
199 TPtr ptrName(iName->Des()); |
|
200 User::LeaveIfError(iRepository.Get(EName, ptrName)); |
|
201 |
|
202 // Load LastAuthorProxyID: |
|
203 TPtr8 writeBuf(NULL, 0); //walkaroud for the TMTPTypeUint128 |
|
204 iLastAuthorProxyID.FirstWriteChunk(writeBuf); |
|
205 User::LeaveIfError(iRepository.Get(ELastAuthorProxyID, writeBuf)); |
|
206 CleanupStack::Pop(this); |
|
207 // Doesn't load object content to cache beacause it can grow up to 100KB |
|
208 __FLOG(_L8("LoadKnowledgeObjPropertiesL - Exit")); |
|
209 } |
|
210 |
|
211 void CMTPKnowledgeHandler::DropCacheWrapper(TAny* aObject) |
|
212 { |
|
213 reinterpret_cast<CMTPKnowledgeHandler*>(aObject)->DropKnowledgeObjPropertiesCache(); |
|
214 } |
|
215 |
|
216 void CMTPKnowledgeHandler::DropKnowledgeObjPropertiesCache() |
|
217 { |
|
218 __FLOG(_L8("DropKnowledgeObjPropertiesCache - Entry")); |
|
219 iCacheStatus = iCacheStatusFlag; |
|
220 iKnowledgeObjectSize = KObjectSizeNotAvaiable; |
|
221 |
|
222 // Load DateModify |
|
223 delete iDateModified; |
|
224 iDateModified = NULL; |
|
225 |
|
226 // Load Name |
|
227 delete iName; |
|
228 iName = NULL; |
|
229 |
|
230 // Reset LastAuthorProxyID |
|
231 TMTPTypeUint128 tmp(MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32), |
|
232 MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32)); |
|
233 iLastAuthorProxyID.Set(tmp.UpperValue(), tmp.LowerValue()); |
|
234 __FLOG(_L8("DropKnowledgeObjPropertiesCache - Exit")); |
|
235 } |
|
236 |
|
237 TMTPResponseCode CMTPKnowledgeHandler::SendObjectInfoL(const CMTPTypeObjectInfo& aObjectInfo, TUint32& aParentHandle, TDes& aSuid) |
|
238 { |
|
239 __FLOG(_L("SendObjectInfoL - Entry")); |
|
240 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
241 if (aParentHandle != KMTPHandleNone && aParentHandle != KMTPHandleNoParent) |
|
242 { |
|
243 responseCode = EMTPRespCodeInvalidParentObject; |
|
244 } |
|
245 else |
|
246 { |
|
247 //if there's a read error reread |
|
248 if(EDirty == iCacheStatus) |
|
249 { |
|
250 LoadKnowledgeObjPropertiesL(); |
|
251 } |
|
252 //already has a knowledge object |
|
253 if(iKnowledgeObjectSize != KObjectSizeNotAvaiable) |
|
254 { |
|
255 responseCode = EMTPRespCodeAccessDenied; |
|
256 } |
|
257 else |
|
258 { |
|
259 iKnowledgeObjectSize = aObjectInfo.Uint32L(CMTPTypeObjectInfo::EObjectCompressedSize); |
|
260 delete iDateModified; |
|
261 iDateModified = NULL; |
|
262 iDateModified = aObjectInfo.StringCharsL(CMTPTypeObjectInfo::EDateModified).AllocL(); |
|
263 aSuid = iSuid; |
|
264 } |
|
265 } |
|
266 __FLOG(_L("SendObjectInfoL - Exit")); |
|
267 return responseCode; |
|
268 } |
|
269 |
|
270 TMTPResponseCode CMTPKnowledgeHandler::SendObjectPropListL(TUint64 aObjectSize, const CMTPTypeObjectPropList& /*aObjectPropList*/, |
|
271 TUint32& aParentHandle, TDes& aSuid) |
|
272 { |
|
273 __FLOG(_L8("SendObjectPropListL - Entry")); |
|
274 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
275 if (aParentHandle != KMTPHandleNone && aParentHandle != KMTPHandleNoParent) |
|
276 { |
|
277 responseCode = EMTPRespCodeInvalidParentObject; |
|
278 } |
|
279 else |
|
280 { |
|
281 //if there's a read error reread |
|
282 aParentHandle = KMTPHandleNoParent; |
|
283 if(EDirty == iCacheStatus) |
|
284 { |
|
285 LoadKnowledgeObjPropertiesL(); |
|
286 } |
|
287 //already has a knowledge object |
|
288 if(iKnowledgeObjectSize != KObjectSizeNotAvaiable) |
|
289 { |
|
290 responseCode = EMTPRespCodeAccessDenied; |
|
291 } |
|
292 else |
|
293 { |
|
294 iKnowledgeObjectSize = aObjectSize; |
|
295 aSuid = iSuid; |
|
296 } |
|
297 } |
|
298 __FLOG(_L8("SendObjectPropListL - Exit")); |
|
299 return responseCode; |
|
300 } |
|
301 |
|
302 TMTPResponseCode CMTPKnowledgeHandler::GetObjectPropertyL(const CMTPObjectMetaData& aObjectMetaData, |
|
303 TUint16 aPropertyCode, CMTPTypeObjectPropList& aPropList) |
|
304 { |
|
305 __FLOG(_L8("GetObjectPropertyL - Entry")); |
|
306 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
307 CMTPTypeObjectPropListElement* propertyElement = NULL; |
|
308 TUint32 aHandle = aObjectMetaData.Uint(CMTPObjectMetaData::EHandle); |
|
309 |
|
310 switch (aPropertyCode) |
|
311 { |
|
312 case EMTPGenObjPropCodeParentID: |
|
313 { |
|
314 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
315 propertyElement->SetUint32L(CMTPTypeObjectPropListElement::EValue, 0x0000); |
|
316 break; |
|
317 } |
|
318 |
|
319 case EMTPGenObjPropCodeName: |
|
320 { |
|
321 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
322 if (iName && iName->Length() > 0) |
|
323 { |
|
324 propertyElement->SetStringL(CMTPTypeObjectPropListElement::EValue, *iName); |
|
325 } |
|
326 else |
|
327 { |
|
328 _LIT(KDefaultKwgObjName, "GenericObject01"); |
|
329 propertyElement->SetStringL(CMTPTypeObjectPropListElement::EValue, KDefaultKwgObjName()); |
|
330 } |
|
331 break; |
|
332 } |
|
333 |
|
334 case EMTPGenObjPropCodePersistentUniqueObjectIdentifier: |
|
335 { |
|
336 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
337 propertyElement->SetUint128L(CMTPTypeObjectPropListElement::EValue, |
|
338 iFramework.ObjectMgr().PuidL(aHandle).UpperValue(), |
|
339 iFramework.ObjectMgr().PuidL(aHandle).LowerValue()); |
|
340 break; |
|
341 } |
|
342 |
|
343 case EMTPGenObjPropCodeObjectFormat: |
|
344 { |
|
345 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
346 propertyElement->SetUint16L(CMTPTypeObjectPropListElement::EValue, iKnowledgeFormatCode); |
|
347 break; |
|
348 } |
|
349 |
|
350 case EMTPGenObjPropCodeObjectSize: |
|
351 { |
|
352 if (iKnowledgeObjectSize != ~0) |
|
353 { |
|
354 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
355 propertyElement->SetUint64L(CMTPTypeObjectPropListElement::EValue,iKnowledgeObjectSize); |
|
356 } |
|
357 break; |
|
358 } |
|
359 |
|
360 case EMTPGenObjPropCodeStorageID: |
|
361 { |
|
362 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
363 propertyElement->SetUint32L(CMTPTypeObjectPropListElement::EValue, iStorageID); |
|
364 break; |
|
365 } |
|
366 |
|
367 case EMTPGenObjPropCodeObjectHidden: |
|
368 { |
|
369 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
370 propertyElement->SetUint16L(CMTPTypeObjectPropListElement::EValue, 0x0001); |
|
371 break; |
|
372 } |
|
373 |
|
374 case EMTPGenObjPropCodeNonConsumable: |
|
375 { |
|
376 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
377 propertyElement->SetUint8L(CMTPTypeObjectPropListElement::EValue, 0x01); |
|
378 break; |
|
379 } |
|
380 |
|
381 case EMTPGenObjPropCodeDateModified: |
|
382 { |
|
383 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
384 if(iDateModified && iDateModified->Length() > 0) |
|
385 { |
|
386 propertyElement->SetStringL(CMTPTypeObjectPropListElement::EValue, *iDateModified); |
|
387 } |
|
388 else |
|
389 { |
|
390 TTime now; |
|
391 now.UniversalTime(); |
|
392 const TInt KMaxTimeStringSize = 50; |
|
393 TBuf<KMaxTimeStringSize> dateTimeBuf; |
|
394 _LIT(KFormat,"%F%Y%M%DT%H%T%S"); |
|
395 now.FormatL(dateTimeBuf, KFormat); |
|
396 propertyElement->SetStringL(CMTPTypeObjectPropListElement::EValue, dateTimeBuf); |
|
397 } |
|
398 break; |
|
399 } |
|
400 |
|
401 case EMTPSvcObjPropCodeLastAuthorProxyID: |
|
402 { |
|
403 const TMTPTypeUint128 unInitValue(MAKE_TUINT64(KMTPUnInitialized32, KMTPUnInitialized32), |
|
404 MAKE_TUINT64(KMTPUnInitialized32, KMTPUnInitialized32)); |
|
405 if(!unInitValue.Equal(iLastAuthorProxyID)) |
|
406 { |
|
407 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
|
408 propertyElement->SetUint128L(CMTPTypeObjectPropListElement::EValue, |
|
409 iLastAuthorProxyID.UpperValue(), |
|
410 iLastAuthorProxyID.LowerValue()); |
|
411 } |
|
412 break; |
|
413 } |
|
414 |
|
415 default: |
|
416 responseCode = EMTPRespCodeInvalidObjectPropCode; |
|
417 break; |
|
418 } |
|
419 if(propertyElement) |
|
420 { |
|
421 aPropList.CommitPropElemL(*propertyElement); |
|
422 } |
|
423 __FLOG(_L8("GetObjectPropertyL - Exit")); |
|
424 return responseCode; |
|
425 } |
|
426 |
|
427 TMTPResponseCode CMTPKnowledgeHandler::SetObjectPropertyL(const TDesC& /*aSuid*/, |
|
428 const CMTPTypeObjectPropListElement& aElement, |
|
429 TMTPOperationCode aOperationCode) |
|
430 { |
|
431 __FLOG(_L8("SetObjectPropertyL - Entry")); |
|
432 TMTPResponseCode responseCode = CheckGenObjectPropertyL(aElement, aOperationCode); |
|
433 if (responseCode == EMTPRespCodeOK) |
|
434 { |
|
435 TInt ret = KErrNone; |
|
436 TUint16 propertyCode(aElement.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode)); |
|
437 switch (propertyCode) |
|
438 { |
|
439 case EMTPGenObjPropCodeObjectSize: |
|
440 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
|
441 { |
|
442 ret = iRepository.Set(ESize, (TInt)aElement.Uint64L(CMTPTypeObjectPropListElement::EValue)); |
|
443 } |
|
444 iKnowledgeObjectSize = aElement.Uint64L(CMTPTypeObjectPropListElement::EValue); |
|
445 break; |
|
446 |
|
447 case EMTPGenObjPropCodeDateModified: |
|
448 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
|
449 { |
|
450 ret = iRepository.Set(EDateModified, aElement.StringL(CMTPTypeObjectPropListElement::EValue)); |
|
451 } |
|
452 delete iDateModified; |
|
453 iDateModified = NULL; |
|
454 iDateModified = aElement.StringL(CMTPTypeObjectPropListElement::EValue).AllocL(); |
|
455 break; |
|
456 |
|
457 case EMTPGenObjPropCodeName: |
|
458 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
|
459 { |
|
460 ret = iRepository.Set(EName, aElement.StringL(CMTPTypeObjectPropListElement::EValue)); |
|
461 } |
|
462 delete iName; |
|
463 iName = NULL; |
|
464 iName = aElement.StringL(CMTPTypeObjectPropListElement::EValue).AllocL(); |
|
465 break; |
|
466 |
|
467 case EMTPSvcObjPropCodeLastAuthorProxyID: |
|
468 { |
|
469 TUint64 high_value = 0; |
|
470 TUint64 low_value = 0; |
|
471 aElement.Uint128L(CMTPTypeObjectPropListElement::EValue, high_value, low_value); |
|
472 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
|
473 { |
|
474 responseCode = SetColumnType128Value(ELastAuthorProxyID, iLastAuthorProxyID); |
|
475 } |
|
476 iLastAuthorProxyID.Set(high_value, low_value); |
|
477 break; |
|
478 } |
|
479 |
|
480 default: |
|
481 responseCode = EMTPRespCodeObjectPropNotSupported; |
|
482 break; |
|
483 } |
|
484 if (KErrNone != ret) |
|
485 { |
|
486 responseCode = EMTPRespCodeGeneralError; |
|
487 } |
|
488 } |
|
489 __FLOG(_L8("SetObjectPropertyL - Exit")); |
|
490 return responseCode; |
|
491 } |
|
492 |
|
493 // Remove the knowledge object |
|
494 TMTPResponseCode CMTPKnowledgeHandler::DeleteObjectL(const CMTPObjectMetaData& /*aObjectMetaData*/) |
|
495 { |
|
496 __FLOG(_L8("DeleteObjectL - Entry")); |
|
497 iCacheStatusFlag = EDirty; |
|
498 TCleanupItem cacheDroper(DropCacheWrapper, this); |
|
499 CleanupStack::PushL(cacheDroper); |
|
500 // Delete obejct properties in transaction, if leave, mgr will rollback all properties. |
|
501 DeleteAllObjectPropertiesL(); |
|
502 CleanupStack::Pop(this); |
|
503 // Drop all cached properties. |
|
504 iCacheStatusFlag = EDeleted; |
|
505 CMTPKnowledgeHandler::DropCacheWrapper(this); |
|
506 LoadKnowledgeObjPropertiesL(); |
|
507 __FLOG(_L8("DeleteObjectL - Exit")); |
|
508 return EMTPRespCodeOK; |
|
509 } |
|
510 |
|
511 // Return the knowledge object content |
|
512 TMTPResponseCode CMTPKnowledgeHandler::GetObjectL(const CMTPObjectMetaData& /*aObjectMetaData*/, MMTPType** aBuffer) |
|
513 { |
|
514 __FLOG(_L8("GetObjectL - Entry")); |
|
515 if (!BaflUtils::FileExists(iFramework.Fs(), iKnowObjFileName)) |
|
516 { |
|
517 RFile file; |
|
518 CleanupClosePushL(file); |
|
519 User::LeaveIfError(file.Create(iFramework.Fs(), iKnowObjFileName, EFileRead)); |
|
520 CleanupStack::PopAndDestroy(&file); |
|
521 } |
|
522 |
|
523 // iKnowledgeObj will be NULL in four cases: 1. Initialize; 2. The Object has been deleted. |
|
524 // 3. it has been commited by SendObject. 4 released by GetObject. |
|
525 if (!iKnowledgeObj) |
|
526 { |
|
527 iKnowledgeObj = CMTPTypeFile::NewL(iFramework.Fs(), iKnowObjFileName, EFileRead); |
|
528 } |
|
529 *aBuffer = iKnowledgeObj; |
|
530 __FLOG(_L8("GetObjectL - Exit")); |
|
531 return EMTPRespCodeOK; |
|
532 } |
|
533 |
|
534 TMTPResponseCode CMTPKnowledgeHandler::DeleteObjectPropertyL(const CMTPObjectMetaData& /*aObjectMetaData*/, const TUint16 aPropertyCode) |
|
535 { |
|
536 __FLOG(_L8("DeleteObjectPropertyL - Entry")); |
|
537 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
538 switch (aPropertyCode) |
|
539 { |
|
540 case EMTPGenObjPropCodeDateModified: |
|
541 delete iDateModified; |
|
542 iDateModified = NULL; |
|
543 if (KErrNone != iRepository.Set(EDateModified, KEmptyContent16)) |
|
544 { |
|
545 responseCode = EMTPRespCodeGeneralError; |
|
546 } |
|
547 break; |
|
548 case EMTPSvcObjPropCodeLastAuthorProxyID: |
|
549 { |
|
550 TMTPTypeUint128 tmp(MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32), |
|
551 MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32)); |
|
552 iLastAuthorProxyID.Set(tmp.UpperValue(), tmp.LowerValue()); |
|
553 responseCode = SetColumnType128Value(ELastAuthorProxyID, iLastAuthorProxyID); |
|
554 break; |
|
555 } |
|
556 |
|
557 case EMTPObjectPropCodeParentObject: |
|
558 case EMTPObjectPropCodeName: |
|
559 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
560 case EMTPObjectPropCodeObjectFormat: |
|
561 case EMTPObjectPropCodeObjectSize: |
|
562 case EMTPObjectPropCodeStorageID: |
|
563 case EMTPObjectPropCodeHidden: |
|
564 case EMTPObjectPropCodeNonConsumable: |
|
565 responseCode = EMTPRespCodeAccessDenied; |
|
566 break; |
|
567 |
|
568 default: |
|
569 responseCode = EMTPRespCodeInvalidObjectPropCode; |
|
570 break; |
|
571 } |
|
572 __FLOG(_L8("DeleteObjectPropertyL - Exit")); |
|
573 return responseCode; |
|
574 } |
|
575 |
|
576 TMTPResponseCode CMTPKnowledgeHandler::GetBufferForSendObjectL(const CMTPObjectMetaData& /*aObjectMetaData*/, MMTPType** aBuffer) |
|
577 { |
|
578 __FLOG(_L8("GetBufferForSendObjectL - Entry")); |
|
579 if (iKnowledgeSwpBuffer) |
|
580 { |
|
581 delete iKnowledgeSwpBuffer; |
|
582 iKnowledgeSwpBuffer = NULL; |
|
583 } |
|
584 iKnowledgeSwpBuffer = CMTPTypeFile::NewL(iFramework.Fs(), iKnowObjSwpFileName, EFileWrite); |
|
585 iKnowledgeSwpBuffer->SetSizeL(0); |
|
586 *aBuffer = iKnowledgeSwpBuffer; |
|
587 __FLOG(_L8("GetBufferForSendObjectL - Exit")); |
|
588 return EMTPRespCodeOK; |
|
589 } |
|
590 |
|
591 void CMTPKnowledgeHandler::BuildObjectInfoL(CMTPTypeObjectInfo& aObjectInfo) const |
|
592 { |
|
593 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EStorageID, iStorageID); |
|
594 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EObjectFormat, iKnowledgeFormatCode); |
|
595 // Not use |
|
596 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EProtectionStatus, 0x0000); |
|
597 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EObjectCompressedSize, iKnowledgeObjectSize); |
|
598 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EThumbFormat, 0); |
|
599 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbCompressedSize, 0); |
|
600 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbPixWidth, 0); |
|
601 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbPixHeight, 0); |
|
602 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EImagePixWidth, 0); |
|
603 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EImagePixHeight, 0); |
|
604 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EImageBitDepth, 0); |
|
605 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EParentObject, KMTPHandleNoParent); |
|
606 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EAssociationType, 0x0000); |
|
607 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EAssociationDescription, 0); |
|
608 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::ESequenceNumber, 0); |
|
609 aObjectInfo.SetStringL(CMTPTypeObjectInfo::EFilename, KNullDesC); |
|
610 aObjectInfo.SetStringL(CMTPTypeObjectInfo::EDateModified, KNullDesC); |
|
611 aObjectInfo.SetStringL(CMTPTypeObjectInfo::EDateCreated, KNullDesC); |
|
612 aObjectInfo.SetStringL(CMTPTypeObjectInfo::EKeywords, KNullDesC); |
|
613 } |
|
614 |
|
615 TMTPResponseCode CMTPKnowledgeHandler::GetObjectInfoL(const CMTPObjectMetaData& /*aObjectMetaData*/, CMTPTypeObjectInfo& aObjectInfo) |
|
616 { |
|
617 __FLOG(_L8("GetObjectInfoL - Entry")); |
|
618 if(iKnowledgeObjectSize != KObjectSizeNotAvaiable) |
|
619 { |
|
620 BuildObjectInfoL(aObjectInfo); |
|
621 } |
|
622 __FLOG(_L8("GetObjectInfoL - Exit")); |
|
623 return EMTPRespCodeOK; |
|
624 } |
|
625 |
|
626 |
|
627 void CMTPKnowledgeHandler::DeleteAllObjectPropertiesL() |
|
628 { |
|
629 __FLOG(_L8("DeleteAllObjectPropertiesL - Entry")); |
|
630 User::LeaveIfError(iRepository.StartTransaction(CRepository::EReadWriteTransaction)); |
|
631 iRepository.CleanupCancelTransactionPushL(); |
|
632 User::LeaveIfError(iRepository.Set(EDateModified, KEmptyContent16)); |
|
633 User::LeaveIfError(iRepository.Set(EName, KEmptyContent16)); |
|
634 User::LeaveIfError(iRepository.Set(ESize, static_cast<TInt>(KObjectSizeNotAvaiable))); |
|
635 |
|
636 TMTPTypeUint128 tmp(MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32), |
|
637 MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32)); |
|
638 if (EMTPRespCodeOK != SetColumnType128Value(ELastAuthorProxyID, tmp)) |
|
639 { |
|
640 User::Leave(KErrGeneral); |
|
641 } |
|
642 // Reset knowledgeobject pointer and close the file. |
|
643 if (iKnowledgeObj) |
|
644 { |
|
645 delete iKnowledgeObj; |
|
646 iKnowledgeObj = NULL; |
|
647 } |
|
648 |
|
649 // Keep file delete is atomic. |
|
650 if (BaflUtils::FileExists(iFramework.Fs(), iKnowObjFileName)) |
|
651 { |
|
652 User::LeaveIfError(iFramework.Fs().Delete(iKnowObjFileName)); |
|
653 } |
|
654 |
|
655 TUint32 keyInfo; |
|
656 User::LeaveIfError(iRepository.CommitTransaction(keyInfo)); |
|
657 CleanupStack::Pop(&iRepository); |
|
658 |
|
659 __FLOG(_L8("DeleteAllObjectPropertiesL - Exit")); |
|
660 return; |
|
661 } |
|
662 |
|
663 void CMTPKnowledgeHandler::ReleaseObjectBuffer() |
|
664 { |
|
665 __FLOG(_L8("ReleaseObjectBuffer - Entry")); |
|
666 if (iKnowledgeObj) |
|
667 { |
|
668 delete iKnowledgeObj; |
|
669 iKnowledgeObj = NULL; |
|
670 } |
|
671 __FLOG(_L8("ReleaseObjectBuffer - Exit")); |
|
672 } |
|
673 |
|
674 TMTPResponseCode CMTPKnowledgeHandler::GetObjectSizeL(const TDesC& aSuid, TUint64& aObjectSize) |
|
675 { |
|
676 __FLOG(_L8("GetObjectSizeL - Entry")); |
|
677 if (aSuid != iSuid) |
|
678 { |
|
679 return EMTPRespCodeGeneralError; |
|
680 } |
|
681 aObjectSize = iKnowledgeObjectSize; |
|
682 __FLOG(_L8("GetObjectSizeL - Exit")); |
|
683 return EMTPRespCodeOK; |
|
684 } |
|
685 |
|
686 TMTPResponseCode CMTPKnowledgeHandler::SetColumnType128Value(TMTPKnowledgeStoreKeyNum aColumnNum, TMTPTypeUint128& aNewData) |
|
687 { |
|
688 __FLOG(_L8("SetColumnType128ValueL - Entry")); |
|
689 TInt ret; |
|
690 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
691 TBuf8<KMTPTypeINT128Size> data; |
|
692 data.FillZ(data.MaxLength()); |
|
693 TUint64 upperValue = aNewData.UpperValue(); |
|
694 TUint64 lowerValue = aNewData.LowerValue(); |
|
695 |
|
696 /** |
|
697 Least significant 64-bit buffer offset. |
|
698 */ |
|
699 const TInt KMTPTypeUint128OffsetLS = 0; |
|
700 /** |
|
701 Most significant 64-bit buffer offset. |
|
702 */ |
|
703 const TInt KMTPTypeUint128OffsetMS = 8; |
|
704 |
|
705 memcpy(&data[KMTPTypeUint128OffsetMS], &upperValue, sizeof(upperValue)); |
|
706 memcpy(&data[KMTPTypeUint128OffsetLS], &lowerValue, sizeof(lowerValue)); |
|
707 |
|
708 ret = iRepository.Set(aColumnNum, data); |
|
709 if (KErrNone != ret) |
|
710 { |
|
711 responseCode = EMTPRespCodeGeneralError; |
|
712 } |
|
713 __FLOG_VA((_L8("SetColumnType128ValueL - Exit with responseCode = 0x%04X"), responseCode)); |
|
714 return responseCode; |
|
715 } |
|
716 |
|
717 TMTPResponseCode CMTPKnowledgeHandler::GetAllObjectPropCodeByGroupL(TUint32 aGroupId, RArray<TUint32>& aPropCodes) |
|
718 { |
|
719 __FLOG(_L8("GetAllObjectPropCodeByGroupL - Entry")); |
|
720 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
721 if (0 == aGroupId) |
|
722 { |
|
723 TInt count = sizeof(KMTPFullEnumSyncKnowledgeObjectProperties) / sizeof(KMTPFullEnumSyncKnowledgeObjectProperties[0]); |
|
724 for (TInt i = 0; i < count; i++) |
|
725 { |
|
726 aPropCodes.Append(KMTPFullEnumSyncKnowledgeObjectProperties[i]); |
|
727 } |
|
728 } |
|
729 else if(2 == aGroupId) |
|
730 { |
|
731 TInt count = sizeof(KMTPKnowledgeObjectPropertiesGroup2) / sizeof(KMTPKnowledgeObjectPropertiesGroup2[0]); |
|
732 for (TInt i = 0; i < count; i++) |
|
733 { |
|
734 aPropCodes.Append(KMTPKnowledgeObjectPropertiesGroup2[i]); |
|
735 } |
|
736 } |
|
737 else if(5 == aGroupId) |
|
738 { |
|
739 TInt count = sizeof(KMTPKnowledgeObjectPropertiesGroup5) / sizeof(KMTPKnowledgeObjectPropertiesGroup5[0]); |
|
740 for (TInt i = 0; i < count; i++) |
|
741 { |
|
742 aPropCodes.Append(KMTPKnowledgeObjectPropertiesGroup5[i]); |
|
743 } |
|
744 } |
|
745 else |
|
746 { |
|
747 responseCode = (TMTPResponseCode)0xA805; |
|
748 } |
|
749 __FLOG(_L8("GetAllObjectPropCodeByGroupL - Exit")); |
|
750 return responseCode; |
|
751 } |