imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagcameraobserver.cpp
changeset 29 4bdfb6b5c9b4
child 30 b67379558a75
equal deleted inserted replaced
25:cb86b71cae0a 29:4bdfb6b5c9b4
       
     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 "thumbagcameraobserver.h"
       
    28 #include "thumbnaillog.h"
       
    29 #include "thumbnailmanagerconstants.h"
       
    30 #include "thumbnailmanagerprivatecrkeys.h"
       
    31 
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // NewLC
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CThumbAGCameraObserver* CThumbAGCameraObserver::NewLC(CThumbAGProcessor* aProcessor)
       
    38     {
       
    39     TN_DEBUG1( "CThumbAGCameraObserver::NewLC() - begin" );
       
    40     
       
    41 	CThumbAGCameraObserver* self = new (ELeave) CThumbAGCameraObserver(aProcessor);
       
    42 	CleanupStack::PushL( self );
       
    43 	self->ConstructL();
       
    44 	return self;
       
    45 	}
       
    46 	
       
    47 // ---------------------------------------------------------------------------
       
    48 // NewL
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CThumbAGCameraObserver* CThumbAGCameraObserver::NewL(CThumbAGProcessor* aProcessor)
       
    52 	{
       
    53 	TN_DEBUG1( "CThumbAGCameraObserver::NewL() - begin" );
       
    54     
       
    55 	CThumbAGCameraObserver* self = CThumbAGCameraObserver::NewLC(aProcessor);
       
    56 	CleanupStack::Pop( self );
       
    57 	return self;
       
    58 	}
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CThumbAGCameraObserver
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CThumbAGCameraObserver::CThumbAGCameraObserver(CThumbAGProcessor* aProcessor)
       
    65  	: iShutdownObserver(NULL), iMDSShutdownObserver(NULL), iMdESession(NULL), iProcessor(aProcessor)
       
    66  	{
       
    67  	// No implementation required
       
    68  	}
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // ConstructL
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CThumbAGCameraObserver::ConstructL()
       
    75 	{
       
    76 	TN_DEBUG1( "CThumbAGCameraObserver::ConstructL() - begin" );
       
    77 	
       
    78 #ifdef _DEBUG
       
    79     iAddCounter = 0;
       
    80     iModCounter = 0;
       
    81 #endif
       
    82     
       
    83     InitializeL();
       
    84     	
       
    85 	TN_DEBUG1( "CThumbAGCameraObserver::ConstructL() - end" );
       
    86 	}
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // ~CThumbAGCameraObserver
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CThumbAGCameraObserver::InitializeL()
       
    93     {
       
    94     TN_DEBUG1( "CThumbAGCameraObserver::InitializeL() - begin" );
       
    95     
       
    96    
       
    97         TN_DEBUG1( "CThumbAGCameraObserver::InitializeL() - create observers" );
       
    98         
       
    99         // create shutdown observer
       
   100         if(iMDSShutdownObserver)
       
   101             {
       
   102             delete iMDSShutdownObserver;
       
   103             iMDSShutdownObserver = NULL;
       
   104             }     
       
   105         iMDSShutdownObserver = CTMShutdownObserver::NewL( *this, KMdSPSShutdown, KMdSShutdown, EFalse );
       
   106 
       
   107         if(iShutdownObserver)
       
   108             {
       
   109             delete iShutdownObserver;
       
   110             iShutdownObserver = NULL;
       
   111             }
       
   112         iShutdownObserver = CTMShutdownObserver::NewL( *this, KTAGDPSNotification, KShutdown, ETrue );  
       
   113         iShutdown = EFalse;
       
   114         
       
   115         // MDS session reconnect timer
       
   116         if (!iReconnect)
       
   117             {
       
   118             iReconnect = CPeriodic::NewL(CActive::EPriorityIdle);
       
   119             }
       
   120         
       
   121         TN_DEBUG1( "CThumbAGCameraObserver::InitializeL() - connect to MDS" );
       
   122         
       
   123         if(iMdESession)
       
   124             {
       
   125             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   126             TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   127         
       
   128             // connect to MDS
       
   129             delete iMdESession;
       
   130             iMdESession = NULL;
       
   131             }
       
   132 
       
   133         iMdESession = CMdESession::NewL( *this );
       
   134         iSessionError = EFalse;
       
   135       
       
   136         TN_DEBUG1( "CThumbAGCameraObserver::InitializeL() - end" );
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // ~CThumbAGCameraObserver
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 CThumbAGCameraObserver::~CThumbAGCameraObserver()
       
   144     {
       
   145     TN_DEBUG1( "CThumbAGCameraObserver::~CThumbAGCameraObserver() - begin" );
       
   146     
       
   147     iShutdown = ETrue;    
       
   148     
       
   149     delete iMDSShutdownObserver;
       
   150     delete iShutdownObserver;
       
   151     
       
   152     if(iReconnect)
       
   153         {
       
   154         iReconnect->Cancel();
       
   155         delete iReconnect;
       
   156         iReconnect = NULL;
       
   157         }
       
   158     
       
   159     if (iMdESession)
       
   160         {
       
   161         // 2 observers
       
   162         TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   163         TRAP_IGNORE( iMdESession->RemoveObjectObserverL( *this ) );
       
   164                 
       
   165         delete iMdESession;
       
   166         iMdESession = NULL;
       
   167         }
       
   168     
       
   169     TN_DEBUG1( "CThumbAGCameraObserver::~CThumbAGCameraObserver() - end" );
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CThumbAGCameraObserver::HandleSessionOpened
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CThumbAGCameraObserver::HandleSessionOpened( CMdESession& /* aSession */, TInt aError )
       
   177     {
       
   178     TN_DEBUG1( "CThumbAGCameraObserver::HandleSessionOpened");
       
   179     
       
   180     if (aError == KErrNone)
       
   181         {
       
   182         TRAPD( err, AddObserversL() );
       
   183         if (err != KErrNone)
       
   184             {
       
   185             TN_DEBUG2( "CThumbAGCameraObserver::HandleSessionOpened, AddObserversL error == %d", err );
       
   186             }
       
   187         }
       
   188     else
       
   189         {
       
   190         TN_DEBUG2( "CThumbAGCameraObserver::HandleSessionOpened error == %d", aError );
       
   191         }
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CThumbAGCameraObserver::HandleSessionError
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CThumbAGCameraObserver::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
       
   199     {
       
   200     TN_DEBUG2( "CThumbAGCameraObserver::HandleSessionError == %d", aError );
       
   201     if (aError != KErrNone && !iSessionError)
       
   202         {
       
   203         iSessionError = ETrue;
       
   204     
       
   205         if (!iShutdown)
       
   206             {
       
   207             if (!iReconnect->IsActive())
       
   208                 {
       
   209                 iReconnect->Start( KMdEReconnect, KMdEReconnect, 
       
   210                                    TCallBack(ReconnectCallBack, this));
       
   211                 
       
   212                 TN_DEBUG1( "CThumbAGCameraObserver::HandleSessionError() - reconnect timer started" );
       
   213                 }
       
   214             }
       
   215 
       
   216         }   
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CThumbAGCameraObserver::HandleObjectNotification
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CThumbAGCameraObserver::HandleObjectNotification( CMdESession& /*aSession*/, 
       
   224                                                TObserverNotificationType aType,
       
   225                                                const RArray<TItemId>& aObjectIdArray )
       
   226     {
       
   227     TN_DEBUG1( "CThumbAGCameraObserver::HandleObjectNotification() - begin" );
       
   228 
       
   229     // no processor or shutting down
       
   230     if ( iShutdown || !iProcessor)
       
   231         {
       
   232         return;
       
   233         }
       
   234     
       
   235 #ifdef _DEBUG
       
   236     if (aType == ENotifyAdd)
       
   237         {
       
   238         TN_DEBUG2( "CThumbAGCameraObserver::HandleObjectNotification() - ENotifyAdd %d", aObjectIdArray.Count() );
       
   239         iAddCounter = aObjectIdArray.Count();
       
   240         }
       
   241     else if (aType == ENotifyModify)
       
   242         {
       
   243         TN_DEBUG2( "CThumbAGCameraObserver::HandleObjectNotification() - ENotifyModify %d", aObjectIdArray.Count() );
       
   244         iModCounter = aObjectIdArray.Count();
       
   245         }
       
   246 #endif
       
   247     
       
   248     if ( (aType == ENotifyAdd || aType == ENotifyModify ) && (aObjectIdArray.Count() > 0) )
       
   249         {
       
   250         TN_DEBUG1( "CThumbAGCameraObserver::HandleObjectNotification() - AddToQueueL" );
       
   251 
       
   252         // Add event to processing queue by type and enable force run        
       
   253         RPointerArray<HBufC> dummyArray;
       
   254         TRAPD(err, iProcessor->AddToQueueL(aType, EGenerationItemTypeCamera, aObjectIdArray, dummyArray, EFalse));
       
   255         if (err != KErrNone)
       
   256             {
       
   257             TN_DEBUG1( "CThumbAGCameraObserver::HandleObjectNotification() - error adding to queue" );
       
   258             }
       
   259         }
       
   260     else
       
   261         {
       
   262         TN_DEBUG1( "CThumbAGCameraObserver::HandleObjectNotification() - bad notification" );
       
   263         }
       
   264     
       
   265 #ifdef _DEBUG
       
   266     TN_DEBUG3( "CThumbAGImageObserver::IN-COUNTERS---------- Add = %d Modify = %d", iAddCounter, iModCounter );
       
   267     iModCounter = 0;
       
   268     iAddCounter = 0;
       
   269 #endif
       
   270 
       
   271     TN_DEBUG1( "CThumbAGCameraObserver::HandleObjectNotification() - end" );
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CThumbAGCameraObserver::ShutdownNotification
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CThumbAGCameraObserver::ShutdownNotification()
       
   279     {
       
   280     TN_DEBUG1( "CThumbAGCameraObserver::ShutdownNotification()" );
       
   281     
       
   282     if (!iShutdown)
       
   283         {
       
   284         TN_DEBUG1( "CThumbAGCameraObserver::ShutdownNotification() shutdown" );
       
   285         iShutdown = ETrue;
       
   286         }
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CThumbAGCameraObserver::AddObserversL
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CThumbAGCameraObserver::AddObserversL()
       
   294     {
       
   295     TN_DEBUG1( "CThumbAGCameraObserver::AddObserversL() - begin" );
       
   296     
       
   297     CMdENamespaceDef& defaultNamespace = iMdESession->GetDefaultNamespaceDefL();
       
   298     CMdEObjectDef& objectDef = defaultNamespace.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
   299     CMdEPropertyDef& originPropDef = objectDef.GetPropertyDefL( MdeConstants::Object::KOriginProperty );
       
   300     
       
   301     // set observing conditions
       
   302     CMdELogicCondition* addCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorAnd );
       
   303     addCondition->AddPropertyConditionL( originPropDef, TMdEUintEqual(MdeConstants::Object::ECamera));
       
   304     CleanupStack::Pop( addCondition );  
       
   305     
       
   306     CMdELogicCondition* modifyCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorAnd );
       
   307     modifyCondition->AddPropertyConditionL( originPropDef, TMdEUintEqual(MdeConstants::Object::ECamera));
       
   308     CleanupStack::Pop( modifyCondition );
       
   309     
       
   310     // add observer
       
   311     iMdESession->AddObjectObserverL( *this, addCondition, ENotifyAdd ); 
       
   312 
       
   313    // modify observer
       
   314    iMdESession->AddObjectObserverL( *this, modifyCondition, ENotifyModify );
       
   315      
       
   316     TN_DEBUG1( "CThumbAGCameraObserver::AddObserversL() - end" );
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // CThumbAGCameraObserver::ReconnectCallBack()
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 TInt CThumbAGCameraObserver::ReconnectCallBack(TAny* aAny)
       
   324     {
       
   325     TN_DEBUG1( "CThumbAGCameraObserver::ReconnectCallBack() - reinitialize");
       
   326     
       
   327     CThumbAGCameraObserver* self = static_cast<CThumbAGCameraObserver*>( aAny );
       
   328     
       
   329     self->iReconnect->Cancel();
       
   330     
       
   331     // reconnect to MDS
       
   332     TRAP_IGNORE( self->InitializeL() );
       
   333     
       
   334     TN_DEBUG1( "CThumbAGCameraObserver::ReconnectCallBack() - done");
       
   335     
       
   336     return KErrNone;
       
   337     }
       
   338 
       
   339 
       
   340 // End of file