/*
* Component Name: Headset Simulator
* Author: Comarch S.A.
* Version: 1.0
* Copyright (c) 2010 Comarch S.A.
*
* This Software is submitted by Comarch S.A. to Symbian Foundation Limited on
* the basis of the Member Contribution Agreement entered between Comarch S.A.
* and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be
* used only in accordance with the terms and conditions of the Agreement.
* Any other usage, duplication or redistribution of this Software is not
* allowed without written permission of Comarch S.A.
*
*/
#include "hsprofilemanager.h"
#include "debug.h"
CHsProfileManager::CHsProfileManager()
{
}
CHsProfileManager::~CHsProfileManager()
{
TRACE_FUNC_ENTRY
DestroyProfile();
DestroyCodL();
DestroySdpL();
REComSession::FinalClose();
TRACE_FUNC_EXIT
}
CHsProfileManager* CHsProfileManager::NewLC()
{
CHsProfileManager* self = new ( ELeave ) CHsProfileManager();
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
CHsProfileManager* CHsProfileManager::NewL()
{
CHsProfileManager* self = CHsProfileManager::NewLC();
CleanupStack::Pop( self ); // self;
return self;
}
void CHsProfileManager::ConstructL()
{
}
void CHsProfileManager::LookupAndManageProfileL( const TUid aProfileUid )
{
TRACE_FUNC_ENTRY
DestroyProfile();
iProfilePlugin = CHsProfileBase::NewL( aProfileUid );
TRACE_FUNC_EXIT
}
void CHsProfileManager::LookupAndManageProfileL( const TDesC8 &aProfileName )
{
TRACE_FUNC_ENTRY
DestroyProfile();
iProfilePlugin = CHsProfileBase::NewL( aProfileName );
TRACE_FUNC_EXIT
}
void CHsProfileManager::UnloadProfile()
{
TRACE_FUNC_ENTRY
if ( iProfilePlugin )
{
delete iProfilePlugin;
iProfilePlugin = NULL;
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::LookupAndManageSdpL( const TUid aSdpUid )
{
TRACE_FUNC_ENTRY
DestroySdpL();
iSdpPlugin = CHsSdpBase::NewL( aSdpUid );
iSdpPlugin->SetServicePort( iSdpServicePort );
TRACE_FUNC_EXIT
}
void CHsProfileManager::LookupAndManageSdpL( const TDesC8 &aSdpName )
{
TRACE_FUNC_ENTRY
DestroySdpL();
iSdpPlugin = CHsSdpBase::NewL( aSdpName );
iSdpPlugin->SetServicePort( iSdpServicePort );
TRACE_FUNC_EXIT
}
void CHsProfileManager::LoadSdpL()
{
TRACE_FUNC_ENTRY
User::LeaveIfNull( iSdpPlugin );
if ( iSdpSet )
{
TRAP_IGNORE( iSdpPlugin->DeleteSdpRecordL() );
iSdpSet = EFalse;
}
iSdpPlugin->SetServicePort( iSdpServicePort );
iSdpPlugin->CreateSdpRecordL();
iSdpSet = ETrue;
TRACE_FUNC_EXIT
}
void CHsProfileManager::UnloadSdpL()
{
TRACE_FUNC_ENTRY
User::LeaveIfNull( iSdpPlugin );
if ( iSdpSet )
{
iSdpPlugin->DeleteSdpRecordL();
iSdpSet = EFalse;
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::SetSdpServicePort( TInt aPort )
{
TRACE_FUNC_ENTRY
if ( iSdpPlugin )
{
iSdpPlugin->SetServicePort( aPort );
}
iSdpServicePort = aPort;
TRACE_FUNC_EXIT
}
void CHsProfileManager::RefreshSdp()
{
TRACE_FUNC_ENTRY
if ( iSdpPlugin )
{
TRAP_IGNORE( iSdpPlugin->DeleteSdpRecordL() );
iSdpSet = EFalse;
TRAPD( err, iSdpPlugin->CreateSdpRecordL() );
if ( KErrNone == err )
{
iSdpSet = ETrue;
}
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::LookupAndManageCodL( const TUid aCoDUid )
{
TRACE_FUNC_ENTRY
DestroyCodL();
iCoDPlugin = CHsCoDBase::NewL( aCoDUid );
User::LeaveIfError( iCoDPlugin->SaveOldCod() );
TRACE_FUNC_EXIT
}
void CHsProfileManager::LookupAndManageCodL( const TDesC8 &aCoDName )
{
TRACE_FUNC_ENTRY
DestroyCodL();
iCoDPlugin = CHsCoDBase::NewL( aCoDName );
User::LeaveIfError( iCoDPlugin->SaveOldCod() );
TRACE_FUNC_EXIT
}
void CHsProfileManager::LoadCodL()
{
TRACE_FUNC_ENTRY
if ( iCoDPlugin )
{
iCoDPlugin->SetNewCodL();
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::UnloadCodL()
{
TRACE_FUNC_ENTRY
if ( iCoDPlugin )
{
User::LeaveIfError( iCoDPlugin->RestoreOldCod() );
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::DestroyProfile()
{
TRACE_FUNC_ENTRY
if ( iProfilePlugin )
{
delete iProfilePlugin;
iProfilePlugin = NULL;
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::DestroySdpL()
{
TRACE_FUNC_ENTRY
if ( iSdpPlugin )
{
iSdpPlugin->DeleteSdpRecordL();
delete iSdpPlugin;
iSdpPlugin = NULL;
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::DestroyCodL()
{
TRACE_FUNC_ENTRY
TInt err;
if ( iCoDPlugin )
{
err = iCoDPlugin->RestoreOldCod();
TRACE_INFO((_L("RestoreOldCoD method returned value %d"), err))
delete iCoDPlugin;
iCoDPlugin = NULL;
User::LeaveIfError( err );
}
TRACE_FUNC_EXIT
}
TBool CHsProfileManager::IsSdpPluginLoaded()
{
return iSdpPlugin ? ETrue : EFalse;
}
TBool CHsProfileManager::IsProfilePluginLoaded()
{
return iProfilePlugin ? ETrue : EFalse;
}
TBool CHsProfileManager::IsCoDPluginLoaded()
{
return iCoDPlugin ? ETrue : EFalse;
}
void CHsProfileManager::HandleCommandL( const TDesC8 &aCommandsIn,
TDes8 &aCommandOut, TBool aFromAG )
{
TRACE_FUNC_ENTRY
User::LeaveIfNull( iProfilePlugin );
iProfilePlugin->HandleCommandL( aCommandsIn, aCommandOut, aFromAG );
TRACE_FUNC_EXIT
}
void CHsProfileManager::HandleClientDisconnected( TInt aErr )
{
TRACE_FUNC_ENTRY
if ( iProfilePlugin )
{
iProfilePlugin->HandleClientDisconnected( aErr );
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::HandleClientConnected( TDes8& aCommandOut )
{
TRACE_FUNC_ENTRY
if ( iProfilePlugin )
{
iProfilePlugin->HandleClientConnected( aCommandOut );
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::AcceptIncomingCallL( TDes8& aProfileResponse )
{
TRACE_FUNC_ENTRY
if ( iProfilePlugin )
{
iProfilePlugin->HandleAcceptCallL( aProfileResponse );
}
TRACE_FUNC_EXIT
}
void CHsProfileManager::ReleaseOngoingCallL( TDes8& aProfileResponse )
{
TRACE_FUNC_ENTRY
if ( iProfilePlugin )
{
iProfilePlugin->HandleReleaseCallL( aProfileResponse );
}
TRACE_FUNC_EXIT
}