|
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 "thumbagaudioobserver.h" |
|
28 #include "thumbnaillog.h" |
|
29 #include "thumbnailmanagerconstants.h" |
|
30 #include "thumbnailmanagerprivatecrkeys.h" |
|
31 |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // NewLC |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CThumbAGAudioObserver* CThumbAGAudioObserver::NewLC(CThumbAGProcessor* aProcessor) |
|
38 { |
|
39 TN_DEBUG1( "CThumbAGAudioObserver::NewLC() - begin" ); |
|
40 |
|
41 CThumbAGAudioObserver* self = new (ELeave) CThumbAGAudioObserver(aProcessor); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // NewL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CThumbAGAudioObserver* CThumbAGAudioObserver::NewL(CThumbAGProcessor* aProcessor) |
|
52 { |
|
53 TN_DEBUG1( "CThumbAGAudioObserver::NewL() - begin" ); |
|
54 |
|
55 CThumbAGAudioObserver* self = CThumbAGAudioObserver::NewLC(aProcessor); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CThumbAGAudioObserver |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CThumbAGAudioObserver::CThumbAGAudioObserver(CThumbAGProcessor* aProcessor) |
|
65 : iShutdownObserver(NULL), iMDSShutdownObserver(NULL), iMdESession(NULL), iProcessor(aProcessor) |
|
66 { |
|
67 // No implementation required |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // ConstructL |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CThumbAGAudioObserver::ConstructL() |
|
75 { |
|
76 TN_DEBUG1( "CThumbAGAudioObserver::ConstructL() - begin" ); |
|
77 |
|
78 #ifdef _DEBUG |
|
79 iAddCounter = 0; |
|
80 iModCounter = 0; |
|
81 #endif |
|
82 |
|
83 InitializeL(); |
|
84 |
|
85 TN_DEBUG1( "CThumbAGAudioObserver::ConstructL() - end" ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // ~CThumbAGAudioObserver |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CThumbAGAudioObserver::InitializeL() |
|
93 { |
|
94 TN_DEBUG1( "CThumbAGAudioObserver::InitializeL() - begin" ); |
|
95 |
|
96 |
|
97 TN_DEBUG1( "CThumbAGAudioObserver::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( "CThumbAGAudioObserver::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( "CThumbAGAudioObserver::InitializeL() - end" ); |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // ~CThumbAGAudioObserver |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 CThumbAGAudioObserver::~CThumbAGAudioObserver() |
|
144 { |
|
145 TN_DEBUG1( "CThumbAGAudioObserver::~CThumbAGAudioObserver() - begin" ); |
|
146 |
|
147 iShutdown = ETrue; |
|
148 |
|
149 Shutdown(); |
|
150 |
|
151 TN_DEBUG1( "CThumbAGAudioObserver::~CThumbAGAudioObserver() - end" ); |
|
152 } |
|
153 |
|
154 void CThumbAGAudioObserver::Shutdown() |
|
155 { |
|
156 TN_DEBUG1( "CThumbAGAudioObserver::Shutdown()" ); |
|
157 |
|
158 delete iMDSShutdownObserver; |
|
159 iMDSShutdownObserver = NULL; |
|
160 delete iShutdownObserver; |
|
161 iShutdownObserver = NULL; |
|
162 |
|
163 if(iReconnect) |
|
164 { |
|
165 iReconnect->Cancel(); |
|
166 delete iReconnect; |
|
167 iReconnect = NULL; |
|
168 } |
|
169 |
|
170 if (iMdESession) |
|
171 { |
|
172 // 2 observers |
|
173 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
174 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
175 |
|
176 delete iMdESession; |
|
177 iMdESession = NULL; |
|
178 } |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CThumbAGAudioObserver::HandleSessionOpened |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CThumbAGAudioObserver::HandleSessionOpened( CMdESession& /* aSession */, TInt aError ) |
|
186 { |
|
187 TN_DEBUG1( "CThumbAGAudioObserver::HandleSessionOpened"); |
|
188 |
|
189 if (aError == KErrNone) |
|
190 { |
|
191 TRAPD( err, AddObserversL() ); |
|
192 if (err != KErrNone) |
|
193 { |
|
194 TN_DEBUG2( "CThumbAGAudioObserver::HandleSessionOpened, AddObserversL error == %d", err ); |
|
195 } |
|
196 } |
|
197 else |
|
198 { |
|
199 TN_DEBUG2( "CThumbAGAudioObserver::HandleSessionOpened error == %d", aError ); |
|
200 } |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CThumbAGAudioObserver::HandleSessionError |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CThumbAGAudioObserver::HandleSessionError( CMdESession& /*aSession*/, TInt aError ) |
|
208 { |
|
209 TN_DEBUG2( "CThumbAGAudioObserver::HandleSessionError == %d", aError ); |
|
210 if (aError != KErrNone && !iSessionError) |
|
211 { |
|
212 iSessionError = ETrue; |
|
213 |
|
214 if (!iShutdown) |
|
215 { |
|
216 if (!iReconnect->IsActive()) |
|
217 { |
|
218 iReconnect->Start( KMdEReconnect, KMdEReconnect, |
|
219 TCallBack(ReconnectCallBack, this)); |
|
220 |
|
221 TN_DEBUG1( "CThumbAGAudioObserver::HandleSessionError() - reconnect timer started" ); |
|
222 } |
|
223 } |
|
224 |
|
225 } |
|
226 } |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CThumbAGAudioObserver::HandleObjectNotification |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 void CThumbAGAudioObserver::HandleObjectNotification( CMdESession& /*aSession*/, |
|
233 TObserverNotificationType aType, |
|
234 const RArray<TItemId>& aObjectIdArray ) |
|
235 { |
|
236 TN_DEBUG1( "CThumbAGAudioObserver::HandleObjectNotification() - begin" ); |
|
237 |
|
238 // no processor or shutting down |
|
239 if ( iShutdown || !iProcessor) |
|
240 { |
|
241 return; |
|
242 } |
|
243 |
|
244 #ifdef _DEBUG |
|
245 if (aType == ENotifyAdd) |
|
246 { |
|
247 TN_DEBUG2( "CThumbAGAudioObserver::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() ); |
|
248 iAddCounter = aObjectIdArray.Count(); |
|
249 } |
|
250 else if (aType == ENotifyModify) |
|
251 { |
|
252 TN_DEBUG2( "CThumbAGAudioObserver::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() ); |
|
253 iModCounter = aObjectIdArray.Count(); |
|
254 } |
|
255 #endif |
|
256 |
|
257 if ( (aType == ENotifyAdd || aType == ENotifyModify ) && (aObjectIdArray.Count() > 0) ) |
|
258 { |
|
259 TN_DEBUG1( "CThumbAGAudioObserver::HandleObjectNotification() - AddToQueueL" ); |
|
260 |
|
261 // Add event to processing queue by type and enable force run |
|
262 RPointerArray<HBufC> dummyArray; |
|
263 TRAPD(err, iProcessor->AddToQueueL(aType, EGenerationItemTypeAudio, aObjectIdArray, dummyArray, EFalse)); |
|
264 if (err != KErrNone) |
|
265 { |
|
266 TN_DEBUG1( "CThumbAGAudioObserver::HandleObjectNotification() - error adding to queue" ); |
|
267 } |
|
268 } |
|
269 else |
|
270 { |
|
271 TN_DEBUG1( "CThumbAGAudioObserver::HandleObjectNotification() - bad notification" ); |
|
272 } |
|
273 |
|
274 #ifdef _DEBUG |
|
275 TN_DEBUG3( "CThumbAGAudioObserver::IN-COUNTERS---------- Add = %d Modify = %d", iAddCounter, iModCounter ); |
|
276 iModCounter = 0; |
|
277 iAddCounter = 0; |
|
278 #endif |
|
279 |
|
280 TN_DEBUG1( "CThumbAGAudioObserver::HandleObjectNotification() - end" ); |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CThumbAGAudioObserver::ShutdownNotification |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CThumbAGAudioObserver::ShutdownNotification() |
|
288 { |
|
289 TN_DEBUG1( "CThumbAGAudioObserver::ShutdownNotification()" ); |
|
290 |
|
291 if (!iShutdown) |
|
292 { |
|
293 TN_DEBUG1( "CThumbAGAudioObserver::ShutdownNotification() shutdown" ); |
|
294 iShutdown = ETrue; |
|
295 } |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // CThumbAGAudioObserver::AddObserversL |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CThumbAGAudioObserver::AddObserversL() |
|
303 { |
|
304 TN_DEBUG1( "CThumbAGAudioObserver::AddObserversL() - begin" ); |
|
305 |
|
306 CMdENamespaceDef& defaultNamespace = iMdESession->GetDefaultNamespaceDefL(); |
|
307 CMdEObjectDef& audioDef = defaultNamespace.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
308 |
|
309 // set observing conditions |
|
310 CMdELogicCondition* addCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorAnd ); |
|
311 addCondition->AddObjectConditionL( audioDef ); |
|
312 CleanupStack::Pop( addCondition ); |
|
313 |
|
314 CMdELogicCondition* modifyCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorAnd ); |
|
315 modifyCondition->AddObjectConditionL( audioDef ); |
|
316 CleanupStack::Pop( modifyCondition ); |
|
317 |
|
318 // add observer |
|
319 iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); |
|
320 |
|
321 // modify observer |
|
322 iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify ); |
|
323 |
|
324 TN_DEBUG1( "CThumbAGAudioObserver::AddObserversL() - end" ); |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // CThumbAGAudioObserver::ReconnectCallBack() |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CThumbAGAudioObserver::ReconnectCallBack(TAny* aAny) |
|
332 { |
|
333 TN_DEBUG1( "CThumbAGAudioObserver::ReconnectCallBack() - reinitialize"); |
|
334 |
|
335 CThumbAGAudioObserver* self = static_cast<CThumbAGAudioObserver*>( aAny ); |
|
336 |
|
337 self->iReconnect->Cancel(); |
|
338 |
|
339 // reconnect to MDS |
|
340 TRAP_IGNORE( self->InitializeL() ); |
|
341 |
|
342 TN_DEBUG1( "CThumbAGAudioObserver::ReconnectCallBack() - done"); |
|
343 |
|
344 return KErrNone; |
|
345 } |
|
346 |
|
347 |
|
348 // End of file |