mmserv/callaudiocontrol/src/CallAudioControlImpl.cpp
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This is the implementation of the CCallAudioControlImpl class.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CallAudioControlImpl.h"
       
    20 #include "CallAudioControlUtility.h"
       
    21 #include "CallAudioControlProperty.h"
       
    22 #include "CallAudioControlRepository.h"
       
    23 #include "CallAudioControlCommon.h"
       
    24 
       
    25 
       
    26 #ifdef __SERIES60_31__
       
    27 #include <features.hrh>
       
    28 #include <FeatMgr.h>
       
    29 #include <MediatorDomainUIDs.h>
       
    30 #include <e32property.h>
       
    31 #include <KPhEngConstants.h>
       
    32 _LIT(KPhoneCltExDllName, "PhoneClientExt.dll");
       
    33 #endif
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CCCallAudioControlImpl::NewL
       
    37 //
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CCallAudioControlImpl* CCallAudioControlImpl::NewL()
       
    41     {
       
    42     CCallAudioControlImpl* self = new (ELeave) CCallAudioControlImpl();
       
    43     CleanupStack::PushL(self);
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CCallAudioControlImpl::CCallAudioControlImpl
       
    51 // C++ constructor.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CCallAudioControlImpl::CCallAudioControlImpl()
       
    55     {
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CCallAudioControlImpl::ConstructL
       
    60 // Symbian 2nd phase constructor can leave.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CCallAudioControlImpl::ConstructL()
       
    64 {
       
    65 	CAC_TRACE1(_L("CCallAudioControlImpl::ConstructL enter"));
       
    66 #ifdef __WINS__
       
    67 	iWinsTesting = ETrue;
       
    68 #endif
       
    69 	//Create objects for data base access (both Central Repository and Publish and Subscribe):
       
    70 	iCsNotifier = CCallAudioControlProperty::NewL(this, KUidCallInfo, KTelephonyCallState, ECallState );
       
    71 #ifdef __SERIES60_31__
       
    72 	CAC_TRACE1(_L("CCallAudioControlImpl::ConstructL Creating CMediatorCommandInitiator for 3.1 "));
       
    73     iCommandInitiator = CMediatorCommandInitiator::NewL( this );
       
    74     iMuteNotifier = CCallAudioControlProperty::NewL(this,KUidSystemCategory, KUidMute.iUid, EMute);
       
    75 #else
       
    76     CAC_TRACE1(_L("CCallAudioControlImpl::ConstructL Creating CPhoneClient for non 3.1 "));
       
    77     iPhoneClient = CPhCltCommandHandler::NewL();
       
    78     iMuteNotifier = CCallAudioControlProperty::NewL(this,KUidMute, KTelephonyMute, EMute);
       
    79 #endif
       
    80 	iIhfVolumeNotifier = CCallAudioControlRepository::NewL(this,KUidVolume, KTelephonyIHFVolume, EIHFVolume);
       
    81 	iEpVolumeNotifier = CCallAudioControlRepository::NewL(this, KUidVolume, KTelephonyEPVolume, EEPVolume);
       
    82     // Get current call state and is it active:
       
    83     TBool active = IsCallActive();
       
    84 	CAC_TRACE2(_L("CCallAudioControl: Current Call State: %d"),iCallState);
       
    85    	// If in active call create TAR, get current audio output routing and
       
    86    	// get volume (based on audio routing) and set iVolume:
       
    87 	if (active)
       
    88 	{
       
    89         CAC_TRACE1(_L("CCallAudioControl: Active Call: Setting iVolume, etc..."));
       
    90 		iTelephonyAudioRouting = CTelephonyAudioRouting::NewL(*this);
       
    91 		iCurrentAudioOutput = (CCallAudioControl::TAudioOutput)iTelephonyAudioRouting->Output();
       
    92 		TInt error = GetVolume();
       
    93 	}
       
    94 	else // Otherwise, get EP volume and set iVolume = EPVolume
       
    95 	{
       
    96    		TInt error = iEpVolumeNotifier->Get(iVolume);
       
    97    		CAC_TRACE2(_L("CCallAudioControl: Not active call, setting iVolume to EPVolume = %d"),iVolume);
       
    98 	}
       
    99 	// Subscribe for call state changes:
       
   100 	// if CAC is created before an active call, then we need to subscribe to Telephony notifications whenever the
       
   101 	// the call is active, so that CAC can create TAR for audio routing
       
   102    	iCsNotifier->Subscribe();
       
   103 	CAC_TRACE1(_L("CCallAudioControlImpl::ConstructL exit"));
       
   104 }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CCallAudioControlImpl::DestructL
       
   108 // Destructor
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CCallAudioControlImpl::~CCallAudioControlImpl()
       
   112     {
       
   113 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::~AudioOutputControlImpl enter"),this);
       
   114     // Empty arrays:
       
   115     iRoutingObservers.Reset();
       
   116     iDownlinkVolumeObservers.Reset();
       
   117   	iUplinkGainObservers.Reset();
       
   118 	CAC_TRACE2(_L("~CAudioOutputControlImpl: Deleting Volume Notifiers..."),this);
       
   119 	delete iEpVolumeNotifier;
       
   120 	delete iIhfVolumeNotifier;
       
   121 	CAC_TRACE2(_L("~CAudioOutputControlImpl: Deleting Call State Notifier..."),this);
       
   122 	delete iCsNotifier;
       
   123 	CAC_TRACE2(_L("~CAudioOutputControlImpl: Deleting Mute Notifier..."),this);
       
   124 	delete iMuteNotifier;
       
   125 	CAC_TRACE2(_L("~CAudioOutputControlImpl: Deleting TAR..."),this);
       
   126 	delete iTelephonyAudioRouting;
       
   127 #ifdef __SERIES60_31__
       
   128     CAC_TRACE2(_L("~CAudioOutputControlImpl: Deleting iCommandInitiator (3.1 ONLY)..."),this);
       
   129     delete iCommandInitiator;
       
   130 #else
       
   131 	CAC_TRACE2(_L("~CAudioOutputControlImpl: Deleting iPhoneClient..."),this);
       
   132 	delete iPhoneClient;
       
   133 #endif
       
   134 
       
   135 
       
   136 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::~AudioOutputControlImpl exit"),this);
       
   137 
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // CCallAudioControlImpl::AppendRoutingObserver
       
   142 // ?implementation_description
       
   143 // (other items were commented in a header).
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 TInt CCallAudioControlImpl::AppendRoutingObserver(CRoutingObserver& aObserver)
       
   147     {
       
   148 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::AppendRoutingObserver enter"),this);
       
   149 	// Return with error if it's already in list:
       
   150 	for( TInt i = 0; i < iRoutingObservers.Count(); i++ )
       
   151    	{
       
   152         if ( iRoutingObservers[i] == &aObserver )
       
   153        	{
       
   154 			CAC_TRACE1(_L("AppendRoutingObserver ERROR: Already Exists"));
       
   155             return KErrAlreadyExists;
       
   156       	}
       
   157  	}
       
   158 	iRoutingObservers.Append(&aObserver);
       
   159 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::AppendRoutingObserver exit"),this);
       
   160 	return KErrNone;
       
   161 
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------
       
   165 // CCallAudioControlImpl::RemoveRoutingObserver
       
   166 // ?implementation_description
       
   167 // (other items were commented in a header).
       
   168 // ---------------------------------------------------------
       
   169 //
       
   170 TInt CCallAudioControlImpl::RemoveRoutingObserver(CRoutingObserver& aObserver)
       
   171     {
       
   172 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::RemoveRoutingObserver enter"),this);
       
   173 	TInt error(KErrNotFound);
       
   174 	for( TInt i = 0; i < iRoutingObservers.Count(); i++ )
       
   175    	{
       
   176         if ( iRoutingObservers[i] == &aObserver )
       
   177        	{
       
   178             iRoutingObservers.Remove(i);
       
   179             error = KErrNone;
       
   180             break;
       
   181       	}
       
   182  	}
       
   183 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::RemoveRoutingObserver exit with error: %d"),this, error);
       
   184 	return error;
       
   185 
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------
       
   189 // CCallAudioControlImpl::AppendDownlinkVolumeObserver
       
   190 // ?implementation_description
       
   191 // (other items were commented in a header).
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 TInt CCallAudioControlImpl::AppendDownlinkVolumeObserver(CDownlinkVolumeObserver& aObserver)
       
   195 {
       
   196 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::AppendDownlinkVolumeObserver enter"),this);
       
   197 	// Return with error if it's already in list:
       
   198 	for( TInt i = 0; i < iDownlinkVolumeObservers.Count(); i++ )
       
   199    	{
       
   200         if ( iDownlinkVolumeObservers[i] == &aObserver )
       
   201        	{
       
   202 			CAC_TRACE1(_L("AppendDownlinkVolumeObserver ERROR: Already Exists"));
       
   203             return KErrAlreadyExists;
       
   204       	}
       
   205  	}
       
   206 	iDownlinkVolumeObservers.Append(&aObserver);
       
   207 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::AppendDownlinkVolumeObserver exit"),this);
       
   208 	return KErrNone;
       
   209 
       
   210 }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CCallAudioControlImpl::RemoveDownlinkVolumeObserver
       
   214 // ?implementation_description
       
   215 // (other items were commented in a header).
       
   216 // ---------------------------------------------------------
       
   217 //
       
   218 TInt CCallAudioControlImpl::RemoveDownlinkVolumeObserver(CDownlinkVolumeObserver& aObserver)
       
   219     {
       
   220 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::RemoveDownlinkVolumeObserver enter"),this);
       
   221 	TInt error(KErrNotFound);
       
   222 	for( TInt i = 0; i < iDownlinkVolumeObservers.Count(); i++ )
       
   223    	{
       
   224         if ( iDownlinkVolumeObservers[i] == &aObserver )
       
   225        	{
       
   226             iDownlinkVolumeObservers.Remove(i);
       
   227             error = KErrNone;
       
   228       	}
       
   229  	}
       
   230 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::RemoveDownlinkVolumeObserver exit with error: %d"),this, error);
       
   231 	return error;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // CCallAudioControlImpl::AppendUplinkGainObserver
       
   236 // ?implementation_description
       
   237 // (other items were commented in a header).
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 TInt CCallAudioControlImpl::AppendUplinkGainObserver(CUplinkGainObserver& aObserver)
       
   241     {
       
   242 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::AppendUplinkGainObserver enter"),this);
       
   243 	TInt error(KErrNone);
       
   244 	// Return with error if it's already in list:
       
   245 	for( TInt i = 0; i < iUplinkGainObservers.Count(); i++ )
       
   246    	{
       
   247         if ( iUplinkGainObservers[i] == &aObserver )
       
   248        	{
       
   249 			CAC_TRACE1(_L("AppendUplinkGainObserver ERROR: Already Exists"));
       
   250             return KErrAlreadyExists;
       
   251       	}
       
   252  	}
       
   253 	error = iUplinkGainObservers.Append(&aObserver);
       
   254     if (error == KErrNone)
       
   255     {
       
   256    		iMuteNotifier->Subscribe();
       
   257     }
       
   258 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::AppendUplinkGainObserver Error [%d] exit"),this, error);
       
   259     return error;
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------
       
   263 // CCallAudioControlImpl::RemoveUplinkGainObserver
       
   264 // ?implementation_description
       
   265 // (other items were commented in a header).
       
   266 // ---------------------------------------------------------
       
   267 //
       
   268 TInt CCallAudioControlImpl::RemoveUplinkGainObserver(CUplinkGainObserver& aObserver)
       
   269 {
       
   270 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]RemoveUplinkGainObserver enter"),this);
       
   271 	TInt error(KErrNotFound);
       
   272 	for( TInt i = 0; i < iUplinkGainObservers.Count(); i++ )
       
   273    	{
       
   274         if ( iUplinkGainObservers[i] == &aObserver )
       
   275        	{
       
   276             iUplinkGainObservers.Remove(i);
       
   277             error = KErrNone;
       
   278       	}
       
   279  	}
       
   280  	// Unsubscribe for mute updates if list is empty and currently subscribed
       
   281  	if ( !iUplinkGainObservers.Count() )
       
   282  	{
       
   283 		iMuteNotifier->Unsubscribe();
       
   284  	}
       
   285 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::RemoveUplinkGainObserver exit with error: %d"),this, error);
       
   286  	return error;
       
   287 }
       
   288 
       
   289 // ---------------------------------------------------------
       
   290 // CCallAudioControlImpl::GetAvaliableOutputs
       
   291 // ?implementation_description
       
   292 // (other items were commented in a header).
       
   293 // ---------------------------------------------------------
       
   294 //
       
   295 TInt CCallAudioControlImpl::GetAvailableOutputs(RArray<CCallAudioControl::TAudioOutput>& aAvailableOutputs)
       
   296 {
       
   297 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::GetAvailableOutputs enter"),this);
       
   298     TInt error(KErrNone);
       
   299     CCallAudioControl::TAudioOutput arrayElement;
       
   300     TBool active = IsCallActive();
       
   301    	if (active)
       
   302     {
       
   303     	if (!iTelephonyAudioRouting)
       
   304     	{
       
   305             CAC_TRACE1(_L("CCallAudioControlImpl[%x]::GetAvailableOutputs TAR not available "));
       
   306             return KErrCompletion;
       
   307     	}
       
   308 		TArray<CTelephonyAudioRouting::TAudioOutput> availableOutputArray = iTelephonyAudioRouting->AvailableOutputs();
       
   309 		TInt arrayCount = availableOutputArray.Count();
       
   310  		for (TInt i = 0; i < arrayCount; i++)
       
   311   		{
       
   312        		CAC_TRACE3(_L("AvailableOutput[%d] = %d"), i, availableOutputArray[i]);
       
   313        		arrayElement = (CCallAudioControl::TAudioOutput)(availableOutputArray[i]);
       
   314       		aAvailableOutputs.Append(arrayElement);
       
   315    		}
       
   316     }
       
   317     else
       
   318     	error = KErrPermissionDenied;
       
   319 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::GetAvailableOutputs exit with error: %d"),this, error);
       
   320     return error;
       
   321 }
       
   322 
       
   323 // ---------------------------------------------------------
       
   324 // CCallAudioControlImpl::GetOutput
       
   325 // ?implementation_description
       
   326 // (other items were commented in a header).
       
   327 // ---------------------------------------------------------
       
   328 //
       
   329 TInt CCallAudioControlImpl::GetOutput(CCallAudioControl::TAudioOutput& aOutput)
       
   330 {
       
   331 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::GetOutput enter"),this);
       
   332 	TInt error(KErrNone);
       
   333     TBool active = IsCallActive();
       
   334    	if (active)
       
   335     {
       
   336     	if (!iTelephonyAudioRouting)
       
   337     	{
       
   338             CAC_TRACE1(_L("CCallAudioControlImpl[%x]::GetOutput TAR not available "));
       
   339             return KErrCompletion;
       
   340     	}
       
   341  		aOutput = (CCallAudioControl::TAudioOutput)(iTelephonyAudioRouting->Output());
       
   342  		iCurrentAudioOutput = aOutput;
       
   343 		CAC_TRACE2(_L("GetOutput: Output retrieved: %d"),aOutput);
       
   344     }
       
   345     else
       
   346     	error = KErrPermissionDenied;
       
   347 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::GetOutput exit with error: %d"),this, error);
       
   348 
       
   349     return error;
       
   350 }
       
   351 
       
   352 // ---------------------------------------------------------
       
   353 // CCallAudioControlImpl::::SetOutput
       
   354 // ?implementation_description
       
   355 // (other items were commented in a header).
       
   356 // ---------------------------------------------------------
       
   357 //
       
   358 TInt CCallAudioControlImpl::SetOutput(CCallAudioControl::TAudioOutput aOutput)
       
   359 {
       
   360 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetOutput with: %d"),this, aOutput);
       
   361     TInt error(KErrNone);
       
   362     TBool active = IsCallActive();
       
   363    	if (active)
       
   364     {
       
   365     	if (!iTelephonyAudioRouting)
       
   366     	{
       
   367             CAC_TRACE1(_L("CCallAudioControlImpl[%x]::SetOutput TAR not available "));
       
   368             return KErrCompletion;
       
   369     	}
       
   370 
       
   371     	if ((aOutput == CTelephonyAudioRouting::ENone) || (aOutput == CTelephonyAudioRouting::ENotActive))
       
   372     	{
       
   373     		return (KErrArgument);
       
   374     	}
       
   375 		TRAP(error,iTelephonyAudioRouting->SetOutputL((CTelephonyAudioRouting::TAudioOutput)aOutput));
       
   376     }
       
   377     else
       
   378     {
       
   379 		error = KErrPermissionDenied;
       
   380     }
       
   381 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetOutput exit with error: %d"),this, error);
       
   382     return error;
       
   383 }
       
   384 
       
   385 // ---------------------------------------------------------
       
   386 // CCallAudioControlImpl::::PreviousOutput
       
   387 // ?implementation_description
       
   388 // (other items were commented in a header).
       
   389 // ---------------------------------------------------------
       
   390 //
       
   391 TInt CCallAudioControlImpl::PreviousOutput(CCallAudioControl::TAudioOutput& aPreviousOutput)
       
   392 {
       
   393 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::PreviousOutput enter"),this);
       
   394     TInt error(KErrNone);
       
   395     TBool active = IsCallActive();
       
   396    	if (active)
       
   397     {
       
   398     	if (!iTelephonyAudioRouting)
       
   399     	{
       
   400             CAC_TRACE1(_L("CCallAudioControlImpl[%x]::PreviousOutput TAR not available "));
       
   401             return KErrCompletion;
       
   402     	}
       
   403 		aPreviousOutput = (CCallAudioControl::TAudioOutput)iTelephonyAudioRouting->PreviousOutput();
       
   404     }
       
   405     else
       
   406     {
       
   407     	error = KErrPermissionDenied;
       
   408     }
       
   409 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::PreviousOutput exit with error: %d"),this, error);
       
   410     return error;
       
   411 }
       
   412 
       
   413 // ---------------------------------------------------------
       
   414 // CCallAudioControlImpl::GetMinDownlinkVolume
       
   415 // ?implementation_description
       
   416 // (other items were commented in a header).
       
   417 // ---------------------------------------------------------
       
   418 //
       
   419 TInt CCallAudioControlImpl::GetMinDownlinkVolume(TUint& aVolume)
       
   420     {
       
   421 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::GetMinDownlinkVolume"),this);
       
   422     // Hard-coded to 0:
       
   423     aVolume = KMinVolume;
       
   424     return KErrNone;
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------
       
   428 // CCallAudioControlImpl::GetDownlinkVolume
       
   429 // ?implementation_description
       
   430 // (other items were commented in a header).
       
   431 // ---------------------------------------------------------
       
   432 //
       
   433 TInt CCallAudioControlImpl::GetDownlinkVolume(TUint& aVolume)
       
   434     {
       
   435 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::GetDownlinkVolume will return: iVolume"),this, iVolume);
       
   436 	TInt error(KErrNone);
       
   437 	if (iVolume < 0) // An error occurred while getting iVolume form DBase prior
       
   438 	{
       
   439 		error = iVolume; // return error to client
       
   440 	}
       
   441 	else
       
   442 	{
       
   443     	aVolume = iVolume;
       
   444 	}
       
   445     return error;
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------
       
   449 // CCallAudioControlImpl::GetMaxDownlinkVolume
       
   450 // ?implementation_description
       
   451 // (other items were commented in a header).
       
   452 // ---------------------------------------------------------
       
   453 //
       
   454 TInt CCallAudioControlImpl::GetMaxDownlinkVolume(TUint& aVolume)
       
   455     {
       
   456 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::GetMaxDownlinkVolume"),this);
       
   457     // Hard-coded to 10:
       
   458     aVolume = KMaxVolume;
       
   459     return KErrNone;
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------
       
   463 // CCallAudioControlImpl::SetDownlinkVolume
       
   464 // ?implementation_description
       
   465 // (other items were commented in a header).
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 TInt CCallAudioControlImpl::SetDownlinkVolume(TUint aVolume)
       
   469     {
       
   470 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetDownlinkVolume to: %d"),this, aVolume);
       
   471 	TInt newVolume = 0;
       
   472     // Verify OK to set volume, which is only allowed during an
       
   473     // active call and if audio routing is appropriate:
       
   474     TInt error = CheckIfOkToSetVolume();
       
   475     if (error != KErrNone)
       
   476     {
       
   477 	CAC_TRACE2(_L("SetDownlinkVolume: ERROR: %d"), error);
       
   478    	return error;
       
   479     }
       
   480     // Make sure aVolume range is valid and set newVolume:
       
   481     newVolume = VerifyAndSetVolume(aVolume);
       
   482     TUint currVol;
       
   483     RETURN_IF_ERROR(GetDownlinkVolume(currVol));
       
   484     if (currVol !=  aVolume)
       
   485         {
       
   486         // Update correct volume key, based on current audio routing:
       
   487         if ( (iCurrentAudioOutput == CTelephonyAudioRouting::EHandset) || (iCurrentAudioOutput == CTelephonyAudioRouting::EWiredAudioAccessory))
       
   488         {
       
   489             error = iEpVolumeNotifier->Set(newVolume);
       
   490             iPendingEpVolLevelOp = ETrue;
       
   491             iRequestedEpVolLevel = aVolume;
       
   492         }
       
   493         else if (iCurrentAudioOutput == CTelephonyAudioRouting::ELoudspeaker)
       
   494         {
       
   495             error = iIhfVolumeNotifier->Set(newVolume);
       
   496             iPendingIhfVolLevelOp = ETrue;
       
   497             iRequestedIhfVolLevel = aVolume;
       
   498         }
       
   499         else
       
   500             error = KErrArgument; // invalid iCurrentAudioOutput value
       
   501         }
       
   502 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetDownlinkVolume exit with error: %d"),this, error);
       
   503     return error;
       
   504 
       
   505     }
       
   506 
       
   507 // ---------------------------------------------------------
       
   508 // CCallAudioControlImpl::GetUplinkMute
       
   509 // ?implementation_description
       
   510 // (other items were commented in a header).
       
   511 // ---------------------------------------------------------
       
   512 //
       
   513 TInt CCallAudioControlImpl::GetUplinkMute(TBool& aMute)
       
   514 {
       
   515 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::GetUplinkMute enter"),this);
       
   516    	TInt error = iMuteNotifier->Get(aMute);
       
   517    	RETURN_IF_ERROR(error);
       
   518 #ifdef __SERIES60_31__
       
   519     if (aMute == EPSMicMuteOn)
       
   520         aMute = ETrue;
       
   521     else if ((aMute == EPSMicMuteOff) || (aMute == EPSMicMuteStateUninitialized))
       
   522         aMute = EFalse;
       
   523     else
       
   524         error = KErrUnknown;
       
   525 #else
       
   526     /* 3.2 and beyond: */
       
   527     /* 3.2 also appears to be an enum defined in s60/app/telephony/inc/KPhEngConstants.h
       
   528      * Check with component owner */
       
   529     #ifndef __SERIES60_32__ /* 5.0 and beyond */
       
   530         if (aMute == EPSTelMicMuteOn)
       
   531             aMute = ETrue;
       
   532         else if ((aMute == EPSTelMicMuteOff) || (aMute == EPSTelMicMuteStateUninitialized))
       
   533             aMute = EFalse;
       
   534         else
       
   535             error = KErrUnknown;
       
   536     #endif /*#ifndef __SERIES60_32__*/
       
   537 #endif /*#ifdef __SERIES60_31__*/
       
   538 
       
   539 	CAC_TRACE2(_L("GetUplinkMute: aMute: %d"),aMute);
       
   540 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::GetUplinkMute exit with error: %d"),this, error);
       
   541 	return error;
       
   542 }
       
   543 
       
   544 // ---------------------------------------------------------
       
   545 // CCallAudioControlImpl::SetUplinkMute
       
   546 // ?implementation_description
       
   547 // (other items were commented in a header).
       
   548 // ---------------------------------------------------------
       
   549 //
       
   550 TInt CCallAudioControlImpl::SetUplinkMute(TBool aMute)
       
   551     {
       
   552 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetUplinkMute with %d"),this, aMute);
       
   553 	// Set only if active call:
       
   554     TInt error(KErrNone);
       
   555     TBool active = IsCallActive();
       
   556 	if (active)
       
   557 	{
       
   558 		if (iWinsTesting)
       
   559 		{
       
   560 			error = KErrPermissionDenied;
       
   561 		}
       
   562 		else
       
   563 		{
       
   564 		TBool curMuteState;
       
   565 		RETURN_IF_ERROR(GetUplinkMute(curMuteState));
       
   566 		if (aMute != curMuteState)
       
   567 		    {
       
   568             error = SetMute(aMute); // Mute audio
       
   569             iPendingMuteSetOp = ETrue;
       
   570             iRequestedMuteState = aMute;
       
   571 		    }
       
   572 		}
       
   573 	}
       
   574 	else
       
   575 	{
       
   576 		error = KErrPermissionDenied;
       
   577 	}
       
   578 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetUplinkMute exit with error: %d"),this, error);
       
   579     return error;
       
   580     }
       
   581 
       
   582 // ---------------------------------------------------------
       
   583 // CCallAudioControlImpl::SetMute
       
   584 // ?implementation_description
       
   585 // (other items were commented in a header).
       
   586 // ---------------------------------------------------------
       
   587 //
       
   588 TInt CCallAudioControlImpl::SetMute(TBool aMute)
       
   589     {
       
   590 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetMute Enter with %d"),this, aMute);
       
   591 	TInt error(KErrNone);
       
   592 #ifdef __SERIES60_31__
       
   593 	TBool coverUIPresent = EFalse;
       
   594     FeatureManager::InitializeLibL();
       
   595     coverUIPresent = FeatureManager::FeatureSupported( KFeatureIdCoverDisplay );
       
   596     FeatureManager::UnInitializeLib();
       
   597 	if ( coverUIPresent )
       
   598 	    {
       
   599         TSESetMicrophonePckg pckg(aMute);
       
   600 	    error = iCommandInitiator->IssueCommand( KMediatorSecondaryDisplayDomain,
       
   601 	            KTSECategory, ECmdMuteOrUnmuteMicrophone, TVersion( KVersioMajor, KVersioMinor, KVersioBuild ), pckg );
       
   602 	    }
       
   603 	else
       
   604 	    {
       
   605         TRequestStatus status;
       
   606         TInt libEntry;
       
   607         // In S60 3.1 CPhCltCommandHandler cannot be directly used. From 3.2 onwards it can be used directly.
       
   608         CPhCltExtFactory* phCltExtFactory = NULL;
       
   609         CPhCltCommandHandler* phCommandHandler = NULL;
       
   610         User::LeaveIfError( iPhoneClientServer.Connect() );
       
   611         User::LeaveIfError( iLibrary.Load( KPhoneCltExDllName ) );
       
   612         libEntry = iLibrary.Lookup(1)();
       
   613         phCltExtFactory = reinterpret_cast<CPhCltExtFactory*>( libEntry );
       
   614         if (phCltExtFactory)
       
   615             {
       
   616             phCommandHandler = phCltExtFactory->CPhCltCommandHandlerLD();
       
   617             User::LeaveIfError( phCommandHandler->Open( iPhoneClientServer ) );
       
   618             if (aMute)
       
   619                 {
       
   620                 phCommandHandler->MuteMicrophone(status, ETrue);
       
   621                 }
       
   622             else
       
   623                 {
       
   624                 phCommandHandler->MuteMicrophone(status, EFalse);
       
   625                 }
       
   626             User::WaitForRequest( status );
       
   627             if (status.Int() != KErrNone)
       
   628                 {
       
   629                 error = KErrGeneral;
       
   630                 }
       
   631             }
       
   632         phCommandHandler = NULL;
       
   633         phCltExtFactory = NULL;
       
   634         iLibrary.Close();
       
   635         iPhoneClientServer.Close();
       
   636 	    }
       
   637 #else
       
   638 	TRequestStatus status;
       
   639 	if (aMute)
       
   640 		iPhoneClient->MuteMicrophone(status, ETrue);
       
   641 	else
       
   642 		iPhoneClient->MuteMicrophone(status, EFalse);
       
   643 	User::WaitForRequest( status );
       
   644 	if (status.Int() != KErrNone)
       
   645 	{
       
   646 		CAC_TRACE2(_L("SetMute: ERROR from PhoneClient->MuteMic: %d"),status.Int());
       
   647 		error = KErrGeneral;
       
   648 	}
       
   649 #endif /*#ifdef __SERIES60_31__*/
       
   650 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetMute exit with error: %d"),this, error);
       
   651     return error;
       
   652     }
       
   653 // ---------------------------------------------------------
       
   654 // CCallAudioControlImpl::GetVolume
       
   655 // ?implementation_description
       
   656 // (other items were commented in a header).
       
   657 // ---------------------------------------------------------
       
   658 //
       
   659 TInt CCallAudioControlImpl::GetVolume()
       
   660  {
       
   661 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::GetVolume enter"),this);
       
   662 	CAC_TRACE2(_L("GetVolume: current audio output = %d"),iCurrentAudioOutput);
       
   663 	TInt error(KErrNone);
       
   664 	switch (iCurrentAudioOutput)
       
   665 	{
       
   666 		case CTelephonyAudioRouting::ENotActive:
       
   667 		case CTelephonyAudioRouting::ENone:
       
   668         case CTelephonyAudioRouting::EBTAudioAccessory:
       
   669 		case CTelephonyAudioRouting::ETTY:
       
   670 			CAC_TRACE1(_L("GetVolume: Audio Routing = Not Active, None, BT or TTY. iVolume set to -19"));
       
   671 			iVolume = KErrUnknown;
       
   672 			iEpVolumeNotifier->NotifyCancel();
       
   673 			iIhfVolumeNotifier->NotifyCancel();
       
   674 			break;
       
   675 		case CTelephonyAudioRouting::EHandset:
       
   676 		case CTelephonyAudioRouting::EWiredAudioAccessory:
       
   677 		    // iVolume = EP Volume, cancel IHF subscription, subscribe to EP
       
   678 			CAC_TRACE1(_L("GetVolume: Audio Routing = Handset or Wired accessory: Get EPVolume"));
       
   679    			error = iEpVolumeNotifier->Get(iVolume);
       
   680    			if (error != KErrNone)
       
   681    			{
       
   682 				CAC_TRACE2(_L("GetVolume: Error returned from EP Volume Get: %d"),error);
       
   683    			}
       
   684 			iIhfVolumeNotifier->NotifyCancel();
       
   685 			iEpVolumeNotifier->NotifyRequest();
       
   686 			break;
       
   687 		case CTelephonyAudioRouting::ELoudspeaker:
       
   688 			// iVolume = IHF volume, cancel EP subscription, subscribe to IHF
       
   689 			CAC_TRACE1(_L("GetVolume: Audio Routing = Loudspeaker: Get IHF Volume"));
       
   690    			error = iIhfVolumeNotifier->Get( iVolume );
       
   691    			if (error != KErrNone)
       
   692    			{
       
   693 				CAC_TRACE2(_L("GetVolume: Error returned from IHFVolume Get: %d"),error);
       
   694    			}
       
   695 			iEpVolumeNotifier->NotifyCancel();
       
   696 			iIhfVolumeNotifier->NotifyRequest();
       
   697 			break;
       
   698 		default:
       
   699 			break;
       
   700 	} // End Switch
       
   701 
       
   702 	if (error != KErrNone) // Set iVolume to error code in case there was an error getting it
       
   703 	{
       
   704 		CAC_TRACE2(_L("GetVolume: ERROR, so iVolume = error = %d"), error);
       
   705 		iVolume = error;
       
   706 	}
       
   707 	CAC_TRACE4(_L("CCallAudioControlImpl[%x]::GetVolume exit with error: %d, and iVolume = %d"),this, error, iVolume);
       
   708 	return error;
       
   709 }
       
   710 
       
   711 // ---------------------------------------------------------
       
   712 // CCallAudioControlImpl::CheckIfOkToSetVolume
       
   713 // ?implementation_description
       
   714 // (other items were commented in a header).
       
   715 // ---------------------------------------------------------
       
   716 //
       
   717 TInt CCallAudioControlImpl::CheckIfOkToSetVolume()
       
   718 {
       
   719 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::CheckIfOkToSetVolume enter"),this);
       
   720 	// if WINS, it's ok to set volume:
       
   721 	if (iWinsTesting)
       
   722 		return KErrNone;
       
   723     TBool active = IsCallActive();
       
   724 	if (!active)
       
   725 	{
       
   726 		CAC_TRACE2(_L("CheckIfOkToSetVolume NOT OK, Not active call. iCallState: %d"), iCallState);
       
   727 		return KErrPermissionDenied;
       
   728 	}
       
   729 	// IF device is BT/TTY/ENone/EActive return KErrNotSupported:
       
   730 	if ((iCurrentAudioOutput == CTelephonyAudioRouting::ENotActive) ||
       
   731 	    (iCurrentAudioOutput == CTelephonyAudioRouting::ENone) ||
       
   732 	    (iCurrentAudioOutput == CTelephonyAudioRouting::EBTAudioAccessory) ||
       
   733 	    (iCurrentAudioOutput == CTelephonyAudioRouting::ETTY) )
       
   734 	{
       
   735 		CAC_TRACE2(_L("CheckIfOkToSetVolume NOT OK, Audio Output: %d"), iCurrentAudioOutput);
       
   736 		return KErrNotSupported;
       
   737 	}
       
   738 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::CheckIfOkToSetVolume exit"),this);
       
   739 	return KErrNone;
       
   740 }
       
   741 
       
   742 // ---------------------------------------------------------
       
   743 // CCallAudioControlImpl::VerifyAndSetVolume
       
   744 // ?implementation_description
       
   745 // (other items were commented in a header).
       
   746 // ---------------------------------------------------------
       
   747 //
       
   748 TInt CCallAudioControlImpl::VerifyAndSetVolume(TInt aVolume)
       
   749     {
       
   750 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::VerifyAndSetVolume for: %d "),this, aVolume);
       
   751 	TInt newVolume;
       
   752 	if (aVolume > KMaxVolume)
       
   753 		newVolume = KMaxVolume;
       
   754 	else if (aVolume < KMinVolume)
       
   755 		newVolume = KMinVolume;
       
   756 	else
       
   757 		newVolume = aVolume;
       
   758 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::VerifyAndSetVolume: newVolume = %d "),this, newVolume);
       
   759 	return newVolume;
       
   760     }
       
   761 
       
   762 // ---------------------------------------------------------
       
   763 // CCallAudioControlImpl::HandleCallStateChange
       
   764 // ?implementation_description
       
   765 // (other items were commented in a header).
       
   766 // ---------------------------------------------------------
       
   767 //
       
   768 TInt CCallAudioControlImpl::HandleCallStateChange()
       
   769 {
       
   770 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::HandleCallStateChange enter"), this);
       
   771 	TInt error(KErrNone);
       
   772     TBool active = IsCallActive();
       
   773 	if (active ) // Active call or WINS
       
   774 	{
       
   775 		if (!iTelephonyAudioRouting)
       
   776 		{
       
   777 			TRAP(error,iTelephonyAudioRouting = CTelephonyAudioRouting::NewL(*this));
       
   778 			if (error != KErrNone)
       
   779 				return error;
       
   780 		}
       
   781 		iCurrentAudioOutput = (CCallAudioControl::TAudioOutput)iTelephonyAudioRouting->Output();
       
   782 		error = GetVolume();
       
   783 		if (error != KErrNone)
       
   784 		{
       
   785 			CAC_TRACE2(_L("HandleCallStateChange: Error trying to get Volume: %d "), error);
       
   786 			return error;
       
   787 		}
       
   788 	} // end if
       
   789     else // Not active, delete TAR if it exists, and set iVolume = EPVolume
       
   790     {
       
   791     	if (iTelephonyAudioRouting)
       
   792     	{
       
   793     		delete iTelephonyAudioRouting;
       
   794     		iTelephonyAudioRouting = NULL;
       
   795     	}
       
   796     	error = iEpVolumeNotifier->Get(iVolume);
       
   797 		if (error != KErrNone)
       
   798 		{
       
   799 			CAC_TRACE2(_L("HandleCallStateChange: Error trying to get EPVolume: %d "), error);
       
   800 			iVolume = error; // set iVolume with error code instead of dBase garbage
       
   801 		}
       
   802     } // end else
       
   803 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::HandleCallStateChange exit with error: %d"), this, error);
       
   804     return error;
       
   805 }
       
   806 
       
   807 // ---------------------------------------------------------
       
   808 // CCallAudioControlImpl::HandleEPVolumeChange
       
   809 // ?implementation_description
       
   810 // (other items were commented in a header).
       
   811 // ---------------------------------------------------------
       
   812 //
       
   813 TInt CCallAudioControlImpl::HandleEPVolumeChange(TInt aVolume)
       
   814     {
       
   815 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::HandleEPVolumeChange for: %d"),this, aVolume);
       
   816 	TInt error(KErrPermissionDenied);
       
   817 	// Ignore volume update unless active call and routing is earpiece or wired accessory:
       
   818     TBool active = IsCallActive();
       
   819 	if (active)
       
   820 	{
       
   821 		error = KErrNone;
       
   822 		if ((iCurrentAudioOutput == CTelephonyAudioRouting::EHandset) || (iCurrentAudioOutput == CTelephonyAudioRouting::EWiredAudioAccessory) )
       
   823 		{
       
   824         if (iPendingEpVolLevelOp && (iRequestedEpVolLevel == aVolume))
       
   825             {
       
   826             return error;
       
   827             }
       
   828         else
       
   829             {
       
   830             iPendingEpVolLevelOp = EFalse;
       
   831             iVolume = aVolume;
       
   832             //Notify clients:
       
   833             NotifyVolumeObservers();
       
   834 			}
       
   835 		}
       
   836 	}
       
   837 	return error;
       
   838     }
       
   839 
       
   840 // ---------------------------------------------------------
       
   841 // CCallAudioControlImpl::HandleIHFVolumeChange
       
   842 // ?implementation_description
       
   843 // (other items were commented in a header).
       
   844 // ---------------------------------------------------------
       
   845 //
       
   846 TInt CCallAudioControlImpl::HandleIHFVolumeChange(TInt aVolume)
       
   847     {
       
   848 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::HandleIHFVolumeChange for: %d "),this, aVolume);
       
   849 	TInt error(KErrPermissionDenied);
       
   850 	// Ignore volume update unless active call and routing is Loudspeaker:
       
   851     TBool active = IsCallActive();
       
   852 	if (active)
       
   853 	{
       
   854 		error = KErrNone;
       
   855 		if (iCurrentAudioOutput == CTelephonyAudioRouting::ELoudspeaker)
       
   856 		{
       
   857         if (iPendingIhfVolLevelOp && (iRequestedIhfVolLevel == aVolume))
       
   858             {
       
   859             return error;
       
   860             }
       
   861         else
       
   862             {
       
   863             iPendingIhfVolLevelOp = EFalse;
       
   864             iVolume = aVolume;
       
   865             //Notify clients:
       
   866             NotifyVolumeObservers();
       
   867             }
       
   868 		}
       
   869 	}
       
   870 	return error;
       
   871     }
       
   872 
       
   873 // ---------------------------------------------------------
       
   874 // CCallAudioControlImpl::HandleMuteChange
       
   875 // ?implementation_description
       
   876 // (other items were commented in a header).
       
   877 // ---------------------------------------------------------
       
   878 //
       
   879 TInt CCallAudioControlImpl::HandleMuteChange(TBool aMute)
       
   880     {
       
   881 	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::HandleMuteChange for: %d "),this, aMute);
       
   882 	TInt error(KErrPermissionDenied);
       
   883     TBool active = IsCallActive();
       
   884 	// Ignore mute update unless active call and mute state has changed
       
   885 	if (active)
       
   886 	{
       
   887 		error = KErrNone;
       
   888         if (iPendingMuteSetOp &&
       
   889                 ( iRequestedMuteState == aMute))
       
   890             {
       
   891             return error;
       
   892             }
       
   893         else
       
   894             {
       
   895             iPendingMuteSetOp = EFalse;
       
   896 			//Notify clients:
       
   897 			NotifyGainObservers();
       
   898             }
       
   899 	}
       
   900 	return error;
       
   901     }
       
   902 
       
   903 // ---------------------------------------------------------
       
   904 // CCallAudioControlImpl::NotifyVolumeObservers
       
   905 // ?implementation_description
       
   906 // (other items were commented in a header).
       
   907 // ---------------------------------------------------------
       
   908 //
       
   909 void CCallAudioControlImpl::NotifyVolumeObservers()
       
   910 {
       
   911 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::NotifyVolumeObservers "),this);
       
   912 	for( TInt i = 0; i < iDownlinkVolumeObservers.Count(); i++ )
       
   913    	{
       
   914 		CAC_TRACE2(_L("NotifyVolumeObservers[%d] "), i);
       
   915     	iDownlinkVolumeObservers[i]->DownlinkVolumeEvent(*(CCallAudioControl*)this, CDownlinkVolumeObserver::KDownlinkVolumeChanged);
       
   916  	}
       
   917 }
       
   918 
       
   919 // ---------------------------------------------------------
       
   920 // CCallAudioControlImpl::NotifyGainObservers
       
   921 // ?implementation_description
       
   922 // (other items were commented in a header).
       
   923 // ---------------------------------------------------------
       
   924 //
       
   925 void CCallAudioControlImpl::NotifyGainObservers()
       
   926 {
       
   927 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::NotifyGainObservers "),this);
       
   928 	for( TInt i = 0; i < iUplinkGainObservers.Count(); i++ )
       
   929    	{
       
   930 		CAC_TRACE2(_L("NotifyGainObservers[%d] "), i);
       
   931     	iUplinkGainObservers[i]->UplinkGainEvent(*(CCallAudioControl*)this, CUplinkGainObserver::KUplinkMuteStateChanged);
       
   932  	}
       
   933 }
       
   934 
       
   935 // ---------------------------------------------------------
       
   936 // CCallAudioControlImpl::NotifyRoutingObservers
       
   937 // ?implementation_description
       
   938 // (other items were commented in a header).
       
   939 // ---------------------------------------------------------
       
   940 //
       
   941 void CCallAudioControlImpl::NotifyRoutingObservers(TUint aEvent, TInt aError)
       
   942 {
       
   943 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::NotifyRoutingObservers "),this);
       
   944 	for( TInt i = 0; i < iRoutingObservers.Count(); i++ )
       
   945    	{
       
   946 		CAC_TRACE2(_L("NotifyRoutingObservers[%d] "), i);
       
   947     	iRoutingObservers[i]->RoutingEvent(*(CCallAudioControl*)this, aEvent, aError);
       
   948  	}
       
   949 }
       
   950 
       
   951 // ---------------------------------------------------------
       
   952 // CCallAudioControlImpl::NotifyRoutingObservers
       
   953 // ?implementation_description
       
   954 // (other items were commented in a header).
       
   955 // ---------------------------------------------------------
       
   956 //
       
   957 void CCallAudioControlImpl::NotifyRoutingObservers(TUint aEvent)
       
   958 {
       
   959 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::NotifyRoutingObservers "),this);
       
   960 	for( TInt i = 0; i < iRoutingObservers.Count(); i++ )
       
   961    	{
       
   962 		CAC_TRACE2(_L("NotifyRoutingObservers[%d] "), i);
       
   963     	iRoutingObservers[i]->RoutingEvent(*(CCallAudioControl*)this, aEvent);
       
   964  	}
       
   965 }
       
   966 
       
   967 // -----------------------------------------------------------------------------
       
   968 // CCallAudioControlImpl::AvailableOutputsChanged
       
   969 // The following methods are required for MTelephonyAudioRoutingObserver
       
   970 // -----------------------------------------------------------------------------
       
   971 //
       
   972 void CCallAudioControlImpl::AvailableOutputsChanged( CTelephonyAudioRouting& /*aTelephonyAudioRouting*/)
       
   973 {
       
   974 	CAC_TRACE1(_L("CCallAudioControlImpl::AvailableOutputsChanged"));
       
   975 	// ignore callback unless this condition is true
       
   976     TBool active = IsCallActive();
       
   977 	if (active)
       
   978     {
       
   979     	// Perform AvailableOutputsChanged callback to all existing CRoutingObservers:
       
   980     	NotifyRoutingObservers(CRoutingObserver::KAvailableOutputsChanged);
       
   981     }
       
   982 }
       
   983 
       
   984 // -----------------------------------------------------------------------------
       
   985 // CCallAudioControlImpl::OutputChanged
       
   986 // -----------------------------------------------------------------------------
       
   987 //
       
   988   void CCallAudioControlImpl::OutputChanged( CTelephonyAudioRouting& aTelephonyAudioRouting)
       
   989   {
       
   990   	CAC_TRACE1(_L("CCallAudioControlImpl[%x]::OutputChanged Enter"));
       
   991 	// Get and save previous and current audio output values:
       
   992    	iCurrentAudioOutput = (CCallAudioControl::TAudioOutput)aTelephonyAudioRouting.Output();
       
   993    	iPreviousAudioOutput = (CCallAudioControl::TAudioOutput)aTelephonyAudioRouting.PreviousOutput();
       
   994 	// ignore callback unless this condition is true
       
   995     TBool active = IsCallActive();
       
   996 	if (active)
       
   997     {
       
   998      	TInt tempVol = iVolume; // save off iVolume
       
   999     	// get volume from keys, based on new audio output, and set iVolume:
       
  1000     	GetVolume();
       
  1001     	// Perform OutputChanged callback to all existing CRoutingObservers:
       
  1002     	NotifyRoutingObservers(CRoutingObserver::KOutputChanged);
       
  1003     	// If there's a volume change, notify all existing CDownlinkVolumeObservers:
       
  1004     	if (tempVol != iVolume)
       
  1005     	{
       
  1006     		NotifyVolumeObservers();
       
  1007     	}
       
  1008     }
       
  1009   	CAC_TRACE1(_L("CCallAudioControlImpl::OutputChanged Exit"));
       
  1010   }
       
  1011 
       
  1012 // -----------------------------------------------------------------------------
       
  1013 // CCallAudioControlImpl::SetOutputComplete
       
  1014 // -----------------------------------------------------------------------------
       
  1015 //
       
  1016   void CCallAudioControlImpl::SetOutputComplete( CTelephonyAudioRouting& aTelephonyAudioRouting, TInt aErr)
       
  1017   {
       
  1018 
       
  1019   	CAC_TRACE3(_L("CCallAudioControlImpl[%x]::SetOutputComplete With Error Code: %d"), this, aErr);
       
  1020    	iCurrentAudioOutput = (CCallAudioControl::TAudioOutput)aTelephonyAudioRouting.Output();
       
  1021    	iPreviousAudioOutput = (CCallAudioControl::TAudioOutput)aTelephonyAudioRouting.PreviousOutput();
       
  1022 	// ignore callback unless this condition is true
       
  1023    	TBool active = IsCallActive();
       
  1024 	if (active)
       
  1025     {
       
  1026     	TInt tempVol = iVolume; // save off iVolume
       
  1027     	// get volume from keys, based on new audio output, and set iVolume:
       
  1028     	GetVolume();
       
  1029     	// Perform OutputChanged callback to all existing CRoutingObservers:
       
  1030     	NotifyRoutingObservers(CRoutingObserver::KSetOutputComplete, aErr);
       
  1031     	// If there's a volume change, notify all existing CDownlinkVolumeObservers:
       
  1032     	if (tempVol != iVolume)
       
  1033     	{
       
  1034     		NotifyVolumeObservers();
       
  1035     	}
       
  1036     }
       
  1037   }
       
  1038 
       
  1039 // -----------------------------------------------------------------------------
       
  1040 // CCallAudioControlImpl::NotifyL
       
  1041 // -----------------------------------------------------------------------------
       
  1042 //
       
  1043 void CCallAudioControlImpl::NotifyL(TAction aAction, TInt aError, TInt aValue)
       
  1044     {
       
  1045     CAC_TRACE5(_L("CCallAudioControlImpl[%x]::NotifyL for Action: %d, Error: %d and Value: %d"),this, aAction, aError, aValue);
       
  1046     switch (aAction)
       
  1047         {
       
  1048         case ECallState: // Call state change notification
       
  1049             {
       
  1050             CAC_TRACE1(_L("NotifyL: Call State Change Notification"));
       
  1051             iCallState = aValue;
       
  1052             HandleCallStateChange();
       
  1053             }
       
  1054             break;
       
  1055         case EEPVolume: // EP Volume change notification
       
  1056             {
       
  1057             CAC_TRACE1(_L("NotifyL: EP VOlume Change Notification"));
       
  1058             TInt tempVol = aValue;
       
  1059             HandleEPVolumeChange(tempVol);
       
  1060             }
       
  1061             break;
       
  1062         case EIHFVolume: // Handle IHF volume change Notification
       
  1063             {
       
  1064             CAC_TRACE1(_L("NotifyL: IHF Volume Change Notification"));
       
  1065             TInt tempVol = aValue;
       
  1066             HandleIHFVolumeChange(tempVol);
       
  1067             }
       
  1068             break;
       
  1069 
       
  1070         case EMute: // Handle mute change Notification
       
  1071             {
       
  1072             CAC_TRACE1(_L("NotifyL: Uplink Mute Change Notification"));
       
  1073             TBool tempMute = aValue;
       
  1074 #ifdef __SERIES60_31__
       
  1075             if (aValue == EPSMicMuteOn)
       
  1076                 tempMute = ETrue;
       
  1077             else
       
  1078                 tempMute = EFalse;
       
  1079 #endif
       
  1080             HandleMuteChange(tempMute);
       
  1081             }
       
  1082             break;
       
  1083         default:
       
  1084             CAC_TRACE1(_L("NotifyL: UNKNOWN Notification"));
       
  1085             break;
       
  1086         } // End switch
       
  1087     }
       
  1088 
       
  1089 // -----------------------------------------------------------------------------
       
  1090 // CCallAudioControlImpl::CommandResponseL
       
  1091 //
       
  1092 // (other items were commented in a header).
       
  1093 // -----------------------------------------------------------------------------
       
  1094 //
       
  1095 #ifdef __SERIES60_31__
       
  1096 void CCallAudioControlImpl::CommandResponseL( TUid /*aKMediatorSecondaryDisplayDomain*/,
       
  1097 						TUid /*aKTSECategory*/,
       
  1098                         TInt aCommandId,
       
  1099                         TInt aStatus,
       
  1100                         const TDesC8& /*aData*/ )
       
  1101      {
       
  1102 	CAC_TRACE2(_L("CCallAudioControlImpl[%x]::CommandResponseL "),this);
       
  1103      if ( aStatus != KErrNone)
       
  1104          {
       
  1105          CAC_TRACE2(_L("CommandResponseL: Command error [%d] "), aStatus);
       
  1106          }
       
  1107      else
       
  1108          {
       
  1109          switch ( aCommandId )
       
  1110              {
       
  1111              case ECmdMuteOrUnmuteMicrophone:
       
  1112 		        CAC_TRACE1(_L("CommandResponseL: Mute Unmute microphone succeeded "));
       
  1113                 break;
       
  1114             default:
       
  1115                 CAC_TRACE1(_L("CommandResponseL: ERROR: Unknown Command Response Received"));
       
  1116                 break;
       
  1117              }
       
  1118          } // End else
       
  1119      }
       
  1120 #endif
       
  1121 
       
  1122 // -----------------------------------------------------------------------------
       
  1123 //
       
  1124 //
       
  1125 //
       
  1126 // -----------------------------------------------------------------------------
       
  1127 //
       
  1128 TBool CCallAudioControlImpl::IsCallActive()
       
  1129 {
       
  1130 	CAC_TRACE1(_L("CCallAudioControlImpl::IsCallActive"));
       
  1131 	iCsNotifier->Get(iCallState);
       
  1132 	if ((iCallState == ECallStateConnected) || (iCallState == ECallStateHold) || iWinsTesting )
       
  1133     {
       
  1134 		return ETrue;
       
  1135     }
       
  1136 	return EFalse;
       
  1137 }
       
  1138 // End of file