sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include "t_crestrictedaudiooutputdata.h" sl@0: sl@0: /*@{*/ sl@0: //Command literals sl@0: _LIT(KCmdNewL, "NewL"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: _LIT(KCmdAppendAllowedOutput, "AppendAllowedOutput"); sl@0: _LIT(KCmdRemoveAllowedOutput, "RemoveAllowedOutput"); sl@0: _LIT(KCmdGetAllowedOutput, "GetAllowedOutput"); sl@0: _LIT(KCmdGetAllowedOutputCount, "GetAllowedOutputCount"); sl@0: _LIT(KCmdReset, "Reset"); sl@0: _LIT(KCmdCommit, "Commit"); sl@0: /*@}*/ sl@0: sl@0: /*@{*/ sl@0: //INI Section name literals sl@0: _LIT(KOutput, "Output"); sl@0: _LIT(KIndex, "Index"); sl@0: _LIT(KDevSoundInstanceName, "DevSoundInstanceName"); sl@0: /*@}*/ sl@0: sl@0: /*@{*/ sl@0: //Enumeration Literals sl@0: _LIT(KEAllowAllAudio, "EAllowAllAudio"); sl@0: _LIT(KEAllowAudioAnalog, "EAllowAudioAnalog"); sl@0: _LIT(KEAllowAudioFMTransmitter, "EAllowAudioFMTransmitter"); sl@0: _LIT(KEAllowAudioBtHFPHSP, "EAllowAudioBtHFPHSP"); sl@0: _LIT(KEAllowAudioBtA2DP, "EAllowAudioBtA2DP"); sl@0: _LIT(KEAllowAudioUplink, "EAllowAudioUplink"); sl@0: _LIT(KEAllowAudioUsb, "EAllowAudioUsb"); sl@0: _LIT(KEAllowAudioRecording, "EAllowAudioRecording"); sl@0: _LIT(KEAllowVisualization, "EAllowVisualization"); sl@0: /*@}*/ sl@0: sl@0: const CDataWrapperBase::TEnumEntryTable CT_CRestrictedAudioOutputData::iEnumAllowedOutputPreference[]= sl@0: { sl@0: { KEAllowAllAudio, CRestrictedAudioOutput::EAllowAllAudio}, sl@0: { KEAllowAudioAnalog, CRestrictedAudioOutput::EAllowAudioAnalog}, sl@0: { KEAllowAudioFMTransmitter, CRestrictedAudioOutput::EAllowAudioFMTransmitter}, sl@0: { KEAllowAudioBtHFPHSP, CRestrictedAudioOutput::EAllowAudioBtHFPHSP}, sl@0: { KEAllowAudioBtA2DP, CRestrictedAudioOutput::EAllowAudioBtA2DP}, sl@0: { KEAllowAudioUplink, CRestrictedAudioOutput::EAllowAudioUplink}, sl@0: { KEAllowAudioUsb, CRestrictedAudioOutput::EAllowAudioUsb}, sl@0: { KEAllowAudioRecording, CRestrictedAudioOutput::EAllowAudioRecording}, sl@0: { KEAllowVisualization, CRestrictedAudioOutput::EAllowVisualization} sl@0: }; sl@0: sl@0: /** sl@0: * Public destructor sl@0: */ sl@0: CT_CRestrictedAudioOutputData::~CT_CRestrictedAudioOutputData() sl@0: { sl@0: DestroyData(); sl@0: } sl@0: sl@0: /** sl@0: * Two phase constructor sl@0: * sl@0: * @leave system wide error sl@0: */ sl@0: CT_CRestrictedAudioOutputData* CT_CRestrictedAudioOutputData::NewL() sl@0: { sl@0: CT_CRestrictedAudioOutputData* ret = new (ELeave) CT_CRestrictedAudioOutputData(); sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * sl@0: * @return pointer to the object that the data wraps sl@0: */ sl@0: TAny* CT_CRestrictedAudioOutputData::GetObject() sl@0: { sl@0: return iRestrictedAudioOutput; sl@0: } sl@0: sl@0: /** sl@0: * Helper destructor sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DestroyData() sl@0: { sl@0: if (iRestrictedAudioOutput) sl@0: { sl@0: delete iRestrictedAudioOutput; sl@0: iRestrictedAudioOutput = NULL; sl@0: } sl@0: } sl@0: /** sl@0: * Process a command read from the Ini file sl@0: * @param aCommand The command to process sl@0: * @param aSection The section get from the *.ini file of the project T_Wlan sl@0: * @param aAsyncErrorIndex Command index dor async calls to returns errors to sl@0: * @return TBool ETrue if the command is process sl@0: * @leave system wide error sl@0: */ sl@0: TBool CT_CRestrictedAudioOutputData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: if (aCommand == KCmdNewL) sl@0: { sl@0: DoCmdNewL(aSection); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else if (aCommand == KCmdAppendAllowedOutput) sl@0: { sl@0: DoCmdAppendAllowedOutput(aSection); sl@0: } sl@0: else if (aCommand == KCmdRemoveAllowedOutput) sl@0: { sl@0: DoCmdRemoveAllowedOutput(aSection); sl@0: } sl@0: else if (aCommand == KCmdGetAllowedOutput) sl@0: { sl@0: DoCmdGetAllowedOutput(aSection); sl@0: } sl@0: else if (aCommand == KCmdGetAllowedOutputCount) sl@0: { sl@0: DoCmdGetAllowedOutputCount(); sl@0: } sl@0: else if (aCommand == KCmdReset) sl@0: { sl@0: DoCmdReset(); sl@0: } sl@0: else if (aCommand == KCmdCommit) sl@0: { sl@0: DoCmdCommit(); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Unknown command")); sl@0: ret=EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Create a new instance of CRestrictedAudioOutput sl@0: * @param aSection - Section to read from the ini file sl@0: * @return void sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DoCmdNewL(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdNewL()")); sl@0: DestroyData(); sl@0: TPtrC devSoundInstanceName; sl@0: if (!GetStringFromConfig(aSection, KDevSoundInstanceName, devSoundInstanceName)) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDevSoundInstanceName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: CMMFDevSound* mMFDevSound = static_cast(GetDataObjectL(devSoundInstanceName)); sl@0: TInt error; sl@0: if ( !iRestrictedAudioOutput ) sl@0: { sl@0: if ( mMFDevSound ) sl@0: { sl@0: CleanupStack::PushL(mMFDevSound); sl@0: iRestrictedAudioOutput = (CRestrictedAudioOutput*)mMFDevSound->CustomInterface(KUidRestrictedAudioOutput); sl@0: if ( iRestrictedAudioOutput == NULL ) sl@0: { sl@0: ERR_PRINTF1(_L("Failed to create RestrictedAudioOutput")); sl@0: error = KErrNotFound; sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("RestrictedAudioOutput created")); sl@0: CleanupStack::Pop(mMFDevSound); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("DevSound not ready")); sl@0: error = KErrNotReady; sl@0: SetError(error); sl@0: } sl@0: } sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdNewL()")); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Delete an instance of CRestrictedAudioOutput sl@0: * @param sl@0: * @return void sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DoCmdDestructor() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdDestructor()")); sl@0: DestroyData(); sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdDestructor()")); sl@0: } sl@0: sl@0: /** sl@0: * Appends an allowed output to the existing list. sl@0: * @param aSection - The section to read from the ini file sl@0: * @return void sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DoCmdAppendAllowedOutput(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdAppendAllowedOutput()")); sl@0: TInt output; sl@0: if ( !GetEnumFromConfig(aSection, KOutput, iEnumAllowedOutputPreference, output) ) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KOutput); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TInt error; sl@0: error = iRestrictedAudioOutput->AppendAllowedOutput((CRestrictedAudioOutput::TAllowedOutputPreference) output); sl@0: sl@0: if ( (error!=KErrNone) && (error!=KErrAlreadyExists) ) sl@0: { sl@0: ERR_PRINTF2(_L("Error in appending allowed output. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Allowed output 0x%x appended"), (CRestrictedAudioOutput::TAllowedOutputPreference) output); sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdAppendAllowedOutput()")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Removes an allowed output from the existing list. sl@0: * @param aSection - The section to read from the ini file sl@0: * @return void sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DoCmdRemoveAllowedOutput(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdRemoveAllowedOutput()")); sl@0: TInt output; sl@0: if(!GetEnumFromConfig(aSection, KOutput, iEnumAllowedOutputPreference, output)) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KOutput); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TInt error; sl@0: error = iRestrictedAudioOutput->RemoveAllowedOutput((CRestrictedAudioOutput::TAllowedOutputPreference) output); sl@0: if (error != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error in removing allowed output. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Allowed output 0x%x removed"), (CRestrictedAudioOutput::TAllowedOutputPreference) output); sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdRemoveAllowedOutput()")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Gets a reference to an allowed output located at a specified position sl@0: * within the list. sl@0: * @param aSection - The section to read from the ini file sl@0: * @return void sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutput(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutput()")); sl@0: TInt index; sl@0: if ( !GetIntFromConfig(aSection, KIndex, index) ) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KIndex); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TInt error; sl@0: CRestrictedAudioOutput::TAllowedOutputPreference allowedOutput; sl@0: error = iRestrictedAudioOutput->GetAllowedOutput(index, allowedOutput); sl@0: if ( error != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting allowed output. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: switch (allowedOutput) sl@0: { sl@0: case CRestrictedAudioOutput::EAllowAllAudio: sl@0: INFO_PRINTF1(_L("AllowAllAudio")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowAudioAnalog: sl@0: INFO_PRINTF1(_L("AllowAudioAnalog")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowAudioFMTransmitter: sl@0: INFO_PRINTF1(_L("AllowAudioFMTransmitter")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowAudioBtHFPHSP: sl@0: INFO_PRINTF1(_L("AllowAudioBtHFPHSP")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowAudioBtA2DP: sl@0: INFO_PRINTF1(_L("AllowAudioBtA2DP")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowAudioUplink: sl@0: INFO_PRINTF1(_L("AllowAudioUplink")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowAudioUsb: sl@0: INFO_PRINTF1(_L("AllowAudioUsb")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowAudioRecording: sl@0: INFO_PRINTF1(_L("AllowAudioRecording")); sl@0: break; sl@0: case CRestrictedAudioOutput::EAllowVisualization: sl@0: INFO_PRINTF1(_L("AllowVisualization")); sl@0: break; sl@0: default: sl@0: INFO_PRINTF2(_L("Unknown output 0x%x"), allowedOutput); sl@0: } sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutput()")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Gets the number of allowed objects in the array. * sl@0: * @param sl@0: * @return void sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutputCount() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutputCount()")); sl@0: TInt error, size; sl@0: error = iRestrictedAudioOutput->GetAllowedOutputCount(size); sl@0: if(error != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting allowed output count. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Allowed output count: %d"), size); sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutputCount()")); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Empties the list, so that it is ready to be reused. sl@0: * sl@0: * @param sl@0: * @return void sl@0: */ sl@0: void CT_CRestrictedAudioOutputData::DoCmdReset() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdReset()")); sl@0: TInt error; sl@0: error = iRestrictedAudioOutput->Reset(); sl@0: if (error!=KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error in reset. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Reset successfully")); sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdReset()")); sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Applies settings cached locally and commits. sl@0: * sl@0: * This function can only be called when the DevSound instance is in Idle OR sl@0: * Stopped state. sl@0: * @param sl@0: * @return sl@0: */ sl@0: sl@0: void CT_CRestrictedAudioOutputData::DoCmdCommit() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdCommit()")); sl@0: TInt error; sl@0: error = iRestrictedAudioOutput->Commit(); sl@0: if (error != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error in Commit. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Commit successfully")); sl@0: INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdCommit()")); sl@0: } sl@0: }