imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagdaemon.cpp
branchRCL_3
changeset 7 2eb74cf6572e
parent 5 82749d516180
child 8 7403edfcf0fb
equal deleted inserted replaced
5:82749d516180 7:2eb74cf6572e
    83     iModCounter = 0;
    83     iModCounter = 0;
    84     iDelCounter = 0;
    84     iDelCounter = 0;
    85 #endif
    85 #endif
    86     
    86     
    87     InitializeL();
    87     InitializeL();
       
    88     
       
    89     iReconnect = CPeriodic::NewL(CActive::EPriorityIdle);
    88     	
    90     	
    89 	TN_DEBUG1( "CThumbAGDaemon::ConstructL() - end" );
    91 	TN_DEBUG1( "CThumbAGDaemon::ConstructL() - end" );
    90 	}
    92 	}
    91 
    93 
    92 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
   161     iShutdown = ETrue;    
   163     iShutdown = ETrue;    
   162     
   164     
   163     delete iMDSShutdownObserver;
   165     delete iMDSShutdownObserver;
   164     delete iShutdownObserver;
   166     delete iShutdownObserver;
   165     
   167     
       
   168     if(iReconnect)
       
   169         {
       
   170         iReconnect->Cancel();
       
   171         delete iReconnect;
       
   172         iReconnect = NULL;
       
   173         }
       
   174     
   166     if (iProcessor)
   175     if (iProcessor)
   167         {
   176         {
   168         delete iProcessor;
   177         delete iProcessor;
   169         iProcessor = NULL;
   178         iProcessor = NULL;
   170         }
   179         }
   171     
   180     
   172     if (iMdESession)
   181     if (iMdESession)
   173         {
   182         {
   174         // 3 observers
   183         // 2 observers
   175         TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
   184         TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
   176         TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
   185 //modify        TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
   177         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
   178         TRAP_IGNORE(iMdESession->RemoveObjectPresentObserverL( * this  ));
   193         TRAP_IGNORE(iMdESession->RemoveObjectPresentObserverL( * this  ));
   179         
   194         
   180         delete iMdESession;
   195         delete iMdESession;
   181         iMdESession = NULL;
   196         iMdESession = NULL;
   182         }
   197         }
   262 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
   277 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
   263     {
   278     {
   264     TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError );
   279     TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError );
   265     if (aError != KErrNone)
   280     if (aError != KErrNone)
   266         {
   281         {
   267         delete iMdESession;
   282         // kill processor right away, because it also has MdESession
   268         iMdESession = NULL;
   283         if(iProcessor)
   269         TRAP_IGNORE(InitializeL());
   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 
   270         }   
   300         }   
   271     }
   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
   272 
   327 
   273 // -----------------------------------------------------------------------------
   328 // -----------------------------------------------------------------------------
   274 // CThumbAGDaemon::HandleObjectNotification
   329 // CThumbAGDaemon::HandleObjectNotification
   275 // -----------------------------------------------------------------------------
   330 // -----------------------------------------------------------------------------
   276 //
   331 //
   288     
   343     
   289 #ifdef _DEBUG
   344 #ifdef _DEBUG
   290     if (aType == ENotifyAdd)
   345     if (aType == ENotifyAdd)
   291         {
   346         {
   292         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() );
   347         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() );
   293         iAddCounter = iAddCounter + aObjectIdArray.Count();
   348         iAddCounter = aObjectIdArray.Count();
   294         }
   349         }
   295     else if (aType == ENotifyModify)
   350     else if (aType == ENotifyModify)
   296         {
   351         {
   297         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() );
   352         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() );
   298         iModCounter = iModCounter + aObjectIdArray.Count();
   353         iModCounter = aObjectIdArray.Count();
   299         }
   354         }
   300     else if (aType == ENotifyRemove)
   355     else if (aType == ENotifyRemove)
   301         {
   356         {
   302         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyRemove %d", aObjectIdArray.Count() );
   357         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyRemove %d", aObjectIdArray.Count() );
   303         iDelCounter = iDelCounter + aObjectIdArray.Count();
   358         iDelCounter = aObjectIdArray.Count();
   304         }
   359         }
   305 #endif
   360 #endif
   306     
   361     
   307     if ( (aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove) &&
   362     if ( (aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove) &&
   308          (aObjectIdArray.Count() > 0) )
   363          (aObjectIdArray.Count() > 0) )
   314             {
   369             {
   315             iProcessor->RemoveFromQueues( aObjectIdArray, EFalse);
   370             iProcessor->RemoveFromQueues( aObjectIdArray, EFalse);
   316             }
   371             }
   317         
   372         
   318         // Add event to processing queue by type and enable force run
   373         // Add event to processing queue by type and enable force run
   319         TRAPD(err, iProcessor->AddToQueueL(aType, aObjectIdArray, EFalse));
   374         
       
   375         RPointerArray<HBufC> dummyArray;
       
   376         TRAPD(err, iProcessor->AddToQueueL(aType, aObjectIdArray, dummyArray, EFalse));
   320         if (err != KErrNone)
   377         if (err != KErrNone)
   321             {
   378             {
   322             TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - error adding to queue" );
   379             TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - error adding to queue" );
   323             }
   380             }
   324         }
   381         }
   326         {
   383         {
   327         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - bad notification" );
   384         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - bad notification" );
   328         }
   385         }
   329     
   386     
   330 #ifdef _DEBUG
   387 #ifdef _DEBUG
   331     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", 
   332                aType, aObjectIdArray.Count(), iAddCounter, iModCounter, iDelCounter );
   389                iAddCounter, iModCounter, iDelCounter );
       
   390     iModCounter = 0;
       
   391     iDelCounter = 0;
       
   392     iAddCounter = 0;
       
   393     
   333 #endif
   394 #endif
   334 
   395 
   335     TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - end" );
   396     TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - end" );
   336     }
   397     }
   337 
   398 
   338 // -----------------------------------------------------------------------------
   399 // -----------------------------------------------------------------------------
   339 // CThumbAGDaemon::HandleObjectPresentNotification
   400 // CThumbAGDaemon::HandleObjectPresentNotification
   340 // -----------------------------------------------------------------------------
   401 // -----------------------------------------------------------------------------
   341 //b
   402 //
   342 void CThumbAGDaemon::HandleObjectPresentNotification(CMdESession& /*aSession*/, 
   403 void CThumbAGDaemon::HandleObjectPresentNotification(CMdESession& /*aSession*/, 
   343                TBool aPresent, const RArray<TItemId>& aObjectIdArray)
   404                TBool aPresent, const RArray<TItemId>& aObjectIdArray)
   344     {
   405     {
   345     TN_DEBUG3( "CThumbAGDaemon::HandleObjectPresentNotification() - aPresent == %d count == %d", aPresent, aObjectIdArray.Count() );
   406     TN_DEBUG3( "CThumbAGDaemon::HandleObjectPresentNotification() - aPresent == %d count == %d", aPresent, aObjectIdArray.Count() );
   346     
   407     
   356     if(aPresent)
   417     if(aPresent)
   357         {
   418         {
   358         if ( aObjectIdArray.Count() > 0) 
   419         if ( aObjectIdArray.Count() > 0) 
   359             {
   420             {
   360 		    // do not force run of these items
   421 		    // do not force run of these items
   361             TRAP(err, iProcessor->AddToQueueL(ENotifyAdd, aObjectIdArray, ETrue));
   422             RPointerArray<HBufC> dummyArray;
       
   423             TRAP(err, iProcessor->AddToQueueL(ENotifyAdd, aObjectIdArray, dummyArray, ETrue));
   362            
   424            
   363             TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd %d", aObjectIdArray.Count() );     
   425             TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd %d", aObjectIdArray.Count() );     
   364            
   426            
   365            #ifdef _DEBUG
   427            #ifdef _DEBUG
   366            iAddCounter = iAddCounter + aObjectIdArray.Count();
   428            iAddCounter = aObjectIdArray.Count();
   367            if (err != KErrNone)
   429            if (err != KErrNone)
   368                {
   430                {
   369                TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" );
   431                TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" );
   370                }
   432                }
   371            #endif
   433            #endif
   380             {
   442             {
   381             iAddCounter = 0;
   443             iAddCounter = 0;
   382             }
   444             }
   383         else
   445         else
   384             {
   446             {
   385             iAddCounter = iAddCounter - aObjectIdArray.Count();
   447             iDelCounter = aObjectIdArray.Count();
   386             }
   448             }
   387         #endif
   449         #endif
   388            
   450            
   389         if ( aObjectIdArray.Count() > 0) 
   451         if ( aObjectIdArray.Count() > 0) 
   390             {
   452             {
   391             iProcessor->RemoveFromQueues( aObjectIdArray, ETrue );
   453             iProcessor->RemoveFromQueues( aObjectIdArray, ETrue );
   392             }
   454             }
   393         }
   455         }
   394     
   456     
   395     #ifdef _DEBUG
   457     #ifdef _DEBUG
   396     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", 
   397                aObjectIdArray.Count(), iAddCounter, iModCounter, iDelCounter );
   459                iAddCounter, iModCounter, iDelCounter );
       
   460     iModCounter = 0;
       
   461     iDelCounter = 0;
       
   462     iAddCounter = 0;
   398     #endif
   463     #endif
   399     
   464     
   400     TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - end" );
   465     TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - end" );
   401     }
   466     }
   402 
   467 
   441     modifyCondition->AddObjectConditionL( audioDef );
   506     modifyCondition->AddObjectConditionL( audioDef );
   442     CleanupStack::Pop( modifyCondition );
   507     CleanupStack::Pop( modifyCondition );
   443     
   508     
   444     // add observer
   509     // add observer
   445     iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); 
   510     iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); 
   446     
   511 
   447     // modify observer
   512    // modify observer
   448     iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify );
   513    //iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify );
   449  
   514  
   450     // remove observer
   515 #ifdef MDS_URI_OBSERVER
   451     iMdESession->AddObjectObserverL( *this, NULL, ENotifyRemove );
   516     // remove observer with uri
       
   517     iMdESession->AddObjectObserverWithUriL( *this, NULL, ENotifyRemove );
       
   518 #endif
   452     
   519     
   453     // object present observer
   520     // object present observer
   454     iMdESession->AddObjectPresentObserverL( *this );
   521     iMdESession->AddObjectPresentObserverL( *this );
   455     
   522     
   456     TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - end" );
   523     TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - end" );
   473     TN_DEBUG3( "CThumbAGDaemon::DaemonEnabledL() - val == %d, ret == %d", val, ret );
   540     TN_DEBUG3( "CThumbAGDaemon::DaemonEnabledL() - val == %d, ret == %d", val, ret );
   474     return val;
   541     return val;
   475     }
   542     }
   476 
   543 
   477 // ---------------------------------------------------------------------------
   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 // ---------------------------------------------------------------------------
   478 // E32Main
   565 // E32Main
   479 // ---------------------------------------------------------------------------
   566 // ---------------------------------------------------------------------------
   480 //
   567 //
   481 TInt E32Main()
   568 TInt E32Main()
   482     {    
   569     {