📄 objectexchangeclient.cpp
字号:
#include "ObjectExchangeClient.h"
#include "ObjectExchangeServiceSearcher.h"
#include "BTObjectExchange.pan"
#include "eikenv.h"
CObjectExchangeClient* CObjectExchangeClient::NewL()
{
CObjectExchangeClient* self = NewLC();
CleanupStack::Pop(self);
return self;
}
CObjectExchangeClient* CObjectExchangeClient::NewLC()
{
CObjectExchangeClient* self = new (ELeave) CObjectExchangeClient();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CObjectExchangeClient::CObjectExchangeClient()
: CActive(CActive::EPriorityStandard),
iState(EWaitingToGetDevice)//,
//iLog(aLog)
{
CActiveScheduler::Add(this);
}
void CObjectExchangeClient::ConstructL()
{
iServiceSearcher = CObjectExchangeServiceSearcher::NewL();
}
CObjectExchangeClient::~CObjectExchangeClient()
{
Cancel();
if (iState != EWaitingToGetDevice && iClient)
{
iClient->Abort();
}
delete iServiceSearcher;
iServiceSearcher = NULL;
delete iClient;
iClient = NULL;
}
void CObjectExchangeClient::DoCancel()
{
}
void CObjectExchangeClient::RunL()
{
if (iStatus != KErrNone)
{
switch (iState)
{
case EGettingDevice:
if (iStatus = KErrCancel)
{
}
break;
case EGettingService:
case EGettingConnection:
case EDisconnecting:
iState = EWaitingToGetDevice;
break;
case EWaitingToSend:
iState = EWaitingToGetDevice;
break;
default:
Panic(EBTObjectExchangeUnexpectedLogicState);
break;
}
}
else
{
switch (iState)
{
case EGettingDevice:
// found a device now search for a suitable service
iState = EGettingService;
iStatus = KRequestPending; // this means that the RunL can not be called until
// this program does something to iStatus
iServiceSearcher->FindServiceL(iStatus);
SetActive();
break;
case EGettingService:
iState = EGettingConnection;
ConnectToServerL();
break;
case EGettingConnection:
iState = EWaitingToSend;
SendMessageL();
break;
case EWaitingToSend:
// DisconnectL();
//iState == EWaitingToGetDevice;
break;
case EDisconnecting:
iState = EWaitingToGetDevice;
break;
default:
Panic(EBTObjectExchangeSdpRecordDelete);
break;
};
}
}
void CObjectExchangeClient::ConnectL()
{
if (iState == EWaitingToGetDevice && !IsActive())
{
iServiceSearcher->SelectDeviceByDiscoveryL(iStatus);
iState = EGettingDevice;
SetActive();
}
else
{
User::Leave(KErrInUse);
}
}
void CObjectExchangeClient::ConnectToServerL()
{
TObexBluetoothProtocolInfo protocolInfo;
protocolInfo.iTransport.Copy(KServerTransportName);
if (direkt==true)
{
protocolInfo.iAddr.SetBTAddr(BTAddy);
}else{
protocolInfo.iAddr.SetBTAddr(iServiceSearcher->BTDevAddr());
}
protocolInfo.iAddr.SetPort(iServiceSearcher->Port());
if (iClient)
{
delete iClient;
iClient = NULL;
}
iClient = CObexClient::NewL(protocolInfo);
iClient->Connect(iStatus);
SetActive();
}
void CObjectExchangeClient::SendMessageL()
{
_LIT(currentFileNameD,"\\system\\apps\\BlueJackX\\jackMSG.VCF");
_LIT(currentFileName,"\\system\\apps\\BlueJackX\\jackMSGdirekt.VCF");
obexFile = CObexFileObject::NewL(TPtrC(NULL, 0));
if (direkt==true)
{
obexFile->InitFromFileL(currentFileNameD);
}else{
obexFile->InitFromFileL(currentFileName);
}
if (iState != EWaitingToSend)
{
User::Leave(KErrDisconnected);
}
else if (IsActive())
{
User::Leave(KErrInUse);
}
iClient->Put(*obexFile, iStatus);
SetActive();
CEikonEnv::Static()->AlertWin(_L("Message"),_L("Send"));
if (obexFile)
{
delete obexFile;
obexFile = NULL;
}
}
void CObjectExchangeClient::StopL()
{
if (iClient && iClient->IsConnected())
{
iClient->Abort();
iState = EWaitingToGetDevice;
}
}
void CObjectExchangeClient::DisconnectL()
{
if (iState == EWaitingToGetDevice)
{
return;
}
if (iState == EWaitingToSend)
{
iState = EDisconnecting;
iClient->Disconnect(iStatus);
SetActive();
}
else
{
User::Leave(KErrInUse);
}
}
TBool CObjectExchangeClient::IsBusy()
{
return IsActive();
}
TBool CObjectExchangeClient::IsConnected()
{
return iState == EWaitingToSend;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -