diff -r 826cea16efd9 -r 13a33d82ad98 videoutils_plat/videoconnutility_api/tsrc/VCXTestCommon/src/TestUtilConnectionWaiter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/videoutils_plat/videoconnutility_api/tsrc/VCXTestCommon/src/TestUtilConnectionWaiter.cpp Wed Sep 01 12:20:37 2010 +0100 @@ -0,0 +1,315 @@ +/* +* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +// INCLUDE FILES + +#include "TestUtilConnectionWaiter.h" +#include "VCXTestLog.h" +#include "MTestUtilConnectionObserver.h" + +const TInt KMillion = 1000000; + +// ========================== MEMBER FUNCTIONS =============================== + +// --------------------------------------------------------------------------- +// CTestUtilConnectionWaiter::NewL() +// +// Constructs CTestUtilConnectionWaiter object +// --------------------------------------------------------------------------- +// +EXPORT_C CTestUtilConnectionWaiter* CTestUtilConnectionWaiter::NewL(MTestUtilConnectionObserver* aObserver) + { + VCXLOGLO1(">>>CTestUtilConnectionWaiter::NewL"); + CTestUtilConnectionWaiter* self = NewLC(aObserver); + CleanupStack::Pop(self); + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::NewLC"); + CTestUtilConnectionWaiter* self = new (ELeave) CTestUtilConnectionWaiter(aObserver); + CleanupStack::PushL(self); + self->ConstructL(); + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::CTestUtilConnectionWaiter"); + + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::~CTestUtilConnectionWaiter"); + + if( IsAdded() ) + { + Deque(); // calls also Cancel() + } + + iServ.Close(); + + iTimer.Close(); + + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::ConstructL"); + + // get connection for the iap + + TInt err = iServ.Connect(); + if(err != KErrNone) + { + VCXLOGLO2("Could not connect to socket server, %d.", err); + User::Leave(err); + } + + User::LeaveIfError(iTimer.CreateLocal()); + + CActiveScheduler::Add(this); + + + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::WaitForConnection"); + + if (!IsActive()) + { + iWaitState = EWaitingConnection; + + iIapId = aIapId; + iTimer.After(iStatus, KMillion); + SetActive(); + iCheckCount = 0; + + VCXLOGLO2(">>>CTestUtilConnectionWaiter:: Waiting until connection is created for Iap: %d", aIapId); + } + else + { + VCXLOGLO1(">>>CTestUtilConnectionWaiter:: error - already ACTIVE"); + } + + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::WaitUntilConnectionIsClosed"); + + if (!IsActive()) + { + iWaitState = EWaitingConnectionClosed; + + iIapId = aIapId; + iTimer.After(iStatus, KMillion); + SetActive(); + iCheckCount = 0; + + VCXLOGLO2(">>>CTestUtilConnectionWaiter:: Waiting until connection closed for Iap: %d", aIapId); + } + else + { + VCXLOGLO1(">>>CTestUtilConnectionWaiter:: error - already ACTIVE"); + } + + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::RunL"); + +// TInt statusCode = iStatus.Int(); + + if( iCheckCount++ == 30 ) + { + VCXLOGLO1("CTestUtilConnectionWaiter:: Connection request timed out."); + iObserver->ConnectionTimeout(); + iCheckCount = 0; + Cancel(); + } + else + { + switch(iWaitState) + { + case EWaitingConnection: + { + if(IsConnectionActive(iIapId)) + { + iObserver->ConnectionCreated(); + iWaitState = ENoWaitState; + VCXLOGLO1("Connection is active!"); + } + else + { + SetActive(); + iTimer.After(iStatus, KMillion); + } + } + break; + + case EWaitingConnectionClosed: + { + if(!IsConnectionActive(iIapId)) + { + iObserver->ConnectionClosed(); + iWaitState = ENoWaitState; + VCXLOGLO1("Connection is closed!"); + } + else + { + SetActive(); + iTimer.After(iStatus, KMillion); + } + } + break; + + default: + break; + } + } + + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::DoCancel"); + iTimer.Cancel(); + VCXLOGLO1("<<>>CTestUtilConnectionWaiter::IsConnectionActive"); + + RConnection connection; + + TUint count; + + TInt err = connection.Open(iServ, KAfInet); + + if(err != KErrNone) + { + iServ.Close(); + VCXLOGLO2("CTestUtilConnectionWaiter::Could not connect to open connection: %d.", err); + User::Leave(err); + } + + err = connection.EnumerateConnections(count); + if(err != KErrNone) + { + connection.Close(); + iServ.Close(); + VCXLOGLO2("CTestUtilConnectionWaiter::Could not enum connections, %d.", err); + User::Leave(err); + } + + for(; count; --count) + { + TPckgBuf connInfo; + + if(connection.GetConnectionInfo(count, connInfo) == KErrNone) + { + VCXLOGLO2("CTestUtilConnectionWaiter:: Connection IAP id: %d", connInfo().iIapId); + + if(aIapId == connInfo().iIapId) + { + VCXLOGLO1("CTestUtilConnectionWaiter:: IAP is connected."); + VCXLOGLO1("<<