?? objectexchangeclient.cpp
字號:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include <StringLoader.h>
#include <BlueShare_0xE0005B8E.rsg>
#include <caknmemoryselectiondialog.h>
#include <caknfileselectiondialog.h>
#include <aknnotewrappers.h>
#include "ObjectExchangeClient.h"
#include "ObjectExchangeServiceSearcher.h"
#include "blueshare.pan"
#include "blueshareconstants.h"
// ============================ MEMBER FUNCTIONS ==============================
// ----------------------------------------------------------------------------
// CObjectExchangeClient::NewL()
// Symbian two-phased constructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeClient* CObjectExchangeClient::NewL()
{
CObjectExchangeClient* self = NewLC();
CleanupStack::Pop( self );
return self;
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::NewLC()
// Symbian two-phased constructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeClient* CObjectExchangeClient::NewLC()
{
CObjectExchangeClient* self = new ( ELeave ) CObjectExchangeClient();
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::CObjectExchangeClient()
// Constructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeClient::CObjectExchangeClient()
: CActive( CActive::EPriorityStandard ),
iState( EWaitingToGetDevice )
{
CActiveScheduler::Add( this );
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::~CObjectExchangeClient()
// Destructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeClient::~CObjectExchangeClient()
{
if ( iState != EWaitingToGetDevice && iClient )
{
iClient->Abort();
iStatus = KErrNone;
}
Cancel();
delete iCurrObject;
iCurrObject = NULL;
delete iServiceSearcher;
iServiceSearcher = NULL;
delete iClient;
iClient = NULL;
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::ConstructL()
// Perform second phase construction of this object.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::ConstructL()
{
iServiceSearcher = CObjectExchangeServiceSearcher::NewL();
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::DoCancel()
// Cancel any outstanding requests.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::DoCancel()
{
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::RunL()
// Respond to an event.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::RunL()
{
if ( iStatus != KErrNone )
{
switch ( iState )
{
case EGettingDevice:
iState = EWaitingToGetDevice;
break;
case EGettingService:
case EDisconnecting:
iState = EWaitingToGetDevice;
break;
case EWaitingToSend:
iState = EWaitingToGetDevice;
break;
default:
Panic( EBlueShareUnexpectedLogicState );
break;
}
}
else
{
switch ( iState )
{
case EGettingDevice:
{
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 = EWaitingToSend;
ConnectToServerL();
break;
}
case EWaitingToSend:
{
TFileName filename;
filename.Copy(KBSAppFileName);
SendObjectL(filename);
iState = EDisconnecting;
break;
}
case EDisconnecting:
{
iState = EWaitingToGetDevice;
DisconnectL();
break;
}
default:
{
Panic( EBlueShareSdpRecordDelete );
break;
}
};
}
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::ConnectL()
// Connect to a service.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::ConnectL()
{
if ( iState == EWaitingToGetDevice && !IsActive() )
{
iServiceSearcher->SelectDeviceByDiscoveryL( iStatus );
iState = EGettingDevice;
SetActive();
}
else
{
User::Leave( KErrInUse );
}
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::ConnectToServerL()
// Connect to the server.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::ConnectToServerL()
{
TObexBluetoothProtocolInfo protocolInfo;
protocolInfo.iTransport.Copy( KServerTransportName );
protocolInfo.iAddr.SetBTAddr( iServiceSearcher->BTDevAddr() );
protocolInfo.iAddr.SetPort( iServiceSearcher->Port() );
if ( iClient )
{
delete iClient;
iClient = NULL;
}
iClient = CObexClient::NewL( protocolInfo );
iClient->Connect( iStatus );
SetActive();
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::SendObjectL()
// Send a message to a service on a remote machine.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::SendObjectL(TFileName& aName)
{
if ( iState != EWaitingToSend )
{
User::Leave( KErrDisconnected );
}
else if ( IsActive() )
{
User::Leave( KErrInUse );
}
ShowMessageL(KDebug);
delete iCurrObject;
iCurrObject = NULL;
iCurrObject = CObexFileObject::NewL(aName);
TParsePtr parsePtr (aName);
TPtrC ptr = parsePtr.NameAndExt();
iCurrObject->SetNameL( ptr );
iClient->Put( *iCurrObject, iStatus );
SetActive();
}
void CObjectExchangeClient::ShowMessageL( const TDesC& aMsg )
{
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD( aMsg);
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::StopL()
// Aborts command.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::StopL()
{
if ( iClient && iClient->IsConnected() )
{
iClient->Abort();
iState = EWaitingToGetDevice;
}
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::DisconnectL()
// Disconnects from the remote machine.
// ----------------------------------------------------------------------------
//
void CObjectExchangeClient::DisconnectL()
{
if ( iState == EWaitingToGetDevice )
{
return;
}
if (iState != EWaitingToGetDevice)
User::Leave(KErrInUse);
else
{
HBufC* strDisconnecting = StringLoader::LoadLC(R_BTOB_DISCONNECTING);
CleanupStack::PopAndDestroy(strDisconnecting);
iClient->Disconnect(iStatus);
SetActive();
}
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::IsBusy()
// True, if the client is performing some operation..
// ----------------------------------------------------------------------------
//
TBool CObjectExchangeClient::IsBusy()
{
return IsActive();
}
// ----------------------------------------------------------------------------
// CObjectExchangeClient::IsConnected()
// True, if the client is performing some operation..
// ----------------------------------------------------------------------------
//
TBool CObjectExchangeClient::IsConnected()
{
return iState == EWaitingToSend;
}
// End of File
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -