?? controller.cpp
字號:
// controller.cpp
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
//
#include "controller.h"
#include "appview.h"
#include "gdp.h"
#include <utf.h>
#include <eikenv.h>
#include <eiklabel.h>
enum TPanic {
ESetupMeNotBlank,
EInitiateNotBlank,
EListenNotBlank,
EReceiveWhenBlank,
ESendNotBound,
};
static void Panic(TInt aPanic)
{
_LIT(KPanicCategory,"RGCPCHAT control");
User::Panic(KPanicCategory, aPanic);
}
// Controller
void CGameController::ConstructL(CGameEngine* aEngine, CRgcpSession* aRgcp, CEikAppUi* aAppUi)
{
// store cached pointers
iEngine=aEngine;
iRgcp=aRgcp;
iAppUi=aAppUi;
iEnv=CEikonEnv::Static();
// say we're the RGCP handler
iRgcp->SetHandler(this);
// construct app view
iAppView=new(ELeave) CGameAppView;
iAppView->ConstructL(iEngine, iAppUi->ClientRect());
iAppUi->AddToStackL(iAppView);
}
CGameController::~CGameController()
{
iAppUi->RemoveFromStack(iAppView);
delete iAppView;
}
// session control
void CGameController::Reset() // set to blank, loopback, my-address from document
{
if (iRgcp->IsBlank())
return;
iEngine->Reset();
iRgcp->Terminate();
iRgcp->SetGdpProtocolL(KGdpLoopbackUid);
SetEngineL(iEngine);
}
void CGameController::SetupMeL(TUid aProtocol)
{
__ASSERT_ALWAYS(iRgcp->IsBlank(), Panic(ESetupMeNotBlank));
iRgcp->SetGdpProtocolL(aProtocol);
}
// The underlying protocol uses 8 bit descriptors. We exchange ascii text messages
// and ascii text network addresses, so we use a simple scheme to convert between the
// two sizes. Within the app & engine we keep cached copies of info in the native size
HBufC16* NewHBufC16LC(const TDesC8& aDataBuffer)
{
HBufC16* buffer = HBufC16::NewLC(aDataBuffer.Length());
TPtr16 buffer_ptr(buffer->Des());
buffer_ptr.Copy(aDataBuffer);
return buffer;
}
HBufC8* NewHBufC8LC(const TDesC16& aDataBuffer)
{
HBufC8* buffer = HBufC8::NewLC(aDataBuffer.Length());
TPtr8 buffer_ptr(buffer->Des());
buffer_ptr.Copy(aDataBuffer);
return buffer;
}
void CGameController::InitiateL(const TDesC& aOtherAddress)
{
__ASSERT_ALWAYS(iRgcp->IsBlank(), Panic(EInitiateNotBlank));
HBufC8* addr8 = NewHBufC8LC(aOtherAddress);
iRgcp->Initiate(*addr8);
CleanupStack::PopAndDestroy();
}
void CGameController::Listen()
{
__ASSERT_ALWAYS(iRgcp->IsBlank(), Panic(EListenNotBlank));
iRgcp->Listen();
}
void CGameController::GetOtherAddress(TDes& aAddress)
{
TBuf8<KMaxGsdpAddress> address;
iRgcp->Gsdp().GetOtherAddress(address);
aAddress.Copy(address);
}
// model update
void CGameController::SetEngineL(CGameEngine* aEngine)
{
iEngine=aEngine;
iAppView->SetEngineL(iEngine);
}
void CGameController::SetRgcpL(CRgcpSession* aRgcp)
{
iRgcp=aRgcp;
iRgcp->SetHandler(this);
}
// MRgcpHandler stuff
void CGameController::RgcpHandleResponse(TInt /* aOpcode */, const TDesC8& /* aData */)
{
}
void CGameController::RgcpHandleRequest(TInt aOpcode, const TDesC8& aData)
{
if (aOpcode==KGameOpcodeText)
{
const TInt KRGCPMaxDataSize = 126;
TBuf<KRGCPMaxDataSize> unicodeData;
TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8(unicodeData, aData);
if (err>0)
iEnv->InfoMsg(R_GAME_CONVERT_TO_UNICODE);
iEngine->SetLastReceivedL(unicodeData); // !! not unicode-safe
User::Beep(440,500000);
iAppView->iLastReceivedLabel->SetTextL(unicodeData); // !! not unicode-safe
iAppView->DrawNow();
}
}
void CGameController::RgcpHandleTerminated(TBool aClientInitiated)
{
if (!aClientInitiated)
{
iEnv->InfoMsg(R_GAME_TERMINATED_BY_OTHER);
}
}
void CGameController::RgcpHandleBound()
{
iEnv->InfoMsg(R_GAME_SESSION_BOUND);
}
void CGameController::RgcpStartRequesting()
{
}
// app UI commands
void CGameController::CmdSendMessageL(const TDesC& aString)
{
TBuf8<256> utf8String;
TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(utf8String, aString);
if (err > 0)
{
// Unconverted characters exist!
iEnv->InfoMsg(R_GAME_CONVERT_FROM_UNICODE);
}
iRgcp->SendRequest(KGameOpcodeText, utf8String); // !! not unicode-safe
iEngine->SetLastSentL(aString);
iAppView->iLastSentLabel->SetTextL(aString);
iAppView->DrawNow();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -