harvester/server/inc/harvesterao.h
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2004-2009 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:  Thread which actually performs the harvesting of the files*
       
    15 */
       
    16 
       
    17 
       
    18 #ifndef __CHARVESTERAO_H__
       
    19 #define __CHARVESTERAO_H__
       
    20 
       
    21 #include <e32cmn.h>
       
    22 #include <e32base.h>
       
    23 
       
    24 #include "contextengine.h"
       
    25 #include "mdeharvestersession.h"
       
    26 
       
    27 #include "harvesterplugin.h"
       
    28 #include "composerplugin.h"
       
    29 #include "harvesterplugininfo.h"
       
    30 #include "harvesterqueue.h"
       
    31 #include "reharvesterao.h"
       
    32 #include "harvesterpluginfactory.h"
       
    33 #include "unmounthandlerao.h"
       
    34 #include "harvesteroomao.h"
       
    35 #include "backupsubscriber.h"
       
    36 #include "harvestermediaidutil.h"
       
    37 
       
    38 
       
    39 // forward declarations
       
    40 class CHarvesterBlacklist;
       
    41 class MProcessOriginMapperInterface;
       
    42 class COnDemandAO;
       
    43 class CMdeObjectHandler;
       
    44 class CHarvesterData;
       
    45 class CHarvesterEventManager;
       
    46 class CRestoreWatcher;
       
    47 class CHarvesterServerSession;
       
    48 struct TScanItem;
       
    49 
       
    50 /**
       
    51  * Helper class to hold all property definitions 
       
    52  * (pointers are not owned) used in harvester AO.
       
    53  */
       
    54 class CHarvesterAoPropertyDefs : public CBase
       
    55 	{
       
    56 	public:
       
    57 		// Common property definitions
       
    58 		CMdEPropertyDef* iCreationDatePropertyDef;
       
    59 		CMdEPropertyDef* iLastModifiedDatePropertyDef;
       
    60 		CMdEPropertyDef* iSizePropertyDef;
       
    61 		CMdEPropertyDef* iOriginPropertyDef;
       
    62 		
       
    63 		// Media property definitions
       
    64 		CMdEPropertyDef* iPreinstalledPropertyDef;
       
    65 
       
    66 	private:
       
    67 		CHarvesterAoPropertyDefs();
       
    68 	
       
    69 		void ConstructL(CMdEObjectDef& aObjectDef);
       
    70 
       
    71 	public:	
       
    72 		static CHarvesterAoPropertyDefs* NewL(CMdEObjectDef& aObjectDef);
       
    73 	};
       
    74 
       
    75 /**
       
    76  * MHarvesterStatusObserver
       
    77  */	
       
    78 
       
    79 class MHarvesterStatusObserver
       
    80 	{
       
    81 	public:
       
    82 		virtual void PauseReady( TInt aError ) = 0;
       
    83 		virtual void ResumeReady( TInt aError ) = 0;
       
    84 	};
       
    85 
       
    86 /**
       
    87 * Harvester server active object.
       
    88 *
       
    89 * @lib harvesterblacklist.lib
       
    90 */
       
    91 
       
    92 class CHarvesterAO : public CActive,
       
    93                      public MHarvesterPluginObserver, 
       
    94                      public MContextInitializationObserver,
       
    95                      public MContextSnapshotObserver,
       
    96                      public MMdESessionObserver,
       
    97                      public MBackupRestoreObserver,
       
    98                      public MUnmountObserver,
       
    99                      public MHarvesterOomObserver
       
   100 	{
       
   101     public:
       
   102     
       
   103         enum TRequest
       
   104         	{
       
   105         	ERequestIdle,
       
   106         	ERequestHarvest,
       
   107         	ERequestPause,
       
   108         	ERequestResume,
       
   109         	ERequestContainerPlaceholder
       
   110         	};
       
   111         	
       
   112 
       
   113 
       
   114         /**
       
   115          * Constructs a new harvesting thread
       
   116          *
       
   117          * @return  Harvester thread implementation
       
   118          */
       
   119         static CHarvesterAO* NewL();
       
   120 
       
   121         /**
       
   122          * Constructs a new harvesting thread and leaves the server implementation
       
   123          * in the cleanup stack.
       
   124          *
       
   125          * @return  Harvester thread implementation
       
   126          */
       
   127         static CHarvesterAO* NewLC();
       
   128 
       
   129         /**
       
   130          * C++ Destructor.
       
   131          */
       
   132         virtual ~CHarvesterAO();
       
   133         		
       
   134         /**
       
   135          * Derived from MHarvesterPluginObserver - used to indicate when harvesting of a file is done
       
   136          * @param aHD  harvester data type
       
   137          */
       
   138         void HarvestingCompleted( CHarvesterData* aHD );
       
   139 
       
   140         /**
       
   141          * Derived from MContextInitializationObserver - for checking Context Engine initialization
       
   142          * @param aErrorCode  Indicates whether Context Engine was successfully initialized
       
   143          */
       
   144         void ContextInitializationStatus( TInt aErrorCode );
       
   145         	
       
   146         /**
       
   147          * Derived from MMdESessionObserver - for checking MdE initialization status
       
   148          * @param aSession  MdE Session which was opened
       
   149          * @param aError  Error code from the opening
       
   150          */
       
   151         void HandleSessionOpened( CMdESession& aSession, TInt aError );
       
   152 
       
   153         /**
       
   154          * Derived from MMdESessionObserver - for checking MdE session errors
       
   155          * @param aSession  MdE Session which was opened
       
   156          * @param aError  Error which has occurred
       
   157          */
       
   158         void HandleSessionError( CMdESession& aSession, TInt aError );
       
   159 
       
   160         /**
       
   161          * Method used to pause monitor plugins
       
   162          */
       
   163         void PauseMonitoring();
       
   164 
       
   165         /**
       
   166          * Method used to resume monitor plugins
       
   167          */       
       
   168         void ResumeMonitoring();
       
   169 
       
   170         /**
       
   171          * Standard RunL-method.
       
   172          * From CActive.
       
   173          */       
       
   174         void RunL();
       
   175 
       
   176         /**
       
   177          * From CActive.
       
   178          */       
       
   179         void DoCancel();
       
   180 
       
   181         /**
       
   182          * From CActive.
       
   183          * @param aError  Leave error code.
       
   184          * @return Always KErrNone.
       
   185          */       
       
   186         TInt RunError( TInt aError );
       
   187 
       
   188         /**
       
   189          * Set next request (=state) of this active object.
       
   190          * @param aRequest  State enumeration.
       
   191          */       
       
   192         void SetNextRequest( TRequest aRequest );
       
   193 
       
   194         /**
       
   195          * Checks if harvester server is paused.
       
   196          * @return Truth value.
       
   197          */       
       
   198         TBool IsServerPaused();
       
   199         
       
   200         /**
       
   201          * Checks whether connection to MDE has been established
       
   202          * @return ETrue if connection to MDE has been made otherwise EFalse
       
   203          */
       
   204          TBool IsConnectedToMde();        
       
   205         
       
   206         
       
   207         /**
       
   208          * Starts a file harvest.
       
   209          * @param aMessage  A message containing file info (URI etc)
       
   210          */       
       
   211         void HarvestFile( const RMessage2& aMessage );
       
   212         
       
   213         /**
       
   214          * Starts a file harvest.
       
   215          * @param aMessage  A message containing file info (URI etc)
       
   216          */       
       
   217         void HarvestFileWithUID( const RMessage2& aMessage );
       
   218 
       
   219         /**
       
   220          * Register an origin value for a process.
       
   221          * @param aMessage  A message containing process id and origin.
       
   222          */       
       
   223         void RegisterProcessOrigin( const RMessage2& aMessage );
       
   224 
       
   225         /**
       
   226          * Unregister an origin value for a process.
       
   227          * @param aMessage  A message containing process id.
       
   228          */       
       
   229         void UnregisterProcessOrigin( const RMessage2& aMessage );
       
   230 
       
   231         /**
       
   232          * This method is called by Context framework after context snapshot is taken
       
   233          * @param aHD  Harvester data type (if ErrorCode() == KErrNone - snapshot taken ok)
       
   234          */
       
   235          void ContextSnapshotStatus( CHarvesterData* aHD );
       
   236 
       
   237 		/**
       
   238          * Register a harvesting complete from server
       
   239          * @param aMessage  Message which was received from the client side.
       
   240          * @param aSession  harvester server session.
       
   241          */ 
       
   242         TInt RegisterHarvestComplete( const CHarvesterServerSession& aSession, const RMessage2& aMessage );
       
   243         
       
   244         /**
       
   245          * Unregister a harvesting complete from server
       
   246          * @param aMessage  Message which was received from the client side.
       
   247          */ 
       
   248         TInt UnregisterHarvestComplete( const CHarvesterServerSession& aSession );
       
   249         
       
   250         /**
       
   251          * Register a harvester event from server
       
   252          * @param aMessage  Message which was received from the client side.
       
   253          */ 
       
   254         void RegisterHarvesterEvent( const RMessage2& aMessage );
       
   255         
       
   256         /**
       
   257 	     * Unregister a harvester event from server
       
   258 	     * @param aMessage  Message which was received from the client side.
       
   259 	     */ 
       
   260 	    void UnregisterHarvesterEvent( const RMessage2& aMessage );
       
   261 	    
       
   262         void GetLastObserverId( const RMessage2& aMessage );
       
   263 
       
   264 	// from MBackupRestoreObserver
       
   265 
       
   266         /**
       
   267          * From MBackupRestoreObserver.
       
   268          * Called by CBlacklistBackupSubscriberAO when
       
   269          * Backup&Restore is backing up or restoring.
       
   270          */
       
   271         void BackupRestoreStart();
       
   272 
       
   273         /**
       
   274          * From MBackupRestoreObserver.
       
   275          * Called by CBlacklistBackupSubscriberAO when
       
   276          * Backup&Restore has finished backup or restore.
       
   277          */
       
   278         void BackupRestoreReady();
       
   279         
       
   280         /** */  	
       
   281         void HandleUnmount( TUint32 aMediaId );
       
   282         
       
   283         void SetHarvesterStatusObserver( MHarvesterStatusObserver* aObserver );
       
   284         
       
   285         /**
       
   286          * From MHarvesterOomObserver
       
   287          */
       
   288         void MemoryLow();
       
   289         
       
   290         /**
       
   291          * From MHarvesterOomObserver
       
   292          */
       
   293         void MemoryGood();
       
   294 		
       
   295 	private:
       
   296 		
       
   297 	struct THarvestFileRequest
       
   298 		{
       
   299 		const CHarvesterServerSession& iSession;
       
   300 		RMessage2 iMessage;
       
   301 			
       
   302 		THarvestFileRequest( const CHarvesterServerSession& aSession,
       
   303 				const RMessage2& aMessage ) :
       
   304 	       		iSession( aSession ), 
       
   305 	       		iMessage( aMessage )
       
   306 	       		{}
       
   307 		};
       
   308 	
       
   309 	/**
       
   310          * C++ Constructor, called by NewLC()
       
   311          */
       
   312         CHarvesterAO();
       
   313 
       
   314         /**
       
   315          * 2nd-phase construction, called by NewLC()
       
   316          */
       
   317         void ConstructL(); 		
       
   318 
       
   319         /**
       
   320          * Method used to load monitor plugins
       
   321          */        
       
   322         void LoadMonitorPluginsL();
       
   323 
       
   324         /**
       
   325          * Method used to delete monitor plugins
       
   326          */           
       
   327         void DeleteMonitorPlugins();
       
   328 
       
   329         /**
       
   330          * Method used to start monitor plugins
       
   331          */  
       
   332         void StartMonitoring();
       
   333 
       
   334         /**
       
   335          * Method used to stop monitor plugins
       
   336          */          
       
   337         void StopMonitoring();
       
   338 
       
   339         /**
       
   340          * Method used to start composer plugins
       
   341          */  
       
   342         void StartComposersL();
       
   343 
       
   344         /**
       
   345          * Method used to stop composer plugins
       
   346          */  		
       
   347         void StopComposers();
       
   348 
       
   349         /**
       
   350          * Method used to delete composer plugins
       
   351          */  
       
   352         void DeleteComposers();
       
   353 
       
   354         /**
       
   355          * Method used to check whether composer plugins are active
       
   356          * @return  Whether all compsosers are ready
       
   357          */  				
       
   358         TBool IsComposingReady();
       
   359 
       
   360         /**
       
   361          * Method used to read one harvester item from queue
       
   362          */	    
       
   363         void ReadItemFromQueueL();
       
   364         
       
   365         /**
       
   366          * Method used to handle placeholder object to database
       
   367          */	    
       
   368         void HandlePlaceholdersL( TBool aCheck );
       
   369 
       
   370         /**
       
   371          * Method used to check file extension and harvest file
       
   372          * @param aFile  File to be harvester 
       
   373          * @param aEventType  Harveting type
       
   374          * @param aTakeSnapshot  Whether context snapshot should be added to metadata
       
   375          */		
       
   376         void CheckFileExtensionAndHarvestL( CHarvesterData* aHD );
       
   377 
       
   378         /**
       
   379          * Method used to pause the operation of the Harvesting thread
       
   380          * @return  Whether pausing of the harvesting thread succeeded 
       
   381          */	
       
   382         TInt PauseHarvester();
       
   383 
       
   384         /**
       
   385          * Method used to resume the operation of the Harvesting thread
       
   386          */			
       
   387         void ResumeHarvesterL();
       
   388         
       
   389         /**
       
   390          * Signals the client observer for file harvesting was completed
       
   391          * @param aClientId, RMessage2.Identity
       
   392          * @param aFile, Harvested file name
       
   393          * @param aErr, KErrNone, or system wide error code if exists
       
   394          */ 
       
   395         void HarvestCompleted( TUid aClientId, const TDesC& aUri, TInt aErr );
       
   396         
       
   397         /**
       
   398          * Scan ROM drive (Z) in first phone boot
       
   399          */
       
   400         void BootRomScanL();
       
   401         
       
   402         /**
       
   403          * Scan system drive (C) after partial restore
       
   404          */
       
   405         void BootPartialRestoreScanL();
       
   406         
       
   407         static TBool IsDescInArray(const TPtrC& aSearch, const RPointerArray<HBufC>& aArray);
       
   408         
       
   409         /**
       
   410          * Method used to scan paths for file to be harvest. This method 
       
   411          * removes paths from aPaths after scanning.
       
   412          * 
       
   413          * @param aScanPaths scan paths
       
   414          * @param aIgnorePaths ignored paths
       
   415          */
       
   416         void BootScanL( RPointerArray<TScanItem>& aScanItems,
       
   417         		        const RPointerArray<HBufC>& aIgnorePaths,
       
   418         		        TBool aCheckDrive );
       
   419         
       
   420         /**
       
   421          * Checks if there are any items unharvested in harvester plugins.
       
   422          * @return  Whether or not there are any files to be harvested in plugin queues.
       
   423          */
       
   424         TBool UnharvestedItemsLeftInPlugins();
       
   425 
       
   426         void PreallocateNamespaceL( CMdENamespaceDef& aNamespaceDef );
       
   427         
       
   428         void StartThumbAGDaemon();
       
   429         
       
   430  	private:
       
   431  	
       
   432         /**
       
   433          * Pointer to Context Engine implementation
       
   434          */	
       
   435         CContextEngine* iCtxEngine;
       
   436 
       
   437         /**
       
   438          * Pointer to Metadata Engine session
       
   439          */			
       
   440         CMdESession* iMdESession;
       
   441         
       
   442         /**
       
   443          * Pointer to Harvester Metadata Engine session
       
   444          */			
       
   445         CMdEHarvesterSession* iMdEHarvesterSession;
       
   446 
       
   447         /**
       
   448          * Harvester server internal event queue
       
   449          */	
       
   450         CHarvesterQueue* iQueue;
       
   451 
       
   452         /**
       
   453          * Blacklister of files that have failed harvesting.
       
   454          */
       
   455         CHarvesterBlacklist* iBlacklist;
       
   456 
       
   457         /**
       
   458          * Publish & Subscribe subscriber for Backup & Restore.
       
   459          * Notifies harvester server when something happens.
       
   460          */
       
   461         CBackupSubscriber* iBackupSubscriber;
       
   462 
       
   463         /**
       
   464          * This array contains pointers to monitor plugins
       
   465          */		
       
   466         RPointerArray<CMonitorPlugin> iMonitorPluginArray;
       
   467         
       
   468         /**
       
   469          * This array contains pointers to composer plugins
       
   470          */		
       
   471         RPointerArray<CComposerPlugin> iComposerPluginArray;
       
   472 
       
   473         /**
       
   474          * Indicates whether server is paused or not
       
   475          */			
       
   476         TBool iServerPaused;		
       
   477 
       
   478         /**
       
   479          * Indicator to show which task will be next to do
       
   480          */
       
   481         TRequest iNextRequest;
       
   482         
       
   483         /** */
       
   484 		RArray<THarvestFileRequest> iHarvestFileMessages;
       
   485         /** Re-harvester */
       
   486         CReHarvesterAO* iReHarvester;
       
   487         
       
   488         /** Flag to signal if mde session is properly initialized. */
       
   489         TBool iMdeSessionInitialized;
       
   490 
       
   491         /** Flag to signal if context engine is properly initialized. */
       
   492         TBool iContextEngineInitialized;
       
   493         
       
   494         /** Connection to file server (CheckForMoveEventL) */
       
   495         RFs iFs;
       
   496 
       
   497         /** */
       
   498         CHarvesterPluginFactory* iHarvesterPluginFactory;
       
   499 
       
   500 		/** */
       
   501         RPointerArray<CHarvesterData> iPHArray;
       
   502 		
       
   503 		/** */
       
   504         RPointerArray<CHarvesterData> iReadyPHArray;
       
   505         
       
   506         /** */
       
   507         RPointerArray<CHarvesterData> iContainerPHArray;
       
   508                 
       
   509         /**
       
   510          * Pointer to process origin mapper for registering mappings.
       
   511          * Implemented by file monitor plugin.
       
   512          */
       
   513         MProcessOriginMapperInterface* iProcessOriginMapper;
       
   514         
       
   515 		/** */
       
   516         COnDemandAO* iOnDemandAO;
       
   517         
       
   518 		/** */
       
   519         CMdeObjectHandler* iMdeObjectHandler;
       
   520 		
       
   521         /** */
       
   522         CUnmountHandlerAO* iUnmountHandlerAO;
       
   523         
       
   524         /** */
       
   525         CHarvesterEventManager* iHarvesterEventManager;
       
   526                 
       
   527         MHarvesterStatusObserver* iHarvesterStatusObserver;
       
   528         TBool iHarvesting;
       
   529         
       
   530         CRestoreWatcher* iRestoreWatcher;
       
   531         
       
   532         CHarvesterOomAO* iHarvesterOomAO;
       
   533         
       
   534         // not own
       
   535         CHarvesterMediaIdUtil* iMediaIdUtil;
       
   536         
       
   537         CHarvesterAoPropertyDefs* iPropDefs;
       
   538 	};
       
   539 	
       
   540 #endif //__CHARVESTERAO_H__