mmapitest/devsoundexthaitest/src/T_CTelephonyAudioRoutingData.cpp
branchRCL_3
changeset 23 545d349d14da
equal deleted inserted replaced
20:67584cc761d1 23:545d349d14da
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "t_ctelephonyaudioroutingdata.h"
       
    21 
       
    22 const TUid EEarPiece		 				= TUid::Uid(0x02);
       
    23 const TUid EHeadSet			 				= TUid::Uid(0x04);
       
    24 /*@{*/
       
    25 //Command literals 
       
    26 _LIT(KCmdNewL, 								"NewL");
       
    27 _LIT(KCmdDestructor, 							"~");
       
    28 _LIT(KCmdAvailableOutputs, 					"AvailableOutputs");
       
    29 _LIT(KCmdOutput, 								"Output");
       
    30 _LIT(KCmdPreviousOutput, 						"PreviousOutput");
       
    31 _LIT(KCmdSetShowNote, 							"SetShowNote");
       
    32 _LIT(KCmdGetShowNote,							"GetShowNote");
       
    33 _LIT(KCmdSetOutputL, 							"SetOutputL");
       
    34 /*@}*/
       
    35 
       
    36 /*@{*/
       
    37 //INI Section name literals 
       
    38 _LIT(KMode, 								"Mode");
       
    39 /*@}*/
       
    40 
       
    41 /*@{*/
       
    42 //Enumeration Literals 
       
    43 _LIT(KENotActive, 							"ENotActive");
       
    44 _LIT(KENone, 								"ENone");
       
    45 _LIT(KEHandset, 							"EHandSet");
       
    46 _LIT(KELoudSpeaker, 						"ELoudSpeaker");
       
    47 _LIT(KEWiredAudioAccessory, 				"EWiredAudioAccessory");
       
    48 _LIT(KEBTAudioAccessory, 					"EBTAudioAccessory");
       
    49 _LIT(KETTY, 								"ETTY");
       
    50 _LIT(KEEarPiece,							"EEarPiece");
       
    51 _LIT(KEHeadSet,								"EHeadSet");
       
    52 /*@}*/
       
    53 
       
    54 const CDataWrapperBase::TEnumEntryTable CT_CTelephonyAudioRoutingData::iEnumOutput[] = 
       
    55 	{ 
       
    56 	{ KENotActive,	CTelephonyAudioRouting::ENotActive},
       
    57 	{ KENone, CTelephonyAudioRouting::ENone},
       
    58 	{ KEHandset, CTelephonyAudioRouting::EHandset},
       
    59 	{ KEEarPiece, EEarPiece.iUid},
       
    60 	{ KELoudSpeaker, CTelephonyAudioRouting::ELoudspeaker},
       
    61 	{ KEWiredAudioAccessory, CTelephonyAudioRouting::EWiredAudioAccessory},
       
    62 	{ KEHeadSet,	EHeadSet.iUid},
       
    63 	{ KEBTAudioAccessory, CTelephonyAudioRouting::EBTAudioAccessory},
       
    64 	{ KETTY, CTelephonyAudioRouting::ETTY}
       
    65 	};
       
    66 
       
    67 /**
       
    68  * Public destructor
       
    69  */
       
    70 CT_CTelephonyAudioRoutingData::~CT_CTelephonyAudioRoutingData()
       
    71 	{
       
    72 	DestroyData();
       
    73 	}
       
    74 
       
    75 /**
       
    76  * Two phase constructor
       
    77  * @leave	system wide error
       
    78  */
       
    79 
       
    80 CT_CTelephonyAudioRoutingData* CT_CTelephonyAudioRoutingData::NewL()
       
    81 	{
       
    82 	CT_CTelephonyAudioRoutingData* ret = new (ELeave) CT_CTelephonyAudioRoutingData();
       
    83 	return ret;
       
    84 	}
       
    85 
       
    86 /**
       
    87  * Private constructor. First phase construction
       
    88  */
       
    89 
       
    90 CT_CTelephonyAudioRoutingData::CT_CTelephonyAudioRoutingData()
       
    91 	:
       
    92 	iTelephonyAudioRouting (NULL)
       
    93 	{
       
    94 	}
       
    95 
       
    96 
       
    97 void CT_CTelephonyAudioRoutingData::DestroyData()
       
    98 {
       
    99 if(iTelephonyAudioRouting)
       
   100 	{
       
   101 	delete iTelephonyAudioRouting;
       
   102 	iTelephonyAudioRouting = NULL;
       
   103 	}
       
   104 }
       
   105 
       
   106 
       
   107 /**
       
   108  * Return a pointer to the object that the data wraps
       
   109  * @return	pointer to the object that the data wraps
       
   110  */
       
   111 TAny* CT_CTelephonyAudioRoutingData::GetObject()
       
   112 	{
       
   113 	return iTelephonyAudioRouting;
       
   114 	}
       
   115 
       
   116 
       
   117 /**
       
   118  * Process a command read from the Ini file
       
   119  * @param aCommand 			The command to process
       
   120  * @param aSection			The section get from the *.ini file of the project T_Wlan
       
   121  * @param aAsyncErrorIndex	Command index dor async calls to returns errors to
       
   122  * @return TBool			ETrue if the command is process
       
   123  * @leave					system wide error
       
   124  */
       
   125 
       
   126 TBool CT_CTelephonyAudioRoutingData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   127 	{
       
   128 	TBool ret = ETrue;
       
   129 	
       
   130 	if (aCommand == KCmdNewL)
       
   131 		{
       
   132 		DoCmdNewL();
       
   133 		}
       
   134 	else if (aCommand == KCmdDestructor)
       
   135 		{
       
   136 		DoCmdDestructor();
       
   137 		}
       
   138 	else if (aCommand == KCmdAvailableOutputs)
       
   139 		{
       
   140 		DoCmdAvailableOutputs();
       
   141 		}
       
   142 	else if (aCommand == KCmdOutput)
       
   143 		{
       
   144 		DoCmdOutput();
       
   145 		}
       
   146 	else if (aCommand == KCmdPreviousOutput)
       
   147 		{
       
   148 		DoCmdPreviousOutput();
       
   149 		}
       
   150 	else if (aCommand == KCmdSetShowNote)
       
   151 		{
       
   152 		DoCmdSetShowNote(aSection);
       
   153 		}
       
   154 	else if (aCommand == KCmdGetShowNote)
       
   155 		{
       
   156 		DoCmdGetShowNote();
       
   157 		}
       
   158 	else if (aCommand == KCmdSetOutputL)
       
   159 		{
       
   160 		DoCmdSetOutputL(aSection);
       
   161 		}
       
   162 	else
       
   163 		{
       
   164 		ERR_PRINTF1(_L("Unknown command"));
       
   165 		ret=EFalse;
       
   166 		}
       
   167 	
       
   168 	return ret;	
       
   169 	}
       
   170 
       
   171 /**
       
   172  * Signals that available audio outputs have changed. 
       
   173  * @param CTelephonyAudioRouting& aTelephonyAudioRouting reference.
       
   174  * @return void
       
   175  */
       
   176 void CT_CTelephonyAudioRoutingData::AvailableOutputsChanged( CTelephonyAudioRouting& /*aTelephonyAudioRouting*/)
       
   177 	{
       
   178 	INFO_PRINTF1(_L("CT_CTelephonyAudioRoutingData::AvailableOutputsChanged"));
       
   179 	}
       
   180 
       
   181 /**
       
   182  * Signals that current output has changed. 
       
   183  * @param CTelephonyAudioRouting& aTelephonyAudioRouting reference.
       
   184  * @return void
       
   185  */
       
   186 void CT_CTelephonyAudioRoutingData::OutputChanged( CTelephonyAudioRouting& /*aTelephonyAudioRouting*/)
       
   187 	{
       
   188 	INFO_PRINTF1(_L("CT_CTelephonyAudioRoutingData::OutputChanged"));
       
   189 	}
       
   190 
       
   191 /**
       
   192  * Signals that CTelephonyAudioRouting::SetOutputL request issued by this
       
   193  * application (on CTelephonyAudioRouting instance) was serviced by the
       
   194  * Adaptation.
       
   195  * Only when the observer receives this callback, the application should consider
       
   196  * CTelephonyAudioRouting::SetOutputL message to be completed.
       
   197  *
       
   198  * @param CTelephonyAudioRouting& aTelephonyAudioRouting reference.
       
   199  * @param aError KErrNone if output requested by application is set, else
       
   200  *        system-wide error code.
       
   201  * @return void
       
   202  */
       
   203 void CT_CTelephonyAudioRoutingData::SetOutputComplete( CTelephonyAudioRouting& /*aTelephonyAudioRouting*/, TInt aError)
       
   204 	{
       
   205 	DecOutstanding();
       
   206 	if(aError != KErrNone)
       
   207 		{
       
   208 		INFO_PRINTF2(_L("Could not set output complete: %d"), aError);
       
   209 		}
       
   210 	else
       
   211 		{
       
   212 		INFO_PRINTF1(_L("CT_CTelephonyAudioRoutingData::SetOutputComplete"));
       
   213 		}
       
   214 	}
       
   215 
       
   216 /**
       
   217  * Create an instance of CTelephonyAudioRouting
       
   218  * @param 
       
   219  * @return
       
   220  */
       
   221 void CT_CTelephonyAudioRoutingData::DoCmdNewL()
       
   222 	{
       
   223 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdNewL"));
       
   224 	DestroyData();
       
   225 	TRAPD(error,iTelephonyAudioRouting = CTelephonyAudioRouting::NewL(*this));
       
   226 	if(error!=KErrNone)
       
   227 		{
       
   228 		ERR_PRINTF2(_L("> Could not create CTelephonyAudioRouting: %d"), error);
       
   229 		SetError(error);
       
   230 		}
       
   231 	else
       
   232 		{
       
   233 		INFO_PRINTF1(_L("CTelephonyAudioRouting created successfully."));
       
   234 		INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdNewL"));
       
   235 		}	
       
   236 	}
       
   237 
       
   238 /**
       
   239  * Delete the instance of CTelephonyAudioRouting
       
   240  * @param
       
   241  * @return
       
   242  */
       
   243 void CT_CTelephonyAudioRoutingData::DoCmdDestructor()
       
   244 	{
       
   245 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdDestructor"));
       
   246 	DestroyData();
       
   247 	INFO_PRINTF1(_L("*END*CTelephonyAudioRouting destroyed successfully."));
       
   248 	}
       
   249 
       
   250 
       
   251 /**
       
   252 * Shows the array of currently available outputs.
       
   253 * The array contains list of following outputs depending on whether the
       
   254 * output is available or not at the time of query:
       
   255 *  - EHandset
       
   256 *  - ELoudspeaker
       
   257 *  - EWiredAudioAccessory,
       
   258 *  - EWiredAccessory,
       
   259 *  - EBTAudioAccessory
       
   260 *  - ETTY
       
   261 * Audio can be routed to any of the available outputs in the list.
       
   262 * @param 
       
   263 * @return 
       
   264 */
       
   265 
       
   266 void CT_CTelephonyAudioRoutingData::DoCmdAvailableOutputs()
       
   267 	{
       
   268 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdAvailableOutputs"));	
       
   269 	TInt availableOutput;
       
   270 	const TArray<CTelephonyAudioRouting::TAudioOutput>& availableOutputsArray(iTelephonyAudioRouting->AvailableOutputs());
       
   271 	
       
   272 	if (availableOutputsArray.Count()==0)
       
   273 		{
       
   274 		INFO_PRINTF1(_L("None available output"));
       
   275 		}
       
   276 	else
       
   277 		{
       
   278 		TBuf<80> msg;
       
   279 		for (TInt i=0;i<availableOutputsArray.Count();i++)
       
   280 			{
       
   281 			availableOutput = availableOutputsArray[i];
       
   282 			switch (availableOutput)
       
   283 				{
       
   284 				case CTelephonyAudioRouting::ENotActive:
       
   285 					msg.Append(_L("not active"));
       
   286 				break;
       
   287 				case CTelephonyAudioRouting::ENone:
       
   288 					msg.Append(_L("none"));
       
   289 				break;
       
   290 				case CTelephonyAudioRouting::EHandset:
       
   291 					msg.Append(_L("handset"));
       
   292 				break;
       
   293 				case CTelephonyAudioRouting::ELoudspeaker:
       
   294 					msg.Append(_L("loudspeaker"));
       
   295 				break;
       
   296 				case CTelephonyAudioRouting::EWiredAudioAccessory:
       
   297 					msg.Append(_L("wired acc"));
       
   298 				break;
       
   299 				case CTelephonyAudioRouting::EBTAudioAccessory:
       
   300 					msg.Append(_L("BT audio acc"));
       
   301 				break;
       
   302 				case CTelephonyAudioRouting::ETTY:
       
   303 					msg.Append(_L("ETTY"));
       
   304 				break;
       
   305 				default:
       
   306 					msg.AppendFormat(_L("0x%x"), availableOutput);
       
   307 				}
       
   308 			if(i+1<availableOutputsArray.Count())
       
   309 				{
       
   310 				msg.Append(_L(","));
       
   311 				}
       
   312 			}
       
   313 			INFO_PRINTF2(_L("Available Outputs: %S"), &msg);
       
   314 		}
       
   315 	INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdAvailableOutputs"));
       
   316 	}
       
   317 
       
   318 
       
   319 /**
       
   320  * Shows the current output configured by the client application to play
       
   321  * telephony audio.
       
   322  * @param none.
       
   323  * @return void.
       
   324  */
       
   325 
       
   326 void CT_CTelephonyAudioRoutingData::DoCmdOutput()
       
   327 	{
       
   328 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdOutput"));
       
   329 	iOutput = iTelephonyAudioRouting->Output();
       
   330     INFO_PRINTF2(_L("Output: 0x%x"),iOutput);
       
   331     switch(iOutput)
       
   332         {
       
   333         case CTelephonyAudioRouting::ENotActive :
       
   334         	INFO_PRINTF1(_L("Not active"));
       
   335         break;
       
   336         case CTelephonyAudioRouting::ENone :
       
   337         	INFO_PRINTF1(_L("None"));
       
   338         break;
       
   339         case CTelephonyAudioRouting::EHandset :
       
   340         	INFO_PRINTF1(_L("Handset"));
       
   341         break;
       
   342         case CTelephonyAudioRouting::ELoudspeaker :
       
   343         	INFO_PRINTF1(_L("Loudspeaker"));
       
   344         break;
       
   345         case CTelephonyAudioRouting::EWiredAudioAccessory :
       
   346         	INFO_PRINTF1(_L("Wired acc"));
       
   347         break;
       
   348         case CTelephonyAudioRouting::EBTAudioAccessory :
       
   349         	INFO_PRINTF1(_L("BT audio acc"));
       
   350         break;
       
   351         case CTelephonyAudioRouting::ETTY :
       
   352         	INFO_PRINTF1(_L("ETTY"));
       
   353         break;
       
   354         default:
       
   355         	INFO_PRINTF2(_L("0x%x"), iOutput);
       
   356         }
       
   357     INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdOutput"));
       
   358 	}
       
   359 
       
   360 
       
   361 /**
       
   362  * Show the second last output that was successfully configured to
       
   363  * play telephony audio.
       
   364  * @param none.
       
   365  * @return void
       
   366  */
       
   367 
       
   368 void CT_CTelephonyAudioRoutingData::DoCmdPreviousOutput()
       
   369 	{
       
   370 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdPreviousOutput"));	
       
   371     CTelephonyAudioRouting::TAudioOutput previousOutput;
       
   372 	previousOutput = iTelephonyAudioRouting->PreviousOutput();
       
   373 	INFO_PRINTF2(_L("Previous audio output: 0x%x"), previousOutput);
       
   374     switch (previousOutput)
       
   375         {
       
   376         case CTelephonyAudioRouting::ENotActive:
       
   377         	INFO_PRINTF1(_L("Not active"));
       
   378         break;
       
   379         case CTelephonyAudioRouting::ENone:
       
   380         	INFO_PRINTF1(_L("None"));
       
   381         break;
       
   382         case CTelephonyAudioRouting::EHandset:
       
   383         	INFO_PRINTF1(_L("Handset"));
       
   384         break;
       
   385         case CTelephonyAudioRouting::ELoudspeaker:
       
   386         	INFO_PRINTF1(_L("Loudspeaker"));
       
   387         break;
       
   388         case CTelephonyAudioRouting::EWiredAudioAccessory:
       
   389         	INFO_PRINTF1(_L("Wired acc"));
       
   390         break;
       
   391         case CTelephonyAudioRouting::EBTAudioAccessory:
       
   392         	INFO_PRINTF1(_L("BT audio acc"));
       
   393         break;
       
   394         case CTelephonyAudioRouting::ETTY:
       
   395         	INFO_PRINTF1(_L("ETTY"));
       
   396         break;
       
   397         default:
       
   398         	INFO_PRINTF2(_L("0x%x"), previousOutput);
       
   399         }
       
   400     INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdPreviousOutput"));	
       
   401 	}
       
   402 
       
   403 
       
   404 /*
       
   405  * Sends the Show Note mode to server along with the next SetOutputL()
       
   406  * request.
       
   407  * After SetOutputL() request from the Application is succesfully
       
   408  * processed by the server and application receives SetOutputComplete()
       
   409  * callback with KErrNone, it can query Show Note mode sent to server by
       
   410  * calling GetShowNote().
       
   411  * Other observers wanting to query Show Note mode can call GetShowNote()
       
   412  * after receiving OutputChanged() callback.
       
   413  *
       
   414  * @param aSection the Section to read from the ini file.
       
   415  * @return 
       
   416  */
       
   417 
       
   418 void CT_CTelephonyAudioRoutingData::DoCmdSetShowNote(const TTEFSectionName& aSection)
       
   419 	{
       
   420 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdSetShowNote"));
       
   421 	TBool mode;
       
   422 	if(!GetBoolFromConfig(aSection, KMode, mode))
       
   423 		{
       
   424 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KMode);
       
   425     	SetBlockResult(EFail);
       
   426 		}
       
   427 	else
       
   428 		{
       
   429 		TInt error = iTelephonyAudioRouting->SetShowNote(mode);
       
   430 	    if (error != KErrNone)
       
   431 	        {
       
   432 	    	ERR_PRINTF2(_L("Could not set show note. Error: %d"), error);
       
   433 	    	SetError(error);
       
   434 	        }
       
   435 	    else
       
   436 	    	{
       
   437 	    	INFO_PRINTF2(_L("Mode set to: %d"), mode);
       
   438 			INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdSetShowNote"));
       
   439 	    	}		
       
   440 		}    
       
   441 	}
       
   442 
       
   443 
       
   444 /**
       
   445  * Shows the  Show Note mode for the last succesfully completed
       
   446  * SetOutputL() request.
       
   447  * @param 
       
   448  * @return 
       
   449  */
       
   450 
       
   451 
       
   452 void CT_CTelephonyAudioRoutingData::DoCmdGetShowNote()
       
   453 	{
       
   454 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdGetShowNote"));
       
   455 	TBool mode;
       
   456 	TInt error = iTelephonyAudioRouting->GetShowNote(mode);
       
   457     if(error != KErrNone) 
       
   458         {
       
   459     	ERR_PRINTF2(_L("Could not get show note. Error: %d"), error);
       
   460     	SetError(error);
       
   461         }
       
   462     else
       
   463     	{
       
   464     	INFO_PRINTF2(_L("Mode: %d"), mode);
       
   465         INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdGetShowNote"));
       
   466     	}    
       
   467 	}
       
   468 
       
   469 /**
       
   470  * Sends an asynchronous request to Adaptation to set the output
       
   471  * where telephony audio will be routed. This request is completed only
       
   472  * when the application receives
       
   473  * MTelephonyAudioRoutingObserver::SetOutputComplete callback.
       
   474  * @param aSection - The section to read from the ini file
       
   475  * @return none.
       
   476  */
       
   477 
       
   478 void CT_CTelephonyAudioRoutingData::DoCmdSetOutputL(const TTEFSectionName& aSection)
       
   479 	{
       
   480 	INFO_PRINTF1(_L("*START*CT_CTelephonyAudioRoutingData::DoCmdSetOutputL"));
       
   481 	TInt output;
       
   482 	if (!GetEnumFromConfig(aSection, KCmdOutput, iEnumOutput, output))
       
   483 		{
       
   484 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KCmdOutput);
       
   485     	SetBlockResult(EFail);
       
   486     	}
       
   487 	else
       
   488 		{
       
   489 		if(iOutput!=output)
       
   490 			{
       
   491 		    TRAPD(error, iTelephonyAudioRouting->SetOutputL((CTelephonyAudioRouting::TAudioOutput)output));
       
   492 		    IncOutstanding();
       
   493 		    if (error != KErrNone)
       
   494 		    	{
       
   495 		    	ERR_PRINTF2(_L("Could not set output. Error: %d"), error);
       
   496 		    	SetError(error);
       
   497 		        }
       
   498 		    else
       
   499 		    	{
       
   500 		    	INFO_PRINTF1(_L("Output set to: "));
       
   501 			    switch (output)
       
   502 				    {
       
   503 				    case CTelephonyAudioRouting::ENotActive:
       
   504 				    	INFO_PRINTF1(_L("Not active"));
       
   505 				    break;
       
   506 				    case CTelephonyAudioRouting::ENone:
       
   507 				    	INFO_PRINTF1(_L("None"));
       
   508 				    break;
       
   509 				    case CTelephonyAudioRouting::EHandset:
       
   510 				    	INFO_PRINTF1(_L("Handset"));
       
   511 				    break;
       
   512 				    case CTelephonyAudioRouting::ELoudspeaker:
       
   513 				    	INFO_PRINTF1(_L("Loudspeaker"));
       
   514 				    break;
       
   515 				    case CTelephonyAudioRouting::EWiredAudioAccessory:
       
   516 				    	INFO_PRINTF1(_L("Wired acc"));
       
   517 				    break;
       
   518 				    case CTelephonyAudioRouting::EBTAudioAccessory:
       
   519 				    	INFO_PRINTF1(_L("BT audio acc"));
       
   520 				    break;
       
   521 				    case CTelephonyAudioRouting::ETTY:
       
   522 				    	INFO_PRINTF1(_L("ETTY"));
       
   523 			        break;
       
   524 				    default:
       
   525 				    	INFO_PRINTF2(_L("%d"), output);
       
   526 				    }
       
   527 		    	}
       
   528 			}    
       
   529 	}
       
   530 	INFO_PRINTF1(_L("*END*CT_CTelephonyAudioRoutingData::DoCmdSetOutputL"));
       
   531 	}