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

📄 bluetoothsocketwriterreader.cpp

📁 基于symbian UIQ 的一款古老的飞机游戏。对入门学习很有帮助。
💻 CPP
字号:
// Copyright (c) Symbian Ltd 2008. All rights reserved.

// INCLUDE FILES

#include "BluetoothSocketWriterReader.h"
#include "common.hrh"
/*
============================================================================
CSocketReader's constructor
============================================================================
*/
CSocketReader::CSocketReader(RSocket& aBtSocket, MSocketWriterReaderObserver& aObserver) :
	CActive(CActive::EPriorityStandard), iBtSocket(aBtSocket), iObserver(aObserver)
    {
	CActiveScheduler::Add(this);
	}

/*
============================================================================
CSocketReader's destructor
============================================================================
*/
CSocketReader::~CSocketReader()
    {
    Cancel();
    }

/*
============================================================================
DoCancel is called as part of the active object's Cancel().
Cancels an outstanding BT socket read operation.
============================================================================
*/
void CSocketReader::DoCancel()
    {
	iBtSocket.CancelRead();
    }

/*
============================================================================
Handles the active object's reading data completion event.
On completion it calls the callback function MSocketWriterReaderObserver::ReportData
to pass to the caller the data received.
============================================================================
*/
void CSocketReader::RunL()
    {
	iObserver.ReportData(iBuffer, iStatus.Int());
    }	

/*
============================================================================
Asynchronous call to wait for incoming data
============================================================================
*/
void CSocketReader::ReadData()
    {
	if (!IsActive())
		{
		iBuffer.Zero();
		iBtSocket.RecvOneOrMore(iBuffer, 0, iStatus, iLen);
	    SetActive();
		}
    }

/*
============================================================================
Handles a leave occurring in the request completion event handler RunL().
============================================================================
*/
TInt CSocketReader::RunError(TInt aError)
	{
	iObserver.ReportData(iBuffer, aError);
	return KErrNone;
	}

///////////////////////////////////////////////////////////////////////////////////

/*
============================================================================
CSocketWriter's constructor
============================================================================
*/
CSocketWriter::CSocketWriter(RSocket& aBtSocket, MSocketWriterReaderObserver& aObserver) :
	CActive(CActive::EPriorityStandard), iBtSocket(aBtSocket), iObserver(aObserver) 
    {
	CActiveScheduler::Add(this);
	}

/*
============================================================================
CSocketWriter's destructor
============================================================================
*/
CSocketWriter::~CSocketWriter()
    {
    Cancel();
    }

/*
============================================================================
DoCancel is called as part of the active object's Cancel().
Cancels an outstanding BT socket write operation.
============================================================================
*/
void CSocketWriter::DoCancel()
    {
	iBtSocket.CancelWrite();
    }

/*
============================================================================
Handles the active object's writing data completion event.
On completion it calls the callback function MSocketWriterReaderObserver::WriteComplete
to notify the caller if the write was succesful
============================================================================
*/
void CSocketWriter::RunL()
	{
	iObserver.WriteComplete(iStatus.Int());
    }

/*
============================================================================
Asynchronous call to send data to the remote device.
Note that we handle only one event at a time. Data to write to the remote device
is not queued if an outstanding write operation is already in progress.
============================================================================
*/
TInt CSocketWriter::Write(const TDesC8& aBuf)
    {
	TInt err = KErrNone;

	if (!IsActive())
		{
		iBtSocket.Write(aBuf,iStatus);
		SetActive();
		}
	else
		{
		err = KErrInUse;
		}
	return(err);
    }

/*
============================================================================
Handles a leave occurring in the request completion event handler RunL().
============================================================================
*/
TInt CSocketWriter::RunError(TInt aError)
	{
	iObserver.WriteComplete(aError);
	return KErrNone;
	}

⌨️ 快捷键说明

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