diff -r 000000000000 -r c6b0df440bee dbgagents/trkagent/engine/TrkSocketCommPort.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbgagents/trkagent/engine/TrkSocketCommPort.cpp Tue Mar 02 10:33:16 2010 +0530 @@ -0,0 +1,190 @@ +/* +* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "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 "TrkSocketCommPort.h" +#include "TrkFramingLayer.h" +#include "TrkEngine.h" +#include + + +CTrkSocketCommPort::CTrkSocketCommPort() + : CTrkCommPort(CActive::EPriorityStandard), + iConnected(EFalse) +{ +} + +void CTrkSocketCommPort::ConstructL(const TDesC &/*aInitFilePath*/, TDes& /*aErrorMessage*/) +{ + CActiveScheduler::Add(this); +} + +void CTrkSocketCommPort::IssueReadRequest() +{ + iNextReadChar = 0; + TSockXfrLength len; + iSocket.RecvOneOrMore(iReceivedChars, 0, iStatus, len); + + SetActive(); +} + +void CTrkSocketCommPort::DoCancel() +{ + iSocket.CancelRead(); +} + +void CTrkSocketCommPort::RunL() +{ + if (iStatus.Int() == KErrNone) + while (iNextReadChar < iReceivedChars.Length()) + iFramingLayer->HandleByte(iReceivedChars[iNextReadChar++]); + + IssueReadRequest(); +} + + +CTrkSocketCommPort::~CTrkSocketCommPort() +{ + Cancel(); +// iSocket.Close(); + iConnected = EFalse; + iSocketServ.Close(); +} + + +CTrkSocketCommPort* CTrkSocketCommPort::NewL(const TDesC& aInitFilePath, TDes& aErrorMessage) +{ + CTrkSocketCommPort* self = new(ELeave) CTrkSocketCommPort; + CleanupStack::PushL(self); + self->ConstructL(aInitFilePath, aErrorMessage); + CleanupStack::Pop(self); + return self; +} + + +void CTrkSocketCommPort::OpenPortL() +{ + TInt error = KErrNone; + + error = iSocketServ.Connect(); + if (error != KErrNone) + User::Leave(100); + + error = iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp); + if (error != KErrNone) + User::Leave(101); + + TUint protocols = 0; + + error = iSocketServ.NumProtocols(protocols); + + TProtocolDesc desc; + + for (TUint i=0; i