os/security/contentmgmt/contentaccessfwfordrm/inc/importfile.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003-2008 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
/** 
sl@0
    21
@file
sl@0
    22
sl@0
    23
@publishedPartner
sl@0
    24
@released
sl@0
    25
*/
sl@0
    26
sl@0
    27
sl@0
    28
#ifndef __IMPORTFILE_H__
sl@0
    29
#define __IMPORTFILE_H__
sl@0
    30
sl@0
    31
#include <e32base.h>
sl@0
    32
#include <f32file.h>
sl@0
    33
#include <caf/caftypes.h>
sl@0
    34
sl@0
    35
namespace ContentAccess
sl@0
    36
	{
sl@0
    37
	class CAgentFactory;
sl@0
    38
	class CSupplierOutputFile;
sl@0
    39
	class CMetaDataArray;
sl@0
    40
	class CAgentSupplier;
sl@0
    41
	class CAgentImportFile;
sl@0
    42
	class CSupplier;
sl@0
    43
	class CAgentInfo;
sl@0
    44
	class CAgentFactory;
sl@0
    45
sl@0
    46
	/**
sl@0
    47
	Created by the CSupplier to import a file. 
sl@0
    48
	
sl@0
    49
	The mime type of the file must be one of the CAF supplier mime types. 
sl@0
    50
	Applications should check using CSupplier::IsImportSupported().
sl@0
    51
	
sl@0
    52
	This class creates a CAgentSupplier and uses it to import the file into the 
sl@0
    53
	content access agent who supports the given mime type.
sl@0
    54
	
sl@0
    55
	This class is single use only and cannot be used to import multiple files. 
sl@0
    56
	The import process may result in one or more output files.
sl@0
    57
	
sl@0
    58
	@publishedPartner
sl@0
    59
	@released	
sl@0
    60
	*/
sl@0
    61
	class CImportFile: public CBase
sl@0
    62
		{
sl@0
    63
		friend class CSupplier;
sl@0
    64
sl@0
    65
	public:
sl@0
    66
		/** Destructor - deleting the CImportFile instance before calling WriteComplete() aborts the import operation 
sl@0
    67
		*/
sl@0
    68
		virtual ~CImportFile();
sl@0
    69
sl@0
    70
		/** Write a block of data from a file to an agent.
sl@0
    71
		
sl@0
    72
		@param aData The block of data.
sl@0
    73
		@return	The result of the write operation.
sl@0
    74
		@return KErrNone if the data was written successfully.
sl@0
    75
		@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().
sl@0
    76
		@return KErrCorrupt if the file does not match the format the agent is expecting.
sl@0
    77
		@return KErrNotReady if the agent was not expecting WriteData() to be called at this point.
sl@0
    78
		@return Otherwise one of the other CAF error codes defined in \c caferr.h  or one of the 
sl@0
    79
				other system-wide error codes for any other errors.
sl@0
    80
		*/
sl@0
    81
		IMPORT_C TInt WriteData(const TDesC8& aData);
sl@0
    82
sl@0
    83
		/** Asynchronously write a block of data from a file to an agent.		 
sl@0
    84
		Notifies the client when the write operation is complete.
sl@0
    85
		NB: It is important that the descriptor passed to 
sl@0
    86
		aData remains in scope until the request has completed.	
sl@0
    87
		
sl@0
    88
		@param aData 	The block of data.	
sl@0
    89
		@param aStatus 	Asynchronous request status. On completion this will 
sl@0
    90
						contain one of the following error codes: KErrNone if the data was written successfully. 
sl@0
    91
						KErrCANewFileHandleRequired if the agent requires a new 
sl@0
    92
						file handle before proceeding - the agent must save its 
sl@0
    93
						state and continue processing when the new handle 
sl@0
    94
						is supplied by ContinueWithNewOutputFile(). KErrCorrupt 
sl@0
    95
						if the file does not match the format the agent is expecting.
sl@0
    96
						KErrNotReady if the agent was not expecting WriteDataComplete() 
sl@0
    97
						to be called at this point. Otherwise one of the other CAF error codes 
sl@0
    98
						defined in \c caferr.h  or one of the other standard system-wide 
sl@0
    99
						error codes for any other errors.
sl@0
   100
		*/
sl@0
   101
		IMPORT_C void WriteData(const TDesC8& aData, TRequestStatus& aStatus);
sl@0
   102
sl@0
   103
		/** Signals to the agent that the entire file has now been transferred to the agent.
sl@0
   104
		
sl@0
   105
		@return The result of the write operation. 
sl@0
   106
		@return KErrNone if the data was written successfully.
sl@0
   107
		@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().
sl@0
   108
		@return KErrCorrupt if the file does not match the format the agent is expecting.
sl@0
   109
		@return KErrNotReady if the agent was not expecting WriteDataComplete() to be called at this point.
sl@0
   110
		@return Otherwise one of the other CAF error codes defined in \c caferr.h  or one of the 
sl@0
   111
				other system-wide error codes for any other errors.		
sl@0
   112
		*/
sl@0
   113
		IMPORT_C TInt WriteDataComplete();
sl@0
   114
sl@0
   115
sl@0
   116
		/** Signals to the agent that the entire file has now been transferred to the agent
sl@0
   117
		
sl@0
   118
		Notifies the client when any final processing operation is complete.
sl@0
   119
		
sl@0
   120
		@param aStatus 	Asynchronous request status. On completion this will 
sl@0
   121
						contain one of the following error codes: KErrNone if the data was written successfully. 
sl@0
   122
						KErrCANewFileHandleRequired if the agent requires a new 
sl@0
   123
						file handle before proceeding - the agent must save its 
sl@0
   124
						state and continue processing when the new handle 
sl@0
   125
						is supplied by ContinueWithNewOutputFile(). KErrCorrupt 
sl@0
   126
						if the file does not match the format the agent is expecting.
sl@0
   127
						KErrNotReady if the agent was not expecting WriteDataComplete() 
sl@0
   128
						to be called at this point. Otherwise one of the other CAF error codes 
sl@0
   129
						defined in \c caferr.h  or one of the other standard system-wide 
sl@0
   130
						error codes for any other errors.
sl@0
   131
		*/
sl@0
   132
		IMPORT_C void WriteDataComplete(TRequestStatus& aStatus);
sl@0
   133
sl@0
   134
		/** Gets the number of output files produced so far. 
sl@0
   135
		@return The number of output files.
sl@0
   136
		*/
sl@0
   137
		IMPORT_C TInt OutputFileCountL() const;
sl@0
   138
sl@0
   139
		/** Return information about an output file generated by the import operation. 
sl@0
   140
		
sl@0
   141
		 It is possible that the output file does not have the same name 
sl@0
   142
		 as the one suggested at the beginning of the import. An agent may
sl@0
   143
		 need to use a particular file extension or a particular name.
sl@0
   144
sl@0
   145
		The agent may decide not to store the output file in the output directory 
sl@0
   146
		suggested at the start of the import. eg. it may store the file in its private 
sl@0
   147
		server directory.
sl@0
   148
sl@0
   149
		The output files may only appear in this array after the WriteDataComplete() 
sl@0
   150
		function has been called. 
sl@0
   151
sl@0
   152
		@param aIndex The zero-based index of the file (must be less than the value returned by OutputFileCountL().
sl@0
   153
		@return The CSupplierOutputFile for this object.
sl@0
   154
		*/
sl@0
   155
		IMPORT_C CSupplierOutputFile& OutputFileL(TInt aIndex) const;
sl@0
   156
sl@0
   157
		/** Retrieve the import status
sl@0
   158
sl@0
   159
		Used to indicate non fatal problems encountered during the import operation.
sl@0
   160
		Provides feedback to the client in case any problems are encountered.
sl@0
   161
sl@0
   162
		The client can then decide whether or not to continue the import.
sl@0
   163
		 
sl@0
   164
		@return	The state of the import operation.
sl@0
   165
		*/
sl@0
   166
		IMPORT_C TImportStatus GetImportStatus() const;
sl@0
   167
sl@0
   168
		/** Get the agents suggestion for the file extension of the output file required by the agent
sl@0
   169
sl@0
   170
		This function should only be called when the agent has returned KErrCANewFileHandleRequired from
sl@0
   171
		WriteData() or WriteDataComplete().
sl@0
   172
sl@0
   173
		The extension must include the dot '.' character.
sl@0
   174
sl@0
   175
		@param aFileExtension On completion this will contain the appropriate file extension.
sl@0
   176
		@return The result of the request for a file extension.
sl@0
   177
		@return KErrNone if the agent populated aFileExtension with the correct file extension.
sl@0
   178
		@return KErrNotReady if the agent is not waiting for another file handle to be provided.
sl@0
   179
		@return KErrUnknown if the agent does not know what extension should be used.
sl@0
   180
		*/
sl@0
   181
		IMPORT_C TInt GetSuggestedOutputFileExtension(TDes& aFileExtension);
sl@0
   182
sl@0
   183
		/** Get the agents suggestion for the file name (with extension) of the output file required by the agent
sl@0
   184
sl@0
   185
		This function should only be called when the agent has returned KErrCANewFileHandleRequired from
sl@0
   186
		WriteData() or WriteDataComplete().
sl@0
   187
sl@0
   188
		The file name is of the form filename.extension.
sl@0
   189
sl@0
   190
		@param aFileName On completion this will contain the appropriate file name.
sl@0
   191
		@return KErrNone if the agent populated aFileName with the correct file name.
sl@0
   192
		@return KErrNotReady if the agent is not waiting for another file handle to be provided.
sl@0
   193
		@return KErrUnknown if the agent does not know what file name should be used.
sl@0
   194
		*/
sl@0
   195
		IMPORT_C TInt GetSuggestedOutputFileName(TDes& aFileName);
sl@0
   196
sl@0
   197
		/** Continue the last write operation with a new file handle as requested by the agent
sl@0
   198
		
sl@0
   199
		@param aFile A new file handle opened with write permission.
sl@0
   200
		@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.
sl@0
   201
		@return The result of the continuing write operation.
sl@0
   202
		@return KErrNone if the WriteData() or WriteDataComplete() operation is now complete.
sl@0
   203
		@return KErrCANewFileHandleRequired if the agent requires a new 
sl@0
   204
						file handle before proceeding - the agent must save its 
sl@0
   205
						state and continue processing when the new handle 
sl@0
   206
						is supplied by ContinueWithNewOutputFile().
sl@0
   207
		@return Otherwise one of the other CAF error codes defined in \c caferr.h  or one of the 
sl@0
   208
				other system-wide error codes for any other errors.		
sl@0
   209
		*/
sl@0
   210
		IMPORT_C TInt ContinueWithNewOutputFile(RFile& aFile, const TDesC& aFileName);
sl@0
   211
sl@0
   212
		/** Continue the last write operation with a new file handle and return the result asynchronously.
sl@0
   213
		NB: It is important that the handle passed to aFile and the
sl@0
   214
		descriptor passed to aFileName remain in scope until the request has completed.	
sl@0
   215
sl@0
   216
		@param aFile  	 A new file handle opened with write permission.
sl@0
   217
		@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		
sl@0
   218
		@param aStatus 	 Asynchronous request status. On completion this will 
sl@0
   219
						 contain one of the following error codes: KErrNone if the 
sl@0
   220
					 	 WriteData() or WriteDataComplete() operation is now complete.
sl@0
   221
					 	 KErrCANewFileHandleRequired if the agent requires a new 
sl@0
   222
						 file handle before proceeding - the agent must save its 
sl@0
   223
						 state and continue processing when the new handle 
sl@0
   224
						 is supplied by ContinueWithNewOutputFile(). Otherwise one of the 
sl@0
   225
						 other CAF error codes defined in \c caferr.h  or one of the 
sl@0
   226
						 other system-wide error codes for any other errors.		
sl@0
   227
		*/
sl@0
   228
		IMPORT_C void ContinueWithNewOutputFile(RFile& aFile, const TDesC& aFileName, TRequestStatus& aStatus);
sl@0
   229
sl@0
   230
		/** Cancel an outstanding asynchronous request to WriteData() or WriteDataComplete().
sl@0
   231
		*/
sl@0
   232
		IMPORT_C void Cancel();
sl@0
   233
		
sl@0
   234
		/** Retrieve the content MIME type based on available data
sl@0
   235
sl@0
   236
		This function should only be called when the agent has returned KErrCANewFileHandleRequired from
sl@0
   237
		WriteData() .
sl@0
   238
		Example of use:
sl@0
   239
		@code
sl@0
   240
		while(!endofsource) 
sl@0
   241
			{
sl@0
   242
			source.read(data); 
sl@0
   243
			err = import->WriteData(data); 
sl@0
   244
sl@0
   245
			// When application supplies file handles it must always check to see if 
sl@0
   246
			// the agent needs a new file handle 
sl@0
   247
			while(err == KErrCANewFileHandleRequired) 
sl@0
   248
				{               
sl@0
   249
				//We need to find out the content MIME type based on available data
sl@0
   250
				TBuf<KMaxDataTypeLength> contentMime;
sl@0
   251
				if(import->ContentMimeTypeL(contentMime) == KErrNone)
sl@0
   252
					{
sl@0
   253
					//content MIME type is discovered. Now client code could do something
sl@0
   254
					//to determine the output location and supply the appropriate file handle
sl@0
   255
					
sl@0
   256
					
sl@0
   257
					}
sl@0
   258
				else
sl@0
   259
					{
sl@0
   260
					//content MIME type can't be determined yet. Client should decide the location for
sl@0
   261
					//output file now,e.g. a default location
sl@0
   262
sl@0
   263
					}
sl@0
   264
				        
sl@0
   265
				err = import->ContinueWithNewOutputFile(outputFileHandle, outputFileName); 
sl@0
   266
				// It is possible that the agent needs yet another file handle 
sl@0
   267
				outputFileHandle.Close(); // agent makes a copy so we don't need to keep our file handle 
sl@0
   268
				}
sl@0
   269
			}
sl@0
   270
sl@0
   271
		@endcode
sl@0
   272
sl@0
   273
		@param aContentMime On return this will contain the appropriate content MIME type.
sl@0
   274
		@return The result of the request for a content MIME type.
sl@0
   275
		@return ETrue if the agent populated aContentMime with the correct content MIME type.
sl@0
   276
		@return EFalse if the agent cannot return the content MIME type (for example, there 
sl@0
   277
					is not enough data, or the content is multi-part)
sl@0
   278
		*/
sl@0
   279
		IMPORT_C TBool ContentMimeTypeL(TDes8& aContentMime); 
sl@0
   280
		
sl@0
   281
	private:
sl@0
   282
		CImportFile();
sl@0
   283
sl@0
   284
		static CImportFile* NewL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aOutputDirectory, const TDesC& aSuggestedFileName);
sl@0
   285
		void ConstructL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aOutputDirectory, const TDesC& aSuggestedFileName);
sl@0
   286
		
sl@0
   287
		static CImportFile* NewL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData);
sl@0
   288
		void ConstructL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData);
sl@0
   289
sl@0
   290
	private:
sl@0
   291
		// Agent within CAF used to import the file
sl@0
   292
		CAgentImportFile* iAgentImportFile;
sl@0
   293
sl@0
   294
		// Agent factory, de-facto ECOM session handle
sl@0
   295
		CAgentFactory* iAgentFactory;
sl@0
   296
		};
sl@0
   297
	}
sl@0
   298
#endif