|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Thumbnail Auto Generate Daemon |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32svr.h> |
|
20 #include <centralrepository.h> |
|
21 |
|
22 #include <mdesession.h> |
|
23 #include <mdeconstants.h> |
|
24 #include <mdequery.h> |
|
25 #include <mdeobject.h> |
|
26 |
|
27 #include "thumbagimageobserver.h" |
|
28 #include "thumbnaillog.h" |
|
29 #include "thumbnailmanagerconstants.h" |
|
30 #include "thumbnailmanagerprivatecrkeys.h" |
|
31 |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // NewLC |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CThumbAGImageObserver* CThumbAGImageObserver::NewLC(CThumbAGProcessor* aProcessor) |
|
38 { |
|
39 TN_DEBUG1( "CThumbAGImageObserver::NewLC() - begin" ); |
|
40 |
|
41 CThumbAGImageObserver* self = new (ELeave) CThumbAGImageObserver(aProcessor); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // NewL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CThumbAGImageObserver* CThumbAGImageObserver::NewL(CThumbAGProcessor* aProcessor) |
|
52 { |
|
53 TN_DEBUG1( "CThumbAGImageObserver::NewL() - begin" ); |
|
54 |
|
55 CThumbAGImageObserver* self = CThumbAGImageObserver::NewLC(aProcessor); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CThumbAGImageObserver |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CThumbAGImageObserver::CThumbAGImageObserver(CThumbAGProcessor* aProcessor) |
|
65 : iShutdownObserver(NULL), iMdESession(NULL), iProcessor(aProcessor) |
|
66 { |
|
67 // No implementation required |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // ConstructL |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CThumbAGImageObserver::ConstructL() |
|
75 { |
|
76 TN_DEBUG1( "CThumbAGImageObserver::ConstructL() - begin" ); |
|
77 |
|
78 #ifdef _DEBUG |
|
79 iAddCounter = 0; |
|
80 iModCounter = 0; |
|
81 #endif |
|
82 |
|
83 InitializeL(); |
|
84 |
|
85 TN_DEBUG1( "CThumbAGImageObserver::ConstructL() - end" ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // ~CThumbAGImageObserver |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CThumbAGImageObserver::InitializeL() |
|
93 { |
|
94 TN_DEBUG1( "CThumbAGImageObserver::InitializeL() - begin" ); |
|
95 |
|
96 |
|
97 TN_DEBUG1( "CThumbAGImageObserver::InitializeL() - create observers" ); |
|
98 |
|
99 // create shutdown observer |
|
100 if(iMDSShutdownObserver) |
|
101 { |
|
102 delete iMDSShutdownObserver; |
|
103 iMDSShutdownObserver = NULL; |
|
104 } |
|
105 iMDSShutdownObserver = CTMShutdownObserver::NewL( *this, KMdSPSShutdown, KMdSShutdown, EFalse ); |
|
106 |
|
107 if(iShutdownObserver) |
|
108 { |
|
109 delete iShutdownObserver; |
|
110 iShutdownObserver = NULL; |
|
111 } |
|
112 iShutdownObserver = CTMShutdownObserver::NewL( *this, KTAGDPSNotification, KShutdown, ETrue ); |
|
113 iShutdown = EFalse; |
|
114 |
|
115 // MDS session reconnect timer |
|
116 if (!iReconnect) |
|
117 { |
|
118 iReconnect = CPeriodic::NewL(CActive::EPriorityIdle); |
|
119 } |
|
120 |
|
121 TN_DEBUG1( "CThumbAGImageObserver::InitializeL() - connect to MDS" ); |
|
122 |
|
123 if(iMdESession) |
|
124 { |
|
125 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
126 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
127 |
|
128 // connect to MDS |
|
129 delete iMdESession; |
|
130 iMdESession = NULL; |
|
131 } |
|
132 |
|
133 iMdESession = CMdESession::NewL( *this ); |
|
134 iSessionError = EFalse; |
|
135 |
|
136 TN_DEBUG1( "CThumbAGImageObserver::InitializeL() - end" ); |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // ~CThumbAGImageObserver |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 CThumbAGImageObserver::~CThumbAGImageObserver() |
|
144 { |
|
145 TN_DEBUG1( "CThumbAGImageObserver::~CThumbAGImageObserver() - begin" ); |
|
146 |
|
147 iShutdown = ETrue; |
|
148 |
|
149 delete iMDSShutdownObserver; |
|
150 delete iShutdownObserver; |
|
151 |
|
152 if(iReconnect) |
|
153 { |
|
154 iReconnect->Cancel(); |
|
155 delete iReconnect; |
|
156 iReconnect = NULL; |
|
157 } |
|
158 |
|
159 if (iMdESession) |
|
160 { |
|
161 // 2 observers |
|
162 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
163 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
164 |
|
165 delete iMdESession; |
|
166 iMdESession = NULL; |
|
167 } |
|
168 |
|
169 TN_DEBUG1( "CThumbAGImageObserver::~CThumbAGImageObserver() - end" ); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CThumbAGImageObserver::HandleSessionOpened |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CThumbAGImageObserver::HandleSessionOpened( CMdESession& /* aSession */, TInt aError ) |
|
177 { |
|
178 TN_DEBUG1( "CThumbAGImageObserver::HandleSessionOpened"); |
|
179 |
|
180 if (aError == KErrNone) |
|
181 { |
|
182 TRAPD( err, AddObserversL() ); |
|
183 if (err != KErrNone) |
|
184 { |
|
185 TN_DEBUG2( "CThumbAGImageObserver::HandleSessionOpened, AddObserversL error == %d", err ); |
|
186 } |
|
187 } |
|
188 else |
|
189 { |
|
190 TN_DEBUG2( "CThumbAGImageObserver::HandleSessionOpened error == %d", aError ); |
|
191 } |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CThumbAGImageObserver::HandleSessionError |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CThumbAGImageObserver::HandleSessionError( CMdESession& /*aSession*/, TInt aError ) |
|
199 { |
|
200 TN_DEBUG2( "CThumbAGImageObserver::HandleSessionError == %d", aError ); |
|
201 if (aError != KErrNone && !iSessionError) |
|
202 { |
|
203 iSessionError = ETrue; |
|
204 |
|
205 if (!iShutdown) |
|
206 { |
|
207 if (!iReconnect->IsActive()) |
|
208 { |
|
209 iReconnect->Start( KMdEReconnect, KMdEReconnect, |
|
210 TCallBack(ReconnectCallBack, this)); |
|
211 |
|
212 TN_DEBUG1( "CThumbAGImageObserver::HandleSessionError() - reconnect timer started" ); |
|
213 } |
|
214 } |
|
215 |
|
216 } |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CThumbAGImageObserver::HandleObjectNotification |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CThumbAGImageObserver::HandleObjectNotification( CMdESession& /*aSession*/, |
|
224 TObserverNotificationType aType, |
|
225 const RArray<TItemId>& aObjectIdArray ) |
|
226 { |
|
227 TN_DEBUG1( "CThumbAGImageObserver::HandleObjectNotification() - begin" ); |
|
228 |
|
229 // no processor or shutting down |
|
230 if (iShutdown || !iProcessor) |
|
231 { |
|
232 return; |
|
233 } |
|
234 |
|
235 #ifdef _DEBUG |
|
236 if (aType == ENotifyAdd) |
|
237 { |
|
238 TN_DEBUG2( "CThumbAGImageObserver::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() ); |
|
239 iAddCounter = aObjectIdArray.Count(); |
|
240 } |
|
241 else if (aType == ENotifyModify) |
|
242 { |
|
243 TN_DEBUG2( "CThumbAGImageObserver::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() ); |
|
244 iModCounter = aObjectIdArray.Count(); |
|
245 } |
|
246 #endif |
|
247 |
|
248 if ( (aType == ENotifyAdd || aType == ENotifyModify) && aObjectIdArray.Count() > 0 ) |
|
249 { |
|
250 TN_DEBUG1( "CThumbAGImageObserver::HandleObjectNotification() - AddToQueueL" ); |
|
251 |
|
252 // Add event to processing queue by type and enable force run |
|
253 RPointerArray<HBufC> dummyArray; |
|
254 TRAPD(err, iProcessor->AddToQueueL(aType, EGenerationItemTypeImage, aObjectIdArray, dummyArray, EFalse)); |
|
255 if (err != KErrNone) |
|
256 { |
|
257 TN_DEBUG1( "CThumbAGImageObserver::HandleObjectNotification() - error adding to queue" ); |
|
258 } |
|
259 } |
|
260 else |
|
261 { |
|
262 TN_DEBUG1( "CThumbAGImageObserver::HandleObjectNotification() - bad notification" ); |
|
263 } |
|
264 |
|
265 #ifdef _DEBUG |
|
266 TN_DEBUG3( "CThumbAGImageObserver::IN-COUNTERS---------- Add = %d Modify = %d", iAddCounter, iModCounter ); |
|
267 iModCounter = 0; |
|
268 iAddCounter = 0; |
|
269 |
|
270 #endif |
|
271 |
|
272 TN_DEBUG1( "CThumbAGImageObserver::HandleObjectNotification() - end" ); |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // CThumbAGImageObserver::AddObserversL |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 void CThumbAGImageObserver::AddObserversL() |
|
280 { |
|
281 TN_DEBUG1( "CThumbAGImageObserver::AddObserversL() - begin" ); |
|
282 |
|
283 CMdENamespaceDef& defaultNamespace = iMdESession->GetDefaultNamespaceDefL(); |
|
284 CMdEObjectDef& objectDef = defaultNamespace.GetObjectDefL( MdeConstants::Object::KBaseObject ); |
|
285 CMdEPropertyDef& originPropDef = objectDef.GetPropertyDefL( MdeConstants::Object::KOriginProperty ); |
|
286 CMdEObjectDef& imageDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject ); |
|
287 |
|
288 // set observing conditions |
|
289 CMdELogicCondition* addCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorAnd ); |
|
290 addCondition->AddObjectConditionL( imageDef ); |
|
291 addCondition->AddPropertyConditionL( originPropDef, TMdEUintNotEqual(MdeConstants::Object::ECamera)); |
|
292 CleanupStack::Pop( addCondition ); |
|
293 |
|
294 CMdELogicCondition* modifyCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorAnd ); |
|
295 modifyCondition->AddObjectConditionL( imageDef ); |
|
296 addCondition->AddPropertyConditionL( originPropDef, TMdEUintNotEqual(MdeConstants::Object::ECamera)); |
|
297 CleanupStack::Pop( modifyCondition ); |
|
298 |
|
299 // add observers |
|
300 iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); |
|
301 |
|
302 // modify observer |
|
303 iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify ); |
|
304 |
|
305 TN_DEBUG1( "CThumbAGImageObserver::AddObserversL() - end" ); |
|
306 } |
|
307 |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CThumbAGCameraObserver::ShutdownNotification |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CThumbAGImageObserver::ShutdownNotification() |
|
314 { |
|
315 TN_DEBUG1( "CThumbAGImageObserver::ShutdownNotification()" ); |
|
316 |
|
317 if (!iShutdown) |
|
318 { |
|
319 TN_DEBUG1( "CThumbAGImageObserver::ShutdownNotification() shutdown" ); |
|
320 iShutdown = ETrue; |
|
321 } |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // CThumbAGImageObserver::ReconnectCallBack() |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 TInt CThumbAGImageObserver::ReconnectCallBack(TAny* aAny) |
|
329 { |
|
330 TN_DEBUG1( "CThumbAGImageObserver::ReconnectCallBack() - reinitialize"); |
|
331 |
|
332 CThumbAGImageObserver* self = static_cast<CThumbAGImageObserver*>( aAny ); |
|
333 |
|
334 self->iReconnect->Cancel(); |
|
335 |
|
336 // reconnect to MDS |
|
337 TRAP_IGNORE( self->InitializeL() ); |
|
338 |
|
339 TN_DEBUG1( "CThumbAGImageObserver::ReconnectCallBack() - done"); |
|
340 |
|
341 return KErrNone; |
|
342 } |
|
343 |
|
344 |
|
345 // End of file |