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