servicediscoveryandcontrol/pnp/test/upnp/Server/Flow/inc/httpserverhandler.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 2008-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 __HTTPSERVERHANDLER_H_
       
    17 #define __HTTPSERVERHANDLER_H_
       
    18 
       
    19 #include "ctransaction.h"
       
    20 #include "cprotocolhandler.h"
       
    21 #include "cupnprequestparser.h"
       
    22 #include "cupnpresponsecomposer.h"
       
    23 #include "cupnptimer.h"
       
    24 
       
    25 #include <rmemchunk.h>
       
    26 
       
    27 NONSHARABLE_CLASS(CServerTransaction) : public CTransaction
       
    28 	{
       
    29 	public:
       
    30 	static CServerTransaction* NewL ( CHeaderCodec& aCodec, RStringPool& aStringPool, MHttpEventObserver& aObserver )
       
    31 		{
       
    32 		CServerTransaction* self = new ( ELeave )CServerTransaction	( aObserver );
       
    33 		CleanupStack::PushL ( self );
       
    34 		self->ConstructL ( aCodec, aStringPool );
       
    35 		CleanupStack::Pop (); // self
       
    36 		return self;
       
    37 		}
       
    38 
       
    39 	inline MHttpEventObserver& ServerObserver () const
       
    40 		{
       
    41 		return *iServerObserver;
       
    42 		}
       
    43 
       
    44 	inline void SetReadyToSend ()
       
    45 		{
       
    46 		iReadyToSend = ETrue;
       
    47 		}
       
    48 
       
    49 	inline TBool ReadyToSend () const
       
    50 		{
       
    51 		return iReadyToSend;
       
    52 		}
       
    53 
       
    54 	inline void SetClosing ()
       
    55 		{
       
    56 		iCloseConnection = ETrue;
       
    57 		}
       
    58 
       
    59 	inline TBool IsClosing () const
       
    60 		{
       
    61 		return iCloseConnection;
       
    62 		}
       
    63 
       
    64 	inline void SetParsing  ( TBool aValue )
       
    65 		{
       
    66 		iParsing = aValue;
       
    67 		}
       
    68 
       
    69 	inline TBool Parsing () const
       
    70 		{
       
    71 		return iParsing;
       
    72 		}
       
    73 
       
    74 	inline void SetComposing ( TBool aValue )
       
    75 		{
       
    76 		iComposing = aValue;
       
    77 		}
       
    78 
       
    79 	inline TBool Composing () const
       
    80 		{
       
    81 		return iComposing;
       
    82 		}
       
    83 
       
    84 	private:
       
    85 	CServerTransaction ( MHttpEventObserver& aObserver )
       
    86 	: iServerObserver ( &aObserver )
       
    87 		{
       
    88 		}
       
    89 
       
    90 	private:
       
    91 		TBool					iReadyToSend : 1;
       
    92 		TBool					iCloseConnection : 1;
       
    93 		TBool					iComposing : 1;
       
    94 		TBool					iParsing : 1;
       
    95 		MHttpEventObserver*		iServerObserver;
       
    96 	};
       
    97 
       
    98 class CServiceInfoArray;
       
    99 class CHttpServerHandler;
       
   100 
       
   101 typedef RPointerArray < CHttpServerHandler > CServerHandlerArray;
       
   102 
       
   103 NONSHARABLE_CLASS(CHttpServerHandler) : public CProtocolHandler,
       
   104 										public MHttpEventObserver
       
   105 	{
       
   106 	public:
       
   107 
       
   108 	static CHttpServerHandler* NewL ( RInternalSocket& aSocket, RMemChunk& aData, CServiceInfoArray& aServiceInfos, CServerHandlerArray& aServerHandlers,
       
   109 									CHeaderCodec& aCodec, RStringPool& aStringPool, CChunkManager* aChunkMgr );
       
   110 	virtual ~CHttpServerHandler ();
       
   111 
       
   112 
       
   113 	static void CreateResponse ( CResponse& aResponse, TInt aStatusCode, MHttpEventObserver* aServerHandler = NULL );
       
   114 	static void CreateResponseL ( CResponse& aResponse, TInt aStatusCode );
       
   115 
       
   116 	private:
       
   117 	CHttpServerHandler ( RInternalSocket& aSocket, RMemChunk& aData, CServiceInfoArray& aServiceInfos, CServerHandlerArray& aServerHandlers,
       
   118 	CHeaderCodec& aCodec, RStringPool& aStringPool, CChunkManager* aChunkMgr );
       
   119 	void ConstructL ();
       
   120 
       
   121 	// From MParserObserver
       
   122 	virtual void GotHeaders ();
       
   123 	virtual void GotBodyData ();
       
   124 	virtual void DataParsed ();
       
   125 	virtual void ParsingComplete ( RMemChunk& aExcessData );
       
   126 	virtual void ParserError ( TInt aError );
       
   127 
       
   128 	// From MComposerObserver
       
   129 	virtual void MessageDataReadyL ( RBuf8& aData );
       
   130 	virtual void ComposingConcluded ();
       
   131 	virtual void ComposerError ( TInt aError );
       
   132 
       
   133 	// From MSocketHandlerObserver
       
   134 	inline virtual void OpenComplete ( RInternalSocket& aSocket );
       
   135 	inline virtual void ConnectComplete ();
       
   136 	virtual void SendComplete ( TInt aLength );
       
   137 	virtual void RecvComplete ( RMBufChain& aData );
       
   138 	virtual void Error ( TOperation aOperation, TInt aError  );
       
   139 
       
   140 	// From MHttpEventObserver
       
   141 	virtual TInt OnHttpEvent ( CTransaction* aTransaction, THTTPEvent& aEvent );
       
   142 
       
   143 	// methods from MHTTPDataSupplier
       
   144 	TBool GetNextDataPart ( TPtrC8& aDataPart );
       
   145 	void ReleaseData ();
       
   146 	TInt OverallDataSize ();
       
   147 
       
   148 	// From MUPnPTimerObserver	
       
   149 	virtual void TimeOut ();
       
   150 
       
   151 	CServerTransaction& CurrentTransaction () const;
       
   152 	CServerTransaction& LastTransaction () const;
       
   153 	void NotifyEvent ( THTTPEvent& aEvent );
       
   154 	TBool CanDestroy () const;
       
   155 	void DestroySelf ();
       
   156 
       
   157 	void StartNewTransactionL ();
       
   158 	void StartNewTransaction ();
       
   159 	void DeleteTransaction ( CTransaction* aTrans );
       
   160 
       
   161 	void SetError ( TInt aError );
       
   162 	TBool Error () const;
       
   163 
       
   164 	private:
       
   165 		RMemChunk 				iReceivedData;
       
   166 		RMemoryAllocator		iAllocator;
       
   167 		CServiceInfoArray&		iServiceInfos;   // Not owned.
       
   168 		CServerHandlerArray&	iServerHandlers; // Not owned
       
   169 		CUpnpRequestParser* 	iRequestParser;
       
   170 		CUpnpResponseComposer* 	iResponseComposer;		
       
   171 		TInt 					iError;
       
   172 
       
   173 		CHeaderCodec& 			iServerCodec; // Not owned
       
   174 		RStringPool& 			iStringPool; // Not owned
       
   175 	};
       
   176 
       
   177 // From MSocketHandlerObserver
       
   178 void CHttpServerHandler::OpenComplete ( RInternalSocket& /* aSocket */ )
       
   179 {
       
   180 // We don't handle this. Assert here
       
   181 }
       
   182 
       
   183 void CHttpServerHandler::ConnectComplete ()
       
   184 {
       
   185 // We don't handle this. Assert here
       
   186 
       
   187 }
       
   188 
       
   189 
       
   190 #endif // __HTTPSERVERHANDLER_H__