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