60 // --------------------------------------------------------------------------- |
60 // --------------------------------------------------------------------------- |
61 // CThumbAGDaemon |
61 // CThumbAGDaemon |
62 // --------------------------------------------------------------------------- |
62 // --------------------------------------------------------------------------- |
63 // |
63 // |
64 CThumbAGDaemon::CThumbAGDaemon() |
64 CThumbAGDaemon::CThumbAGDaemon() |
65 : CServer2( CActive::EPriorityStandard, CServer2::EUnsharableSessions ) |
65 : CServer2( CActive::EPriorityStandard, CServer2::EUnsharableSessions ), iShutdownObserver(NULL), |
|
66 iMDSShutdownObserver(NULL), iMdESession(NULL), iProcessor(NULL) |
66 { |
67 { |
67 // No implementation required |
68 // No implementation required |
68 } |
69 } |
69 |
70 |
70 // --------------------------------------------------------------------------- |
71 // --------------------------------------------------------------------------- |
80 #ifdef _DEBUG |
81 #ifdef _DEBUG |
81 iAddCounter = 0; |
82 iAddCounter = 0; |
82 iModCounter = 0; |
83 iModCounter = 0; |
83 iDelCounter = 0; |
84 iDelCounter = 0; |
84 #endif |
85 #endif |
85 |
86 |
|
87 InitializeL(); |
|
88 |
|
89 iReconnect = CPeriodic::NewL(CActive::EPriorityIdle); |
|
90 |
|
91 TN_DEBUG1( "CThumbAGDaemon::ConstructL() - end" ); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // ~CThumbAGDaemon |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CThumbAGDaemon::InitializeL() |
|
99 { |
|
100 TN_DEBUG1( "CThumbAGDaemon::InitializeL() - begin" ); |
|
101 |
86 if (DaemonEnabledL()) |
102 if (DaemonEnabledL()) |
87 { |
103 { |
88 TN_DEBUG1( "CThumbAGDaemon::ConstructL() - create observers" ); |
104 TN_DEBUG1( "CThumbAGDaemon::InitializeL() - create observers" ); |
89 |
105 |
90 // create shutdown observer |
106 // create shutdown observer |
|
107 if(iMDSShutdownObserver) |
|
108 { |
|
109 delete iMDSShutdownObserver; |
|
110 iMDSShutdownObserver = NULL; |
|
111 } |
91 iMDSShutdownObserver = CTMShutdownObserver::NewL( *this, KMdSPSShutdown, KMdSShutdown, EFalse ); |
112 iMDSShutdownObserver = CTMShutdownObserver::NewL( *this, KMdSPSShutdown, KMdSShutdown, EFalse ); |
92 iShutdownObserver = CTMShutdownObserver::NewL( *this, KTAGDPSNotification, KShutdown, ETrue ); |
113 |
93 iShutdown = EFalse; |
114 if(iShutdownObserver) |
94 |
115 { |
|
116 delete iShutdownObserver; |
|
117 iShutdownObserver = NULL; |
|
118 } |
|
119 iShutdownObserver = CTMShutdownObserver::NewL( *this, KTAGDPSNotification, KShutdown, ETrue ); |
|
120 iShutdown = EFalse; |
|
121 |
95 // create processor |
122 // create processor |
96 iProcessor = NULL; |
123 if(iProcessor) |
97 iProcessor = CThumbAGProcessor::NewL(); |
124 { |
98 |
125 delete iProcessor; |
99 TN_DEBUG1( "CThumbAGDaemon::ConstructL() - connect to MDS" ); |
126 iProcessor = NULL; |
100 |
127 } |
101 // connect to MDS |
128 |
102 iMdESession = NULL; |
129 iProcessor = CThumbAGProcessor::NewL(); |
103 iMdESession = CMdESession::NewL( *this ); |
130 |
|
131 TN_DEBUG1( "CThumbAGDaemon::InitializeL() - connect to MDS" ); |
|
132 |
|
133 if(iMdESession) |
|
134 { |
|
135 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
136 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
137 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
|
138 TRAP_IGNORE( iMdESession->RemoveObjectPresentObserverL( * this )); |
|
139 |
|
140 // connect to MDS |
|
141 delete iMdESession; |
|
142 iMdESession = NULL; |
|
143 } |
|
144 |
|
145 iMdESession = CMdESession::NewL( *this ); |
104 } |
146 } |
105 else |
147 else |
106 { |
148 { |
107 // no error here, but need to shutdown daemon neatly |
149 // no error here, but need to shutdown daemon neatly |
108 User::Leave(KErrNone); |
150 User::Leave(KErrNone); |
109 } |
151 } |
110 |
152 TN_DEBUG1( "CThumbAGDaemon::InitializeL() - end" ); |
111 TN_DEBUG1( "CThumbAGDaemon::ConstructL() - end" ); |
153 } |
112 } |
|
113 |
154 |
114 // --------------------------------------------------------------------------- |
155 // --------------------------------------------------------------------------- |
115 // ~CThumbAGDaemon |
156 // ~CThumbAGDaemon |
116 // --------------------------------------------------------------------------- |
157 // --------------------------------------------------------------------------- |
117 // |
158 // |
122 iShutdown = ETrue; |
163 iShutdown = ETrue; |
123 |
164 |
124 delete iMDSShutdownObserver; |
165 delete iMDSShutdownObserver; |
125 delete iShutdownObserver; |
166 delete iShutdownObserver; |
126 |
167 |
|
168 if(iReconnect) |
|
169 { |
|
170 iReconnect->Cancel(); |
|
171 delete iReconnect; |
|
172 iReconnect = NULL; |
|
173 } |
|
174 |
127 if (iProcessor) |
175 if (iProcessor) |
128 { |
176 { |
129 delete iProcessor; |
177 delete iProcessor; |
130 iProcessor = NULL; |
178 iProcessor = NULL; |
131 } |
179 } |
132 |
180 |
133 if (iMdESession) |
181 if (iMdESession) |
134 { |
182 { |
135 // 3 observers |
183 // 2 observers |
136 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
184 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
137 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
185 //modify TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
138 TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) ); |
186 |
|
187 #ifdef MDS_URI_OBSERVER |
|
188 // remove observer with uri |
|
189 TRAP_IGNORE( iMdESession->RemoveObjectObserverWithUriL( *this ) ); |
|
190 #endif |
|
191 |
|
192 //present observer |
139 TRAP_IGNORE(iMdESession->RemoveObjectPresentObserverL( * this )); |
193 TRAP_IGNORE(iMdESession->RemoveObjectPresentObserverL( * this )); |
140 |
194 |
141 delete iMdESession; |
195 delete iMdESession; |
142 iMdESession = NULL; |
196 iMdESession = NULL; |
143 } |
197 } |
201 TN_DEBUG1( "CThumbAGDaemon::HandleSessionOpened"); |
255 TN_DEBUG1( "CThumbAGDaemon::HandleSessionOpened"); |
202 |
256 |
203 if (aError == KErrNone) |
257 if (aError == KErrNone) |
204 { |
258 { |
205 iProcessor->SetMdESession(iMdESession); |
259 iProcessor->SetMdESession(iMdESession); |
206 TRAP_IGNORE(iProcessor->QueryForPlaceholdersL()); |
|
207 |
260 |
208 TRAPD( err, AddObserversL() ); |
261 TRAPD( err, AddObserversL() ); |
209 if (err != KErrNone) |
262 if (err != KErrNone) |
210 { |
263 { |
211 TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened, AddObserversL error == %d", err ); |
264 TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened, AddObserversL error == %d", err ); |
221 // CThumbAGDaemon::HandleSessionError |
274 // CThumbAGDaemon::HandleSessionError |
222 // ----------------------------------------------------------------------------- |
275 // ----------------------------------------------------------------------------- |
223 // |
276 // |
224 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError ) |
277 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError ) |
225 { |
278 { |
|
279 TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError ); |
226 if (aError != KErrNone) |
280 if (aError != KErrNone) |
227 { |
281 { |
228 TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError ); |
282 // kill processor right away, because it also has MdESession |
|
283 if(iProcessor) |
|
284 { |
|
285 delete iProcessor; |
|
286 iProcessor = NULL; |
|
287 } |
|
288 |
|
289 if (!iShutdown) |
|
290 { |
|
291 if (!iReconnect->IsActive()) |
|
292 { |
|
293 iReconnect->Start( KMdEReconnect, KMdEReconnect, |
|
294 TCallBack(ReconnectCallBack, this)); |
|
295 |
|
296 TN_DEBUG1( "CThumbAGDaemon::HandleSessionError() - reconnect timer started" ); |
|
297 } |
|
298 } |
|
299 |
229 } |
300 } |
230 } |
301 } |
|
302 |
|
303 #ifdef MDS_URI_OBSERVER |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CThumbAGDaemon::HandleObjectNotification |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 |
|
309 void CThumbAGDaemon::HandleUriObjectNotification(CMdESession& aSession, |
|
310 TObserverNotificationType aType, |
|
311 const RArray<TItemId>& aObjectIdArray, |
|
312 const RPointerArray<HBufC>& aObjectUriArray) |
|
313 { |
|
314 TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - begin" ); |
|
315 |
|
316 if(aType == ENotifyRemove) |
|
317 { |
|
318 TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - removed"); |
|
319 TInt err(0); |
|
320 TRAP(err, iProcessor->AddToQueueL(aType, aObjectIdArray, aObjectUriArray, EFalse)); |
|
321 __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGDaemon::HandleUriObjectNotification()"), err)); |
|
322 err = KErrNone; |
|
323 } |
|
324 TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - end" ); |
|
325 } |
|
326 #endif |
231 |
327 |
232 // ----------------------------------------------------------------------------- |
328 // ----------------------------------------------------------------------------- |
233 // CThumbAGDaemon::HandleObjectNotification |
329 // CThumbAGDaemon::HandleObjectNotification |
234 // ----------------------------------------------------------------------------- |
330 // ----------------------------------------------------------------------------- |
235 // |
331 // |
247 |
343 |
248 #ifdef _DEBUG |
344 #ifdef _DEBUG |
249 if (aType == ENotifyAdd) |
345 if (aType == ENotifyAdd) |
250 { |
346 { |
251 TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() ); |
347 TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() ); |
252 iAddCounter = iAddCounter + aObjectIdArray.Count(); |
348 iAddCounter = aObjectIdArray.Count(); |
253 } |
349 } |
254 else if (aType == ENotifyModify) |
350 else if (aType == ENotifyModify) |
255 { |
351 { |
256 TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() ); |
352 TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() ); |
257 iModCounter = iModCounter + aObjectIdArray.Count(); |
353 iModCounter = aObjectIdArray.Count(); |
258 } |
354 } |
259 else if (aType == ENotifyRemove) |
355 else if (aType == ENotifyRemove) |
260 { |
356 { |
261 TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyRemove %d", aObjectIdArray.Count() ); |
357 TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyRemove %d", aObjectIdArray.Count() ); |
262 iDelCounter = iDelCounter + aObjectIdArray.Count(); |
358 iDelCounter = aObjectIdArray.Count(); |
263 } |
359 } |
264 #endif |
360 #endif |
265 |
361 |
266 if ( (aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove) && |
362 if ( (aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove) && |
267 (aObjectIdArray.Count() > 0) ) |
363 (aObjectIdArray.Count() > 0) ) |
269 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - AddToQueueL" ); |
365 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - AddToQueueL" ); |
270 |
366 |
271 // If delete event, remove IDs from Modify and Add queues |
367 // If delete event, remove IDs from Modify and Add queues |
272 if ( aType == ENotifyRemove ) |
368 if ( aType == ENotifyRemove ) |
273 { |
369 { |
274 iProcessor->RemoveFromQueues( aObjectIdArray ); |
370 iProcessor->RemoveFromQueues( aObjectIdArray, EFalse); |
275 } |
371 } |
276 |
372 |
277 // Add event to processing queue by type and enable force run |
373 // Add event to processing queue by type and enable force run |
278 TRAPD(err, iProcessor->AddToQueueL(aType, aObjectIdArray, EFalse)); |
374 |
|
375 RPointerArray<HBufC> dummyArray; |
|
376 TRAPD(err, iProcessor->AddToQueueL(aType, aObjectIdArray, dummyArray, EFalse)); |
279 if (err != KErrNone) |
377 if (err != KErrNone) |
280 { |
378 { |
281 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - error adding to queue" ); |
379 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - error adding to queue" ); |
282 } |
380 } |
283 } |
381 } |
285 { |
383 { |
286 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - bad notification" ); |
384 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - bad notification" ); |
287 } |
385 } |
288 |
386 |
289 #ifdef _DEBUG |
387 #ifdef _DEBUG |
290 TN_DEBUG6( "CThumbAGDaemon::IN-COUNTERS---------- Type: %d Amount: %d, Add = %d Modify = %d Delete = %d", |
388 TN_DEBUG4( "CThumbAGDaemon::IN-COUNTERS---------- Add = %d Modify = %d Delete = %d", |
291 aType, aObjectIdArray.Count(), iAddCounter, iModCounter, iDelCounter ); |
389 iAddCounter, iModCounter, iDelCounter ); |
|
390 iModCounter = 0; |
|
391 iDelCounter = 0; |
|
392 iAddCounter = 0; |
|
393 |
292 #endif |
394 #endif |
293 |
395 |
294 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - end" ); |
396 TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - end" ); |
295 } |
397 } |
296 |
398 |
312 TInt err = 0; |
414 TInt err = 0; |
313 |
415 |
314 //tread present objects as added |
416 //tread present objects as added |
315 if(aPresent) |
417 if(aPresent) |
316 { |
418 { |
317 TRAP_IGNORE( iProcessor->QueryForPlaceholdersL()); |
|
318 if ( aObjectIdArray.Count() > 0) |
419 if ( aObjectIdArray.Count() > 0) |
319 { |
420 { |
320 // do not force run of these items |
421 // do not force run of these items |
321 TRAP(err, iProcessor->AddToQueueL(ENotifyModify, aObjectIdArray, ETrue)); |
422 RPointerArray<HBufC> dummyArray; |
|
423 TRAP(err, iProcessor->AddToQueueL(ENotifyAdd, aObjectIdArray, dummyArray, ETrue)); |
322 |
424 |
323 TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd %d", aObjectIdArray.Count() ); |
425 TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd %d", aObjectIdArray.Count() ); |
324 |
426 |
325 |
427 #ifdef _DEBUG |
326 #ifdef _DEBUG |
428 iAddCounter = aObjectIdArray.Count(); |
327 iAddCounter = iAddCounter + aObjectIdArray.Count(); |
|
328 if (err != KErrNone) |
429 if (err != KErrNone) |
329 { |
430 { |
330 TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" ); |
431 TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" ); |
331 } |
432 } |
332 #endif |
433 #endif |
333 } |
434 } |
334 } |
435 } |
335 else |
436 else |
336 { |
437 { |
337 TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - handle not present" ); |
438 TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - handle not present" ); |
338 TRAP_IGNORE( iProcessor->QueryForPlaceholdersL() ); |
439 |
339 #ifdef _DEBUG |
440 #ifdef _DEBUG |
340 if( iModCounter < aObjectIdArray.Count() ) |
441 if( iAddCounter < aObjectIdArray.Count() ) |
341 { |
442 { |
342 iModCounter = 0; |
443 iAddCounter = 0; |
343 } |
444 } |
344 else |
445 else |
345 { |
446 { |
346 iModCounter = iModCounter - aObjectIdArray.Count(); |
447 iDelCounter = aObjectIdArray.Count(); |
347 } |
448 } |
348 #endif |
449 #endif |
349 |
450 |
350 if ( aObjectIdArray.Count() > 0) |
451 if ( aObjectIdArray.Count() > 0) |
351 { |
452 { |
352 iProcessor->RemoveFromQueues( aObjectIdArray, ETrue ); |
453 iProcessor->RemoveFromQueues( aObjectIdArray, ETrue ); |
353 } |
454 } |
354 } |
455 } |
355 |
456 |
356 #ifdef _DEBUG |
457 #ifdef _DEBUG |
357 TN_DEBUG5( "CThumbAGDaemon::IN-COUNTERS---------- Amount: %d, Add = %d Modify = %d Delete = %d", |
458 TN_DEBUG4( "CThumbAGDaemon::IN-COUNTERS---------- Add = %d Modify = %d Delete = %d", |
358 aObjectIdArray.Count(), iAddCounter, iModCounter, iDelCounter ); |
459 iAddCounter, iModCounter, iDelCounter ); |
|
460 iModCounter = 0; |
|
461 iDelCounter = 0; |
|
462 iAddCounter = 0; |
359 #endif |
463 #endif |
360 |
464 |
361 TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - end" ); |
465 TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - end" ); |
362 } |
466 } |
363 |
467 |
402 modifyCondition->AddObjectConditionL( audioDef ); |
506 modifyCondition->AddObjectConditionL( audioDef ); |
403 CleanupStack::Pop( modifyCondition ); |
507 CleanupStack::Pop( modifyCondition ); |
404 |
508 |
405 // add observer |
509 // add observer |
406 iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); |
510 iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); |
407 |
511 |
408 // modify observer |
512 // modify observer |
409 iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify ); |
513 //iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify ); |
410 |
514 |
411 // remove observer |
515 #ifdef MDS_URI_OBSERVER |
412 iMdESession->AddObjectObserverL( *this, NULL, ENotifyRemove ); |
516 // remove observer with uri |
|
517 iMdESession->AddObjectObserverWithUriL( *this, NULL, ENotifyRemove ); |
|
518 #endif |
413 |
519 |
414 // object present observer |
520 // object present observer |
415 iMdESession->AddObjectPresentObserverL( *this ); |
521 iMdESession->AddObjectPresentObserverL( *this ); |
416 |
522 |
417 TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - end" ); |
523 TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - end" ); |
434 TN_DEBUG3( "CThumbAGDaemon::DaemonEnabledL() - val == %d, ret == %d", val, ret ); |
540 TN_DEBUG3( "CThumbAGDaemon::DaemonEnabledL() - val == %d, ret == %d", val, ret ); |
435 return val; |
541 return val; |
436 } |
542 } |
437 |
543 |
438 // --------------------------------------------------------------------------- |
544 // --------------------------------------------------------------------------- |
|
545 // CThumbAGDaemon::ReconnectCallBack() |
|
546 // --------------------------------------------------------------------------- |
|
547 // |
|
548 TInt CThumbAGDaemon::ReconnectCallBack(TAny* aAny) |
|
549 { |
|
550 TN_DEBUG1( "CThumbAGDaemon::ReconnectCallBack() - reinitialize"); |
|
551 |
|
552 CThumbAGDaemon* self = static_cast<CThumbAGDaemon*>( aAny ); |
|
553 |
|
554 self->iReconnect->Cancel(); |
|
555 |
|
556 // reconnect to MDS |
|
557 TRAP_IGNORE( self->InitializeL() ); |
|
558 |
|
559 TN_DEBUG1( "CThumbAGDaemon::ReconnectCallBack() - done"); |
|
560 |
|
561 return KErrNone; |
|
562 } |
|
563 |
|
564 // --------------------------------------------------------------------------- |
439 // E32Main |
565 // E32Main |
440 // --------------------------------------------------------------------------- |
566 // --------------------------------------------------------------------------- |
441 // |
567 // |
442 TInt E32Main() |
568 TInt E32Main() |
443 { |
569 { |