📄 conn.cpp
字号:
/* Copyright (C) 2006 Lucas Gomez All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// INCLUDE FILES
#include <in_sock.h>
#include "Conn.h"
#include "VncViewer.pan"
#include "VncViewerAppUi.h"
#include "DesktopWindowContainer.h"
#include "LogWriter.h"
//LITERALS
_LIT8(KConnErrorConnecting,"Connecting Error");
_LIT8(KConnErrorReading,"Reading Error");
_LIT8(KConnErrorWriting,"Writing Error");
// CONSTANTS
const TInt KTransferBufLength=8192;
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CConn::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CConn* CConn::NewL(CVncViewerAppUi* aCallback)
{
CConn* self=NewLC(aCallback);
CleanupStack::Pop(self);
return self;
}
// -----------------------------------------------------------------------------
// CConn::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CConn* CConn::NewLC(CVncViewerAppUi* aCallback)
{
CConn* self=new (ELeave) CConn(aCallback);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
// -----------------------------------------------------------------------------
// CConn::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CConn::ConstructL()
{
CConnection::ConstructL();
iVIS=new (ELeave) VncInStream(this);
iVOS= new (ELeave) VncOutStream(this);
SetStreams(iVIS,iVOS);
iCurrentEncoding=EEncodingHextile;
iLastUsedEncoding=EEncodingMax;
iFullColour=EFalse;
iAutoSelect=EFalse;
iShared=EFalse;
iColourLevel=1;
iViewOnly=EFalse;
iAcceptClipboard=EFalse;
iSendClipboard=EFalse;
iFastCopyRect=ETrue;
SetShared(iShared);
AddSecTypeL(ESecTypeNone);
AddSecTypeL(ESecTypeVncAuth);
iModifiersArray=new (ELeave) CArrayFixFlat<TInt>(4);
iCP->SetSupportsDesktopResize(ETrue);
iCP->SetSupportsLocalCursor(ETrue);
iSockServ.Connect();
iSock.Open(iSockServ,KAfInet,KSockStream,KProtocolInetTcp);
iSendBuf=HBufC8::NewL(KTransferBufLength);
iSendBufPtr.Set(iSendBuf->Des());
iRecvBuf=HBufC8::NewL(KTransferBufLength);
iRecvBufPtr.Set(iRecvBuf->Des());
iMutex=new (ELeave) CStack<CActiveSchedulerWait,EFalse>;
CActiveScheduler::Add(this);
}
// -----------------------------------------------------------------------------
// CConn::CConn()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CConn::CConn(CVncViewerAppUi* aCallback) : CActive(EPriorityStandard), iSendBufPtr(NULL,0), iRecvBufPtr(NULL,0)
{
iCallback=aCallback;
iSockState=ESockIdle;
}
// ---------------------------------------------------------------------------
// CConn::~CConn()
// Destructor.
// ---------------------------------------------------------------------------
//
CConn::~CConn()
{
Cancel();
iSock.Close();
iSockServ.Close();
if(iVIS)
{
delete iVIS;
iVIS=NULL;
}
if(iVOS)
{
delete iVOS;
iVOS=NULL;
}
if(iSendBuf)
{
delete iSendBuf;
iSendBuf=NULL;
}
if(iRecvBuf)
{
delete iRecvBuf;
iRecvBuf=NULL;
}
if(iMutex)
{
while(!iMutex->IsEmpty())
{
CActiveSchedulerWait* temp=iMutex->Pop();
if(temp->IsStarted())
temp->AsyncStop();
delete temp;
}
delete iMutex;
iMutex=NULL;
}
if(iServerPF)
{
delete iServerPF;
iServerPF=NULL;
}
if(iModifiersArray);
{
delete iModifiersArray;
iModifiersArray=NULL;
}
}
// The usual active object stuff - every Active Object _must_ implement RunL, DoCancel,
// and a request method of some description
void CConn::RunL()
{
switch(iSockState)
{
case ESockConnecting:
{
iSockState=ESockIdle;
if(iStatus==KErrNone)
{
TBuf<100> temp;
temp.Copy(_L("connected to host "));
temp.Append(iServerName);
CLogWriter::InstanceL()->LogTrace(temp);
InitialiseProtocol();
while(ETrue)
{
ProcessMsg();
}
}
else
{
iCallback->ConnError(KConnErrorConnecting);
}
}
break;
case ESockReading:
{
iSockState=ESockIdle;
if(iStatus==KErrNone)
{
while(!iMutex->IsEmpty())
{
CActiveSchedulerWait* temp=iMutex->Pop();
if(temp->IsStarted())
temp->AsyncStop();
delete temp;
}
}
else
{
iCallback->ConnError(KConnErrorReading);
}
}
break;
case ESockWriting:
{
iSockState=ESockIdle;
if(iStatus==KErrNone)
{
while(!iMutex->IsEmpty())
{
CActiveSchedulerWait* temp=iMutex->Pop();
if(temp->IsStarted())
temp->AsyncStop();
delete temp;
}
}
else
{
iCallback->ConnError(KConnErrorWriting);
}
}
break;
case ESockIdle:
default:
{
}
}
}
void CConn::DoCancel()
{
switch(iSockState)
{
case ESockConnecting:
{
iSock.CancelConnect();
iSockState=ESockIdle;
}
break;
case ESockReading:
{
iSock.CancelRecv();
iSockState=ESockIdle;
while(!iMutex->IsEmpty())
{
CActiveSchedulerWait* temp=iMutex->Pop();
if(temp->IsStarted())
temp->AsyncStop();
delete temp;
}
}
break;
case ESockWriting:
{
iSock.CancelSend();
iSockState=ESockIdle;
while(!iMutex->IsEmpty())
{
CActiveSchedulerWait* temp=iMutex->Pop();
if(temp->IsStarted())
temp->AsyncStop();
delete temp;
}
}
break;
case ESockIdle:
default:
{
}
}
}
void CConn::Init(TInetAddr aHostName,TInt aPort)
{
iInetAddr=aHostName;
iInetAddr.SetPort(aPort);
TBuf<KServerNameLength> serverName;
aHostName.Output(serverName);
serverName.Append(_L("::"));
serverName.AppendNum(aPort);
SetServerName(serverName);
iSockState=ESockConnecting;
iSock.Connect(iInetAddr,iStatus);
SetActive();
}
void CConn::ConnError(const TDesC8& aError)
{
iCallback->ConnError(aError);
}
MSecurity* CConn::GetSecurity(TSecType aSecType)
{
switch(aSecType)
{
case ESecTypeNone:
return new (ELeave) SecurityNone();
case ESecTypeVncAuth:
return new (ELeave) SecurityVncAuth();
default:
User::Leave(EVncViewerUnsupportedSecType);
}
}
void CConn::ServerInit()
{
iRfbState=ERfbStateNormal;
CLogWriter::InstanceL()->LogTrace(_L("initialisation done"));
iServerPF=new (ELeave) CPixelFormat(iCP->GetPF()->GetBpp(),iCP->GetPF()->GetDepth(),iCP->GetPF()->GetBigEndian(),iCP->GetPF()->GetTrueColor(),
iCP->GetPF()->GetRedMax(),iCP->GetPF()->GetGreenMax(),iCP->GetPF()->GetBlueMax(),
iCP->GetPF()->GetRedShift(),iCP->GetPF()->GetGreenShift(),iCP->GetPF()->GetBlueShift());
iFullColourPF=iCallback->GetDesktopWindow()->GetPF();
if(!iServerPF->GetTrueColor())
iFullColour=ETrue;
RecreateViewport();
iFormatChange=iEncodingChange=ETrue;
RequestNewUpdate();
}
void CConn::SetDesktopSize(TInt aW,TInt aH)
{
iCP->SetWidth(aW);
iCP->SetHeight(aH);
if(iCallback->GetDesktopWindow()!=NULL)
{
iCallback->GetDesktopWindow()->Resize();
RecreateViewport();
}
}
void CConn::FramebufferUpdateStart()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -