📄 objectexchangeserver.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include <es_sock.h>
#include <StringLoader.h>
#include <BtObjectExchange.rsg>
#include "ObjectExchangeServer.h"
#include "ObjectExchangeServiceAdvertiser.h"
#include "ObjectExchangeProtocolConstants.h"
#include "Log.h"
#include "BTObjectExchange.pan"
#include <btmanclient.h>
#include <bt_sock.h> // New for 8.0
#include <bautils.h>
#include <eikenv.h>
// ============================ MEMBER FUNCTIONS ==============================
// ----------------------------------------------------------------------------
// CObjectExchangeServer::NewL()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeServer* CObjectExchangeServer::NewL( MLog& aLog )
{
CObjectExchangeServer* self = CObjectExchangeServer::NewLC( aLog );
CleanupStack::Pop( self );
return self;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::NewLC()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeServer* CObjectExchangeServer::NewLC( MLog& aLog )
{
CObjectExchangeServer* self = new ( ELeave ) CObjectExchangeServer( aLog );
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::CObjectExchangeServer()
// Constructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeServer::CObjectExchangeServer( MLog& aLog )
: iLog( aLog )
{
}
// -----------------------------------------------------------------------------
// CObjectExchangeServer::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CObjectExchangeServer::ConstructL()
{
iAdvertiser = CObjectExchangeServiceAdvertiser::NewL();
User::LeaveIfError(iFs.Connect());
iTempFile = KTempFile().AllocL();
//Make sure the file directory exists
TFileName file = KTempFile();
TParsePtr parsePtr ( file );
TFileName filename = parsePtr.DriveAndPath();
BaflUtils::EnsurePathExistsL( CEikonEnv::Static()->FsSession(), filename);
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::~CObjectExchangeServer()
// Destructor.
// ----------------------------------------------------------------------------
//
CObjectExchangeServer::~CObjectExchangeServer()
{
if ( iObexServer && iObexServer->IsStarted() )
{
iObexServer->Stop();
}
delete iObexServer;
iObexServer = NULL;
//This is used for temp purposes, see TransportDownIndication
delete iObexBufData;
iObexBufData = NULL;
delete iObexBufObject;
iObexBufObject = NULL;
delete iAdvertiser;
iAdvertiser = NULL;
delete iTempFile;
iTempFile=NULL;
iFs.Delete( *iTempFile ); //Destroy temp file
iFs.Close();
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::ErrorIndication()
// Receive error indication.
// ----------------------------------------------------------------------------
//
void CObjectExchangeServer::ErrorIndication( TInt aError )
{
HBufC* strErrorPrefix =NULL;
//ignore possible error
TRAPD(ignore,
strErrorPrefix = StringLoader::LoadL ( R_BTOB_ERROR_PREFIX )
);
Log(*strErrorPrefix, aError );
delete strErrorPrefix;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::TransportUpIndication()
// Called when the underlying socket transport connection is made from
// a remote client to the server
// ----------------------------------------------------------------------------
//
void CObjectExchangeServer::TransportUpIndication()
{
HBufC* strConnected = NULL;
TRAPD(ignore,
strConnected = StringLoader::LoadL ( R_BTOB_CONNECTED )
);
Log(*strConnected);
delete strConnected;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::TransportDownIndication()
// Transport connection is dropped.
// ----------------------------------------------------------------------------
//
void CObjectExchangeServer::TransportDownIndication()
{
HBufC* strDisconnecting = NULL;
TRAPD(ignore,
strDisconnecting = StringLoader::LoadL( R_BTOB_DISCONNECTING )
);
Log(*strDisconnecting );
if ( iObexBufObject )
{
//transfer cancelled, set temporary
//buffer so obexobject doesn't create the file again
delete iObexBufData;
iObexBufData = NULL;
TRAPD( err, ( iObexBufData = CBufFlat::NewL( KBufferGranularity ) ) );
if ( err == KErrNone )
{
TRAP( err, ( iObexBufObject->SetDataBufL( iObexBufData ) ) );
}
}
if ( iTempFile )
{
iFs.Delete( *iTempFile );
}
delete strDisconnecting;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::ObexConnectIndication()
// Invoked when an OBEX connection is made from a remote client.
// ----------------------------------------------------------------------------
//
TInt CObjectExchangeServer::ObexConnectIndication(
const TObexConnectInfo&, const TDesC8& )
{
return KErrNone;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::ObexDisconnectIndication()
// OBEX server has been disconnected.
// ----------------------------------------------------------------------------
//
void CObjectExchangeServer::ObexDisconnectIndication( const TDesC8& /*aInfo*/ )
{
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::PutRequestIndication()
// ----------------------------------------------------------------------------
//
CObexBufObject* CObjectExchangeServer::PutRequestIndication()
{
delete iObexBufObject;
iObexBufObject = NULL;
iFs.Delete( *iTempFile );
//Can't leave here
TRAPD(err,
{
iObexBufObject = CObexBufObject::NewL( NULL );
//The file is created if it doesn't exist
iObexBufObject->SetDataBufL( *iTempFile );
}
);
if(err )
{
Log(KPutRequestIndication, err);
return NULL;
}
return iObexBufObject;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::PutPacketIndication()
// ----------------------------------------------------------------------------
//
TInt CObjectExchangeServer::PutPacketIndication()
{
return KErrNone;
}
// ----------------------------------------------------------------------------
// CObjectExchangeServer::PutCompleteIndication()
// ----------------------------------------------------------------------------
//
TInt CObjectExchangeServer::PutCompleteIndication()
{
Log( iObexBufObject->Name() );
TFileName file = KTempFile();
TParsePtr parsePtr ( file );
TFileName filename = parsePtr.DriveAndPath();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -