33 #include "mtpimagedpconst.h" |
33 #include "mtpimagedpconst.h" |
34 #include "cmtpimagedpmdeobserver.h" |
34 #include "cmtpimagedpmdeobserver.h" |
35 #include "cmtpimagedp.h" |
35 #include "cmtpimagedp.h" |
36 #include "cmtpimagedpobjectpropertymgr.h" |
36 #include "cmtpimagedpobjectpropertymgr.h" |
37 #include "mtpimagedputilits.h" |
37 #include "mtpimagedputilits.h" |
38 |
38 #include "OstTraceDefinitions.h" |
39 __FLOG_STMT(_LIT8(KComponent, "CMTPImageDpMdeObserver");) |
39 #ifdef OST_TRACE_COMPILER_IN_USE |
|
40 #include "cmtpimagedpmdeobserverTraces.h" |
|
41 #endif |
|
42 |
40 |
43 |
41 CMTPImageDpMdeObserver* CMTPImageDpMdeObserver::NewL(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) |
44 CMTPImageDpMdeObserver* CMTPImageDpMdeObserver::NewL(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) |
42 { |
45 { |
43 CMTPImageDpMdeObserver* self = new (ELeave) CMTPImageDpMdeObserver(aFramework, aDataProvider); |
46 CMTPImageDpMdeObserver* self = new (ELeave) CMTPImageDpMdeObserver(aFramework, aDataProvider); |
44 CleanupStack::PushL(self); |
47 CleanupStack::PushL(self); |
57 { |
60 { |
58 } |
61 } |
59 |
62 |
60 void CMTPImageDpMdeObserver::ConstructL() |
63 void CMTPImageDpMdeObserver::ConstructL() |
61 { |
64 { |
62 __FLOG_OPEN(KMTPSubsystem, KComponent); |
65 OstTraceFunctionEntry0( CMTPIMAGEDPMDEOBSERVER_CONSTRUCTL_ENTRY ); |
63 __FLOG(_L8("CMTPImageDpMdeObserver::ConstructL - Entry")); |
66 OstTraceFunctionExit0( CMTPIMAGEDPMDEOBSERVER_CONSTRUCTL_EXIT ); |
64 __FLOG(_L8("CMTPImageDpMdeObserver::ConstructL - Exit")); |
|
65 } |
67 } |
66 |
68 |
67 CMTPImageDpMdeObserver::~CMTPImageDpMdeObserver() |
69 CMTPImageDpMdeObserver::~CMTPImageDpMdeObserver() |
68 { |
70 { |
69 __FLOG(_L8("CMTPImageDpMdeObserver::~CMTPImageDpMdeObserver - Entry")); |
71 OstTraceFunctionEntry0( CMTPIMAGEDPMDEOBSERVER_CMTPIMAGEDPMDEOBSERVER_ENTRY ); |
70 __FLOG(_L8("CMTPImageDpMdeObserver::~CMTPImageDpMdeObserver - Exit")); |
72 OstTraceFunctionExit0( CMTPIMAGEDPMDEOBSERVER_CMTPIMAGEDPMDEOBSERVER_EXIT ); |
71 __FLOG_CLOSE; |
|
72 } |
73 } |
73 |
74 |
74 void CMTPImageDpMdeObserver::CreateMetadataL(const TParsePtrC& aParse, TMTPFormatCode aFormat, TUint32 aParentHandle, CMTPObjectMetaData& aMetaData) |
75 void CMTPImageDpMdeObserver::CreateMetadataL(const TParsePtrC& aParse, TMTPFormatCode aFormat, TUint32 aParentHandle, CMTPObjectMetaData& aMetaData) |
75 { |
76 { |
76 TInt32 storageId = MTPImageDpUtilits::FindStorage(iFramework, aParse.FullName()); |
77 TInt32 storageId = MTPImageDpUtilits::FindStorage(iFramework, aParse.FullName()); |
77 |
78 |
78 __FLOG_VA((_L16("Addition - New Image:%S"), &aParse.FullName())); |
79 OstTraceExt1( TRACE_NORMAL, CMTPIMAGEDPMDEOBSERVER_CREATEMETADATAL, "Addition - New Image:%S", aParse.FullName() ); |
79 aMetaData.SetUint(CMTPObjectMetaData::EDataProviderId, iFramework.DataProviderId()); |
80 aMetaData.SetUint(CMTPObjectMetaData::EDataProviderId, iFramework.DataProviderId()); |
80 aMetaData.SetUint(CMTPObjectMetaData::EFormatCode, aFormat); |
81 aMetaData.SetUint(CMTPObjectMetaData::EFormatCode, aFormat); |
81 aMetaData.SetUint(CMTPObjectMetaData::EStorageId, storageId); |
82 aMetaData.SetUint(CMTPObjectMetaData::EStorageId, storageId); |
82 aMetaData.SetDesCL(CMTPObjectMetaData::ESuid, aParse.FullName()); |
83 aMetaData.SetDesCL(CMTPObjectMetaData::ESuid, aParse.FullName()); |
83 aMetaData.SetUint(CMTPObjectMetaData::EParentHandle, aParentHandle); |
84 aMetaData.SetUint(CMTPObjectMetaData::EParentHandle, aParentHandle); |
87 ++iNewPics; |
88 ++iNewPics; |
88 } |
89 } |
89 |
90 |
90 void CMTPImageDpMdeObserver::ProcessMdeNotificationL(const RArray<TItemId>& aObjectIdArray, TObserverNotificationType /*aType*/) |
91 void CMTPImageDpMdeObserver::ProcessMdeNotificationL(const RArray<TItemId>& aObjectIdArray, TObserverNotificationType /*aType*/) |
91 { |
92 { |
92 __FLOG_VA((_L8("CMTPImageDpMdeObserver::ProcessMdeNotificationL Start"))); |
93 OstTraceFunctionEntry0( CMTPIMAGEDPMDEOBSERVER_PROCESSMDENOTIFICATIONL_ENTRY ); |
93 |
94 |
94 //Because image dp only subscribe add notification from MdS, only the add notifictions can reach here |
95 //Because image dp only subscribe add notification from MdS, only the add notifictions can reach here |
95 //we ignore checking ENotifyAdd notification type to reduce complexity. |
96 //we ignore checking ENotifyAdd notification type to reduce complexity. |
96 CMdESession& mdeSession = iDataProvider.PropertyMgr().MdeSession(); |
97 CMdESession& mdeSession = iDataProvider.PropertyMgr().MdeSession(); |
97 CMdENamespaceDef& defaultNamespaceDef = mdeSession.GetDefaultNamespaceDefL(); |
98 CMdENamespaceDef& defaultNamespaceDef = mdeSession.GetDefaultNamespaceDefL(); |
104 if (mdeObject == NULL) |
105 if (mdeObject == NULL) |
105 { |
106 { |
106 continue; |
107 continue; |
107 } |
108 } |
108 CleanupStack::PushL(mdeObject); |
109 CleanupStack::PushL(mdeObject); |
109 __FLOG_VA((_L16("Addition - ObjectId:%u, URI:%S"), aObjectIdArray[i], &mdeObject->Uri())); |
110 OstTraceExt2( TRACE_NORMAL, CMTPIMAGEDPMDEOBSERVER_PROCESSMDENOTIFICATIONL, |
110 |
111 "Addition - ObjectId:%u, URI:%S", aObjectIdArray[i], mdeObject->Uri()); |
|
112 |
111 //filter out all image files other jpeg files |
113 //filter out all image files other jpeg files |
112 TParsePtrC parse(mdeObject->Uri()); |
114 TParsePtrC parse(mdeObject->Uri()); |
113 TMTPFormatCode format = iDataProvider.FindFormat(parse.Ext().Mid(1)); |
115 TMTPFormatCode format = iDataProvider.FindFormat(parse.Ext().Mid(1)); |
114 if (format != EMTPFormatCodeUndefined) |
116 if (format != EMTPFormatCodeUndefined) |
115 { |
117 { |
121 * if we can't find parent handle we should issue a notification to framework, let framework to enumerate new folder if need |
123 * if we can't find parent handle we should issue a notification to framework, let framework to enumerate new folder if need |
122 */ |
124 */ |
123 TUint32 parentHandle = MTPImageDpUtilits::FindParentHandleL(iFramework, iDataProvider, parse.FullName()); |
125 TUint32 parentHandle = MTPImageDpUtilits::FindParentHandleL(iFramework, iDataProvider, parse.FullName()); |
124 if (parentHandle == KMTPHandleNone) |
126 if (parentHandle == KMTPHandleNone) |
125 { |
127 { |
126 __FLOG_VA((_L16("Notify framework - URI:%S"), &mdeObject->Uri())); |
128 OstTraceExt1( TRACE_NORMAL, DUP1_CMTPIMAGEDPMDEOBSERVER_PROCESSMDENOTIFICATIONL, "Notify framework - URI:%S", mdeObject->Uri() ); |
127 TMTPNotificationParamsFolderChange param = {mdeObject->Uri()}; |
129 TMTPNotificationParamsFolderChange param = {mdeObject->Uri()}; |
128 iFramework.NotifyFrameworkL(EMTPAddFolder, ¶m); |
130 iFramework.NotifyFrameworkL(EMTPAddFolder, ¶m); |
129 |
131 |
130 //try to get parent handle if framework complete it's tasks |
132 //try to get parent handle if framework complete it's tasks |
131 parentHandle = MTPImageDpUtilits::FindParentHandleL(iFramework, iDataProvider, parse.FullName()); |
133 parentHandle = MTPImageDpUtilits::FindParentHandleL(iFramework, iDataProvider, parse.FullName()); |
132 __FLOG_VA((_L16("Framework enumeration parent handle:%u"), parentHandle)); |
134 OstTrace1( TRACE_NORMAL, DUP2_CMTPIMAGEDPMDEOBSERVER_PROCESSMDENOTIFICATIONL, "Framework enumeration parent handle:%u", parentHandle ); |
133 } |
135 } |
134 |
136 |
135 if (parentHandle != KMTPHandleNone) |
137 if (parentHandle != KMTPHandleNone) |
136 { |
138 { |
137 CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC(); |
139 CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC(); |
138 CreateMetadataL(parse, format, parentHandle, *object); |
140 CreateMetadataL(parse, format, parentHandle, *object); |
139 iFramework.ObjectMgr().InsertObjectL(*object); |
141 iFramework.ObjectMgr().InsertObjectL(*object); |
140 __FLOG_VA((_L16("Addition - New Handle:%u"), object->Uint(CMTPObjectMetaData::EHandle))); |
142 OstTrace1( TRACE_NORMAL, DUP3_CMTPIMAGEDPMDEOBSERVER_PROCESSMDENOTIFICATIONL, |
|
143 "Addition - New Handle:%u", object->Uint(CMTPObjectMetaData::EHandle) ); |
141 |
144 |
142 TMTPTypeEvent event; |
145 TMTPTypeEvent event; |
143 event.SetUint16(TMTPTypeEvent::EEventCode, EMTPEventCodeObjectAdded); |
146 event.SetUint16(TMTPTypeEvent::EEventCode, EMTPEventCodeObjectAdded); |
144 event.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll); |
147 event.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll); |
145 event.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdNone); |
148 event.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdNone); |
146 |
149 |
147 TUint32 handle = object->Uint(CMTPObjectMetaData::EHandle); |
150 TUint32 handle = object->Uint(CMTPObjectMetaData::EHandle); |
148 event.SetUint32(TMTPTypeEvent::EEventParameter1, handle); |
151 event.SetUint32(TMTPTypeEvent::EEventParameter1, handle); |
149 iFramework.SendEventL(event); |
152 iFramework.SendEventL(event); |
150 __FLOG_VA((_L8("ProcessMdeNotificationL - EMTPEventCodeObjectAdd, object handle:%u"), handle)); |
153 OstTrace1( TRACE_NORMAL, DUP4_CMTPIMAGEDPMDEOBSERVER_PROCESSMDENOTIFICATIONL, |
|
154 "ProcessMdeNotificationL - EMTPEventCodeObjectAdd, object handle:%u", handle ); |
|
155 |
151 CleanupStack::PopAndDestroy(object);//object |
156 CleanupStack::PopAndDestroy(object);//object |
152 } |
157 } |
153 } |
158 } |
154 } |
159 } |
155 |
160 |
156 CleanupStack::PopAndDestroy(mdeObject);//mdeObject |
161 CleanupStack::PopAndDestroy(mdeObject);//mdeObject |
157 } |
162 } |
158 |
163 |
159 __FLOG_VA((_L8("CMTPImageDpMdeObserver::ProcessMdeNotificationL - Exit"))); |
164 OstTraceFunctionExit0( CMTPIMAGEDPMDEOBSERVER_PROCESSMDENOTIFICATIONL_EXIT ); |
160 } |
165 } |
161 |
166 |
162 /* |
167 /* |
163 * After receiving object change notification, check if there is any dp subscribed right now. |
168 * After receiving object change notification, check if there is any dp subscribed right now. |
164 * if none, store change into database |
169 * if none, store change into database |
177 */ |
182 */ |
178 void CMTPImageDpMdeObserver::HandleObjectNotificationL(CMdESession& /*aSession*/, |
183 void CMTPImageDpMdeObserver::HandleObjectNotificationL(CMdESession& /*aSession*/, |
179 TObserverNotificationType aType, |
184 TObserverNotificationType aType, |
180 const RArray<TItemId>& aObjectIdArray) |
185 const RArray<TItemId>& aObjectIdArray) |
181 { |
186 { |
182 __FLOG_VA((_L8("CMTPImageDpMdeObserver::HandleObjectNotificationL - changeType = %d"), aType)); |
187 OstTraceFunctionEntry0( CMTPIMAGEDPMDEOBSERVER_HANDLEOBJECTNOTIFICATIONL_ENTRY ); |
|
188 OstTrace1( TRACE_NORMAL, CMTPIMAGEDPMDEOBSERVER_HANDLEOBJECTNOTIFICATIONL, "changeType = %d", aType ); |
183 |
189 |
184 ProcessMdeNotificationL(aObjectIdArray, aType); |
190 ProcessMdeNotificationL(aObjectIdArray, aType); |
185 |
191 |
186 //Update RProperty to notify the subscribers. |
192 //Update RProperty to notify the subscribers. |
187 if (iNewPics > 0) |
193 if (iNewPics > 0) |
188 { |
194 { |
189 __FLOG_1(_L16("CMTPImageDpMdeObserver::CMTPImageDpMdeObserver - New Pics: %u"), iNewPics); |
195 OstTrace1( TRACE_NORMAL, DUP1_CMTPIMAGEDPMDEOBSERVER_HANDLEOBJECTNOTIFICATIONL, "CMTPImageDpMdeObserver::CMTPImageDpMdeObserver - New Pics: %u", iNewPics ); |
190 iDataProvider.IncreaseNewPictures(iNewPics); |
196 iDataProvider.IncreaseNewPictures(iNewPics); |
191 iNewPics = 0; |
197 iNewPics = 0; |
192 } |
198 } |
193 |
199 |
194 __FLOG(_L8("CMTPImageDpMdeObserver::CMTPImageDpMdeObserver - Exit")); |
200 OstTraceFunctionExit0( CMTPIMAGEDPMDEOBSERVER_HANDLEOBJECTNOTIFICATIONL_EXIT ); |
195 } |
201 } |
196 |
202 |
197 /* |
203 /* |
198 * Subscribe MdS notifications |
204 * Subscribe MdS notifications |
199 */ |
205 */ |
200 void CMTPImageDpMdeObserver::SubscribeForChangeNotificationL() |
206 void CMTPImageDpMdeObserver::SubscribeForChangeNotificationL() |
201 { |
207 { |
202 __FLOG_VA((_L8("CMTPImageDpMdeObserver::SubscribeForChangeNotificationL"))); |
208 OstTraceFunctionEntry0( CMTPIMAGEDPMDEOBSERVER_SUBSCRIBEFORCHANGENOTIFICATIONL_ENTRY ); |
203 |
209 |
204 if (!iSubscribed) |
210 if (!iSubscribed) |
205 { |
211 { |
206 CMdESession& mdeSession = iDataProvider.PropertyMgr().MdeSession(); |
212 CMdESession& mdeSession = iDataProvider.PropertyMgr().MdeSession(); |
207 |
213 |
214 mdeSession.AddObjectObserverL(*this, addCondition, ENotifyAdd); |
220 mdeSession.AddObjectObserverL(*this, addCondition, ENotifyAdd); |
215 CleanupStack::Pop(addCondition); |
221 CleanupStack::Pop(addCondition); |
216 |
222 |
217 iSubscribed = ETrue; |
223 iSubscribed = ETrue; |
218 } |
224 } |
219 |
225 |
220 __FLOG(_L8("CMTPImageDpMdeObserver::SubscribeForChangeNotificationL - Exit")); |
226 OstTraceFunctionExit0( CMTPIMAGEDPMDEOBSERVER_SUBSCRIBEFORCHANGENOTIFICATIONL_EXIT ); |
221 } |
227 } |
222 |
228 |
223 /* |
229 /* |
224 * Unsubscribe MdS notifications |
230 * Unsubscribe MdS notifications |
225 */ |
231 */ |
226 void CMTPImageDpMdeObserver::UnsubscribeForChangeNotificationL() |
232 void CMTPImageDpMdeObserver::UnsubscribeForChangeNotificationL() |
227 { |
233 { |
228 __FLOG_VA((_L8("CMTPImageDpMdeObserver::UnsubscribeForChangeNotificationL"))); |
234 OstTraceFunctionEntry0( CMTPIMAGEDPMDEOBSERVER_UNSUBSCRIBEFORCHANGENOTIFICATIONL_ENTRY ); |
229 |
235 |
230 if (iSubscribed) |
236 if (iSubscribed) |
231 { |
237 { |
232 CMdESession& mdeSession = iDataProvider.PropertyMgr().MdeSession(); |
238 CMdESession& mdeSession = iDataProvider.PropertyMgr().MdeSession(); |
233 |
239 |
234 mdeSession.RemoveObjectObserverL(*this);//add observer |
240 mdeSession.RemoveObjectObserverL(*this);//add observer |
235 iSubscribed = EFalse; |
241 iSubscribed = EFalse; |
236 } |
242 } |
237 |
243 |
238 __FLOG(_L8("CMTPImageDpMdeObserver::UnsubscribeForChangeNotificationL - Exit")); |
244 OstTraceFunctionExit0( CMTPIMAGEDPMDEOBSERVER_UNSUBSCRIBEFORCHANGENOTIFICATIONL_EXIT ); |
239 } |
245 } |