imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagdaemon.cpp
branchRCL_3
changeset 5 82749d516180
parent 0 2014ca87e772
child 9 2eb74cf6572e
equal deleted inserted replaced
1:235a7fc86938 5:82749d516180
    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 	TN_DEBUG1( "CThumbAGDaemon::ConstructL() - end" );
       
    90 	}
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // ~CThumbAGDaemon
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CThumbAGDaemon::InitializeL()
       
    97     {
       
    98     TN_DEBUG1( "CThumbAGDaemon::InitializeL() - begin" );
       
    99     
    86     if (DaemonEnabledL())
   100     if (DaemonEnabledL())
    87         {
   101         {
    88         TN_DEBUG1( "CThumbAGDaemon::ConstructL() - create observers" );
   102         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - create observers" );
    89         
   103         
    90     	// create shutdown observer
   104         // create shutdown observer
       
   105         if(iMDSShutdownObserver)
       
   106             {
       
   107             delete iMDSShutdownObserver;
       
   108             iMDSShutdownObserver = NULL;
       
   109             }     
    91         iMDSShutdownObserver = CTMShutdownObserver::NewL( *this, KMdSPSShutdown, KMdSShutdown, EFalse );
   110         iMDSShutdownObserver = CTMShutdownObserver::NewL( *this, KMdSPSShutdown, KMdSShutdown, EFalse );
    92     	iShutdownObserver = CTMShutdownObserver::NewL( *this, KTAGDPSNotification, KShutdown, ETrue );  
   111 
    93     	iShutdown = EFalse;
   112         if(iShutdownObserver)
    94     	
   113             {
       
   114             delete iShutdownObserver;
       
   115             iShutdownObserver = NULL;
       
   116             }
       
   117         iShutdownObserver = CTMShutdownObserver::NewL( *this, KTAGDPSNotification, KShutdown, ETrue );  
       
   118         iShutdown = EFalse;
       
   119         
    95         // create processor
   120         // create processor
    96         iProcessor = NULL;
   121         if(iProcessor)
    97         iProcessor = CThumbAGProcessor::NewL();	
   122             {
    98     	
   123             delete iProcessor;
    99         TN_DEBUG1( "CThumbAGDaemon::ConstructL() - connect to MDS" );
   124             iProcessor = NULL; 
   100         
   125             }
   101     	// connect to MDS
   126         
   102     	iMdESession = NULL;
   127         iProcessor = CThumbAGProcessor::NewL(); 
   103     	iMdESession = CMdESession::NewL( *this );
   128         
       
   129         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - connect to MDS" );
       
   130         
       
   131         if(iMdESession)
       
   132             {
       
   133             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   134             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   135             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   136             TRAP_IGNORE( iMdESession->RemoveObjectPresentObserverL( * this  ));
       
   137         
       
   138             // connect to MDS
       
   139             delete iMdESession;
       
   140             iMdESession = NULL;
       
   141             }
       
   142 
       
   143         iMdESession = CMdESession::NewL( *this );
   104         }
   144         }
   105     else
   145     else
   106         {
   146         {
   107         // no error here, but need to shutdown daemon neatly
   147         // no error here, but need to shutdown daemon neatly
   108         User::Leave(KErrNone);
   148         User::Leave(KErrNone);
   109         }
   149         }
   110 	
   150         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - end" );
   111 	TN_DEBUG1( "CThumbAGDaemon::ConstructL() - end" );
   151     }
   112 	}
       
   113 
   152 
   114 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   115 // ~CThumbAGDaemon
   154 // ~CThumbAGDaemon
   116 // ---------------------------------------------------------------------------
   155 // ---------------------------------------------------------------------------
   117 //
   156 //
   201     TN_DEBUG1( "CThumbAGDaemon::HandleSessionOpened");
   240     TN_DEBUG1( "CThumbAGDaemon::HandleSessionOpened");
   202     
   241     
   203     if (aError == KErrNone)
   242     if (aError == KErrNone)
   204         {
   243         {
   205         iProcessor->SetMdESession(iMdESession);
   244         iProcessor->SetMdESession(iMdESession);
   206         TRAP_IGNORE(iProcessor->QueryForPlaceholdersL());
       
   207         
   245         
   208         TRAPD( err, AddObserversL() );
   246         TRAPD( err, AddObserversL() );
   209         if (err != KErrNone)
   247         if (err != KErrNone)
   210             {
   248             {
   211             TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened, AddObserversL error == %d", err );
   249             TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened, AddObserversL error == %d", err );
   221 // CThumbAGDaemon::HandleSessionError
   259 // CThumbAGDaemon::HandleSessionError
   222 // -----------------------------------------------------------------------------
   260 // -----------------------------------------------------------------------------
   223 //
   261 //
   224 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
   262 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
   225     {
   263     {
       
   264     TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError );
   226     if (aError != KErrNone)
   265     if (aError != KErrNone)
   227         {
   266         {
   228         TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError );
   267         delete iMdESession;
       
   268         iMdESession = NULL;
       
   269         TRAP_IGNORE(InitializeL());
   229         }   
   270         }   
   230     }
   271     }
   231 
   272 
   232 // -----------------------------------------------------------------------------
   273 // -----------------------------------------------------------------------------
   233 // CThumbAGDaemon::HandleObjectNotification
   274 // CThumbAGDaemon::HandleObjectNotification
   269         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - AddToQueueL" );
   310         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - AddToQueueL" );
   270 		
   311 		
   271         // If delete event, remove IDs from Modify and Add queues
   312         // If delete event, remove IDs from Modify and Add queues
   272         if ( aType == ENotifyRemove )
   313         if ( aType == ENotifyRemove )
   273             {
   314             {
   274             iProcessor->RemoveFromQueues( aObjectIdArray );
   315             iProcessor->RemoveFromQueues( aObjectIdArray, EFalse);
   275             }
   316             }
   276         
   317         
   277         // Add event to processing queue by type and enable force run
   318         // Add event to processing queue by type and enable force run
   278         TRAPD(err, iProcessor->AddToQueueL(aType, aObjectIdArray, EFalse));
   319         TRAPD(err, iProcessor->AddToQueueL(aType, aObjectIdArray, EFalse));
   279         if (err != KErrNone)
   320         if (err != KErrNone)
   295     }
   336     }
   296 
   337 
   297 // -----------------------------------------------------------------------------
   338 // -----------------------------------------------------------------------------
   298 // CThumbAGDaemon::HandleObjectPresentNotification
   339 // CThumbAGDaemon::HandleObjectPresentNotification
   299 // -----------------------------------------------------------------------------
   340 // -----------------------------------------------------------------------------
   300 //
   341 //b
   301 void CThumbAGDaemon::HandleObjectPresentNotification(CMdESession& /*aSession*/, 
   342 void CThumbAGDaemon::HandleObjectPresentNotification(CMdESession& /*aSession*/, 
   302                TBool aPresent, const RArray<TItemId>& aObjectIdArray)
   343                TBool aPresent, const RArray<TItemId>& aObjectIdArray)
   303     {
   344     {
   304     TN_DEBUG3( "CThumbAGDaemon::HandleObjectPresentNotification() - aPresent == %d count == %d", aPresent, aObjectIdArray.Count() );
   345     TN_DEBUG3( "CThumbAGDaemon::HandleObjectPresentNotification() - aPresent == %d count == %d", aPresent, aObjectIdArray.Count() );
   305     
   346     
   312     TInt err = 0;
   353     TInt err = 0;
   313     
   354     
   314     //tread present objects as added
   355     //tread present objects as added
   315     if(aPresent)
   356     if(aPresent)
   316         {
   357         {
   317         TRAP_IGNORE( iProcessor->QueryForPlaceholdersL());
       
   318         if ( aObjectIdArray.Count() > 0) 
   358         if ( aObjectIdArray.Count() > 0) 
   319            {
   359             {
   320 		   // do not force run of these items
   360 		    // do not force run of these items
   321            TRAP(err, iProcessor->AddToQueueL(ENotifyModify, aObjectIdArray, ETrue));
   361             TRAP(err, iProcessor->AddToQueueL(ENotifyAdd, aObjectIdArray, ETrue));
   322            
   362            
   323            TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd %d", aObjectIdArray.Count() );
   363             TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd %d", aObjectIdArray.Count() );     
   324            
   364            
   325            
   365            #ifdef _DEBUG
   326 #ifdef _DEBUG
       
   327            iAddCounter = iAddCounter + aObjectIdArray.Count();
   366            iAddCounter = iAddCounter + aObjectIdArray.Count();
   328            if (err != KErrNone)
   367            if (err != KErrNone)
   329                {
   368                {
   330                TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" );
   369                TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" );
   331                }
   370                }
   332 #endif
   371            #endif
   333            }
   372            }
   334         }
   373         }
   335     else
   374     else
   336         {
   375         {
   337         TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - handle not present" );
   376         TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - handle not present" );
   338         TRAP_IGNORE( iProcessor->QueryForPlaceholdersL() );
   377 
   339 #ifdef _DEBUG    
   378         #ifdef _DEBUG    
   340         if( iModCounter < aObjectIdArray.Count() )
   379         if( iAddCounter < aObjectIdArray.Count() )
   341             {
   380             {
   342             iModCounter = 0;
   381             iAddCounter = 0;
   343             }
   382             }
   344         else
   383         else
   345             {
   384             {
   346             iModCounter = iModCounter - aObjectIdArray.Count();
   385             iAddCounter = iAddCounter - aObjectIdArray.Count();
   347             }
   386             }
   348 #endif
   387         #endif
   349            
   388            
   350         if ( aObjectIdArray.Count() > 0) 
   389         if ( aObjectIdArray.Count() > 0) 
   351            {
   390             {
   352            iProcessor->RemoveFromQueues( aObjectIdArray, ETrue );
   391             iProcessor->RemoveFromQueues( aObjectIdArray, ETrue );
   353            }
   392             }
   354         }
   393         }
   355     
   394     
   356     #ifdef _DEBUG
   395     #ifdef _DEBUG
   357     TN_DEBUG5( "CThumbAGDaemon::IN-COUNTERS---------- Amount: %d, Add = %d Modify = %d Delete = %d", 
   396     TN_DEBUG5( "CThumbAGDaemon::IN-COUNTERS---------- Amount: %d, Add = %d Modify = %d Delete = %d", 
   358                aObjectIdArray.Count(), iAddCounter, iModCounter, iDelCounter );
   397                aObjectIdArray.Count(), iAddCounter, iModCounter, iDelCounter );