imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagdaemon.cpp
changeset 54 48dd0f169f0d
parent 42 2e2a89493e2b
equal deleted inserted replaced
42:2e2a89493e2b 54:48dd0f169f0d
     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 "thumbagdaemon.h"
       
    28 #include "thumbnaillog.h"
       
    29 #include "thumbnailmanagerconstants.h"
       
    30 #include "thumbnailmanagerprivatecrkeys.h"
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "thumbagdaemonTraces.h"
       
    34 #endif
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // NewLC
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CThumbAGDaemon* CThumbAGDaemon::NewLC()
       
    42     {
       
    43     TN_DEBUG1( "CThumbAGDaemon::NewLC() - begin" );
       
    44     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_NEWLC, "CThumbAGDaemon::NewLC - begin" );
       
    45     
       
    46 	CThumbAGDaemon* self = new (ELeave) CThumbAGDaemon();
       
    47 	CleanupStack::PushL( self );
       
    48 	self->ConstructL();
       
    49 	return self;
       
    50 	}
       
    51 	
       
    52 // ---------------------------------------------------------------------------
       
    53 // NewL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CThumbAGDaemon* CThumbAGDaemon::NewL()
       
    57 	{
       
    58 	TN_DEBUG1( "CThumbAGDaemon::NewL() - begin" );
       
    59     OstTrace0( TRACE_NORMAL, CTHUMBAGDAEMON_NEWL, "CThumbAGDaemon::NewL" );
       
    60     
       
    61 	CThumbAGDaemon* self = CThumbAGDaemon::NewLC();
       
    62 	CleanupStack::Pop( self );
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CThumbAGDaemon
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CThumbAGDaemon::CThumbAGDaemon()
       
    71  	: CServer2( CActive::EPriorityStandard, CServer2::EUnsharableSessions ), iShutdownObserver(NULL), 
       
    72  	       iMDSShutdownObserver(NULL), iMdESession(NULL), iProcessor(NULL)
       
    73  	{
       
    74  	// No implementation required
       
    75  	}
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // ConstructL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CThumbAGDaemon::ConstructL()
       
    82 	{
       
    83 	TN_DEBUG1( "CThumbAGDaemon::ConstructL() - begin" );
       
    84 	OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_CONSTRUCTL, "CThumbAGDaemon::ConstructL - begin" );
       
    85 	
       
    86 	StartL( KTAGDaemonName );
       
    87 	
       
    88 #ifdef _DEBUG
       
    89     iAddCounter = 0;
       
    90     iDelCounter = 0;
       
    91 #endif
       
    92     
       
    93     InitializeL();
       
    94     	
       
    95 	TN_DEBUG1( "CThumbAGDaemon::ConstructL() - end" );
       
    96 	OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_CONSTRUCTL, "CThumbAGDaemon::ConstructL - end" );
       
    97 	}
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // ~CThumbAGDaemon
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CThumbAGDaemon::InitializeL()
       
   104     {
       
   105     TN_DEBUG1( "CThumbAGDaemon::InitializeL() - begin" );
       
   106     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_INITIALIZEL, "CThumbAGDaemon::InitializeL - begin" );
       
   107     
       
   108     if (DaemonEnabledL())
       
   109         {
       
   110         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - create observers" );
       
   111         OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_INITIALIZEL, "CThumbAGDaemon::InitializeL - create observers" );
       
   112         
       
   113         // create shutdown observer
       
   114         if(iMDSShutdownObserver)
       
   115             {
       
   116             delete iMDSShutdownObserver;
       
   117             iMDSShutdownObserver = NULL;
       
   118             }     
       
   119         iMDSShutdownObserver = CTMShutdownObserver::NewL( *this, KMdSPSShutdown, KMdSShutdown, EFalse );
       
   120 
       
   121         if(iShutdownObserver)
       
   122             {
       
   123             delete iShutdownObserver;
       
   124             iShutdownObserver = NULL;
       
   125             }
       
   126         iShutdownObserver = CTMShutdownObserver::NewL( *this, KTAGDPSNotification, KShutdown, ETrue );  
       
   127         iShutdown = EFalse;
       
   128         
       
   129         // create processor
       
   130         if(iProcessor)
       
   131             {
       
   132             iProcessor->Shutdown();
       
   133             delete iProcessor;
       
   134             iProcessor = NULL; 
       
   135             }
       
   136         
       
   137         iProcessor = CThumbAGProcessor::NewL(); 
       
   138         
       
   139         // MDS session reconnect timer
       
   140         if (!iReconnect)
       
   141             {
       
   142             iReconnect = CPeriodic::NewL(CActive::EPriorityIdle);
       
   143             }
       
   144         
       
   145         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - connect to MDS" );
       
   146         
       
   147         if(iMdESession)
       
   148             {
       
   149             TRAP_IGNORE( iMdESession->RemoveObjectObserverWithUriL( *this ) );
       
   150             TRAP_IGNORE( iMdESession->RemoveObjectPresentObserverL( * this  ));
       
   151         
       
   152             // connect to MDS
       
   153             delete iMdESession;
       
   154             iMdESession = NULL;
       
   155             }
       
   156 
       
   157         iMdESession = CMdESession::NewL( *this );
       
   158         iSessionError = EFalse;
       
   159         
       
   160         delete iImageObserver;
       
   161         iImageObserver = NULL;
       
   162         iImageObserver = CThumbAGImageObserver::NewL(iProcessor);
       
   163        
       
   164         delete iCameraObserver;
       
   165         iCameraObserver = NULL;
       
   166         iCameraObserver = CThumbAGCameraObserver::NewL(iProcessor);
       
   167         
       
   168         delete iAudioObserver;
       
   169         iAudioObserver = NULL;
       
   170         iAudioObserver = CThumbAGAudioObserver::NewL(iProcessor);
       
   171         
       
   172         delete iVideoObserver;
       
   173         iVideoObserver = NULL;
       
   174         iVideoObserver = CThumbAGVideoObserver::NewL(iProcessor);
       
   175         }
       
   176     else
       
   177         {
       
   178         // no error here, but need to shutdown daemon neatly
       
   179         User::Leave(KErrNone);
       
   180         }
       
   181         TN_DEBUG1( "CThumbAGDaemon::InitializeL() - end" );
       
   182         OstTrace0( TRACE_FATAL, DUP2_CTHUMBAGDAEMON_INITIALIZEL, "CThumbAGDaemon::InitializeL - end" );
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // ~CThumbAGDaemon
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 CThumbAGDaemon::~CThumbAGDaemon()
       
   190     {
       
   191     TN_DEBUG1( "CThumbAGDaemon::~CThumbAGDaemon() - begin" );
       
   192     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_CTHUMBAGDAEMON, "CThumbAGDaemon::~CThumbAGDaemon - begin" );
       
   193     
       
   194     iShutdown = ETrue;
       
   195     
       
   196     delete iImageObserver;
       
   197     iImageObserver = NULL;
       
   198     
       
   199     delete iCameraObserver;
       
   200     iCameraObserver = NULL;
       
   201     
       
   202     delete iVideoObserver;
       
   203     iVideoObserver = NULL;
       
   204     
       
   205     delete iAudioObserver;
       
   206     iAudioObserver = NULL;
       
   207     
       
   208     delete iMDSShutdownObserver;
       
   209     iMDSShutdownObserver = NULL;
       
   210     
       
   211     delete iShutdownObserver;
       
   212     iShutdownObserver = NULL;
       
   213     
       
   214     if(iReconnect)
       
   215         {
       
   216         iReconnect->Cancel();
       
   217         delete iReconnect;
       
   218         iReconnect = NULL;
       
   219         }
       
   220     
       
   221     if (iProcessor)
       
   222         {
       
   223         iProcessor->Shutdown();
       
   224         delete iProcessor;
       
   225         iProcessor = NULL;
       
   226         }
       
   227     
       
   228     if (iMdESession)
       
   229         {
       
   230 #ifdef MDS_URI_OBSERVER
       
   231         // remove observer with uri
       
   232         TRAP_IGNORE( iMdESession->RemoveObjectObserverWithUriL( *this ) );
       
   233 #endif
       
   234         
       
   235         //present observer
       
   236         TRAP_IGNORE( iMdESession->RemoveObjectPresentObserverL( *this ) );
       
   237         
       
   238         delete iMdESession;
       
   239         iMdESession = NULL;
       
   240         }
       
   241     
       
   242     TN_DEBUG1( "CThumbAGDaemon::~CThumbAGDaemon() - end" );
       
   243     OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_CTHUMBAGDAEMON, "CThumbAGDaemon::~CThumbAGDaemon - end" );
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CThumbnailServer::NewSessionL()
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 CSession2* CThumbAGDaemon::NewSessionL( const TVersion& /*aVersion*/,
       
   251                                         const RMessage2& /*aMessage*/ )const
       
   252     {
       
   253     // no services, no clients, no sessions
       
   254     User::Leave(KErrNotSupported);
       
   255     
       
   256     //just for getting rid of compiler warning about missing return value
       
   257     return NULL;
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // CThumbAGDaemon::ThreadFunctionL
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CThumbAGDaemon::ThreadFunctionL()
       
   265     {
       
   266 	TN_DEBUG1( "CThumbAGDaemon::ThreadFunctionL() - begin" );
       
   267     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_THREADFUNCTIONL, "CThumbAGDaemon::ThreadFunctionL - begin" );
       
   268     
       
   269     User::LeaveIfError( User::RenameThread( KTAGDaemonName ) );
       
   270 
       
   271     CThumbAGDaemon* server = NULL;
       
   272     CActiveScheduler* scheduler = new( ELeave )CActiveScheduler();
       
   273 
       
   274     if ( scheduler )
       
   275         {
       
   276         CActiveScheduler::Install( scheduler );
       
   277         
       
   278         CleanupStack::PushL( scheduler );
       
   279         server = CThumbAGDaemon::NewL(); // Adds server in scheduler
       
   280 
       
   281         RProcess::Rendezvous( KErrNone );
       
   282 
       
   283         CActiveScheduler::Start();
       
   284        
       
   285         // comes here if server gets shut down
       
   286         delete server;
       
   287         server = NULL;
       
   288         
       
   289         CleanupStack::PopAndDestroy( scheduler );
       
   290         }
       
   291     
       
   292     TN_DEBUG1( "CThumbAGDaemon::ThreadFunctionL() - end" );
       
   293 	OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_THREADFUNCTIONL, "CThumbAGDaemon::ThreadFunctionL - end" );
       
   294 	}
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CThumbAGDaemon::HandleSessionOpened
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void CThumbAGDaemon::HandleSessionOpened( CMdESession& /* aSession */, TInt aError )
       
   301     {
       
   302     TN_DEBUG1( "CThumbAGDaemon::HandleSessionOpened");
       
   303     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_HANDLESESSIONOPENED, "CThumbAGDaemon::HandleSessionOpened" );
       
   304     
       
   305     if (aError == KErrNone)
       
   306         {
       
   307         TRAPD(err, iProcessor->SetMdESessionL(iMdESession));
       
   308         
       
   309         TRAP( err, AddObserversL() );
       
   310         if (err != KErrNone)
       
   311             {
       
   312             TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened, AddObserversL error == %d", err );
       
   313             OstTrace1( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_HANDLESESSIONOPENED, "CThumbAGDaemon::HandleSessionOpened;err=%d", err );
       
   314             }
       
   315         }
       
   316     else
       
   317         {
       
   318         TN_DEBUG2( "CThumbAGDaemon::HandleSessionOpened error == %d", aError );
       
   319         OstTrace1( TRACE_FATAL, DUP2_CTHUMBAGDAEMON_HANDLESESSIONOPENED, "CThumbAGDaemon::HandleSessionOpened;aError=%d", aError );
       
   320         }
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CThumbAGDaemon::HandleSessionError
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CThumbAGDaemon::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
       
   328     {
       
   329     TN_DEBUG2( "CThumbAGDaemon::HandleSessionError == %d", aError );
       
   330     OstTrace1( TRACE_FATAL, CTHUMBAGDAEMON_HANDLESESSIONERROR, "CThumbAGDaemon::HandleSessionError;aError=%d", aError );
       
   331     if (aError != KErrNone && !iShutdown && !iSessionError)
       
   332         {
       
   333         iSessionError = ETrue;
       
   334     
       
   335 	    delete iImageObserver;
       
   336 	    iImageObserver = NULL;
       
   337     
       
   338 	    delete iCameraObserver;
       
   339 	    iCameraObserver = NULL;
       
   340     
       
   341 	    delete iVideoObserver;
       
   342 	    iVideoObserver = NULL;
       
   343     
       
   344 	    delete iAudioObserver;
       
   345 	    iAudioObserver = NULL;
       
   346 		
       
   347         // kill processor right away, because it also has MdESession
       
   348         if(iProcessor)
       
   349             {
       
   350 			iProcessor->Shutdown();
       
   351             delete iProcessor;
       
   352             iProcessor = NULL; 
       
   353             }
       
   354     
       
   355         if (!iReconnect->IsActive())
       
   356             {
       
   357             iReconnect->Start( KMdEReconnect, KMdEReconnect, 
       
   358                                TCallBack(ReconnectCallBack, this));
       
   359             
       
   360             TN_DEBUG1( "CThumbAGDaemon::HandleSessionError() - reconnect timer started" );
       
   361             OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_HANDLESESSIONERROR, "CThumbAGDaemon::HandleSessionError - reconnect timer started" );
       
   362             }
       
   363 
       
   364         }   
       
   365     }
       
   366 
       
   367 #ifdef MDS_URI_OBSERVER
       
   368 // -----------------------------------------------------------------------------
       
   369 // CThumbAGDaemon::HandleObjectNotification
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 
       
   373 void CThumbAGDaemon::HandleUriObjectNotification(CMdESession& /*aSession*/, 
       
   374         TObserverNotificationType aType,
       
   375         const RArray<TItemId>& aObjectIdArray,
       
   376         const RPointerArray<HBufC>& aObjectUriArray)
       
   377     {
       
   378     TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - begin" );
       
   379     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_HANDLEURIOBJECTNOTIFICATION, "CThumbAGDaemon::HandleUriObjectNotification - begin" );
       
   380     
       
   381     if(!iProcessor || iShutdown)
       
   382         {
       
   383         return;
       
   384         }
       
   385     
       
   386     if(aType == ENotifyRemove)
       
   387         {
       
   388         TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - removed");
       
   389         OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_HANDLEURIOBJECTNOTIFICATION, "CThumbAGDaemon::HandleUriObjectNotification - removed" );
       
   390         TInt err(0);
       
   391         TRAP(err, iProcessor->AddToQueueL(aType, EGenerationItemTypeAny, aObjectIdArray, aObjectUriArray, EFalse));
       
   392         __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGDaemon::HandleUriObjectNotification()"), err));
       
   393 
       
   394         err = KErrNone;
       
   395         }
       
   396     TN_DEBUG1( "CThumbAGDaemon::HandleUriObjectNotification() - end" );
       
   397     OstTrace0( TRACE_FATAL, DUP2_CTHUMBAGDAEMON_HANDLEURIOBJECTNOTIFICATION, "CThumbAGDaemon::HandleUriObjectNotification - end" );
       
   398     }
       
   399 #endif
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CThumbAGDaemon::HandleObjectNotification
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CThumbAGDaemon::HandleObjectNotification( CMdESession& /*aSession*/, 
       
   406                                                TObserverNotificationType aType,
       
   407                                                const RArray<TItemId>& aObjectIdArray )
       
   408     {
       
   409     TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - begin" );
       
   410     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_HANDLEOBJECTNOTIFICATION, "CThumbAGDaemon::HandleObjectNotification - begin" );
       
   411 
       
   412     // no processor or shutting down
       
   413     if (!iProcessor || iShutdown)
       
   414         {
       
   415         return;
       
   416         }
       
   417     
       
   418 #ifdef _DEBUG
       
   419     if (aType == ENotifyRemove)
       
   420         {
       
   421         TN_DEBUG2( "CThumbAGDaemon::HandleObjectNotification() - ENotifyRemove %d", aObjectIdArray.Count() );
       
   422         OstTrace1( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_HANDLEOBJECTNOTIFICATION, "CThumbAGDaemon::HandleObjectNotification - ENotifyRemove;aObjectIdArray.Count()=%d", aObjectIdArray.Count() );
       
   423         iDelCounter = aObjectIdArray.Count();
       
   424         }
       
   425 #endif
       
   426     
       
   427     if ( aType == ENotifyRemove && aObjectIdArray.Count() > 0 )
       
   428         {
       
   429         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - AddToQueueL" );
       
   430 		OstTrace0( TRACE_FATAL, DUP2_CTHUMBAGDAEMON_HANDLEOBJECTNOTIFICATION, "CThumbAGDaemon::HandleObjectNotification - AddToQueueL" );
       
   431 		
       
   432         // If delete event, remove IDs from Modify and Add queues
       
   433         iProcessor->RemoveFromQueues( aObjectIdArray, EFalse);
       
   434         
       
   435         // Add event to processing queue by type and enable force run        
       
   436         RPointerArray<HBufC> dummyArray;
       
   437         TRAPD(err, iProcessor->AddToQueueL(aType, EGenerationItemTypeAny, aObjectIdArray, dummyArray, EFalse));
       
   438         if (err != KErrNone)
       
   439             {
       
   440             TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - error adding to queue" );
       
   441             OstTrace0( TRACE_FATAL, DUP3_CTHUMBAGDAEMON_HANDLEOBJECTNOTIFICATION, "CThumbAGDaemon::HandleObjectNotification - error adding to queue" );
       
   442             }
       
   443         }
       
   444     else
       
   445         {
       
   446         TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - bad notification" );
       
   447         OstTrace0( TRACE_FATAL, DUP4_CTHUMBAGDAEMON_HANDLEOBJECTNOTIFICATION, "CThumbAGDaemon::HandleObjectNotification - bad notification" );
       
   448         }
       
   449     
       
   450 #ifdef _DEBUG
       
   451     TN_DEBUG2( "CThumbAGDaemon::IN-COUNTERS---------- Delete = %d", iDelCounter );
       
   452     OstTrace1( TRACE_FATAL, DUP5_CTHUMBAGDAEMON_HANDLEOBJECTNOTIFICATION, "CThumbAGDaemon::IN-COUNTERS---------- Delete;iDelCounter=%u", iDelCounter );
       
   453     iDelCounter = 0;
       
   454 #endif
       
   455 
       
   456     TN_DEBUG1( "CThumbAGDaemon::HandleObjectNotification() - end" );
       
   457     OstTrace0( TRACE_FATAL, DUP6_CTHUMBAGDAEMON_HANDLEOBJECTNOTIFICATION, "CThumbAGDaemon::HandleObjectNotification - end" );
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // CThumbAGDaemon::HandleObjectPresentNotification
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 void CThumbAGDaemon::HandleObjectPresentNotification(CMdESession& /*aSession*/, 
       
   465                TBool aPresent, const RArray<TItemId>& aObjectIdArray)
       
   466     {
       
   467     TN_DEBUG3( "CThumbAGDaemon::HandleObjectPresentNotification() - aPresent == %d count == %d", aPresent, aObjectIdArray.Count() );
       
   468     OstTraceExt2( TRACE_FATAL, CTHUMBAGDAEMON_HANDLEOBJECTPRESENTNOTIFICATION, "CThumbAGDaemon::HandleObjectPresentNotification;aPresent=%d;aObjectIdArray.Count()=%d", aPresent, aObjectIdArray.Count() );
       
   469     
       
   470     // no processor or shutting down
       
   471     if (!iProcessor || iShutdown)
       
   472         {
       
   473         return;
       
   474         }
       
   475     
       
   476     TInt err = 0;
       
   477     
       
   478     //tread present objects as added
       
   479     if(aPresent)
       
   480         {
       
   481         if ( aObjectIdArray.Count() > 0) 
       
   482             {
       
   483 		    // do not force run of these items
       
   484             RPointerArray<HBufC> dummyArray;
       
   485             TRAP(err, iProcessor->AddToQueueL(ENotifyAdd, EGenerationItemTypeUnknown, aObjectIdArray, dummyArray, ETrue));
       
   486            
       
   487             TN_DEBUG2( "CThumbAGDaemon::HandleObjectPresentNotification() - ENotifyAdd unknown items %d", aObjectIdArray.Count() );     
       
   488             OstTrace1( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_HANDLEOBJECTPRESENTNOTIFICATION, "CThumbAGDaemon::HandleObjectPresentNotification - ENotifyAdd unknown items;aObjectIdArray.Count()=%d", aObjectIdArray.Count() );
       
   489            #ifdef _DEBUG
       
   490            iAddCounter = aObjectIdArray.Count();
       
   491            if (err != KErrNone)
       
   492                {
       
   493                TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - error adding to queue" );
       
   494                OstTrace0( TRACE_FATAL, DUP2_CTHUMBAGDAEMON_HANDLEOBJECTPRESENTNOTIFICATION, "CThumbAGDaemon::HandleObjectPresentNotification - error adding to queue" );
       
   495                }
       
   496            #endif
       
   497            }
       
   498         }
       
   499     else
       
   500         {
       
   501         TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - handle not present" );
       
   502         OstTrace0( TRACE_FATAL, DUP3_CTHUMBAGDAEMON_HANDLEOBJECTPRESENTNOTIFICATION, "CThumbAGDaemon::HandleObjectPresentNotification - handle not present" );
       
   503 
       
   504         #ifdef _DEBUG    
       
   505         if( iAddCounter < aObjectIdArray.Count() )
       
   506             {
       
   507             iAddCounter = 0;
       
   508             }
       
   509         else
       
   510             {
       
   511             iDelCounter = aObjectIdArray.Count();
       
   512             }
       
   513         #endif
       
   514            
       
   515         if ( aObjectIdArray.Count() > 0) 
       
   516             {
       
   517             iProcessor->RemoveFromQueues( aObjectIdArray, ETrue );
       
   518             }
       
   519         }
       
   520     
       
   521     #ifdef _DEBUG
       
   522     TN_DEBUG3( "CThumbAGDaemon::IN-COUNTERS---------- Add = %d Delete = %d", iAddCounter, iDelCounter );
       
   523     OstTraceExt2( TRACE_FATAL, DUP4_CTHUMBAGDAEMON_HANDLEOBJECTPRESENTNOTIFICATION, "CThumbAGDaemon::::IN-COUNTERS---------- Add, Delete;iAddCounter=%u;iDelCounter=%u", iAddCounter, iDelCounter );
       
   524     iDelCounter = 0;
       
   525 	iAddCounter = 0;
       
   526     #endif
       
   527     
       
   528     TN_DEBUG1( "CThumbAGDaemon::HandleObjectPresentNotification() - end" );
       
   529     OstTrace0( TRACE_FATAL, DUP5_CTHUMBAGDAEMON_HANDLEOBJECTPRESENTNOTIFICATION, "CThumbAGDaemon::HandleObjectPresentNotification - end" );
       
   530     }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CThumbAGDaemon::ShutdownNotification
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CThumbAGDaemon::ShutdownNotification()
       
   537     {
       
   538     TN_DEBUG1( "CThumbAGDaemon::ShutdownNotification()" );
       
   539     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_SHUTDOWNNOTIFICATION, "CThumbAGDaemon::ShutdownNotification" );
       
   540     
       
   541     if (!iShutdown)
       
   542         {
       
   543         CActiveScheduler::Stop();
       
   544         iShutdown = ETrue;
       
   545         }
       
   546     }
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CThumbAGDaemon::AddObserversL
       
   550 // ---------------------------------------------------------------------------
       
   551 //
       
   552 void CThumbAGDaemon::AddObserversL()
       
   553     {
       
   554     TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - begin" );
       
   555     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_ADDOBSERVERSL, "CThumbAGDaemon::AddObserversL - begin" );
       
   556  
       
   557 #ifdef MDS_URI_OBSERVER
       
   558     // remove observer with uri
       
   559     iMdESession->AddObjectObserverWithUriL( *this, NULL, ENotifyRemove );
       
   560 #endif
       
   561     
       
   562     // object present observer
       
   563     iMdESession->AddObjectPresentObserverL( *this );
       
   564     
       
   565     TN_DEBUG1( "CThumbAGDaemon::AddObserversL() - end" );
       
   566     OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_ADDOBSERVERSL, "CThumbAGDaemon::AddObserversL - end" );
       
   567     }
       
   568 
       
   569 // ---------------------------------------------------------------------------
       
   570 // CThumbAGDaemon::DaemonEnabledL
       
   571 // ---------------------------------------------------------------------------
       
   572 //
       
   573 TBool CThumbAGDaemon::DaemonEnabledL()
       
   574     {
       
   575     TN_DEBUG1( "CThumbAGDaemon::DaemonEnabledL() - begin" );
       
   576     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_DAEMONENABLEDL, "CThumbAGDaemon::DaemonEnabledL - begin" );
       
   577     CRepository* rep = CRepository::NewL( TUid::Uid( THUMBNAIL_CENREP_UID ));
       
   578     
       
   579     // get value
       
   580     TBool val( EFalse );
       
   581     TInt ret = rep->Get( KEnableDaemon, val );
       
   582     
       
   583     delete rep;
       
   584     rep = NULL;
       
   585     
       
   586     TN_DEBUG3( "CThumbAGDaemon::DaemonEnabledL() - val == %d, ret == %d", val, ret );
       
   587     OstTraceExt2( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_DAEMONENABLEDL, "CThumbAGDaemon::DaemonEnabledL;val=%u;ret=%d", val, ret );
       
   588     return val;
       
   589     }
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 // CThumbAGDaemon::ReconnectCallBack()
       
   593 // ---------------------------------------------------------------------------
       
   594 //
       
   595 TInt CThumbAGDaemon::ReconnectCallBack(TAny* aAny)
       
   596     {
       
   597     TN_DEBUG1( "CThumbAGDaemon::ReconnectCallBack() - reinitialize");
       
   598     OstTrace0( TRACE_FATAL, CTHUMBAGDAEMON_RECONNECTCALLBACK, "CThumbAGDaemon::ReconnectCallBack - reinitialize" );
       
   599     
       
   600     CThumbAGDaemon* self = static_cast<CThumbAGDaemon*>( aAny );
       
   601     
       
   602     self->iReconnect->Cancel();
       
   603     
       
   604     // reconnect to MDS
       
   605     TRAP_IGNORE( self->InitializeL() );
       
   606     
       
   607     TN_DEBUG1( "CThumbAGDaemon::ReconnectCallBack() - done");
       
   608     OstTrace0( TRACE_FATAL, DUP1_CTHUMBAGDAEMON_RECONNECTCALLBACK, "CThumbAGDaemon::ReconnectCallBack - done" );
       
   609     
       
   610     return KErrNone;
       
   611     }
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // E32Main
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 TInt E32Main()
       
   618     {    
       
   619     TN_DEBUG1( "CThumbAGDaemon::E32Main() - begin" );
       
   620     OstTrace0( TRACE_FATAL, _E32MAIN, "::E32Main - begin" );
       
   621 
       
   622     __UHEAP_MARK;
       
   623 
       
   624     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   625     TInt result = KErrNoMemory;
       
   626     
       
   627     if ( cleanup )
       
   628         {
       
   629         TRAP( result, CThumbAGDaemon::ThreadFunctionL());
       
   630         delete cleanup;
       
   631         cleanup = NULL;
       
   632         }
       
   633     
       
   634     if ( result != KErrNone )
       
   635         {
       
   636         TN_DEBUG1( "CThumbAGDaemon::E32Main() - error" );
       
   637         OstTrace0( TRACE_FATAL, DUP1__E32MAIN, "::E32Main - error" );
       
   638         
       
   639         // Signal the client that server creation failed
       
   640         RProcess::Rendezvous( result );
       
   641         }    
       
   642     
       
   643     __UHEAP_MARKEND;
       
   644 
       
   645     TN_DEBUG1( "CThumbAGDaemon::E32Main() - end" );
       
   646     OstTrace0( TRACE_FATAL, DUP2__E32MAIN, "::E32Main - end" );
       
   647     
       
   648     return result;
       
   649     }
       
   650 
       
   651 // End of file