mds_plat/harvester_framework_api/inc/harvesterplugin.h
changeset 58 fe894bb075c2
parent 51 87e65c44ff3a
child 60 79f826a55db2
equal deleted inserted replaced
51:87e65c44ff3a 58:fe894bb075c2
     1 /*
       
     2 * Copyright (c) 2006-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:  Definition of the Harvester plug-in ECom interface.*
       
    15 */
       
    16 
       
    17 #ifndef __CHARVESTERPLUGIN_H__
       
    18 #define __CHARVESTERPLUGIN_H__
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <ecom.h>
       
    22 
       
    23 // forward declarations
       
    24 class CMdESession;
       
    25 class CHarvesterBlacklist;
       
    26 class CHarvesterData;
       
    27 class CMdEPropertyDef;
       
    28 class CHarvesterPluginFactory;
       
    29 
       
    30 // Uid for this interface
       
    31 const TUid KCHarvesterPluginInterfaceUid = { 0x200009F8 };
       
    32 
       
    33 struct THarvestResult
       
    34     {
       
    35     HBufC16* iUri;   // URI of the file/item
       
    36     TInt iErrorCode; // Harvesting error code
       
    37     };
       
    38 
       
    39 /**
       
    40  * Harvester Plug-in ECom interface definition. Harvester plug-in implementation
       
    41  * needs to inherit this class and implement the pure virtual method (HarvestL) which exist 
       
    42  * in this interface.
       
    43  *
       
    44  * Example:
       
    45  * 
       
    46  * class CMyHarvesterPlugin:  public CHarvesterPlugin
       
    47  *     {
       
    48  *     public:
       
    49  *
       
    50  *         // This method should also be overwritten in the plug-in
       
    51  *         void GetObjectType( const TDesC& aUri, TDes& aObjectType );
       
    52  *
       
    53  *         void HarvestL( CHarvesterData* aHD );
       
    54  *     }
       
    55  *
       
    56  * void GetObjectType( const TDesC& aUri, TDes& aObjectType )
       
    57  *     {
       
    58  *      // Idea in this method is that it MUST return one of the object types
       
    59  *	    // supported by the MdE DB - for example "Image", "Video" or "Audio".
       
    60  * 	    // If plug-in supports only one type of objects then it can just return
       
    61  * 	    // always that like:  
       
    62  * 	    // TPtrC ptrImage( KImage );
       
    63  * 	    // aObjectType.Copy( KImage ); return;
       
    64  * 	    //
       
    65  * 	    // However if multiple MdE object types are supported then file content
       
    66  * 	    // needs to be checked for example from file MIME-type like here:
       
    67  * 	  
       
    68  *	   	TRAPD( err, content = CContent::NewL( aUri ) );
       
    69  *	    if (err == KErrNone) 
       
    70  *		    {
       
    71  *		    err = content->GetStringAttribute( EMimeType, mime );
       
    72  *		    delete content;
       
    73  *		    }
       
    74  *
       
    75  *	    TPtrC ptrImage( KImage );
       
    76  *	    
       
    77  *	    // MdsUtils::Find tries to find word "image" from the MIME-type
       
    78  *      // so that we know the file is an image
       
    79  *		if( MdsUtils::Find( mime, ptrImage ) != KErrNotFound )
       
    80  *			{
       
    81  *			WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Image", &mime );
       
    82  *			aObjectType.Copy( KImage );
       
    83  *			return;
       
    84  *			}
       
    85  *		
       
    86  *		TPtrC ptrVideo( KVideo );
       
    87  *		if( MdsUtils::Find( mime, ptrVideo ) != KErrNotFound )
       
    88  *			{
       
    89  *			WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Video", &mime );
       
    90  *			aObjectType.Copy( KVideo );
       
    91  *			return;
       
    92  *			}
       
    93  *     }
       
    94  *
       
    95  * void HarvestL( CHarvesterData* aHD )
       
    96  *     {
       
    97  *     CMdEObject& mdeObject = aHD->MdeObject();
       
    98  *      
       
    99  *     CMdeObjectWrapper* wrapper = CMdeObjectWrapper::NewL();
       
   100  *     }	 
       
   101  */
       
   102 class CHarvesterPlugin : public CActive
       
   103     {
       
   104 public:
       
   105 	    
       
   106 	enum THarvesterState
       
   107 	    {
       
   108 	    EHarvesterIdle = 0,   // No harvesting requests to process
       
   109 	    EHarvesterGathering,  // Harvesting a file
       
   110 	    };
       
   111 	
       
   112 	/** 
       
   113 	 * Construction 
       
   114 	 */
       
   115 	IMPORT_C static CHarvesterPlugin* NewL( const TUid& aUid );
       
   116 	
       
   117     /**
       
   118      * Lists all available implementations which satisfy this given interface.
       
   119      * 
       
   120      * @param aImplInfoArray  Reference to a list which will be populated with 
       
   121      *                        plug-in implementation details. 
       
   122      */
       
   123 	IMPORT_C static void ListImplementationsL( RImplInfoPtrArray& aImplInfoArray );
       
   124 	
       
   125 	/**
       
   126 	 * Destructor - virtual and class not intended
       
   127 	 * for derivation, so not exported.
       
   128 	 */
       
   129 	IMPORT_C virtual ~CHarvesterPlugin();
       
   130 	
       
   131 	/**
       
   132 	 *  Method sets the Harvesting queue to the plug-in.
       
   133 	 * 
       
   134 	 * @param aQueue  Queue which contains harvesting requests.
       
   135 	 */
       
   136 	IMPORT_C virtual void SetQueue( RPointerArray<CHarvesterData>& aQueue );
       
   137 	
       
   138 	/** 
       
   139 	 * Method which starts the harvesting of the file. Called by the 
       
   140 	 * harvesting framework from CHarvesterPluginFactory::HarvestL.
       
   141 	 */
       
   142 	IMPORT_C virtual void StartHarvest();
       
   143 	
       
   144 	/** 
       
   145 	 * Method which returns the MdE object type to harvesting FW when passing the file
       
   146 	 * name to this method (aURI). The harvesting plug-in should overwrite method. In the
       
   147 	 * case there are more than one plug-ins which support same file extension atleast
       
   148 	 * one of these plug-ins needs to read the binary file for determining the valid MdE
       
   149 	 * object type for the file.
       
   150 	 *
       
   151 	 * @param aUri         URI of the file/item.
       
   152 	 * @param aObjectType  Reference to an object type which will returned to the FW 
       
   153 	 *                     from the plug-in
       
   154 	 */
       
   155 	IMPORT_C virtual void GetObjectType( const TDesC& aUri, TDes& aObjectType );
       
   156 	
       
   157 	/** 
       
   158 	 * Method for setting the blacklisting functionality for the plug-in.
       
   159 	 * 
       
   160 	 * @param aBlacklist  Reference to blacklisting component.
       
   161 	 */
       
   162 	IMPORT_C virtual void SetBlacklist( CHarvesterBlacklist& aBlacklist );
       
   163 	
       
   164     /** 
       
   165 	 * Method to stop harvester plugin if needed.
       
   166 	 */
       
   167 	IMPORT_C virtual void StopHarvest();
       
   168 
       
   169 protected:
       
   170     
       
   171 	/** 
       
   172 	 * The method which does the actual harvesting. Harvesting plug-in MUST
       
   173 	 * implelemt this method.
       
   174 	 * 
       
   175 	 * @param aHD  Pointer to harvesting data/request.
       
   176 	 */
       
   177 	IMPORT_C virtual void HarvestL( CHarvesterData* aHD ) = 0;
       
   178 	
       
   179 	/** 
       
   180 	 * Active object RunL implementation.
       
   181 	 */
       
   182 	IMPORT_C virtual void RunL();
       
   183 	  
       
   184 	/** 
       
   185 	 * Active object DoCancel implementation.
       
   186 	 */
       
   187 	IMPORT_C virtual void DoCancel();
       
   188 	  
       
   189 	/** 
       
   190 	 * Active object RunError implementation.
       
   191 	 */
       
   192 	IMPORT_C virtual TInt RunError( TInt aError );
       
   193 	
       
   194 	 /** 
       
   195 	  * Construction of the interface class
       
   196 	  */
       
   197 	 void ConstructL();
       
   198 	
       
   199 	 /** 
       
   200 	  * Constuctor 
       
   201 	  */
       
   202 	 IMPORT_C CHarvesterPlugin();
       
   203 
       
   204 public:
       
   205 
       
   206     /** 
       
   207      * Method for getting the mime type for given uri
       
   208      */
       
   209     IMPORT_C virtual void GetMimeType( const TDesC& aUri, TDes& aMimeType );
       
   210     
       
   211     /** 
       
   212      * Method for adding reference to harvester plugin factory
       
   213      */
       
   214     IMPORT_C void SetHarvesterPluginFactory( CHarvesterPluginFactory& aFactory );
       
   215          
       
   216     /** 
       
   217      * Method for checking if the plugin is in idle state
       
   218      */
       
   219     IMPORT_C TBool PluginInIdleState();
       
   220     
       
   221 private:
       
   222     
       
   223 	/** 
       
   224 	 * Sets next state for the active object
       
   225 	 *
       
   226 	 * @param aState  Next state to execute with RunL.
       
   227 	 */
       
   228 	void SetNextRequest( THarvesterState aState );
       
   229 		
       
   230 	/** 
       
   231 	 * Method sets some default properties to the metadata object
       
   232 	 * 
       
   233 	 * @param aData  Pointer to harvesting data/request.
       
   234 	 */
       
   235 	void SetDefaultPropertiesL(CHarvesterData& aData);
       
   236 	
       
   237 protected:
       
   238 	
       
   239 	/** 
       
   240 	 * Handle to File server session.
       
   241 	 */
       
   242 	RFs iFs;
       
   243 	
       
   244 	/**
       
   245 	 *  State of this active object.
       
   246 	*/
       
   247 	THarvesterState iState;
       
   248 	     
       
   249 	/** 
       
   250 	 * Pointer to Harvesting request queue.
       
   251 	 */
       
   252 	RPointerArray<CHarvesterData>* iQueue;
       
   253 	
       
   254 	/** 
       
   255 	 * Pointer to blacklisting functionality
       
   256 	 */
       
   257 	CHarvesterBlacklist* iBlacklist;
       
   258 
       
   259     // Not own
       
   260     CHarvesterPluginFactory* iFactory;
       
   261     
       
   262     TBool iFastModeEnabled;
       
   263     
       
   264 private:
       
   265 	
       
   266 	/* Identification on cleanup */ 
       
   267 	TUid iDtor_ID_Key;
       
   268 
       
   269 	CMdEPropertyDef* iOriginPropertyDef;
       
   270 	CMdEPropertyDef* iTitlePropertyDef;
       
   271 	
       
   272     TBool iHarvesting;
       
   273     TBool iPaused;
       
   274 	
       
   275     };
       
   276 
       
   277 #endif // __CHARVESTERPLUGIN_H__