37 _LIT(KMTPNoBackupFolder, "nobackup\\"); |
37 _LIT(KMTPNoBackupFolder, "nobackup\\"); |
38 _LIT(KMTPSlash, "\\"); |
38 _LIT(KMTPSlash, "\\"); |
39 _LIT(KMTPKnowledgeObjFileName, "mtp_knowledgeobj.dat"); |
39 _LIT(KMTPKnowledgeObjFileName, "mtp_knowledgeobj.dat"); |
40 _LIT(KMTPKnowledgeObjSwpFileName, "mtp_knowledgeobj.swp"); |
40 _LIT(KMTPKnowledgeObjSwpFileName, "mtp_knowledgeobj.swp"); |
41 |
41 |
|
42 |
|
43 CKnowledgeObject* CKnowledgeObject::NewL(CRepository& aRepository) |
|
44 { |
|
45 CKnowledgeObject *self = new (ELeave) CKnowledgeObject(aRepository); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CKnowledgeObject::CKnowledgeObject(CRepository& aRepository) : iRepository(aRepository) |
|
53 { |
|
54 |
|
55 } |
|
56 CKnowledgeObject::~CKnowledgeObject() |
|
57 { |
|
58 __FLOG(_L8("~CKnowledgeObject - Entry")); |
|
59 iDateModified.Close(); |
|
60 iName.Close(); |
|
61 __FLOG(_L8("~CKnowledgeObject - Exit")); |
|
62 __FLOG_CLOSE; |
|
63 } |
|
64 void CKnowledgeObject::ConstructL() |
|
65 { |
|
66 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
67 __FLOG(_L8("CKnowledgeObject Construct - Entry")); |
|
68 iKnowledgeObjectSize = KObjectSizeNotAvaiable; |
|
69 iDateModified.CreateL(KDateTimeMaxLength); |
|
70 iName.CreateL(KNameMaxLength); |
|
71 iLastAuthorProxyID.Set(KMTPUnInitialized64, KMTPUnInitialized64); |
|
72 iDirty = EBitFlagAll; |
|
73 __FLOG(_L8("CKnowledgeObject Construct - Exit")); |
|
74 } |
|
75 |
|
76 void CKnowledgeObject::LoadL() |
|
77 { |
|
78 __FLOG(_L8("CKnowledgeObject LoadL - Entry")); |
|
79 // Load ObjectSize |
|
80 TInt objSize; |
|
81 User::LeaveIfError(iRepository.Get(ESize, objSize)); |
|
82 iKnowledgeObjectSize = objSize; |
|
83 |
|
84 // Load DateModify |
|
85 iDateModified.Zero(); |
|
86 User::LeaveIfError(iRepository.Get(EDateModified, iDateModified)); |
|
87 |
|
88 // Load Name |
|
89 iName.Zero(); |
|
90 User::LeaveIfError(iRepository.Get(EName, iName)); |
|
91 |
|
92 // Load LastAuthorProxyID: |
|
93 TPtr8 writeBuf(NULL, 0); //walkaroud for the TMTPTypeUint128 |
|
94 iLastAuthorProxyID.FirstWriteChunk(writeBuf); |
|
95 User::LeaveIfError(iRepository.Get(ELastAuthorProxyID, writeBuf)); |
|
96 iDirty = EBitFlagNone; |
|
97 __FLOG(_L8("CKnowledgeObject LoadL - Exit")); |
|
98 return; |
|
99 } |
|
100 |
|
101 |
|
102 void CKnowledgeObject::Clear() |
|
103 { |
|
104 __FLOG(_L8("CKnowledgeObject Clear - Entry")); |
|
105 iKnowledgeObjectSize = KObjectSizeNotAvaiable; |
|
106 iDateModified.Zero(); |
|
107 iName.Zero(); |
|
108 iLastAuthorProxyID.Set(KMTPUnInitialized64, KMTPUnInitialized64); |
|
109 iDirty = EBitFlagAll; |
|
110 __FLOG(_L8("CKnowledgeObject Clear - Exit")); |
|
111 } |
|
112 |
|
113 void CKnowledgeObject::SetSize(TUint64 aSize) |
|
114 { |
|
115 iKnowledgeObjectSize = aSize; |
|
116 iDirty |= EBitFlagSize; |
|
117 } |
|
118 |
|
119 void CKnowledgeObject::SetDateModified(const TDesC& /*aDateModified*/) |
|
120 { |
|
121 /** |
|
122 * DateModifed will be auto updated when commit. If PC set this prop, it will be ignored. |
|
123 * If someday PC want to force the DateModifed be saved, the following code piece should |
|
124 * be opened, and add check in commit when save DateModified. |
|
125 *iDateModified.Copy(aDateModified); |
|
126 *iDirty |= EBitFlagDateModified; |
|
127 **/ |
|
128 } |
|
129 |
|
130 void CKnowledgeObject::SetName(const TDesC& aName) |
|
131 { |
|
132 iName.Copy(aName); |
|
133 iDirty |= EBitFlagName; |
|
134 } |
|
135 |
|
136 void CKnowledgeObject::SetLastAuthorProxyID(TUint64 aHigh, TUint64 aLow) |
|
137 { |
|
138 iLastAuthorProxyID.Set(aHigh, aLow); |
|
139 iDirty |= EBitFlagLastAuthorProxyID; |
|
140 } |
|
141 |
|
142 void CKnowledgeObject::CommitL() |
|
143 { |
|
144 __FLOG(_L8("CKnowledgeObject CommitL - Entry")); |
|
145 if (EBitFlagSize == (iDirty & EBitFlagSize)) |
|
146 { |
|
147 // TUint64 -> TInt, some capability is lost, |
|
148 // anyway, it's enough for knowledge object. |
|
149 User::LeaveIfError(iRepository.Set(ESize, (TInt)iKnowledgeObjectSize)); |
|
150 } |
|
151 |
|
152 if (EBitFlagName == (iDirty & EBitFlagName)) |
|
153 { |
|
154 User::LeaveIfError(iRepository.Set(EName, iName)); |
|
155 } |
|
156 |
|
157 if (EBitFlagLastAuthorProxyID == (iDirty & EBitFlagLastAuthorProxyID)) |
|
158 { |
|
159 if (EMTPRespCodeOK != SetColumnType128Value(ELastAuthorProxyID, iLastAuthorProxyID)) |
|
160 { |
|
161 User::Leave(KErrGeneral); |
|
162 } |
|
163 } |
|
164 |
|
165 // update DateModified to be the time of Commit |
|
166 RefreshDateModifed(); |
|
167 User::LeaveIfError(iRepository.Set(EDateModified, iDateModified)); |
|
168 |
|
169 iDirty = EBitFlagNone; |
|
170 __FLOG(_L8("CKnowledgeObject KnowledgeObject CommitL - Exit")); |
|
171 return; |
|
172 } |
|
173 |
|
174 TMTPResponseCode CKnowledgeObject::SetColumnType128Value(TMTPKnowledgeStoreKeyNum aColumnNum, TMTPTypeUint128& aNewData) |
|
175 { |
|
176 __FLOG(_L8("CKnowledgeObject SetColumnType128ValueL - Entry")); |
|
177 TInt ret; |
|
178 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
179 TBuf8<KMTPTypeINT128Size> data; |
|
180 data.FillZ(data.MaxLength()); |
|
181 TUint64 upperValue = aNewData.UpperValue(); |
|
182 TUint64 lowerValue = aNewData.LowerValue(); |
|
183 |
|
184 /** |
|
185 Least significant 64-bit buffer offset. |
|
186 */ |
|
187 const TInt KMTPTypeUint128OffsetLS = 0; |
|
188 /** |
|
189 Most significant 64-bit buffer offset. |
|
190 */ |
|
191 const TInt KMTPTypeUint128OffsetMS = 8; |
|
192 |
|
193 memcpy(&data[KMTPTypeUint128OffsetMS], &upperValue, sizeof(upperValue)); |
|
194 memcpy(&data[KMTPTypeUint128OffsetLS], &lowerValue, sizeof(lowerValue)); |
|
195 |
|
196 ret = iRepository.Set(aColumnNum, data); |
|
197 if (KErrNone != ret) |
|
198 { |
|
199 responseCode = EMTPRespCodeGeneralError; |
|
200 } |
|
201 __FLOG_VA((_L8("CKnowledgeObject SetColumnType128ValueL - Exit with responseCode = 0x%04X"), responseCode)); |
|
202 return responseCode; |
|
203 } |
|
204 |
|
205 |
|
206 void CKnowledgeObject::RefreshDateModifed() |
|
207 { |
|
208 __FLOG(_L8("CKnowledgeObject RefreshDateModifed - Entry")); |
|
209 //get current time |
|
210 TTime now; |
|
211 now.UniversalTime(); |
|
212 _LIT(KFormat,"%F%Y%M%DT%H%T%SZ"); |
|
213 iDateModified.Zero(); |
|
214 now.FormatL(iDateModified, KFormat); |
|
215 __FLOG(_L8("CKnowledgeObject RefreshDateModifed - Exit")); |
|
216 return; |
|
217 } |
|
218 |
42 EXPORT_C CMTPKnowledgeHandler* CMTPKnowledgeHandler::NewL(MMTPDataProviderFramework& aFramework, TUint16 aFormatCode, |
219 EXPORT_C CMTPKnowledgeHandler* CMTPKnowledgeHandler::NewL(MMTPDataProviderFramework& aFramework, TUint16 aFormatCode, |
43 CRepository& aReposotry, const TDesC& aKwgSuid) |
220 CRepository& aReposotry, const TDesC& aKwgSuid) |
44 { |
221 { |
45 CMTPKnowledgeHandler *self = new (ELeave) CMTPKnowledgeHandler(aFramework, aFormatCode, aReposotry, aKwgSuid); |
222 CMTPKnowledgeHandler *self = new (ELeave) CMTPKnowledgeHandler(aFramework, aFormatCode, aReposotry, aKwgSuid); |
46 CleanupStack::PushL(self); |
223 CleanupStack::PushL(self); |
50 } |
227 } |
51 |
228 |
52 EXPORT_C CMTPKnowledgeHandler::~CMTPKnowledgeHandler() |
229 EXPORT_C CMTPKnowledgeHandler::~CMTPKnowledgeHandler() |
53 { |
230 { |
54 __FLOG(_L8("~CMTPKnowledgeHandler - Entry")); |
231 __FLOG(_L8("~CMTPKnowledgeHandler - Entry")); |
55 delete iDateModified; |
|
56 delete iName; |
|
57 delete iKnowledgeObj; |
232 delete iKnowledgeObj; |
58 delete iKnowledgeSwpBuffer; |
233 delete iKnowledgeSwpBuffer; |
|
234 delete iCachedKnowledgeObject; |
59 __FLOG(_L8("~CMTPKnowledgeHandler - Exit")); |
235 __FLOG(_L8("~CMTPKnowledgeHandler - Exit")); |
60 __FLOG_CLOSE; |
236 __FLOG_CLOSE; |
61 } |
237 } |
62 |
238 |
63 CMTPKnowledgeHandler::CMTPKnowledgeHandler(MMTPDataProviderFramework& aFramework, TUint16 aFormatCode, |
239 CMTPKnowledgeHandler::CMTPKnowledgeHandler(MMTPDataProviderFramework& aFramework, TUint16 aFormatCode, |
64 CRepository& aReposotry, const TDesC& aKwgSuid) : |
240 CRepository& aReposotry, const TDesC& aKwgSuid) : |
65 iFramework(aFramework), iRepository(aReposotry), iKnowledgeFormatCode(aFormatCode), |
241 iFramework(aFramework), iRepository(aReposotry), iKnowledgeFormatCode(aFormatCode), iSuid(aKwgSuid) |
66 iKnowledgeObjectSize(KObjectSizeNotAvaiable), iCacheStatus(EOK), iSuid(aKwgSuid) |
|
67 { |
242 { |
68 } |
243 } |
69 |
244 |
70 void CMTPKnowledgeHandler::ConstructL() |
245 void CMTPKnowledgeHandler::ConstructL() |
71 { |
246 { |
158 } |
321 } |
159 |
322 |
160 void CMTPKnowledgeHandler::RollBack() |
323 void CMTPKnowledgeHandler::RollBack() |
161 { |
324 { |
162 __FLOG(_L8("Rollback - Entry")); |
325 __FLOG(_L8("Rollback - Entry")); |
163 TRAP_IGNORE(LoadKnowledgeObjPropertiesL()); |
326 iCachedKnowledgeObject->Clear(); |
|
327 TRAP_IGNORE(iCachedKnowledgeObject->LoadL()); |
164 __FLOG(_L8("Rollback - Exit")); |
328 __FLOG(_L8("Rollback - Exit")); |
165 } |
329 } |
166 |
330 |
167 EXPORT_C void CMTPKnowledgeHandler::GetObjectSuidL(TDes& aSuid) const |
331 EXPORT_C void CMTPKnowledgeHandler::GetObjectSuidL(TDes& aSuid) const |
168 { |
332 { |
169 __FLOG(_L8("GetObjectSuidL - Entry")); |
333 __FLOG(_L8("GetObjectSuidL - Entry")); |
170 if(iKnowledgeObjectSize != KObjectSizeNotAvaiable) |
334 if(iCachedKnowledgeObject->Size() != KObjectSizeNotAvaiable) |
171 { |
335 { |
172 aSuid.Append(iSuid); |
336 aSuid.Append(iSuid); |
173 } |
337 } |
174 __FLOG(_L8("GetObjectSuidL - Exit")); |
338 __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 } |
339 } |
236 |
340 |
237 TMTPResponseCode CMTPKnowledgeHandler::SendObjectInfoL(const CMTPTypeObjectInfo& aObjectInfo, TUint32& aParentHandle, TDes& aSuid) |
341 TMTPResponseCode CMTPKnowledgeHandler::SendObjectInfoL(const CMTPTypeObjectInfo& aObjectInfo, TUint32& aParentHandle, TDes& aSuid) |
238 { |
342 { |
239 __FLOG(_L("SendObjectInfoL - Entry")); |
343 __FLOG(_L("SendObjectInfoL - Entry")); |
378 break; |
492 break; |
379 } |
493 } |
380 |
494 |
381 case EMTPGenObjPropCodeDateModified: |
495 case EMTPGenObjPropCodeDateModified: |
382 { |
496 { |
|
497 if(iCachedKnowledgeObject->DateModified().Length() == 0) |
|
498 { |
|
499 iCachedKnowledgeObject->RefreshDateModifed(); |
|
500 } |
383 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
501 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
384 if(iDateModified && iDateModified->Length() > 0) |
502 propertyElement->SetStringL(CMTPTypeObjectPropListElement::EValue, iCachedKnowledgeObject->DateModified()); |
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; |
503 break; |
399 } |
504 } |
400 |
505 |
401 case EMTPSvcObjPropCodeLastAuthorProxyID: |
506 case EMTPSvcObjPropCodeLastAuthorProxyID: |
402 { |
507 { |
403 const TMTPTypeUint128 unInitValue(MAKE_TUINT64(KMTPUnInitialized32, KMTPUnInitialized32), |
508 if ((iCachedKnowledgeObject->LastAuthorProxyID().UpperValue() != KMTPUnInitialized64) |
404 MAKE_TUINT64(KMTPUnInitialized32, KMTPUnInitialized32)); |
509 && (iCachedKnowledgeObject->LastAuthorProxyID().LowerValue() !=KMTPUnInitialized64)) |
405 if(!unInitValue.Equal(iLastAuthorProxyID)) |
|
406 { |
510 { |
407 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
511 propertyElement = &(aPropList.ReservePropElemL(aHandle, aPropertyCode)); |
408 propertyElement->SetUint128L(CMTPTypeObjectPropListElement::EValue, |
512 propertyElement->SetUint128L(CMTPTypeObjectPropListElement::EValue, |
409 iLastAuthorProxyID.UpperValue(), |
513 iCachedKnowledgeObject->LastAuthorProxyID().UpperValue(), |
410 iLastAuthorProxyID.LowerValue()); |
514 iCachedKnowledgeObject->LastAuthorProxyID().LowerValue()); |
411 } |
515 } |
412 break; |
516 break; |
413 } |
517 } |
414 |
518 |
415 default: |
519 default: |
435 TInt ret = KErrNone; |
539 TInt ret = KErrNone; |
436 TUint16 propertyCode(aElement.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode)); |
540 TUint16 propertyCode(aElement.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode)); |
437 switch (propertyCode) |
541 switch (propertyCode) |
438 { |
542 { |
439 case EMTPGenObjPropCodeObjectSize: |
543 case EMTPGenObjPropCodeObjectSize: |
440 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
544 { |
441 { |
545 iCachedKnowledgeObject->SetSize(aElement.Uint64L(CMTPTypeObjectPropListElement::EValue)); |
442 ret = iRepository.Set(ESize, (TInt)aElement.Uint64L(CMTPTypeObjectPropListElement::EValue)); |
|
443 } |
|
444 iKnowledgeObjectSize = aElement.Uint64L(CMTPTypeObjectPropListElement::EValue); |
|
445 break; |
546 break; |
446 |
547 } |
447 case EMTPGenObjPropCodeDateModified: |
548 case EMTPGenObjPropCodeDateModified: |
448 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
549 { |
449 { |
550 // DateModified will be updated when Commit |
450 ret = iRepository.Set(EDateModified, aElement.StringL(CMTPTypeObjectPropListElement::EValue)); |
551 iCachedKnowledgeObject->SetDateModified(aElement.StringL(CMTPTypeObjectPropListElement::EValue)); |
451 } |
|
452 delete iDateModified; |
|
453 iDateModified = NULL; |
|
454 iDateModified = aElement.StringL(CMTPTypeObjectPropListElement::EValue).AllocL(); |
|
455 break; |
552 break; |
456 |
553 } |
457 case EMTPGenObjPropCodeName: |
554 case EMTPGenObjPropCodeName: |
458 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
555 { |
459 { |
556 iCachedKnowledgeObject->SetName(aElement.StringL(CMTPTypeObjectPropListElement::EValue)); |
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; |
557 break; |
466 |
558 } |
467 case EMTPSvcObjPropCodeLastAuthorProxyID: |
559 case EMTPSvcObjPropCodeLastAuthorProxyID: |
468 { |
560 { |
469 TUint64 high_value = 0; |
561 TUint64 high_value = 0; |
470 TUint64 low_value = 0; |
562 TUint64 low_value = 0; |
471 aElement.Uint128L(CMTPTypeObjectPropListElement::EValue, high_value, low_value); |
563 aElement.Uint128L(CMTPTypeObjectPropListElement::EValue, high_value, low_value); |
472 if(aOperationCode == EMTPOpCodeSetObjectPropList) |
564 iCachedKnowledgeObject->SetLastAuthorProxyID(high_value, low_value); |
473 { |
|
474 responseCode = SetColumnType128Value(ELastAuthorProxyID, iLastAuthorProxyID); |
|
475 } |
|
476 iLastAuthorProxyID.Set(high_value, low_value); |
|
477 break; |
565 break; |
478 } |
566 } |
479 |
567 |
480 default: |
568 default: |
481 responseCode = EMTPRespCodeObjectPropNotSupported; |
569 responseCode = EMTPRespCodeObjectPropNotSupported; |
492 |
580 |
493 // Remove the knowledge object |
581 // Remove the knowledge object |
494 TMTPResponseCode CMTPKnowledgeHandler::DeleteObjectL(const CMTPObjectMetaData& /*aObjectMetaData*/) |
582 TMTPResponseCode CMTPKnowledgeHandler::DeleteObjectL(const CMTPObjectMetaData& /*aObjectMetaData*/) |
495 { |
583 { |
496 __FLOG(_L8("DeleteObjectL - Entry")); |
584 __FLOG(_L8("DeleteObjectL - Entry")); |
497 iCacheStatusFlag = EDirty; |
585 |
498 TCleanupItem cacheDroper(DropCacheWrapper, this); |
586 User::LeaveIfError(iRepository.StartTransaction(CRepository::EReadWriteTransaction)); |
499 CleanupStack::PushL(cacheDroper); |
587 iRepository.CleanupCancelTransactionPushL(); |
|
588 |
500 // Delete obejct properties in transaction, if leave, mgr will rollback all properties. |
589 // Delete obejct properties in transaction, if leave, mgr will rollback all properties. |
501 DeleteAllObjectPropertiesL(); |
590 iCachedKnowledgeObject->Clear(); |
502 CleanupStack::Pop(this); |
591 iCachedKnowledgeObject->CommitL(); |
503 // Drop all cached properties. |
592 |
504 iCacheStatusFlag = EDeleted; |
593 // Reset knowledgeobject pointer and close the file. |
505 CMTPKnowledgeHandler::DropCacheWrapper(this); |
594 if (iKnowledgeObj) |
506 LoadKnowledgeObjPropertiesL(); |
595 { |
|
596 delete iKnowledgeObj; |
|
597 iKnowledgeObj = NULL; |
|
598 } |
|
599 |
|
600 // Keep file delete is atomic. |
|
601 if (BaflUtils::FileExists(iFramework.Fs(), iKnowObjFileName)) |
|
602 { |
|
603 User::LeaveIfError(iFramework.Fs().Delete(iKnowObjFileName)); |
|
604 } |
|
605 |
|
606 TUint32 keyInfo; |
|
607 User::LeaveIfError(iRepository.CommitTransaction(keyInfo)); |
|
608 CleanupStack::Pop(&iRepository); |
|
609 |
507 __FLOG(_L8("DeleteObjectL - Exit")); |
610 __FLOG(_L8("DeleteObjectL - Exit")); |
508 return EMTPRespCodeOK; |
611 return EMTPRespCodeOK; |
509 } |
612 } |
510 |
613 |
511 // Return the knowledge object content |
614 // Return the knowledge object content |
536 __FLOG(_L8("DeleteObjectPropertyL - Entry")); |
639 __FLOG(_L8("DeleteObjectPropertyL - Entry")); |
537 TMTPResponseCode responseCode = EMTPRespCodeOK; |
640 TMTPResponseCode responseCode = EMTPRespCodeOK; |
538 switch (aPropertyCode) |
641 switch (aPropertyCode) |
539 { |
642 { |
540 case EMTPGenObjPropCodeDateModified: |
643 case EMTPGenObjPropCodeDateModified: |
541 delete iDateModified; |
644 // DateModified will be updated when Commit |
542 iDateModified = NULL; |
645 iCachedKnowledgeObject->SetDateModified(KEmptyContent16); |
543 if (KErrNone != iRepository.Set(EDateModified, KEmptyContent16)) |
|
544 { |
|
545 responseCode = EMTPRespCodeGeneralError; |
|
546 } |
|
547 break; |
646 break; |
548 case EMTPSvcObjPropCodeLastAuthorProxyID: |
647 case EMTPSvcObjPropCodeLastAuthorProxyID: |
549 { |
648 { |
550 TMTPTypeUint128 tmp(MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32), |
649 iCachedKnowledgeObject->SetLastAuthorProxyID(KMTPUnInitialized64, KMTPUnInitialized64); |
551 MAKE_TINT64(KMTPUnInitialized32, KMTPUnInitialized32)); |
|
552 iLastAuthorProxyID.Set(tmp.UpperValue(), tmp.LowerValue()); |
|
553 responseCode = SetColumnType128Value(ELastAuthorProxyID, iLastAuthorProxyID); |
|
554 break; |
650 break; |
555 } |
651 } |
556 |
652 |
557 case EMTPObjectPropCodeParentObject: |
653 case EMTPObjectPropCodeParentObject: |
558 case EMTPObjectPropCodeName: |
654 case EMTPObjectPropCodeName: |
592 { |
688 { |
593 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EStorageID, iStorageID); |
689 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EStorageID, iStorageID); |
594 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EObjectFormat, iKnowledgeFormatCode); |
690 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EObjectFormat, iKnowledgeFormatCode); |
595 // Not use |
691 // Not use |
596 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EProtectionStatus, 0x0000); |
692 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EProtectionStatus, 0x0000); |
597 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EObjectCompressedSize, iKnowledgeObjectSize); |
693 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EObjectCompressedSize, iCachedKnowledgeObject->Size()); |
598 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EThumbFormat, 0); |
694 aObjectInfo.SetUint16L(CMTPTypeObjectInfo::EThumbFormat, 0); |
599 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbCompressedSize, 0); |
695 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbCompressedSize, 0); |
600 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbPixWidth, 0); |
696 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbPixWidth, 0); |
601 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbPixHeight, 0); |
697 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EThumbPixHeight, 0); |
602 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EImagePixWidth, 0); |
698 aObjectInfo.SetUint32L(CMTPTypeObjectInfo::EImagePixWidth, 0); |
613 } |
709 } |
614 |
710 |
615 TMTPResponseCode CMTPKnowledgeHandler::GetObjectInfoL(const CMTPObjectMetaData& /*aObjectMetaData*/, CMTPTypeObjectInfo& aObjectInfo) |
711 TMTPResponseCode CMTPKnowledgeHandler::GetObjectInfoL(const CMTPObjectMetaData& /*aObjectMetaData*/, CMTPTypeObjectInfo& aObjectInfo) |
616 { |
712 { |
617 __FLOG(_L8("GetObjectInfoL - Entry")); |
713 __FLOG(_L8("GetObjectInfoL - Entry")); |
618 if(iKnowledgeObjectSize != KObjectSizeNotAvaiable) |
714 if(iCachedKnowledgeObject->Size() != KObjectSizeNotAvaiable) |
619 { |
715 { |
620 BuildObjectInfoL(aObjectInfo); |
716 BuildObjectInfoL(aObjectInfo); |
621 } |
717 } |
622 __FLOG(_L8("GetObjectInfoL - Exit")); |
718 __FLOG(_L8("GetObjectInfoL - Exit")); |
623 return EMTPRespCodeOK; |
719 return EMTPRespCodeOK; |
624 } |
720 } |
625 |
721 |
626 |
722 |
627 void CMTPKnowledgeHandler::DeleteAllObjectPropertiesL() |
723 void CMTPKnowledgeHandler::ReleaseObjectBuffer() |
628 { |
724 { |
629 __FLOG(_L8("DeleteAllObjectPropertiesL - Entry")); |
725 __FLOG(_L8("ReleaseObjectBuffer - 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) |
726 if (iKnowledgeObj) |
644 { |
727 { |
645 delete iKnowledgeObj; |
728 delete iKnowledgeObj; |
646 iKnowledgeObj = NULL; |
729 iKnowledgeObj = NULL; |
647 } |
730 } |
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")); |
731 __FLOG(_L8("ReleaseObjectBuffer - Exit")); |
672 } |
732 } |
673 |
733 |
674 TMTPResponseCode CMTPKnowledgeHandler::GetObjectSizeL(const TDesC& aSuid, TUint64& aObjectSize) |
734 TMTPResponseCode CMTPKnowledgeHandler::GetObjectSizeL(const TDesC& aSuid, TUint64& aObjectSize) |
675 { |
735 { |
676 __FLOG(_L8("GetObjectSizeL - Entry")); |
736 __FLOG(_L8("GetObjectSizeL - Entry")); |
677 if (aSuid != iSuid) |
737 if (aSuid != iSuid) |
678 { |
738 { |
679 return EMTPRespCodeGeneralError; |
739 return EMTPRespCodeGeneralError; |
680 } |
740 } |
681 aObjectSize = iKnowledgeObjectSize; |
741 aObjectSize = iCachedKnowledgeObject->Size(); |
682 __FLOG(_L8("GetObjectSizeL - Exit")); |
742 __FLOG(_L8("GetObjectSizeL - Exit")); |
683 return EMTPRespCodeOK; |
743 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 } |
744 } |
716 |
745 |
717 TMTPResponseCode CMTPKnowledgeHandler::GetAllObjectPropCodeByGroupL(TUint32 aGroupId, RArray<TUint32>& aPropCodes) |
746 TMTPResponseCode CMTPKnowledgeHandler::GetAllObjectPropCodeByGroupL(TUint32 aGroupId, RArray<TUint32>& aPropCodes) |
718 { |
747 { |
719 __FLOG(_L8("GetAllObjectPropCodeByGroupL - Entry")); |
748 __FLOG(_L8("GetAllObjectPropCodeByGroupL - Entry")); |