applayerprotocols/httpservice/test/httpservicetest/clocaltestserver.cpp
changeset 0 b16258d2340f
child 37 5f1cd966e0d9
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-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 #include <chttptransportlayer.h>
       
    17 
       
    18 #include "clocaltestserver.h"
       
    19 #include "httptestutils.h"
       
    20 #include "mlocaltestserverobserver.h"
       
    21 #include "ctestserverstreammanager.h"
       
    22 #include "chttpclienttestparams.h"
       
    23 
       
    24 const TUint16 KListeningPort = 80;  
       
    25 const TInt KDefaultBufferSize = 16 * 1024;
       
    26 
       
    27 CLocalTestServer* CLocalTestServer::NewL(CHTTPTestUtils& aTestUtils, MLocalTestServerObserver& aObserver, CHttpClientTestParamArray& aTestParamArray)
       
    28 	{
       
    29 	CLocalTestServer* self = new (ELeave) CLocalTestServer(aTestUtils, aObserver, aTestParamArray);
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CLocalTestServer::CLocalTestServer(CHTTPTestUtils& aTestUtils, MLocalTestServerObserver& aObserver, CHttpClientTestParamArray& aTestParamArray)
       
    37 : iTestUtils(aTestUtils), iObserver(aObserver), iTestParamArray(aTestParamArray)
       
    38 	{
       
    39 	}
       
    40 	
       
    41 void CLocalTestServer::ConstructL()
       
    42 	{
       
    43 	_LIT8(KTxtTCP, "TCP");
       
    44 	THttpTransportConstructionParams params(*this); 
       
    45 	iTCPLayer = CHttpTransportLayer::NewL(KTxtTCP(), params);	
       
    46 	}
       
    47 
       
    48 CLocalTestServer::~CLocalTestServer()
       
    49 	{
       
    50 	iStreamManagers.ResetAndDestroy();
       
    51 	iStreamManagers.Close();
       
    52 	StopServer();
       
    53 	delete iTCPLayer;
       
    54 	}
       
    55 
       
    56 void CLocalTestServer::StartServerL()
       
    57 	{
       
    58 	iTCPLayer->ListenL(*this, KListeningPort);
       
    59 	}
       
    60 
       
    61 void CLocalTestServer::StopServer()
       
    62 	{
       
    63 	if( iTCPLayer != NULL )
       
    64 		{
       
    65 		iTCPLayer->StopListen();
       
    66 		}
       
    67 	}
       
    68 
       
    69 void CLocalTestServer::ResetServer()
       
    70 	{
       
    71 	iStreamManagers.ResetAndDestroy();
       
    72 	}
       
    73 	
       
    74 // From MSocketListenObserver
       
    75 void CLocalTestServer::ConnectionReceivedL(MInputStream& aInputStream, MOutputStream& aOutputStream)
       
    76 	{
       
    77 	// New connection received, create a new stream manager to manage the requests and responses
       
    78 /*	const TInt connectionCount = iStreamManager.Count();
       
    79 */	
       
    80 	CLocalTestServerStreamManager* newStreamMgr = CLocalTestServerStreamManager::NewL(iTestUtils, &aInputStream, &aOutputStream, iTestParamArray);
       
    81 	CleanupStack::PushL(newStreamMgr);
       
    82 	User::LeaveIfError(iStreamManagers.Append(newStreamMgr));
       
    83 	CleanupStack::Pop(newStreamMgr);
       
    84 
       
    85 	_LIT(KTxtConnection, "Server - Client connection received and connected.");
       
    86 	iTestUtils.LogIt(KTxtConnection());
       
    87 	}
       
    88 	
       
    89 TInt CLocalTestServer::HandleListenError(TInt aError)
       
    90 	{
       
    91 	_LIT(KTxtListenError, "Server listening error: Error code = %d");
       
    92 	iTestUtils.LogIt(KTxtListenError(), aError);
       
    93 
       
    94 	iObserver.EndTest(aError);
       
    95 	return KErrNone;
       
    96 	}
       
    97 	
       
    98 void CLocalTestServer::MSocketListenObserver_Reserved()
       
    99 	{
       
   100 	}
       
   101 
       
   102 // From MConnectionPrefsProvider
       
   103 TBool CLocalTestServer::SupplyCommsConnection(RConnection*& /* aConnectionPtr */)
       
   104 	{	
       
   105 	return EFalse;
       
   106 	}
       
   107 	
       
   108 
       
   109 void CLocalTestServer::SetCommsConnectionL(RConnection* /* aConnectionPtr */)
       
   110 	{
       
   111 	//do nothing
       
   112 	}
       
   113 	
       
   114 void CLocalTestServer::GetSecurityPrefs(TBool& aDialogPrompt, MSecurityPolicy*& aSecurityPolicy)
       
   115 	{
       
   116 	aDialogPrompt = EFalse;
       
   117 	aSecurityPolicy = NULL;
       
   118 	}
       
   119 
       
   120 TBool CLocalTestServer::ImmediateSocketShutdown()
       
   121 	{
       
   122 	return EFalse;
       
   123 	}
       
   124 
       
   125 TInt CLocalTestServer::SessionId()
       
   126 	{
       
   127 	return KErrNotSupported;
       
   128 	}
       
   129 
       
   130 TBool CLocalTestServer::SupplySocketServerHandle ( TInt& aSocketServerHandle )
       
   131   	{
       
   132   	aSocketServerHandle = 0;
       
   133   	return EFalse;
       
   134   	}
       
   135   	
       
   136 void CLocalTestServer::SetSocketServerHandleL ( TInt /*aSocketServerHandle*/ )	
       
   137   	{	
       
   138   	// do nothing
       
   139   	}
       
   140 
       
   141 TInt CLocalTestServer::GetRecvBufferSize()
       
   142 	{
       
   143 	return KDefaultBufferSize;
       
   144 	}
       
   145