serviceproviders/sapi_sysinfo/tsrc/dev/servicetests/manual/tsysinfonetworktests/src/tsysinfohomenetworknotify.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 31 Aug 2010 16:06:03 +0300
branchRCL_3
changeset 65 0b68a1b0c15e
parent 58 ea43c23d28d2
child 66 a9c0808a1095
permissions -rw-r--r--
Revision: 201033 Kit: 201035

/*
* Copyright (c) 2002 - 2007 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:   tsysinfohomenetworknotify
*
*/



#include "tsysinfonetworktests.h"
#include "sysinfoservice.h"
#include "entitykeys.h"
#include "tsysinfohomenetworknotify.h"

using namespace SysInfo;

CHomeNetworkNotify* CHomeNetworkNotify::NewL(CStifLogger* aLog)
	{
	CHomeNetworkNotify* self = new(ELeave) CHomeNetworkNotify(aLog);
	self->ConstructL();
	return self;
	}

CHomeNetworkNotify::~CHomeNetworkNotify()
	{
	Cancel();
	
	if(iWaitSchedular->IsStarted())
		iWaitSchedular->AsyncStop();
	
	delete iSysInfoService;
	delete iWaitSchedular;
	delete iTimer;
	}

void CHomeNetworkNotify::ConstructL()
	{
	iSysInfoService = CSysInfoService::NewL();
	iWaitSchedular  = new(ELeave) CActiveSchedulerWait();
	iTimer			= CWatchTimer::NewL(EPriorityNormal,this);
	CActiveScheduler::Add(this);
	}

CHomeNetworkNotify::CHomeNetworkNotify(CStifLogger* aLog)
							 :CActive(EPriorityStandard),
								iLog(aLog)
	{
	}

void CHomeNetworkNotify::DoCancel()
	{
	}

void CHomeNetworkNotify::RunL()
	{
	TestFuncL();
	}

void CHomeNetworkNotify::Start()
	{
	SetActive();
	TRequestStatus* temp = &iStatus;
	User::RequestComplete(temp, KErrNone);
	iWaitSchedular->Start();	
	}

TInt CHomeNetworkNotify::Result()
	{
	return iResult;
	}

void CHomeNetworkNotify::TestFuncL()
	{
	const TTimeIntervalMicroSeconds32 OneMinute(6000000000);
	iTransId = 222;
	TRAPD(err,iSysInfoService->GetNotificationL(KNetwork,KCurrentNetwork,iTransId,this));
	iResult  = err;
	iTimer->After(OneMinute);
	
	if(iResult == KErrNotFound)
		{
		iLog->Log(_L(" KErrNotFound: "));
		iResult =  0;
		iWaitSchedular->AsyncStop();
		}
	else
		{
		iResult =  -1;	
		}
		
	}

void CHomeNetworkNotify::HandleResponseL(const TDesC& /*aEntity*/,const TDesC& /*aKey*/,
	 					CSysData* aOutput, TInt32 aTransID, TSysRequest::TRequestType /*aType*/,TInt aError)
	{
	iResult =KErrGeneral;

	iWaitSchedular->AsyncStop();
	}

void CHomeNetworkNotify::HandleTimeOut()
{
	iLog->Log(_L("TimeOut reached..."));
	iSysInfoService->Cancel(1);
	iResult = FAIL;
	iWaitSchedular->AsyncStop();
}