📄 msgreader.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 "MsgReader.h"
#include "VncViewer.pan"
#include "MsgWriter.h"
#include "LogWriter.h"
//LITERALS
//CONSTANTS
const TInt KNameLength=50;
// ============================ MEMBER FUNCTIONS ===============================
CMsgReader::CMsgReader(CMsgHandler* aHandler,InStream* aIS)
{
iHandler=aHandler;
iIS=aIS;
iImageBufSize=0;
for(TInt i=0;i<static_cast<TInt>(EEncodingMax)+1;i++)
{
iDecoders.Append(NULL);
}
}
// ---------------------------------------------------------------------------
// CMsgReader::~CMsgReader()
// Destructor.
// ---------------------------------------------------------------------------
//
CMsgReader::~CMsgReader()
{
iImageBuf.Close();
for(TInt i=0;i<iDecoders.Count();i++)
{
if(iDecoders[i])
{
delete iDecoders[i];
iDecoders[i]=NULL;
}
}
iDecoders.Close();
}
void CMsgReader::GetImageBuf(TInt aRequired,TInt aRequested,RBuf8& aBuf)
{
TInt requiredBytes=aRequired*(iHandler->GetCP()->GetPF()->GetBpp()/8);
TInt requestedBytes=aRequested*(iHandler->GetCP()->GetPF()->GetBpp()/8);
TInt size=requestedBytes;
if(size>iImageBufIdealSize) size=iImageBufIdealSize;
if(size<requiredBytes)
size=requiredBytes;
if(iImageBufSize<size)
{
iImageBufSize=size;
iImageBuf.Close();
iImageBuf.CreateMaxL(iImageBufSize);
}
aBuf.CreateL(iImageBuf,iImageBuf.MaxLength());
}
void CMsgReader::ReadSetColourMapEntries()
{
iIS->Skip(1);
TInt firstColour=iIS->ReadU16();
TInt nColours=iIS->ReadU16();
RArray<TInt> rgbs;
for(TInt i=0;i<nColours*3;i++)
rgbs.Append(iIS->ReadU16());
EndMsg();
iHandler->SetColourMapEntries(firstColour,nColours,rgbs);
rgbs.Close();
}
void CMsgReader::ReadBell()
{
EndMsg();
iHandler->Bell();
}
void CMsgReader::ReadServerCutText()
{
iIS->Skip(3);
TInt len=iIS->ReadU32();
if(len>256*1024)
{
iIS->Skip(len);
CLogWriter::InstanceL()->LogTrace(_L("cut text too long - ignoring"));
return;
}
RBuf8 buf;
buf.CreateMaxL(len);
iIS->ReadBytes(buf,0,len);
EndMsg();
HBufC* temp=HBufC::NewL(len);
TPtr tempPtr(temp->Des());
tempPtr.Copy(buf);
iHandler->ServerCutText(tempPtr);
delete temp;
}
void CMsgReader::EndMsg()
{
}
void CMsgReader::ReadFramebufferUpdateStart()
{
EndMsg();
iHandler->FramebufferUpdateStart();
}
void CMsgReader::ReadFramebufferUpdateEnd()
{
EndMsg();
iHandler->FramebufferUpdateEnd();
}
void CMsgReader::ReadRect(TInt aX,TInt aY,TInt aW,TInt aH,TEncodings aEncoding)
{
if((aX+aW>iHandler->GetCP()->GetWidth()) || (aY+aH>iHandler->GetCP()->GetHeight()))
{
CLogWriter::InstanceL()->LogTrace(_L("Rect too big"));
User::Leave(EVncViewerRectTooBig);
}
if(aW*aH==0)
{
CLogWriter::InstanceL()->LogTrace(_L("Ignoring zero size rect"));
return;
}
iHandler->BeginRect(aX,aY,aW,aH,aEncoding);
if(aEncoding==EEncodingCopyRect)
{
ReadCopyRect(aX,aY,aW,aH);
}
else
{
if(iDecoders[aEncoding]==NULL)
{
iDecoders[aEncoding]=MDecoder::CreateDecoder(aEncoding,this);
if(iDecoders[aEncoding]==NULL)
{
CLogWriter::InstanceL()->LogTrace(_L("Unknown rect encoding"));
User::Leave(EVncViewerUnknownRectEncoding);
}
}
iDecoders[aEncoding]->ReadRect(aX,aY,aW,aH,iHandler);
}
iHandler->EndRect(aX,aY,aW,aH,aEncoding);
}
void CMsgReader::ReadCopyRect(TInt aX,TInt aY,TInt aW,TInt aH)
{
TInt srcX=iIS->ReadU16();
TInt srcY=iIS->ReadU16();
iHandler->CopyRect(aX,aY,aW,aH,srcX,srcY);
}
void CMsgReader::ReadSetCursor(TInt aHotspotX,TInt aHotspotY,TInt aW,TInt aH)
{
TInt data_len=aW*aH*(iHandler->GetCP()->GetPF()->GetBpp()/8);
TInt mask_len=((aW+7)/8)*aH;
RBuf8 data;
data.CreateMaxL(data_len);
RBuf8 mask;
mask.CreateMaxL(mask_len);
iIS->ReadBytes(data,0,data_len);
iIS->ReadBytes(mask,0,mask_len);
iHandler->SetCursor(aHotspotX,aHotspotY,aW,aH,data,mask);
data.Close();
mask.Close();
}
CMsgReaderV3::~CMsgReaderV3()
{
}
CMsgReaderV3::CMsgReaderV3(CMsgHandler* aHandler,InStream* aIS) : CMsgReader(aHandler,aIS)
{
iNUpdateRectsLeft=0;
}
void CMsgReaderV3::ReadServerInit()
{
CLogWriter::InstanceL()->LogTrace(_L("reading server init"));
TInt width=iIS->ReadU16();
TInt height=iIS->ReadU16();
iHandler->SetDesktopSize(width, height);
CPixelFormat* pf=new CPixelFormat();
pf->Read(iIS);
iHandler->SetPixelFormat(pf);
TBuf8<KNameLength> name;
iIS->ReadString(name);
iHandler->SetName(name);
EndMsg();
iHandler->ServerInit();
}
void CMsgReaderV3::ReadMsg()
{
CLogWriter::InstanceL()->LogTrace(_L("reading message"));
if(iNUpdateRectsLeft==0)
{
TInt type=iIS->ReadU8();
switch(type)
{
case MsgType::KFramebufferUpdate: ReadFramebufferUpdate(); break;
case MsgType::KSetColourMapEntries: ReadSetColourMapEntries(); break;
case MsgType::KBell: ReadBell(); break;
case MsgType::KServerCutText: ReadServerCutText(); break;
default:
User::Leave(EVncViewerUnknownMsgType);
CLogWriter::InstanceL()->LogTrace(_L("unknown message type"));
}
}
else
{
TInt x=iIS->ReadU16();
TInt y=iIS->ReadU16();
TInt w=iIS->ReadU16();
TInt h=iIS->ReadU16();
TEncodings encoding=static_cast<TEncodings>(iIS->ReadU32());
switch(encoding)
{
case EEncodingPseudoEncodingDesktopSize:
iHandler->SetDesktopSize(w,h);
break;
case EEncodingPseudoEncodingCursor:
ReadSetCursor(x,y,w,h);
break;
default:
ReadRect(x,y,w,h,encoding);
break;
}
iNUpdateRectsLeft--;
if(iNUpdateRectsLeft==0) iHandler->FramebufferUpdateEnd();
}
}
void CMsgReaderV3::ReadFramebufferUpdate()
{
iIS->Skip(1);
iNUpdateRectsLeft=iIS->ReadU16();
EndMsg();
iHandler->FramebufferUpdateStart();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -