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

📄 infraredtransport.cpp

📁 Symbian OS C++ for Mobile Phones Volume 3 源码
💻 CPP
字号:
// Copyright (c) 2004 - 2007, Symbian Software Ltd. All rights reserved.

#include "infraredtransport.h"


// -------- (de)allocation --------

CInfraredTransport* CInfraredTransport::NewL(TAny* aTransportCreateInfo)
/**
	This factory function is defined so the class can be instantiated
	via ECOM, which means it can only take a single TAny* argument.
	
	@param	aTransportCreateInfo	Pointer to an instance of
							TTransportCreateInfo, which contains the
							data required to allocate the transport.
	@return					Transport that sends messages to a remote
							device over infrared.  This is owned by
							the caller.
 */
	{
	const TTransportInterfaceCreateInfo& tci =
		*reinterpret_cast<TTransportInterfaceCreateInfo*>(aTransportCreateInfo);
	return New2L(tci.iObserver, *tci.iAddress, tci.iInitListen);
	}

CInfraredTransport* CInfraredTransport::New2L(MTransportObserver& aObserver, const TDesC& aProtocolName, TBool aInitListen)
/**
	Factory function allocates a new instance of CInfraredTransport.

	@param	aObserver		Observer to notify about transport events.
							This is managed by the CTransport superclass.
	@param	aProtocolName	Which protocol is used to communicate with the
							remote device.  Supported values are "IrTinyTP"
							and "Irmux".
	@param	aInitListen		If true, the transport should initially expect a
							payload from the remote device.  Otherwise it
							should wait for the local owner to send a payload
							to the remote device.  If this value is true,
							the transport is created as an infrared server (receiver;)
							otherwise it is created as a infrared client (sender.)
	@return					Transport which is connected to a remote device.
							This is owned by the caller.
 */
	{
	if (aInitListen)
		return CIrClientToServer::NewL(aObserver, aProtocolName);
	else
		return CIrServerToClient::NewL(aObserver, aProtocolName);
	}

CInfraredTransport::CInfraredTransport(MTransportObserver& aObserver)
/**
	This c'tor is defined to pass the supplied observer to the superclass.

	@param	aObserver		Observer to notify about transport events.
							This is managed by the CTransport superclass.
 */
:	CTransport(aObserver)
	{
	// empty.
	}

void CInfraredTransport::ConstructL(const TDesC& aProtocolName)
/**
	This function should be called from the subclasses' initialization
	functions.  It loads the serial device drivers and connects to the
	socket server.
	
	@param	aProtocolName	Infrared protocol to use, "Irmux" or "IrTinyTP".
 */
	{
	SerialUtils::LoadDeviceDriversL(iLoadedLdd, iLoadedPdd);
	
	TInt r = iSocketServ.Connect();
	if (r == KErrNone)
		r = iSocketServ.FindProtocol(aProtocolName, iProtoDesc);
	TRAN_LOG3("-CInfraredTransport::ConnectToSocketServerL,nm=\"%S\", fam=%d,socktype=%d", &iProtoDesc.iName, iProtoDesc.iAddrFamily, iProtoDesc.iSockType);
	User::LeaveIfError(r);
	}

CInfraredTransport::~CInfraredTransport()
/**
	Close resources used by both server and client infrared devices.
	
	Specifically, closes the connection to the socket server and unloads
	the logical and physical devices drivers.
 */
	{
	iSocketServ.Close();
	SerialUtils::FreeDeviceDrivers(iLoadedLdd, iLoadedPdd);
	}

void CInfraredTransport::CloseDataSocket()
/**
	This function can be called from the subclasses' d'tors.
	It closes the data socket, so the server to client connection
	can do this before closing the listen socket.
 */
	{
	iSocket.Close();
	}


// -------- implement CTransport --------

void CInfraredTransport::DoLaunchRead()
/**
	Implement CTransport by reading a payload from the remote
	device.
 */
	{
	iSocket.Read(iPayload8, iStatus);
	// CTransport::LaunchRead calls SetActive
	}

void CInfraredTransport::DoSendPayloadL()
/**
	Implement CTransport by writing the data in iPayload to the
	remote device.
 */
	{
	iPayload8.Copy(iPayload);
	iSocket.Write(iPayload8, iStatus);
	// CTransport::SendPayload calls SetActive
	}


// -------- implement CActive, override CTransport --------

void CInfraredTransport::RunL()
/**
	Implement CActive and override CTransport by handling the
	completed read or write.  CTransport notifies the observer.
 */
	{
	// if successful read then widen into iPayload
	if (iStatus == KErrNone && iListening)
		iPayload.Copy(iPayload8);
	
	CTransport::RunL();
	}

void CInfraredTransport::DoCancel()
/**
	Implement CActive by cancelling any outstanding read or write.
 */
	{
	// This could be implemented more efficiently by calling CancelAll
	// but, for the sake of demonstration, it is useful to separate the
	// accept, connect, read, and write cancellations.
	
	iSocket.CancelRead();
	iSocket.CancelWrite();
	}

⌨️ 快捷键说明

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