49 #include "mtpdebug.h" |
49 #include "mtpdebug.h" |
50 |
50 |
51 // Class constants. |
51 // Class constants. |
52 __FLOG_STMT(_LIT8(KComponent,"MTPImageDpPropertyMgr");) |
52 __FLOG_STMT(_LIT8(KComponent,"MTPImageDpPropertyMgr");) |
53 |
53 |
|
54 // Indicate how many cache can be stored |
|
55 const TUint KCacheThreshold = 16; |
|
56 |
54 /** |
57 /** |
55 The properties cache table content. |
58 The properties cache table content. |
56 */ |
59 */ |
57 const CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::TElementMetaData CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::KElements[CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::ENumProperties] = |
60 const CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::TElementMetaData CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::KElements[CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::ENumProperties] = |
58 { |
61 { |
110 //nothing to do |
113 //nothing to do |
111 __DEBUG_ONLY(User::Invariant()); |
114 __DEBUG_ONLY(User::Invariant()); |
112 break; |
115 break; |
113 } |
116 } |
114 } |
117 } |
115 |
|
116 iObjectHandle = KMTPHandleNone; |
|
117 } |
118 } |
118 |
119 |
119 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::ResetL() |
120 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::ResetL() |
120 { |
121 { |
121 iObjectHandle = KMTPHandleNone; |
|
122 SetUint(EImagePixWidth, 0); |
122 SetUint(EImagePixWidth, 0); |
123 SetUint(EImagePixHeight, 0); |
123 SetUint(EImagePixHeight, 0); |
124 SetUint(EImageBitDepth, 0); |
124 SetUint(EImageBitDepth, 0); |
125 SetDesCL(EDateCreated, KNullDesC); |
125 SetDesCL(EDateCreated, KNullDesC); |
126 } |
126 } |
133 |
133 |
134 TUint CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::Uint(TUint aId) const |
134 TUint CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::Uint(TUint aId) const |
135 { |
135 { |
136 __ASSERT_DEBUG((iElements[aId].iType == EUint), Panic(EMTPImageDpTypeMismatch)); |
136 __ASSERT_DEBUG((iElements[aId].iType == EUint), Panic(EMTPImageDpTypeMismatch)); |
137 return iElementsUint[iElements[aId].iOffset]; |
137 return iElementsUint[iElements[aId].iOffset]; |
138 } |
|
139 |
|
140 TUint CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::ObjectHandle() const |
|
141 { |
|
142 return iObjectHandle; |
|
143 } |
138 } |
144 |
139 |
145 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::SetDesCL(TUint aId, const TDesC& aValue) |
140 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::SetDesCL(TUint aId, const TDesC& aValue) |
146 { |
141 { |
147 const TElementMetaData& KElement(iElements[aId]); |
142 const TElementMetaData& KElement(iElements[aId]); |
155 { |
150 { |
156 __ASSERT_DEBUG((iElements[aId].iType == EUint), Panic(EMTPImageDpTypeMismatch)); |
151 __ASSERT_DEBUG((iElements[aId].iType == EUint), Panic(EMTPImageDpTypeMismatch)); |
157 iElementsUint[iElements[aId].iOffset] = aValue; |
152 iElementsUint[iElements[aId].iOffset] = aValue; |
158 } |
153 } |
159 |
154 |
160 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::SetObjectHandle(TUint aObjectHandle) |
|
161 { |
|
162 iObjectHandle = aObjectHandle; |
|
163 } |
|
164 |
|
165 CMTPImageDpObjectPropertyMgr* CMTPImageDpObjectPropertyMgr::NewL(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) |
155 CMTPImageDpObjectPropertyMgr* CMTPImageDpObjectPropertyMgr::NewL(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) |
166 { |
156 { |
167 CMTPImageDpObjectPropertyMgr* self = new (ELeave) CMTPImageDpObjectPropertyMgr(aFramework, aDataProvider); |
157 CMTPImageDpObjectPropertyMgr* self = new (ELeave) CMTPImageDpObjectPropertyMgr(aFramework, aDataProvider); |
168 CleanupStack::PushL(self); |
158 CleanupStack::PushL(self); |
169 self->ConstructL(aFramework); |
159 self->ConstructL(aFramework); |
173 |
163 |
174 CMTPImageDpObjectPropertyMgr::CMTPImageDpObjectPropertyMgr(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) : |
164 CMTPImageDpObjectPropertyMgr::CMTPImageDpObjectPropertyMgr(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) : |
175 iFramework(aFramework), |
165 iFramework(aFramework), |
176 iDataProvider(aDataProvider), |
166 iDataProvider(aDataProvider), |
177 iFs(aFramework.Fs()), |
167 iFs(aFramework.Fs()), |
178 iObjectMgr(aFramework.ObjectMgr()) |
168 iObjectMgr(aFramework.ObjectMgr()) |
179 { |
169 { |
180 __FLOG_OPEN(KMTPSubsystem, KComponent); |
170 __FLOG_OPEN(KMTPSubsystem, KComponent); |
181 } |
171 } |
182 |
172 |
183 void CMTPImageDpObjectPropertyMgr::ConstructL(MMTPDataProviderFramework& /*aFramework*/) |
173 void CMTPImageDpObjectPropertyMgr::ConstructL(MMTPDataProviderFramework& /*aFramework*/) |
184 { |
174 { |
185 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::ConstructL - Entry")); |
175 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::ConstructL - Entry")); |
186 iPropertiesCache = CMTPImagePropertiesCache::NewL(); |
|
187 iMetaDataSession = CMdESession::NewL(*this); |
176 iMetaDataSession = CMdESession::NewL(*this); |
188 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::ConstructL - Exit")); |
177 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::ConstructL - Exit")); |
189 } |
178 } |
190 |
179 |
191 CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr() |
180 CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr() |
192 { |
181 { |
193 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Entry")); |
182 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Entry")); |
194 delete iPropertiesCache; |
|
195 delete iObject; |
183 delete iObject; |
196 delete iMetaDataSession; |
184 delete iMetaDataSession; |
197 delete iThumbnailCache.iThumbnailData; |
185 delete iThumbnailCache.iThumbnailData; |
|
186 |
|
187 //Clear propreties cache map |
|
188 ClearAllCache(); |
|
189 iPropretiesCacheMap.Close(); |
198 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Exit")); |
190 __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Exit")); |
199 __FLOG_CLOSE; |
191 __FLOG_CLOSE; |
200 } |
192 } |
201 |
193 |
202 void CMTPImageDpObjectPropertyMgr::SetCurrentObjectL(CMTPObjectMetaData& aObjectInfo, TBool aRequireForModify, TBool aSaveToCache) |
194 void CMTPImageDpObjectPropertyMgr::SetCurrentObjectL(CMTPObjectMetaData& aObjectInfo, TBool aRequireForModify, TBool aSaveToCache) |
210 if(!aRequireForModify) |
202 if(!aRequireForModify) |
211 { |
203 { |
212 /** |
204 /** |
213 * determine whether the cache hit is occured |
205 * determine whether the cache hit is occured |
214 */ |
206 */ |
215 if (iPropertiesCache->ObjectHandle() == iObjectInfo->Uint(CMTPObjectMetaData::EHandle)) |
207 iCacheHit = FindPropertiesCache(iObjectInfo->Uint(CMTPObjectMetaData::EHandle)); |
216 { |
208 if (!iCacheHit) |
217 iCacheHit = ETrue; |
209 { |
218 } |
|
219 else |
|
220 { |
|
221 iCacheHit = EFalse; |
|
222 |
|
223 /** |
|
224 * if cache miss, we should clear the cache content |
|
225 */ |
|
226 ClearCacheL(); |
|
227 |
|
228 //need parse image file by our self if fail to get properties from MdS |
|
229 iNeedParse = ETrue; |
|
230 |
|
231 //clear previous Mde object |
|
232 delete iObject; |
210 delete iObject; |
233 iObject = NULL; |
211 iObject = NULL; |
234 } |
212 } |
235 } |
213 } |
236 else |
214 else |
237 { |
215 { |
238 /** |
216 /** |
239 * Set image object properties, because the cached properties are all readonly, |
217 * Set image object properties, because the cached properties are all readonly, |
240 * so only sendobjectproplist/sendobjectinfo operations can use cache mechanism, |
218 * so only sendobjectproplist/sendobjectinfo operations can use cache mechanism, |
241 * other operations will not use cache, such as setobjectvalue/setobjectproplist |
219 * other operations will not use cache, such as setobjectvalue/setobjectproplist |
242 */ |
220 */ |
243 if (aSaveToCache) |
221 if (aSaveToCache) |
244 { |
222 { |
245 TUint objectHandle = iObjectInfo->Uint(CMTPObjectMetaData::EHandle); |
223 TUint objectHandle = iObjectInfo->Uint(CMTPObjectMetaData::EHandle); |
246 if (iPropertiesCache->ObjectHandle() != objectHandle) |
224 if (FindPropertiesCache(objectHandle)) |
247 { |
225 { |
248 iPropertiesCache->ResetL(); |
226 __FLOG_VA((_L16("SetCurrentObjectL - find object in cache:%u"), objectHandle)); |
249 } |
227 iCurrentPropertiesCache->ResetL(); |
250 iPropertiesCache->SetObjectHandle(objectHandle); |
228 } |
|
229 else |
|
230 { |
|
231 if (iPropretiesCacheMap.Count() > KCacheThreshold) |
|
232 { |
|
233 // Find the first object handle from cache map and then destory it |
|
234 RHashMap<TUint, CMTPImagePropertiesCache*>::TIter iter(iPropretiesCacheMap); |
|
235 DestroyPropertiesCahce(*iter.NextKey()); |
|
236 __FLOG_VA((_L16("SetCurrentObjectL - destory object:%u"), objectHandle)); |
|
237 } |
|
238 |
|
239 iCurrentPropertiesCache = CMTPImagePropertiesCache::NewL(); |
|
240 iPropretiesCacheMap.Insert(objectHandle, iCurrentPropertiesCache); |
|
241 __FLOG_VA((_L16("SetCurrentObjectL - create new object:%u"), objectHandle)); |
|
242 } |
251 } |
243 } |
252 } |
244 } |
253 |
245 |
254 __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::SetCurrentObjectL")); |
246 __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::SetCurrentObjectL")); |
255 } |
247 } |
302 break; |
294 break; |
303 case EMTPObjectPropCodeParentObject: |
295 case EMTPObjectPropCodeParentObject: |
304 iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, aValue); |
296 iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, aValue); |
305 break; |
297 break; |
306 case EMTPObjectPropCodeWidth: |
298 case EMTPObjectPropCodeWidth: |
307 iPropertiesCache->SetUint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixWidth, aValue); |
299 if (iCurrentPropertiesCache != NULL) |
|
300 { |
|
301 iCurrentPropertiesCache->SetUint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixWidth, aValue); |
|
302 } |
308 break; |
303 break; |
309 case EMTPObjectPropCodeHeight: |
304 case EMTPObjectPropCodeHeight: |
310 iPropertiesCache->SetUint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixHeight, aValue); |
305 if (iCurrentPropertiesCache != NULL) |
|
306 { |
|
307 iCurrentPropertiesCache->SetUint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixHeight, aValue); |
|
308 } |
311 break; |
309 break; |
312 case EMTPObjectPropCodeImageBitDepth: |
310 case EMTPObjectPropCodeImageBitDepth: |
313 iPropertiesCache->SetUint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImageBitDepth, aValue); |
311 if (iCurrentPropertiesCache != NULL) |
|
312 { |
|
313 iCurrentPropertiesCache->SetUint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImageBitDepth, aValue); |
|
314 } |
314 break; |
315 break; |
315 default: |
316 default: |
316 //nothing to do |
317 //nothing to do |
317 break; |
318 break; |
318 } |
319 } |
361 iFs.SetModified(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), modifiedTime); |
362 iFs.SetModified(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), modifiedTime); |
362 } |
363 } |
363 break; |
364 break; |
364 |
365 |
365 case EMTPObjectPropCodeDateCreated://MdS property |
366 case EMTPObjectPropCodeDateCreated://MdS property |
366 iPropertiesCache->SetDesCL(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated, aValue); |
367 if (iCurrentPropertiesCache != NULL) |
|
368 { |
|
369 iCurrentPropertiesCache->SetDesCL(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated, aValue); |
|
370 } |
367 break; |
371 break; |
368 |
372 |
369 default: |
373 default: |
370 //nothing to do |
374 //nothing to do |
371 break; |
375 break; |
638 * The object hit the cache, so we query properties from cache |
642 * The object hit the cache, so we query properties from cache |
639 */ |
643 */ |
640 switch (aProperty) |
644 switch (aProperty) |
641 { |
645 { |
642 case EMTPObjectPropCodeDateCreated: |
646 case EMTPObjectPropCodeDateCreated: |
643 (*(static_cast<CMTPTypeString*>(aValue))).SetL(iPropertiesCache->DesC(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated)); |
647 (*(static_cast<CMTPTypeString*>(aValue))).SetL(iCurrentPropertiesCache->DesC(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated)); |
644 break; |
648 break; |
645 |
649 |
646 case EMTPObjectPropCodeWidth: |
650 case EMTPObjectPropCodeWidth: |
647 *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixWidth); |
651 *static_cast<TUint32*>(aValue) = iCurrentPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixWidth); |
648 break; |
652 break; |
649 |
653 |
650 case EMTPObjectPropCodeHeight: |
654 case EMTPObjectPropCodeHeight: |
651 *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixHeight); |
655 *static_cast<TUint32*>(aValue) = iCurrentPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixHeight); |
652 break; |
656 break; |
653 |
657 |
654 case EMTPObjectPropCodeImageBitDepth: |
658 case EMTPObjectPropCodeImageBitDepth: |
655 *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImageBitDepth); |
659 *static_cast<TUint32*>(aValue) = iCurrentPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImageBitDepth); |
656 break; |
660 break; |
657 |
661 |
658 default: |
662 default: |
659 //nothing to do |
663 //nothing to do |
660 break; |
664 break; |
956 void CMTPImageDpObjectPropertyMgr::SetMdeSessionError(TInt aError) |
960 void CMTPImageDpObjectPropertyMgr::SetMdeSessionError(TInt aError) |
957 { |
961 { |
958 iMdeSessionError = aError; |
962 iMdeSessionError = aError; |
959 } |
963 } |
960 |
964 |
961 void CMTPImageDpObjectPropertyMgr::ClearCacheL() |
965 void CMTPImageDpObjectPropertyMgr::ClearAllCache() |
962 { |
966 { |
963 iPropertiesCache->ResetL(); |
967 while (iPropretiesCacheMap.Count()) |
|
968 { |
|
969 RHashMap<TUint, CMTPImagePropertiesCache*>::TIter iter(iPropretiesCacheMap); |
|
970 DestroyPropertiesCahce(*iter.NextKey()); |
|
971 }; |
|
972 } |
|
973 |
|
974 void CMTPImageDpObjectPropertyMgr::ClearCache(TUint aHandle) |
|
975 { |
|
976 DestroyPropertiesCahce(aHandle); |
964 } |
977 } |
965 |
978 |
966 void CMTPImageDpObjectPropertyMgr::OpenMdeObjectL() |
979 void CMTPImageDpObjectPropertyMgr::OpenMdeObjectL() |
967 { |
980 { |
968 if (iObject == NULL) |
981 if (iObject == NULL) |
984 delete iThumbnailCache.iThumbnailData; |
997 delete iThumbnailCache.iThumbnailData; |
985 iThumbnailCache.iThumbnailData = NULL; |
998 iThumbnailCache.iThumbnailData = NULL; |
986 |
999 |
987 iThumbnailCache.iObjectHandle = KMTPHandleNone; |
1000 iThumbnailCache.iObjectHandle = KMTPHandleNone; |
988 } |
1001 } |
|
1002 |
|
1003 TBool CMTPImageDpObjectPropertyMgr::FindPropertiesCache(TUint aObjectHandle) |
|
1004 { |
|
1005 TBool ret = EFalse; |
|
1006 CMTPImagePropertiesCache** ppCache = iPropretiesCacheMap.Find(aObjectHandle); |
|
1007 if (ppCache) |
|
1008 { |
|
1009 iCurrentPropertiesCache = *ppCache; |
|
1010 ret = (iCurrentPropertiesCache != NULL) ? ETrue : EFalse; |
|
1011 } |
|
1012 else |
|
1013 { |
|
1014 iCurrentPropertiesCache = NULL; |
|
1015 ret = EFalse; |
|
1016 } |
|
1017 |
|
1018 return ret; |
|
1019 } |
|
1020 |
|
1021 void CMTPImageDpObjectPropertyMgr::DestroyPropertiesCahce(TUint aObjectHandle) |
|
1022 { |
|
1023 CMTPImagePropertiesCache** ppCache = iPropretiesCacheMap.Find(aObjectHandle); |
|
1024 if (ppCache) |
|
1025 { |
|
1026 CMTPImagePropertiesCache* pCache = *ppCache; |
|
1027 delete pCache; |
|
1028 iPropretiesCacheMap.Remove(aObjectHandle); |
|
1029 } |
|
1030 } |