loadgen/engine/inc/loadgen_httpreceiver.h
changeset 51 b048e15729d6
equal deleted inserted replaced
44:5db69f4c3d06 51:b048e15729d6
       
     1 
       
     2 
       
     3 #ifndef CHTTPReceiver_H
       
     4 #define CHTTPReceiver_H
       
     5 
       
     6 #include <http.h>
       
     7 #include <mhttpdatasupplier.h>
       
     8 #include <mhttptransactioncallback.h>
       
     9 #include <Es_sock.h>
       
    10 #include <chttpformencoder.h> 
       
    11 
       
    12 // CONSTANTS
       
    13 // None.
       
    14 
       
    15 // MACROS
       
    16 #ifdef _DEBUG
       
    17 #define TRACE( text )         RDebug::Printf( text );
       
    18 #define TRACE2( text, arg )   RDebug::Printf( text, arg );
       
    19 #else
       
    20 #define TRACE( text )
       
    21 #define TRACE2( text, arg )
       
    22 #endif
       
    23 
       
    24 // DATA TYPES
       
    25 // None.
       
    26 
       
    27 // FUNCTION PROTOTYPES
       
    28 // None.
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 // None.
       
    32 
       
    33 class MHTTPRecvObserver
       
    34     {
       
    35     public:
       
    36        
       
    37         /**
       
    38         * Callback for HTTP response received.
       
    39         * @param aStatus Status code.
       
    40         * @return None.
       
    41         */
       
    42         virtual void HTTPFileReceived( TInt aStatus ) = 0;        
       
    43     };
       
    44 
       
    45 // CLASS DECLARATION
       
    46 
       
    47 class CHTTPReceiver
       
    48         : public CBase,
       
    49           public MHTTPTransactionCallback
       
    50     {
       
    51     public: // Constructors and destructor
       
    52         
       
    53         /**
       
    54         * Two-phased constructor.
       
    55         */
       
    56         static CHTTPReceiver* NewL( MHTTPRecvObserver& aObserver );
       
    57         
       
    58         /**
       
    59         * Two-phased constructor.
       
    60         */
       
    61         static CHTTPReceiver* NewLC( MHTTPRecvObserver& aObserver );        
       
    62         
       
    63         /**
       
    64         * Destructor.
       
    65         */        
       
    66         virtual ~CHTTPReceiver();
       
    67       
       
    68         /**
       
    69         * Cancels the current HTTP transaction.
       
    70         */   
       
    71         void CancelTransaction();
       
    72 
       
    73         /**
       
    74         * Opens a connection to destination aUri and sends data using HTTP GET. 
       
    75         * Callbacks via MHTTPRecvObserver::HTTPFileReceived
       
    76         * Leaves with KErrNotReady If network is not available
       
    77         * @param aUri Destination URL, if http scheme not specified, prepends scheme.       
       
    78         */                                 
       
    79         void SendHTTPGetL( const TDesC8& aUri );
       
    80         
       
    81     protected: // Constructors and destructor
       
    82 
       
    83         /**
       
    84         * C++ default constructor.
       
    85         */
       
    86         CHTTPReceiver( MHTTPRecvObserver& aObserver );
       
    87 
       
    88         /**
       
    89         * Symbian 2nd phase constructor.
       
    90         */
       
    91         void ConstructL();
       
    92       
       
    93         /**
       
    94         * Sets HTTP header fields.
       
    95         * @param aHeaders HTTP headers.
       
    96         * @param aHdrField Header field to set.
       
    97         * @param aHdrValue Header field value.
       
    98         */   
       
    99         void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
       
   100 						const TDesC8& aHdrValue);
       
   101 
       
   102 		//From MHTTPTransactionCallback
       
   103         /**
       
   104         * Called by HTTP framework when HTTP events occur.
       
   105         * @param aTransaction The transaction that the event has occurred on.
       
   106         * @param aEvent The event that has occurred.
       
   107         */           
       
   108 		void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
       
   109 		
       
   110         /**
       
   111         * Called when RunL leaves from a transaction event.
       
   112         * @param aError The leave code that RunL left with.
       
   113         * @param aTransaction The transaction that was being processed.
       
   114         * @param aEvent The event that was being processed.
       
   115         * @return KErrNone.
       
   116         */   
       
   117 		TInt MHFRunError(	TInt aError,
       
   118 						RHTTPTransaction aTransaction,
       
   119 						const THTTPEvent& aEvent);
       
   120 						
       
   121 		/**
       
   122         * Starts HTTP connection.
       
   123         */   
       
   124        	void SetupConnectionL();
       
   125         
       
   126         /**
       
   127         * Utility:Checks for http uri scheme and prepends if not exists to the url
       
   128         * @param aUri UriParser.
       
   129         * @param aURL URL to check for.
       
   130         * @return None 
       
   131         */
       
   132         void CheckForHTTPSchemeL(TUriParser8& aUri, const TDesC8& aURL);
       
   133 
       
   134         /**
       
   135         * Utility: finish receiving, call calback HTTPFileReceived()
       
   136         * @param aError to be signaled
       
   137         * @return None 
       
   138         */
       
   139         void Finalize();
       
   140         
       
   141     private:
       
   142       	
       
   143         // Request uri, might need to prepend http scheme.
       
   144         HBufC8*					iUrl;
       
   145         
       
   146         // RSocketServ object.
       
   147 	    RSocketServ 			iSocketServ;
       
   148         
       
   149         // RConnection object.
       
   150 	    RConnection 			iConnection;
       
   151 	    
       
   152 	    // HTTP session.
       
   153 		RHTTPSession			iSession;
       
   154 		
       
   155 		// HTTP transaction used for request.
       
   156 		RHTTPTransaction		iTransaction;
       
   157 	
       
   158 		// Observer to notify.
       
   159 		MHTTPRecvObserver&	    iObserver;	
       
   160 
       
   161 		// ETrue if transaction in progress.
       
   162 		TBool					iRunning;	
       
   163 		
       
   164 		// ETrue if connection set up done.
       
   165 		TBool 					iConnectionSetupDone;                        
       
   166 		
       
   167 		// Response Status 
       
   168 		TInt                    iResponseStatus;
       
   169 		
       
   170 #ifdef _DEBUG
       
   171 		// Http response body written to file
       
   172 		RFile 					iResponseFile;
       
   173 		
       
   174 		// RFs to be used for writing to iResponseFile
       
   175 		RFs                     iFs;
       
   176 #endif
       
   177 		
       
   178 };
       
   179     
       
   180 #endif
       
   181 
       
   182 // CHTTPReceiver_H
       
   183 // End of File