os/security/contentmgmt/contentaccessfwfordrm/inc/importfile.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/inc/importfile.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,298 @@
     1.4 +/*
     1.5 +* Copyright (c) 2003-2008 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +/** 
    1.24 +@file
    1.25 +
    1.26 +@publishedPartner
    1.27 +@released
    1.28 +*/
    1.29 +
    1.30 +
    1.31 +#ifndef __IMPORTFILE_H__
    1.32 +#define __IMPORTFILE_H__
    1.33 +
    1.34 +#include <e32base.h>
    1.35 +#include <f32file.h>
    1.36 +#include <caf/caftypes.h>
    1.37 +
    1.38 +namespace ContentAccess
    1.39 +	{
    1.40 +	class CAgentFactory;
    1.41 +	class CSupplierOutputFile;
    1.42 +	class CMetaDataArray;
    1.43 +	class CAgentSupplier;
    1.44 +	class CAgentImportFile;
    1.45 +	class CSupplier;
    1.46 +	class CAgentInfo;
    1.47 +	class CAgentFactory;
    1.48 +
    1.49 +	/**
    1.50 +	Created by the CSupplier to import a file. 
    1.51 +	
    1.52 +	The mime type of the file must be one of the CAF supplier mime types. 
    1.53 +	Applications should check using CSupplier::IsImportSupported().
    1.54 +	
    1.55 +	This class creates a CAgentSupplier and uses it to import the file into the 
    1.56 +	content access agent who supports the given mime type.
    1.57 +	
    1.58 +	This class is single use only and cannot be used to import multiple files. 
    1.59 +	The import process may result in one or more output files.
    1.60 +	
    1.61 +	@publishedPartner
    1.62 +	@released	
    1.63 +	*/
    1.64 +	class CImportFile: public CBase
    1.65 +		{
    1.66 +		friend class CSupplier;
    1.67 +
    1.68 +	public:
    1.69 +		/** Destructor - deleting the CImportFile instance before calling WriteComplete() aborts the import operation 
    1.70 +		*/
    1.71 +		virtual ~CImportFile();
    1.72 +
    1.73 +		/** Write a block of data from a file to an agent.
    1.74 +		
    1.75 +		@param aData The block of data.
    1.76 +		@return	The result of the write operation.
    1.77 +		@return KErrNone if the data was written successfully.
    1.78 +		@return	KErrCANewFileHandleRequired if the agent requires the client to provide a new file handle before proceeding. The agent must save its state and continue processing when the new handle is supplied by ContinueWithNewOutputFile().
    1.79 +		@return KErrCorrupt if the file does not match the format the agent is expecting.
    1.80 +		@return KErrNotReady if the agent was not expecting WriteData() to be called at this point.
    1.81 +		@return Otherwise one of the other CAF error codes defined in \c caferr.h  or one of the 
    1.82 +				other system-wide error codes for any other errors.
    1.83 +		*/
    1.84 +		IMPORT_C TInt WriteData(const TDesC8& aData);
    1.85 +
    1.86 +		/** Asynchronously write a block of data from a file to an agent.		 
    1.87 +		Notifies the client when the write operation is complete.
    1.88 +		NB: It is important that the descriptor passed to 
    1.89 +		aData remains in scope until the request has completed.	
    1.90 +		
    1.91 +		@param aData 	The block of data.	
    1.92 +		@param aStatus 	Asynchronous request status. On completion this will 
    1.93 +						contain one of the following error codes: KErrNone if the data was written successfully. 
    1.94 +						KErrCANewFileHandleRequired if the agent requires a new 
    1.95 +						file handle before proceeding - the agent must save its 
    1.96 +						state and continue processing when the new handle 
    1.97 +						is supplied by ContinueWithNewOutputFile(). KErrCorrupt 
    1.98 +						if the file does not match the format the agent is expecting.
    1.99 +						KErrNotReady if the agent was not expecting WriteDataComplete() 
   1.100 +						to be called at this point. Otherwise one of the other CAF error codes 
   1.101 +						defined in \c caferr.h  or one of the other standard system-wide 
   1.102 +						error codes for any other errors.
   1.103 +		*/
   1.104 +		IMPORT_C void WriteData(const TDesC8& aData, TRequestStatus& aStatus);
   1.105 +
   1.106 +		/** Signals to the agent that the entire file has now been transferred to the agent.
   1.107 +		
   1.108 +		@return The result of the write operation. 
   1.109 +		@return KErrNone if the data was written successfully.
   1.110 +		@return	KErrCANewFileHandleRequired if the agent requires the client to provide a new file handle before proceeding. The agent must save its state and continue processing when the new handle is supplied by ContinueWithNewOutputFile().
   1.111 +		@return KErrCorrupt if the file does not match the format the agent is expecting.
   1.112 +		@return KErrNotReady if the agent was not expecting WriteDataComplete() to be called at this point.
   1.113 +		@return Otherwise one of the other CAF error codes defined in \c caferr.h  or one of the 
   1.114 +				other system-wide error codes for any other errors.		
   1.115 +		*/
   1.116 +		IMPORT_C TInt WriteDataComplete();
   1.117 +
   1.118 +
   1.119 +		/** Signals to the agent that the entire file has now been transferred to the agent
   1.120 +		
   1.121 +		Notifies the client when any final processing operation is complete.
   1.122 +		
   1.123 +		@param aStatus 	Asynchronous request status. On completion this will 
   1.124 +						contain one of the following error codes: KErrNone if the data was written successfully. 
   1.125 +						KErrCANewFileHandleRequired if the agent requires a new 
   1.126 +						file handle before proceeding - the agent must save its 
   1.127 +						state and continue processing when the new handle 
   1.128 +						is supplied by ContinueWithNewOutputFile(). KErrCorrupt 
   1.129 +						if the file does not match the format the agent is expecting.
   1.130 +						KErrNotReady if the agent was not expecting WriteDataComplete() 
   1.131 +						to be called at this point. Otherwise one of the other CAF error codes 
   1.132 +						defined in \c caferr.h  or one of the other standard system-wide 
   1.133 +						error codes for any other errors.
   1.134 +		*/
   1.135 +		IMPORT_C void WriteDataComplete(TRequestStatus& aStatus);
   1.136 +
   1.137 +		/** Gets the number of output files produced so far. 
   1.138 +		@return The number of output files.
   1.139 +		*/
   1.140 +		IMPORT_C TInt OutputFileCountL() const;
   1.141 +
   1.142 +		/** Return information about an output file generated by the import operation. 
   1.143 +		
   1.144 +		 It is possible that the output file does not have the same name 
   1.145 +		 as the one suggested at the beginning of the import. An agent may
   1.146 +		 need to use a particular file extension or a particular name.
   1.147 +
   1.148 +		The agent may decide not to store the output file in the output directory 
   1.149 +		suggested at the start of the import. eg. it may store the file in its private 
   1.150 +		server directory.
   1.151 +
   1.152 +		The output files may only appear in this array after the WriteDataComplete() 
   1.153 +		function has been called. 
   1.154 +
   1.155 +		@param aIndex The zero-based index of the file (must be less than the value returned by OutputFileCountL().
   1.156 +		@return The CSupplierOutputFile for this object.
   1.157 +		*/
   1.158 +		IMPORT_C CSupplierOutputFile& OutputFileL(TInt aIndex) const;
   1.159 +
   1.160 +		/** Retrieve the import status
   1.161 +
   1.162 +		Used to indicate non fatal problems encountered during the import operation.
   1.163 +		Provides feedback to the client in case any problems are encountered.
   1.164 +
   1.165 +		The client can then decide whether or not to continue the import.
   1.166 +		 
   1.167 +		@return	The state of the import operation.
   1.168 +		*/
   1.169 +		IMPORT_C TImportStatus GetImportStatus() const;
   1.170 +
   1.171 +		/** Get the agents suggestion for the file extension of the output file required by the agent
   1.172 +
   1.173 +		This function should only be called when the agent has returned KErrCANewFileHandleRequired from
   1.174 +		WriteData() or WriteDataComplete().
   1.175 +
   1.176 +		The extension must include the dot '.' character.
   1.177 +
   1.178 +		@param aFileExtension On completion this will contain the appropriate file extension.
   1.179 +		@return The result of the request for a file extension.
   1.180 +		@return KErrNone if the agent populated aFileExtension with the correct file extension.
   1.181 +		@return KErrNotReady if the agent is not waiting for another file handle to be provided.
   1.182 +		@return KErrUnknown if the agent does not know what extension should be used.
   1.183 +		*/
   1.184 +		IMPORT_C TInt GetSuggestedOutputFileExtension(TDes& aFileExtension);
   1.185 +
   1.186 +		/** Get the agents suggestion for the file name (with extension) of the output file required by the agent
   1.187 +
   1.188 +		This function should only be called when the agent has returned KErrCANewFileHandleRequired from
   1.189 +		WriteData() or WriteDataComplete().
   1.190 +
   1.191 +		The file name is of the form filename.extension.
   1.192 +
   1.193 +		@param aFileName On completion this will contain the appropriate file name.
   1.194 +		@return KErrNone if the agent populated aFileName with the correct file name.
   1.195 +		@return KErrNotReady if the agent is not waiting for another file handle to be provided.
   1.196 +		@return KErrUnknown if the agent does not know what file name should be used.
   1.197 +		*/
   1.198 +		IMPORT_C TInt GetSuggestedOutputFileName(TDes& aFileName);
   1.199 +
   1.200 +		/** Continue the last write operation with a new file handle as requested by the agent
   1.201 +		
   1.202 +		@param aFile A new file handle opened with write permission.
   1.203 +		@param aFileName The name of the file handle that has  been supplied. This is used by the agent when creating CSupplierOutputFile objects. It should include the full path and filename in order to be consistent with files generated by the agent.
   1.204 +		@return The result of the continuing write operation.
   1.205 +		@return KErrNone if the WriteData() or WriteDataComplete() operation is now complete.
   1.206 +		@return KErrCANewFileHandleRequired if the agent requires a new 
   1.207 +						file handle before proceeding - the agent must save its 
   1.208 +						state and continue processing when the new handle 
   1.209 +						is supplied by ContinueWithNewOutputFile().
   1.210 +		@return Otherwise one of the other CAF error codes defined in \c caferr.h  or one of the 
   1.211 +				other system-wide error codes for any other errors.		
   1.212 +		*/
   1.213 +		IMPORT_C TInt ContinueWithNewOutputFile(RFile& aFile, const TDesC& aFileName);
   1.214 +
   1.215 +		/** Continue the last write operation with a new file handle and return the result asynchronously.
   1.216 +		NB: It is important that the handle passed to aFile and the
   1.217 +		descriptor passed to aFileName remain in scope until the request has completed.	
   1.218 +
   1.219 +		@param aFile  	 A new file handle opened with write permission.
   1.220 +		@param aFileName The name of the file handle that has  been supplied. This is used by the agent when creating CSupplierOutputFile objects. It should include the full path and filename in order to be consistent with files generated by the agent		
   1.221 +		@param aStatus 	 Asynchronous request status. On completion this will 
   1.222 +						 contain one of the following error codes: KErrNone if the 
   1.223 +					 	 WriteData() or WriteDataComplete() operation is now complete.
   1.224 +					 	 KErrCANewFileHandleRequired if the agent requires a new 
   1.225 +						 file handle before proceeding - the agent must save its 
   1.226 +						 state and continue processing when the new handle 
   1.227 +						 is supplied by ContinueWithNewOutputFile(). Otherwise one of the 
   1.228 +						 other CAF error codes defined in \c caferr.h  or one of the 
   1.229 +						 other system-wide error codes for any other errors.		
   1.230 +		*/
   1.231 +		IMPORT_C void ContinueWithNewOutputFile(RFile& aFile, const TDesC& aFileName, TRequestStatus& aStatus);
   1.232 +
   1.233 +		/** Cancel an outstanding asynchronous request to WriteData() or WriteDataComplete().
   1.234 +		*/
   1.235 +		IMPORT_C void Cancel();
   1.236 +		
   1.237 +		/** Retrieve the content MIME type based on available data
   1.238 +
   1.239 +		This function should only be called when the agent has returned KErrCANewFileHandleRequired from
   1.240 +		WriteData() .
   1.241 +		Example of use:
   1.242 +		@code
   1.243 +		while(!endofsource) 
   1.244 +			{
   1.245 +			source.read(data); 
   1.246 +			err = import->WriteData(data); 
   1.247 +
   1.248 +			// When application supplies file handles it must always check to see if 
   1.249 +			// the agent needs a new file handle 
   1.250 +			while(err == KErrCANewFileHandleRequired) 
   1.251 +				{               
   1.252 +				//We need to find out the content MIME type based on available data
   1.253 +				TBuf<KMaxDataTypeLength> contentMime;
   1.254 +				if(import->ContentMimeTypeL(contentMime) == KErrNone)
   1.255 +					{
   1.256 +					//content MIME type is discovered. Now client code could do something
   1.257 +					//to determine the output location and supply the appropriate file handle
   1.258 +					
   1.259 +					
   1.260 +					}
   1.261 +				else
   1.262 +					{
   1.263 +					//content MIME type can't be determined yet. Client should decide the location for
   1.264 +					//output file now,e.g. a default location
   1.265 +
   1.266 +					}
   1.267 +				        
   1.268 +				err = import->ContinueWithNewOutputFile(outputFileHandle, outputFileName); 
   1.269 +				// It is possible that the agent needs yet another file handle 
   1.270 +				outputFileHandle.Close(); // agent makes a copy so we don't need to keep our file handle 
   1.271 +				}
   1.272 +			}
   1.273 +
   1.274 +		@endcode
   1.275 +
   1.276 +		@param aContentMime On return this will contain the appropriate content MIME type.
   1.277 +		@return The result of the request for a content MIME type.
   1.278 +		@return ETrue if the agent populated aContentMime with the correct content MIME type.
   1.279 +		@return EFalse if the agent cannot return the content MIME type (for example, there 
   1.280 +					is not enough data, or the content is multi-part)
   1.281 +		*/
   1.282 +		IMPORT_C TBool ContentMimeTypeL(TDes8& aContentMime); 
   1.283 +		
   1.284 +	private:
   1.285 +		CImportFile();
   1.286 +
   1.287 +		static CImportFile* NewL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aOutputDirectory, const TDesC& aSuggestedFileName);
   1.288 +		void ConstructL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aOutputDirectory, const TDesC& aSuggestedFileName);
   1.289 +		
   1.290 +		static CImportFile* NewL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData);
   1.291 +		void ConstructL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData);
   1.292 +
   1.293 +	private:
   1.294 +		// Agent within CAF used to import the file
   1.295 +		CAgentImportFile* iAgentImportFile;
   1.296 +
   1.297 +		// Agent factory, de-facto ECOM session handle
   1.298 +		CAgentFactory* iAgentFactory;
   1.299 +		};
   1.300 +	}
   1.301 +#endif