?? irservertoclient.cpp
字號:
// Copyright (c) 2004 - 2007, Symbian Software Ltd. All rights reserved.
#include "infraredtransport.h"
// -------- (de)allocation --------
CIrServerToClient* CIrServerToClient::NewL(MTransportObserver& aObserver, const TDesC& aProtocolName)
/**
Factory function allocates infrared transport.
@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".
@return New, connected instance of CIrServerToClient.
This is owned by the caller.
*/
{
CIrServerToClient* self = new(ELeave) CIrServerToClient(aObserver);
CleanupStack::PushL(self);
self->ConstructL(aProtocolName);
CleanupStack::Pop(self);
return self;
}
CIrServerToClient::CIrServerToClient(MTransportObserver& aObserver)
/**
This constructor 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.
*/
: CInfraredTransport(aObserver)
{
// empty.
}
void CIrServerToClient::ConstructL(const TDesC& aProtocolName)
/**
Connect to the remote client. This function returns when the connection
has been made, or has failed.
@param aProtocolName Which protocol is used to communicate with the
remote device. Supported values are "IrTinyTP"
and "Irmux".
*/
{
TRAN_LOG1(">CIrServerToClient::ConstructL,pr=\"%S\"", &aProtocolName);
CInfraredTransport::ConstructL(aProtocolName);
// open the receiving socket
TInt r = iListenSocket.Open(iSocketServ, iProtoDesc.iAddrFamily, iProtoDesc.iSockType, iProtoDesc.iProtocol);
TRAN_LOG1("-CInfraredTransport::ConstructL,lsopen=%d", r);
User::LeaveIfError(r);
TIrdaSockAddr sockAddr;
sockAddr.SetPort(KIrSocketPortNum);
iListenSocket.Bind(sockAddr);
r = iListenSocket.Listen(/*qSize*/ 1);
TRAN_LOG1("-CInfraredTransport::ConstructL,listen=%d", r);
User::LeaveIfError(r);
// open blank socket to accept incoming connection
r = iSocket.Open(iSocketServ);
TRAN_LOG1("-CInfraredTransport::ConstructL,open=%d", r);
User::LeaveIfError(r);
// accept an incoming connection
iListenSocket.Accept(iSocket, iStatus);
SetActive();
// dialog will be dismissed by the user or by RunL
r = (! iObserver.StartedWaitingForClientL()) ? KErrCancel : iAcceptError;
TRAN_LOG1("-CInfraredTransport::ConstructL,accept=%d", r);
User::LeaveIfError(r);
CTransport::ConstructL(/*aInitListen*/ EFalse);
TRAN_LOG0("<CIrServerToClient::ConstructL");
}
CIrServerToClient::~CIrServerToClient()
/**
Free resources used specifically by the server to client layer.
*/
{
Cancel();
CloseDataSocket();
iListenSocket.Close();
}
// -------- implement CActive / override CTransport --------
void CIrServerToClient::RunL()
/**
Implement CActive and override CTransport by handling accept event.
If the socket is already connected then delegate to CInfraredTransport which
will convert the payload from 8 bit to native width.
*/
{
TRAN_LOG2(">CIrServerToClient::RunL,st=%d,ac=%d", iStatus.Int(), iAccepted);
// if already accepted, must be data transfer operation, so handle in superclass.
if (iAccepted)
CInfraredTransport::RunL();
else
{
iAcceptError = iStatus.Int();
iAccepted = ETrue;
iObserver.StoppedWaitingForClient();
}
TRAN_LOG0("<CIrServerToClient::RunL");
}
void CIrServerToClient::DoCancel()
/**
Implement CActive and override CInfraredTransport by
cancelling any pending acceptance. If the socket is already
accepted then call CInfraredTransport::DoCancel to cancel
any pending read or write.
*/
{
if (! iAccepted)
iListenSocket.CancelAccept();
else
CInfraredTransport::DoCancel();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -