imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagdaemon.cpp
changeset 29 4bdfb6b5c9b4
parent 22 a67f74060682
child 33 221be23823c5
equal deleted inserted replaced
25:cb86b71cae0a 29:4bdfb6b5c9b4
    78 	
    78 	
    79 	StartL( KTAGDaemonName );
    79 	StartL( KTAGDaemonName );
    80 	
    80 	
    81 #ifdef _DEBUG
    81 #ifdef _DEBUG
    82     iAddCounter = 0;
    82     iAddCounter = 0;
    83     iModCounter = 0;
       
    84     iDelCounter = 0;
    83     iDelCounter = 0;
    85 #endif
    84 #endif
    86     
    85     
    87     InitializeL();
    86     InitializeL();
    88     	
    87     	
   118         iShutdown = EFalse;
   117         iShutdown = EFalse;
   119         
   118         
   120         // create processor
   119         // create processor
   121         if(iProcessor)
   120         if(iProcessor)
   122             {
   121             {
       
   122             iProcessor->Shutdown();
   123             delete iProcessor;
   123             delete iProcessor;
   124             iProcessor = NULL; 
   124             iProcessor = NULL; 
   125             }
   125             }
   126         
   126         
   127         iProcessor = CThumbAGProcessor::NewL(); 
   127         iProcessor = CThumbAGProcessor::NewL(); 
   134         
   134         
   135         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - connect to MDS" );
   135         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - connect to MDS" );
   136         
   136         
   137         if(iMdESession)
   137         if(iMdESession)
   138             {
   138             {
   139             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
   139             TRAP_IGNORE( iMdESession->RemoveObjectObserverWithUriL( *this ) );
   140             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   141             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   142             TRAP_IGNORE( iMdESession->RemoveObjectPresentObserverL( * this  ));
   140             TRAP_IGNORE( iMdESession->RemoveObjectPresentObserverL( * this  ));
   143         
   141         
   144             // connect to MDS
   142             // connect to MDS
   145             delete iMdESession;
   143             delete iMdESession;
   146             iMdESession = NULL;
   144             iMdESession = NULL;
   147             }
   145             }
   148 
   146 
   149         iMdESession = CMdESession::NewL( *this );
   147         iMdESession = CMdESession::NewL( *this );
   150         iSessionError = EFalse;
   148         iSessionError = EFalse;
       
   149         
       
   150         delete iImageObserver;
       
   151         iImageObserver = NULL;
       
   152         iImageObserver = CThumbAGImageObserver::NewL(iProcessor);
       
   153        
       
   154         delete iCameraObserver;
       
   155         iCameraObserver = NULL;
       
   156         iCameraObserver = CThumbAGCameraObserver::NewL(iProcessor);
       
   157         
       
   158         delete iAudioObserver;
       
   159         iAudioObserver = NULL;
       
   160         iAudioObserver = CThumbAGAudioObserver::NewL(iProcessor);
       
   161         
       
   162         delete iVideoObserver;
       
   163         iVideoObserver = NULL;
       
   164         iVideoObserver = CThumbAGVideoObserver::NewL(iProcessor);
   151         }
   165         }
   152     else
   166     else
   153         {
   167         {
   154         // no error here, but need to shutdown daemon neatly
   168         // no error here, but need to shutdown daemon neatly
   155         User::Leave(KErrNone);
   169         User::Leave(KErrNone);
   163 //
   177 //
   164 CThumbAGDaemon::~CThumbAGDaemon()
   178 CThumbAGDaemon::~CThumbAGDaemon()
   165     {
   179     {
   166     TN_DEBUG1( "CThumbAGDaemon::~CThumbAGDaemon() - begin" );
   180     TN_DEBUG1( "CThumbAGDaemon::~CThumbAGDaemon() - begin" );
   167     
   181     
   168     iShutdown = ETrue;    
   182     iShutdown = ETrue;
       
   183     
       
   184     delete iImageObserver;
       
   185     iImageObserver = NULL;
       
   186     
       
   187     delete iCameraObserver;
       
   188     iCameraObserver = NULL;
       
   189     
       
   190     delete iVideoObserver;
       
   191     iVideoObserver = NULL;
       
   192     
       
   193     delete iAudioObserver;
       
   194     iAudioObserver = NULL;
   169     
   195     
   170     delete iMDSShutdownObserver;
   196     delete iMDSShutdownObserver;
   171     delete iShutdownObserver;
   197     delete iShutdownObserver;
   172     
   198     
   173     if(iReconnect)
   199     if(iReconnect)
   177         iReconnect = NULL;
   203         iReconnect = NULL;
   178         }
   204         }
   179     
   205     
   180     if (iProcessor)
   206     if (iProcessor)
   181         {
   207         {
       
   208         iProcessor->Shutdown();
   182         delete iProcessor;
   209         delete iProcessor;
   183         iProcessor = NULL;
   210         iProcessor = NULL;
   184         }
   211         }
   185     
   212     
   186     if (iMdESession)
   213     if (iMdESession)
   187         {
   214         {
   188         // 2 observers
       
   189         TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   190         
       
   191 #ifdef MDS_URI_OBSERVER
   215 #ifdef MDS_URI_OBSERVER
   192         // remove observer with uri
   216         // remove observer with uri
   193         TRAP_IGNORE( iMdESession->RemoveObjectObserverWithUriL( *this ) );
   217         TRAP_IGNORE( iMdESession->RemoveObjectObserverWithUriL( *this ) );
   194 #endif
   218 #endif
   195         
   219         
   258     {
   282     {
   259     TN_DEBUG1( "CThumbAGDaemon::HandleSessionOpened");
   283     TN_DEBUG1( "CThumbAGDaemon::HandleSessionOpened");
   260     
   284     
   261     if (aError == KErrNone)
   285     if (aError == KErrNone)
   262         {
   286         {
   263         iProcessor->SetMdESession(iMdESession);
   287         TRAPD(err, iProcessor->SetMdESessionL(iMdESession));
   264         
   288         
   265         TRAPD( err, AddObserversL() );
   289         TRAP( err, AddObserversL() );
   266         if (err != KErrNone)
   290         if (err != KErrNone)
   267             {
   291             {
   268             TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened, AddObserversL error == %d", err );
   292             TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened, AddObserversL error == %d", err );
   269             }
   293             }
   270         }
   294         }
   279 // -----------------------------------------------------------------------------
   303 // -----------------------------------------------------------------------------
   280 //
   304 //
   281 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
   305 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
   282     {
   306     {
   283     TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError );
   307     TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError );
   284     if (aError != KErrNone && !iSessionError)
   308     if (aError != KErrNone && !iShutdown && !iSessionError)
   285         {
   309         {
   286         iSessionError = ETrue;
   310         iSessionError = ETrue;
   287     
   311     
       
   312 	    delete iImageObserver;
       
   313 	    iImageObserver = NULL;
       
   314     
       
   315 	    delete iCameraObserver;
       
   316 	    iCameraObserver = NULL;
       
   317     
       
   318 	    delete iVideoObserver;
       
   319 	    iVideoObserver = NULL;
       
   320     
       
   321 	    delete iAudioObserver;
       
   322 	    iAudioObserver = NULL;
       
   323 		
   288         // kill processor right away, because it also has MdESession
   324         // kill processor right away, because it also has MdESession
   289         if(iProcessor)
   325         if(iProcessor)
   290             {
   326             {
       
   327 			iProcessor->Shutdown();
   291             delete iProcessor;
   328             delete iProcessor;
   292             iProcessor = NULL; 
   329             iProcessor = NULL; 
   293             }
   330             }
   294     
   331     
   295         if (!iShutdown)
   332         if (!iReconnect->IsActive())
   296             {
   333             {
   297             if (!iReconnect->IsActive())
   334             iReconnect->Start( KMdEReconnect, KMdEReconnect, 
   298                 {
   335                                TCallBack(ReconnectCallBack, this));
   299                 iReconnect->Start( KMdEReconnect, KMdEReconnect, 
   336             
   300                                    TCallBack(ReconnectCallBack, this));
   337             TN_DEBUG1( "CThumbAGDaemon::HandleSessionError() - reconnect timer started" );
   301                 
       
   302                 TN_DEBUG1( "CThumbAGDaemon::HandleSessionError() - reconnect timer started" );
       
   303                 }
       
   304             }
   338             }
   305 
   339 
   306         }   
   340         }   
   307     }
   341     }
   308 
   342 
   317         const RArray<TItemId>& aObjectIdArray,
   351         const RArray<TItemId>& aObjectIdArray,
   318         const RPointerArray<HBufC>& aObjectUriArray)
   352         const RPointerArray<HBufC>& aObjectUriArray)
   319     {
   353     {
   320     TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - begin" );
   354     TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - begin" );
   321     
   355     
       
   356     if(!iProcessor || iShutdown)
       
   357         {
       
   358         return;
       
   359         }
       
   360     
   322     if(aType == ENotifyRemove)
   361     if(aType == ENotifyRemove)
   323         {
   362         {
   324         TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - removed");
   363         TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - removed");
   325         TInt err(0);
   364         TInt err(0);
   326         TRAP(err, iProcessor->AddToQueueL(aType, aObjectIdArray, aObjectUriArray, EFalse));
   365         TRAP(err, iProcessor->AddToQueueL(aType, EGenerationItemTypeAny, aObjectIdArray, aObjectUriArray, EFalse));
   327         __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGDaemon::HandleUriObjectNotification()"), err));
   366         __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGDaemon::HandleUriObjectNotification()"), err));
       
   367 
   328         err = KErrNone;
   368         err = KErrNone;
   329         }
   369         }
   330     TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - end" );
   370     TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - end" );
   331     }
   371     }
   332 #endif
   372 #endif
   346         {
   386         {
   347         return;
   387         return;
   348         }
   388         }
   349     
   389     
   350 #ifdef _DEBUG
   390 #ifdef _DEBUG
   351     if (aType == ENotifyAdd)
   391     if (aType == ENotifyRemove)
   352         {
       
   353         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() );
       
   354         iAddCounter = aObjectIdArray.Count();
       
   355         }
       
   356     else if (aType == ENotifyModify)
       
   357         {
       
   358         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() );
       
   359         iModCounter = aObjectIdArray.Count();
       
   360         }
       
   361     else if (aType == ENotifyRemove)
       
   362         {
   392         {
   363         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyRemove %d", aObjectIdArray.Count() );
   393         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyRemove %d", aObjectIdArray.Count() );
   364         iDelCounter = aObjectIdArray.Count();
   394         iDelCounter = aObjectIdArray.Count();
   365         }
   395         }
   366 #endif
   396 #endif
   367     
   397     
   368     if ( (aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove) &&
   398     if ( aType == ENotifyRemove && aObjectIdArray.Count() > 0 )
   369          (aObjectIdArray.Count() > 0) )
       
   370         {
   399         {
   371         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - AddToQueueL" );
   400         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - AddToQueueL" );
   372 		
   401 		
   373         // If delete event, remove IDs from Modify and Add queues
   402         // If delete event, remove IDs from Modify and Add queues
   374         if ( aType == ENotifyRemove )
   403         iProcessor->RemoveFromQueues( aObjectIdArray, EFalse);
   375             {
       
   376             iProcessor->RemoveFromQueues( aObjectIdArray, EFalse);
       
   377             }
       
   378         
   404         
   379         // Add event to processing queue by type and enable force run        
   405         // Add event to processing queue by type and enable force run        
   380         RPointerArray<HBufC> dummyArray;
   406         RPointerArray<HBufC> dummyArray;
   381         TRAPD(err, iProcessor->AddToQueueL(aType, aObjectIdArray, dummyArray, EFalse));
   407         TRAPD(err, iProcessor->AddToQueueL(aType, EGenerationItemTypeAny, aObjectIdArray, dummyArray, EFalse));
   382         if (err != KErrNone)
   408         if (err != KErrNone)
   383             {
   409             {
   384             TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - error adding to queue" );
   410             TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - error adding to queue" );
   385             }
   411             }
   386         }
   412         }
   388         {
   414         {
   389         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - bad notification" );
   415         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - bad notification" );
   390         }
   416         }
   391     
   417     
   392 #ifdef _DEBUG
   418 #ifdef _DEBUG
   393     TN_DEBUG4( "CThumbAGDaemon::IN-COUNTERS---------- Add = %d Modify = %d Delete = %d", 
   419     TN_DEBUG2( "CThumbAGDaemon::IN-COUNTERS---------- Delete = %d", iDelCounter );
   394                iAddCounter, iModCounter, iDelCounter );
       
   395     iModCounter = 0;
       
   396     iDelCounter = 0;
   420     iDelCounter = 0;
   397     iAddCounter = 0;
       
   398     
       
   399 #endif
   421 #endif
   400 
   422 
   401     TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - end" );
   423     TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - end" );
   402     }
   424     }
   403 
   425 
   423         {
   445         {
   424         if ( aObjectIdArray.Count() > 0) 
   446         if ( aObjectIdArray.Count() > 0) 
   425             {
   447             {
   426 		    // do not force run of these items
   448 		    // do not force run of these items
   427             RPointerArray<HBufC> dummyArray;
   449             RPointerArray<HBufC> dummyArray;
   428             TRAP(err, iProcessor->AddToQueueL(ENotifyAdd, aObjectIdArray, dummyArray, ETrue));
   450             TRAP(err, iProcessor->AddToQueueL(ENotifyAdd, EGenerationItemTypeUnknown, aObjectIdArray, dummyArray, ETrue));
   429            
   451            
   430             TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd %d", aObjectIdArray.Count() );     
   452             TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd unknown items %d", aObjectIdArray.Count() );     
   431            
       
   432            #ifdef _DEBUG
   453            #ifdef _DEBUG
   433            iAddCounter = aObjectIdArray.Count();
   454            iAddCounter = aObjectIdArray.Count();
   434            if (err != KErrNone)
   455            if (err != KErrNone)
   435                {
   456                {
   436                TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" );
   457                TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" );
   458             iProcessor->RemoveFromQueues( aObjectIdArray, ETrue );
   479             iProcessor->RemoveFromQueues( aObjectIdArray, ETrue );
   459             }
   480             }
   460         }
   481         }
   461     
   482     
   462     #ifdef _DEBUG
   483     #ifdef _DEBUG
   463     TN_DEBUG4( "CThumbAGDaemon::IN-COUNTERS---------- Add = %d Modify = %d Delete = %d", 
   484     TN_DEBUG3( "CThumbAGDaemon::IN-COUNTERS---------- Add = %d Delete = %d", iAddCounter, iDelCounter );
   464                iAddCounter, iModCounter, iDelCounter );
       
   465     iModCounter = 0;
       
   466     iDelCounter = 0;
   485     iDelCounter = 0;
   467     iAddCounter = 0;
   486 	iAddCounter = 0;
   468     #endif
   487     #endif
   469     
   488     
   470     TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - end" );
   489     TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - end" );
   471     }
   490     }
   472 
   491 
   491 //
   510 //
   492 void CThumbAGDaemon::AddObserversL()
   511 void CThumbAGDaemon::AddObserversL()
   493     {
   512     {
   494     TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - begin" );
   513     TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - begin" );
   495     
   514     
   496     CMdENamespaceDef& defaultNamespace = iMdESession->GetDefaultNamespaceDefL();
       
   497     CMdEObjectDef& imageDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
       
   498     CMdEObjectDef& videoDef = defaultNamespace.GetObjectDefL( MdeConstants::Video::KVideoObject );
       
   499     CMdEObjectDef& audioDef = defaultNamespace.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   500     
       
   501     // set observing conditions
       
   502     CMdELogicCondition* addCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorOr );
       
   503     addCondition->AddObjectConditionL( imageDef );
       
   504     addCondition->AddObjectConditionL( videoDef );
       
   505     addCondition->AddObjectConditionL( audioDef );
       
   506     CleanupStack::Pop( addCondition );  
       
   507     
       
   508     CMdELogicCondition* modifyCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorOr );
       
   509     modifyCondition->AddObjectConditionL( imageDef );
       
   510     modifyCondition->AddObjectConditionL( videoDef );
       
   511     modifyCondition->AddObjectConditionL( audioDef );
       
   512     CleanupStack::Pop( modifyCondition );
       
   513     
       
   514     // add observer
       
   515     iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); 
       
   516 
       
   517    // modify observer
       
   518 #ifdef MDS_MODIFY_OBSERVER
       
   519    iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify );
       
   520 #endif
       
   521  
   515  
   522 #ifdef MDS_URI_OBSERVER
   516 #ifdef MDS_URI_OBSERVER
   523     // remove observer with uri
   517     // remove observer with uri
   524     iMdESession->AddObjectObserverWithUriL( *this, NULL, ENotifyRemove );
   518     iMdESession->AddObjectObserverWithUriL( *this, NULL, ENotifyRemove );
   525 #endif
   519 #endif