applayerprotocols/httptransportfw/Test/T_WspProtHnd/CWspFileDataSupplier.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CWSPFILEDATASUPPLIER_H__
       
    17 #define __CWSPFILEDATASUPPLIER_H__
       
    18 
       
    19 // System includes
       
    20 #include <f32file.h>
       
    21 #include <http/mhttpdatasupplier.h>
       
    22 
       
    23 
       
    24 /** Definition of class 'CWspFileDataSupplier'.
       
    25 */
       
    26 class CWspFileDataSupplier : public CBase, public MHTTPDataSupplier
       
    27 	{
       
    28 public: // methods
       
    29 
       
    30 	/** Factory construction: create an uninitialised data supplier
       
    31 	*/
       
    32 	static CWspFileDataSupplier* NewL();
       
    33 
       
    34 	/** Factory construction: create a data supplier, to read from the specified file
       
    35 	*/
       
    36 	static CWspFileDataSupplier* NewL(const TDesC& aFileName);
       
    37 
       
    38 	/** Destructor
       
    39 	*/
       
    40 	virtual ~CWspFileDataSupplier();
       
    41 
       
    42 	/** Clean-up support required by the client's item store
       
    43 	*/
       
    44 	static void CleanUp(TAny* aDataSupplierItem);
       
    45 
       
    46 	/** Open the specified file.  Must be called straight after construction.  If a
       
    47 		previous file was open, it is closed first.
       
    48 	*/
       
    49 	void SetFileL(const TDesC& aFileName);
       
    50 
       
    51 	/** Get the next data part. The supplied buffer is set to point at the data.  The returned flag indicates ETrue if no more
       
    52 		data is to come, ie. aDataPart is the final buffer.
       
    53 	*/
       
    54 	virtual TBool GetNextDataPart(TPtrC8& aDataPart);
       
    55 
       
    56 	/** Release the current data part being held at the data
       
    57 		supplier.  This call indicates to the supplier that the part
       
    58 		is no longer needed, and another one can be supplied, if
       
    59 		appropriate.
       
    60 	*/
       
    61 	virtual void ReleaseData();
       
    62 
       
    63 	/** Obtain the overall size of the data being supplied, if known
       
    64 		to the supplier.  Where a body of data is supplied in several
       
    65 		parts this size will be the sum of all the part sizes. If
       
    66 		the size is not known, KErrNotFound is returned; in this case
       
    67 		the client must use the return code of GetNextDataPart to find
       
    68 		out when the data is complete.
       
    69 
       
    70 		@return A size in bytes, or KErrNotFound if the size is not known.  */
       
    71 	virtual TInt OverallDataSize();
       
    72 
       
    73 	/** Reset the data supplier.  This indicates to the data supplier that it should
       
    74 		return to the first part of the data.  This could be used in a situation where
       
    75 		the data consumer has encountered an error and needs the data to be supplied
       
    76 		afresh.  Even if the last part has been supplied (i.e. GetNextDataPart has
       
    77 		returned ETrue), the data supplier should reset to the first part.
       
    78 	
       
    79 		If the supplier cannot reset it should return an error code; otherwise it should
       
    80 		return KErrNone, where the reset will be assumed to have succeeded*/
       
    81 	virtual TInt Reset();
       
    82 
       
    83 private:
       
    84 
       
    85 	/** Normal constructor
       
    86 	*/
       
    87 	CWspFileDataSupplier();
       
    88 
       
    89 	/** Second phase construction, default.
       
    90 	*/
       
    91 	void ConstructL();
       
    92 
       
    93 	/** Second phase construction, opens the named file
       
    94 	*/
       
    95 	void ConstructL(const TDesC& aFileName);
       
    96 
       
    97 private:
       
    98 
       
    99 	/** A buffer used to hold the data specified in the script, which is copied to the invoker of this API
       
   100 	*/
       
   101 	HBufC8* iBuffer;
       
   102 
       
   103 	/** Handle to the file server
       
   104 	*/
       
   105 	RFs iFileSrvHnd;
       
   106 
       
   107 	/** Parsed version of the filename to be read
       
   108 	*/
       
   109 	TParse iParsedFileName;
       
   110 
       
   111 	/** Handle to the file being supplied by this data supplier
       
   112 	*/
       
   113 	RFile iFileHnd;
       
   114 
       
   115 	/** Flag that indicates whether a file is currently open
       
   116 	*/
       
   117 	TBool iFileOpen;
       
   118 	};
       
   119 
       
   120 
       
   121 #endif // __CWSPFILEDATASUPPLIER_H__