applayerprotocols/httptransportfw/Test/t_httptransporthandler/ctestsocketreader.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 __CTESTSOCKETREADER_H__
       
    17 #define __CTESTSOCKETREADER_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <minputstreamobserver.h>
       
    21 
       
    22 class MInputStream;
       
    23 class MTestReaderObserver;
       
    24 
       
    25 /**	@class		CTestSocketReader
       
    26 	The CTestSocketReader class encapsulates the input stream of a connected 
       
    27 	socket. The state machine is initially in the Idle state. When data is 
       
    28 	expected to be received, the observer passes the expected data using the 
       
    29 	ExpectData() API. The descriptor buffer passed in must remain valid until 
       
    30 	the test socket reader termibates.
       
    31 
       
    32 	The ExpectData() API binds the test socket reader to the input stream. The
       
    33 	state changes to PendingReceivedData and the test socket reader waits for 
       
    34 	the input strean to notify it that data has been received.
       
    35 
       
    36 	The input stream uses the MInputStreamObserver::ReceivedDataInd() API to 
       
    37 	notify the test socket reader that data has been received. The test socket
       
    38 	reader verifies that the received data is part of the expected data. If so
       
    39 	that part is removed from the expected data. The test socket reader moves 
       
    40 	to the ReceiveAck state and self-completes. If the received data was not 
       
    41 	part of the expected data or if there was extra data in the received buffer
       
    42 	then a panic occurs.
       
    43 
       
    44 	In the ReceiveAck state the test socket reader notifies the input stream 
       
    45 	that it has finished with the received buffer. If all the expected data has
       
    46 	been received then the test socket reader moves to the Idle state. If more 
       
    47 	data is expected the test socket reader moves to the PendingReceivedData.
       
    48 
       
    49 	The test socket reader observer can request that the input stream be closed
       
    50 	using the CloseReader() API. The test socket reader must be in the Idle 
       
    51 	state or else there will be a panic. The state changes to Closing and the 
       
    52 	test socket reader self-completes.
       
    53 
       
    54 	In the Closing state the test socket reader requests that the input stream
       
    55 	close asynchronously. The test socket reader moves to the PendingClosed 
       
    56 	state and waits to be notified that the input stream is closed.
       
    57 	
       
    58 	Once the stream has closed, the test socket reader is notified via the 
       
    59 	MInputStreamObserver::InputStreamCloseInd() API. The test socket reader 
       
    60 	moves to the Closed state.
       
    61 
       
    62 	If the input stream is closed, either because the corresponding output 
       
    63 	stream has been closed, the remote host has closed the socket or there has
       
    64 	been a socket error, the test socket reader is notified via the 
       
    65 	MInputStreamObserver::InputStreamCloseInd() API.
       
    66 	@componentInternal		
       
    67 */
       
    68 class CTestSocketReader : public CActive,
       
    69 						  public MInputStreamObserver
       
    70 	{
       
    71 public:	// methods
       
    72 
       
    73 	static CTestSocketReader* NewL(MTestReaderObserver& aObserver, MInputStream& aInputStream, TBool aSecure);
       
    74 
       
    75 	virtual ~CTestSocketReader();
       
    76 
       
    77 	void ExpectData(const TDesC8& aData);
       
    78 
       
    79 	void CloseReader();
       
    80 
       
    81 private:	// methods from MInputStreamObserver
       
    82 
       
    83 	virtual void ReceivedDataIndL(const TDesC8& aBuffer);
       
    84 	
       
    85 	virtual void InputStreamCloseInd(TInt aError);
       
    86 
       
    87 	virtual void SecureServerCnf();
       
    88 
       
    89 	virtual void MInputStreamObserver_Reserved();
       
    90 	
       
    91 	MHttpResponse* CurrentResponse();
       
    92     
       
    93     virtual void OnReceiveTimeOut(); 
       
    94 	
       
    95 private:	// methods from CActive
       
    96 
       
    97 	virtual void RunL();
       
    98 
       
    99 	virtual void DoCancel();
       
   100 
       
   101 	virtual TInt RunError(TInt aError);
       
   102 
       
   103 private:	// methods
       
   104 
       
   105 	CTestSocketReader(MTestReaderObserver& aObserver, MInputStream& aInputStream, TBool aSecure);
       
   106 
       
   107 	TInt UpdateData(const TDesC8& aReceivedData, TPtrC8& aExcessData);
       
   108 
       
   109 	TInt CheckResponseStatusL(const TDesC8& aReceivedData);
       
   110 
       
   111 	void CompleteSelf();
       
   112 
       
   113 private:	// enums
       
   114 
       
   115 /**	@enum		TReaderState
       
   116 	The test socket reader state machine.
       
   117 	@componentInternal		
       
   118 */
       
   119 	enum TReaderState
       
   120 		{
       
   121 		/**	The test socket reader is idle.
       
   122 		*/
       
   123 		EIdle					=0,
       
   124 		/**	The test socket reader is expecting to receive more data.
       
   125 		*/
       
   126 		EPendingReceivedData,
       
   127 		/**	The test socket reader needs to acknowledge the received data packet.
       
   128 		*/
       
   129 		EReceiveAck,
       
   130 		/** The test socket reader observer has requested that the test socket reader 
       
   131 			close the input stream.
       
   132 		*/
       
   133 		EClosing,
       
   134 		/**	The test socket reader is waiting for the input stream to notify it that
       
   135 			it has closed.
       
   136 		*/
       
   137 		EPendingClosed,
       
   138 		/**	The test socket reader is closed - no more data can be received.
       
   139 		*/
       
   140 		EClosed
       
   141 		};
       
   142 
       
   143 private:	// attributes
       
   144 
       
   145 	MTestReaderObserver&	iObserver;
       
   146 	MInputStream*			iInputStream;
       
   147 	TReaderState			iState;
       
   148 	TBool					iBoundToInputStream;
       
   149 	TPtrC8					iExpectedData;
       
   150 	TPtrC8					iReceivedBuffer;
       
   151 	TBool					iSecure;
       
   152 	TBool					iSecureTestPassed;
       
   153 	};
       
   154 
       
   155 #endif	// __CTESTSOCKETREADER_H__