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_ctelephonyaudioroutingdata.h" sl@0: sl@0: const TUid EEarPiece = TUid::Uid(0x02); sl@0: const TUid EHeadSet = TUid::Uid(0x04); sl@0: /*@{*/ sl@0: //Command literals sl@0: _LIT(KCmdNewL, "NewL"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: _LIT(KCmdAvailableOutputs, "AvailableOutputs"); sl@0: _LIT(KCmdOutput, "Output"); sl@0: _LIT(KCmdPreviousOutput, "PreviousOutput"); sl@0: _LIT(KCmdSetShowNote, "SetShowNote"); sl@0: _LIT(KCmdGetShowNote, "GetShowNote"); sl@0: _LIT(KCmdSetOutputL, "SetOutputL"); sl@0: /*@}*/ sl@0: sl@0: /*@{*/ sl@0: //INI Section name literals sl@0: _LIT(KMode, "Mode"); sl@0: /*@}*/ sl@0: sl@0: /*@{*/ sl@0: //Enumeration Literals sl@0: _LIT(KENotActive, "ENotActive"); sl@0: _LIT(KENone, "ENone"); sl@0: _LIT(KEHandset, "EHandSet"); sl@0: _LIT(KELoudSpeaker, "ELoudSpeaker"); sl@0: _LIT(KEWiredAudioAccessory, "EWiredAudioAccessory"); sl@0: _LIT(KEBTAudioAccessory, "EBTAudioAccessory"); sl@0: _LIT(KETTY, "ETTY"); sl@0: _LIT(KEEarPiece, "EEarPiece"); sl@0: _LIT(KEHeadSet, "EHeadSet"); sl@0: /*@}*/ sl@0: sl@0: const CDataWrapperBase::TEnumEntryTable CT_CTelephonyAudioRoutingData::iEnumOutput[] = sl@0: { sl@0: { KENotActive, CTelephonyAudioRouting::ENotActive}, sl@0: { KENone, CTelephonyAudioRouting::ENone}, sl@0: { KEHandset, CTelephonyAudioRouting::EHandset}, sl@0: { KEEarPiece, EEarPiece.iUid}, sl@0: { KELoudSpeaker, CTelephonyAudioRouting::ELoudspeaker}, sl@0: { KEWiredAudioAccessory, CTelephonyAudioRouting::EWiredAudioAccessory}, sl@0: { KEHeadSet, EHeadSet.iUid}, sl@0: { KEBTAudioAccessory, CTelephonyAudioRouting::EBTAudioAccessory}, sl@0: { KETTY, CTelephonyAudioRouting::ETTY} sl@0: }; sl@0: sl@0: /** sl@0: * Public destructor sl@0: */ sl@0: CT_CTelephonyAudioRoutingData::~CT_CTelephonyAudioRoutingData() sl@0: { sl@0: DestroyData(); sl@0: } sl@0: sl@0: /** sl@0: * Two phase constructor sl@0: * @leave system wide error sl@0: */ sl@0: sl@0: CT_CTelephonyAudioRoutingData* CT_CTelephonyAudioRoutingData::NewL() sl@0: { sl@0: CT_CTelephonyAudioRoutingData* ret = new (ELeave) CT_CTelephonyAudioRoutingData(); sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Private constructor. First phase construction sl@0: */ sl@0: sl@0: CT_CTelephonyAudioRoutingData::CT_CTelephonyAudioRoutingData() sl@0: : sl@0: iTelephonyAudioRouting (NULL) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CT_CTelephonyAudioRoutingData::DestroyData() sl@0: { sl@0: if(iTelephonyAudioRouting) sl@0: { sl@0: delete iTelephonyAudioRouting; sl@0: iTelephonyAudioRouting = NULL; sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * @return pointer to the object that the data wraps sl@0: */ sl@0: TAny* CT_CTelephonyAudioRoutingData::GetObject() sl@0: { sl@0: return iTelephonyAudioRouting; sl@0: } 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: sl@0: TBool CT_CTelephonyAudioRoutingData::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(); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else if (aCommand == KCmdAvailableOutputs) sl@0: { sl@0: DoCmdAvailableOutputs(); sl@0: } sl@0: else if (aCommand == KCmdOutput) sl@0: { sl@0: DoCmdOutput(); sl@0: } sl@0: else if (aCommand == KCmdPreviousOutput) sl@0: { sl@0: DoCmdPreviousOutput(); sl@0: } sl@0: else if (aCommand == KCmdSetShowNote) sl@0: { sl@0: DoCmdSetShowNote(aSection); sl@0: } sl@0: else if (aCommand == KCmdGetShowNote) sl@0: { sl@0: DoCmdGetShowNote(); sl@0: } sl@0: else if (aCommand == KCmdSetOutputL) sl@0: { sl@0: DoCmdSetOutputL(aSection); 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: * Signals that available audio outputs have changed. sl@0: * @param CTelephonyAudioRouting& aTelephonyAudioRouting reference. sl@0: * @return void sl@0: */ sl@0: void CT_CTelephonyAudioRoutingData::AvailableOutputsChanged( CTelephonyAudioRouting& /*aTelephonyAudioRouting*/) sl@0: { sl@0: INFO_PRINTF1(_L("CT_CTelephonyAudioRoutingData::AvailableOutputsChanged")); sl@0: } sl@0: sl@0: /** sl@0: * Signals that current output has changed. sl@0: * @param CTelephonyAudioRouting& aTelephonyAudioRouting reference. sl@0: * @return void sl@0: */ sl@0: void CT_CTelephonyAudioRoutingData::OutputChanged( CTelephonyAudioRouting& /*aTelephonyAudioRouting*/) sl@0: { sl@0: INFO_PRINTF1(_L("CT_CTelephonyAudioRoutingData::OutputChanged")); sl@0: } sl@0: sl@0: /** sl@0: * Signals that CTelephonyAudioRouting::SetOutputL request issued by this sl@0: * application (on CTelephonyAudioRouting instance) was serviced by the sl@0: * Adaptation. sl@0: * Only when the observer receives this callback, the application should consider sl@0: * CTelephonyAudioRouting::SetOutputL message to be completed. sl@0: * sl@0: * @param CTelephonyAudioRouting& aTelephonyAudioRouting reference. sl@0: * @param aError KErrNone if output requested by application is set, else sl@0: * system-wide error code. sl@0: * @return void sl@0: */ sl@0: void CT_CTelephonyAudioRoutingData::SetOutputComplete( CTelephonyAudioRouting& /*aTelephonyAudioRouting*/, TInt aError) sl@0: { sl@0: DecOutstanding(); sl@0: if(aError != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Could not set output complete: %d"), aError); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("CT_CTelephonyAudioRoutingData::SetOutputComplete")); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Create an instance of CTelephonyAudioRouting sl@0: * @param sl@0: * @return sl@0: */ sl@0: void CT_CTelephonyAudioRoutingData::DoCmdNewL() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdNewL")); sl@0: DestroyData(); sl@0: TRAPD(error,iTelephonyAudioRouting = CTelephonyAudioRouting::NewL(*this)); sl@0: if(error!=KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("> Could not create CTelephonyAudioRouting: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("CTelephonyAudioRouting created successfully.")); sl@0: INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdNewL")); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Delete the instance of CTelephonyAudioRouting sl@0: * @param sl@0: * @return sl@0: */ sl@0: void CT_CTelephonyAudioRoutingData::DoCmdDestructor() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdDestructor")); sl@0: DestroyData(); sl@0: INFO_PRINTF1(_L("*END*CTelephonyAudioRouting destroyed successfully.")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Shows the array of currently available outputs. sl@0: * The array contains list of following outputs depending on whether the sl@0: * output is available or not at the time of query: sl@0: * - EHandset sl@0: * - ELoudspeaker sl@0: * - EWiredAudioAccessory, sl@0: * - EWiredAccessory, sl@0: * - EBTAudioAccessory sl@0: * - ETTY sl@0: * Audio can be routed to any of the available outputs in the list. sl@0: * @param sl@0: * @return sl@0: */ sl@0: sl@0: void CT_CTelephonyAudioRoutingData::DoCmdAvailableOutputs() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdAvailableOutputs")); sl@0: TInt availableOutput; sl@0: const TArray& availableOutputsArray(iTelephonyAudioRouting->AvailableOutputs()); sl@0: sl@0: if (availableOutputsArray.Count()==0) sl@0: { sl@0: INFO_PRINTF1(_L("None available output")); sl@0: } sl@0: else sl@0: { sl@0: TBuf<80> msg; sl@0: for (TInt i=0;iOutput(); sl@0: INFO_PRINTF2(_L("Output: 0x%x"),iOutput); sl@0: switch(iOutput) sl@0: { sl@0: case CTelephonyAudioRouting::ENotActive : sl@0: INFO_PRINTF1(_L("Not active")); sl@0: break; sl@0: case CTelephonyAudioRouting::ENone : sl@0: INFO_PRINTF1(_L("None")); sl@0: break; sl@0: case CTelephonyAudioRouting::EHandset : sl@0: INFO_PRINTF1(_L("Handset")); sl@0: break; sl@0: case CTelephonyAudioRouting::ELoudspeaker : sl@0: INFO_PRINTF1(_L("Loudspeaker")); sl@0: break; sl@0: case CTelephonyAudioRouting::EWiredAudioAccessory : sl@0: INFO_PRINTF1(_L("Wired acc")); sl@0: break; sl@0: case CTelephonyAudioRouting::EBTAudioAccessory : sl@0: INFO_PRINTF1(_L("BT audio acc")); sl@0: break; sl@0: case CTelephonyAudioRouting::ETTY : sl@0: INFO_PRINTF1(_L("ETTY")); sl@0: break; sl@0: default: sl@0: INFO_PRINTF2(_L("0x%x"), iOutput); sl@0: } sl@0: INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdOutput")); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Show the second last output that was successfully configured to sl@0: * play telephony audio. sl@0: * @param none. sl@0: * @return void sl@0: */ sl@0: sl@0: void CT_CTelephonyAudioRoutingData::DoCmdPreviousOutput() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdPreviousOutput")); sl@0: CTelephonyAudioRouting::TAudioOutput previousOutput; sl@0: previousOutput = iTelephonyAudioRouting->PreviousOutput(); sl@0: INFO_PRINTF2(_L("Previous audio output: 0x%x"), previousOutput); sl@0: switch (previousOutput) sl@0: { sl@0: case CTelephonyAudioRouting::ENotActive: sl@0: INFO_PRINTF1(_L("Not active")); sl@0: break; sl@0: case CTelephonyAudioRouting::ENone: sl@0: INFO_PRINTF1(_L("None")); sl@0: break; sl@0: case CTelephonyAudioRouting::EHandset: sl@0: INFO_PRINTF1(_L("Handset")); sl@0: break; sl@0: case CTelephonyAudioRouting::ELoudspeaker: sl@0: INFO_PRINTF1(_L("Loudspeaker")); sl@0: break; sl@0: case CTelephonyAudioRouting::EWiredAudioAccessory: sl@0: INFO_PRINTF1(_L("Wired acc")); sl@0: break; sl@0: case CTelephonyAudioRouting::EBTAudioAccessory: sl@0: INFO_PRINTF1(_L("BT audio acc")); sl@0: break; sl@0: case CTelephonyAudioRouting::ETTY: sl@0: INFO_PRINTF1(_L("ETTY")); sl@0: break; sl@0: default: sl@0: INFO_PRINTF2(_L("0x%x"), previousOutput); sl@0: } sl@0: INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdPreviousOutput")); sl@0: } sl@0: sl@0: sl@0: /* sl@0: * Sends the Show Note mode to server along with the next SetOutputL() sl@0: * request. sl@0: * After SetOutputL() request from the Application is succesfully sl@0: * processed by the server and application receives SetOutputComplete() sl@0: * callback with KErrNone, it can query Show Note mode sent to server by sl@0: * calling GetShowNote(). sl@0: * Other observers wanting to query Show Note mode can call GetShowNote() sl@0: * after receiving OutputChanged() callback. sl@0: * sl@0: * @param aSection the Section to read from the ini file. sl@0: * @return sl@0: */ sl@0: sl@0: void CT_CTelephonyAudioRoutingData::DoCmdSetShowNote(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdSetShowNote")); sl@0: TBool mode; sl@0: if(!GetBoolFromConfig(aSection, KMode, mode)) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KMode); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TInt error = iTelephonyAudioRouting->SetShowNote(mode); sl@0: if (error != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Could not set show note. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Mode set to: %d"), mode); sl@0: INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdSetShowNote")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Shows the Show Note mode for the last succesfully completed sl@0: * SetOutputL() request. sl@0: * @param sl@0: * @return sl@0: */ sl@0: sl@0: sl@0: void CT_CTelephonyAudioRoutingData::DoCmdGetShowNote() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdGetShowNote")); sl@0: TBool mode; sl@0: TInt error = iTelephonyAudioRouting->GetShowNote(mode); sl@0: if(error != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Could not get show note. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Mode: %d"), mode); sl@0: INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdGetShowNote")); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Sends an asynchronous request to Adaptation to set the output sl@0: * where telephony audio will be routed. This request is completed only sl@0: * when the application receives sl@0: * MTelephonyAudioRoutingObserver::SetOutputComplete callback. sl@0: * @param aSection - The section to read from the ini file sl@0: * @return none. sl@0: */ sl@0: sl@0: void CT_CTelephonyAudioRoutingData::DoCmdSetOutputL(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdSetOutputL")); sl@0: TInt output; sl@0: if (!GetEnumFromConfig(aSection, KCmdOutput, iEnumOutput, output)) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KCmdOutput); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: if(iOutput!=output) sl@0: { sl@0: TRAPD(error, iTelephonyAudioRouting->SetOutputL((CTelephonyAudioRouting::TAudioOutput)output)); sl@0: IncOutstanding(); sl@0: if (error != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Could not set output. Error: %d"), error); sl@0: SetError(error); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Output set to: ")); sl@0: switch (output) sl@0: { sl@0: case CTelephonyAudioRouting::ENotActive: sl@0: INFO_PRINTF1(_L("Not active")); sl@0: break; sl@0: case CTelephonyAudioRouting::ENone: sl@0: INFO_PRINTF1(_L("None")); sl@0: break; sl@0: case CTelephonyAudioRouting::EHandset: sl@0: INFO_PRINTF1(_L("Handset")); sl@0: break; sl@0: case CTelephonyAudioRouting::ELoudspeaker: sl@0: INFO_PRINTF1(_L("Loudspeaker")); sl@0: break; sl@0: case CTelephonyAudioRouting::EWiredAudioAccessory: sl@0: INFO_PRINTF1(_L("Wired acc")); sl@0: break; sl@0: case CTelephonyAudioRouting::EBTAudioAccessory: sl@0: INFO_PRINTF1(_L("BT audio acc")); sl@0: break; sl@0: case CTelephonyAudioRouting::ETTY: sl@0: INFO_PRINTF1(_L("ETTY")); sl@0: break; sl@0: default: sl@0: INFO_PRINTF2(_L("%d"), output); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdSetOutputL")); sl@0: }