⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp_srv.cpp

📁 一个symbian下的tcp连接的客户端/服务器源代码
💻 CPP
字号:
// tcp_srv.cpp
//
// Copyright (c) 1997 - 1999 Psion Software plc.  All rights reserved.
//


#include "tcp_srv.h"

//
// EXPORTed functions
//

EXPORT_C CApaApplication* NewApplication()
	{
	return new CExampleApplication;
	}

GLDEF_C TInt E32Dll(TDllReason)
	{
	return KErrNone;
	}

////////////////////////////////////////////////////////////////
//
// Application class, CExampleApplication
//
////////////////////////////////////////////////////////////////

TUid CExampleApplication::AppDllUid() const
	{
	return KUidMinTcp;
	}

CApaDocument* CExampleApplication::CreateDocumentL()
	{
	return CExampleDocument::NewL(*this);	// Construct the document
	}


////////////////////////////////////////////////////////////////
//
// Document class, CExampleDocument
//
////////////////////////////////////////////////////////////////

// C++ constructor
CExampleDocument::CExampleDocument(CEikApplication& aApp)
		: CEikDocument(aApp)
	{
	}

// Implement two-phase construction for document
CExampleDocument* CExampleDocument::NewL(CEikApplication& aApp)
	{
	CExampleDocument* self=new (ELeave) CExampleDocument(aApp);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop();
	return self;
	}

void CExampleDocument::ConstructL()
	{
	iModel = CTcpSrvEngine::NewL();		// Construct the model
	}

CExampleDocument::~CExampleDocument()
	{
	delete iModel;						// delete the model
	}

CEikAppUi* CExampleDocument::CreateAppUiL()
	{
    return new(ELeave) CExampleAppUi;
	}


////////////////////////////////////////////////////////////////
//
// App UI class, CExampleAppUi
//
////////////////////////////////////////////////////////////////

void CExampleAppUi::ConstructL()
    {
    BaseConstructL();
	iModel=STATIC_CAST(CExampleDocument*,iDocument)->Model();
    iAppView=new(ELeave) CExampleAppView;
    iAppView->ConstructL(ClientRect(),iModel);
	CEikFileNameLabel* filenameLabel=STATIC_CAST(CEikFileNameLabel*, iToolBar->ControlById(EExampleCmdFileName));
	filenameLabel->UpdateL();
    }

CExampleAppUi::~CExampleAppUi()
	{
    delete iAppView;
	}

void CExampleAppUi::HandleCommandL(TInt aCommand)
	{
	switch (aCommand)
		{
	case EExampleCmdStartTest:
		iModel->StartTestL();
		break;
	case EExampleCmdCancel:
		iModel->Cancel();
		break;
	case EExampleCmd2:
		iEikonEnv->InfoMsg(R_EXAMPLE_COMMAND_2);
		break;
	case EExampleCmd3:
		iEikonEnv->InfoMsg(R_EXAMPLE_COMMAND_3);
		break;
	case EEikCmdExit: 
		iModel->Cancel();
		Exit();
		break;
	default:
		break;
		}
	}



////////////////////////////////////////////////////////////////
//
// Application view class, CExampleAppView
//
////////////////////////////////////////////////////////////////

void CExampleAppView::ConstructL(const TRect& aRect, CTcpSrvEngine* aModel)
    {
	iModel=aModel; // Give the app view a pointer to the model
	iModel->SetObserver(this);
	CreateWindowL();
	iStatusLabel=CreateLabelL();
    SetRectL(aRect);
    ActivateL();
    }

CExampleAppView::~CExampleAppView()
	{
	delete iStatusLabel;
	}

CEikLabel* CExampleAppView::CreateLabelL()
	{
	CEikLabel* label = new(ELeave) CEikLabel;
	CleanupStack::PushL(label);
	label->SetContainerWindowL(*this);
	label->SetTextL(_L("Press Start to begin comms test"));
   	label->SetAlignment(EHLeftVCenter);
	label->SetSizeL(label->MinimumSize());
	CleanupStack::Pop();
	label->SetNonFocusing();
	return label;
	}

void CExampleAppView::AppendToLabelL(const TDesC& aText)
	{
	HBufC* buf=HBufC::NewL(iStatusLabel->Text()->Length() + aText.Length());
	CleanupStack::PushL(buf);
	*buf=*iStatusLabel->Text();
	TPtr ptr=buf->Des();
	ptr.Append(aText);
	iStatusLabel->SetTextL(*buf);
	iStatusLabel->SetSizeL(iStatusLabel->MinimumSize());
	CleanupStack::PopAndDestroy(); //buf
	}

void CExampleAppView::HandleProgressEvent()
	{
	AppendToLabelL(iModel->StatusText());
	DrawNow();
	}

TInt CExampleAppView::CountComponentControls() const
	{
	return 1;
	}


CCoeControl* CExampleAppView::ComponentControl(TInt /*aIndex*/) const
	{
	return(iStatusLabel); 
	}

void CExampleAppView::SizeChangedL()
    {
	// Set position of status label within main view
	TInt x=Size().iWidth/4;
	TInt y=Size().iHeight/4;
	TPoint pos(x,y);
	iStatusLabel->SetPosition(pos);
	}

void CExampleAppView::Draw(const TRect& /*aRect*/) const
	{
	}

void CExampleAppView::HandlePointerEventL(const TPointerEvent& /*aPointerEvent*/)
	{
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -