cellularsrvapitest/telephonydevsoundhaitest/devsound/src/T_CAudioOutputData.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 #include "T_CAudioOutputData.h"
       
    19 
       
    20 /*@{*/
       
    21 // Output options Id's
       
    22 const TUid OUTPUT_NOPREFERENCE					= TUid::Uid(0x00);
       
    23 const TUid OUTPUT_ALL 							= TUid::Uid(0x01);
       
    24 const TUid OUTPUT_NOOUTPUT 						= TUid::Uid(0x02);
       
    25 const TUid OUTPUT_PRIVATE 						= TUid::Uid(0x03);
       
    26 const TUid OUTPUT_PUBLIC  						= TUid::Uid(0x04);
       
    27 /*@}*/
       
    28 
       
    29 
       
    30 /*@{*/
       
    31 //Section name literals 
       
    32 _LIT(KDevSoundKey, 								"DevSoundInstanceName");
       
    33 _LIT(KAudioOutputPar, 							"AudioOutput");
       
    34 _LIT(KSecureOutputPar,							"SecureOutput");
       
    35 /*@}*/
       
    36 
       
    37 /*@{*/
       
    38 //Command literals 
       
    39 _LIT(KCmdNewL, 									"NewL");
       
    40 _LIT(KCmdDestructor, 							"~");
       
    41 _LIT(KCmdAudioOutput,							"AudioOutput");
       
    42 _LIT(KCmdDefaultAudioOutput, 					"DefaultAudioOutput");
       
    43 _LIT(KCmdRegisterObserver, 						"RegisterObserver");
       
    44 _LIT(KCmdSecureOutput, 							"SecureOutput");
       
    45 _LIT(KCmdSetAudioOutput, 						"SetAudioOutput");
       
    46 _LIT(KCmdSetSecureOutput, 						"SetSecureOutput");
       
    47 _LIT(KCmdUnregisterObserver, 					"UnregisterObserver");
       
    48 /*@}*/
       
    49 
       
    50 
       
    51 /*@{*/
       
    52 // Output options literal
       
    53 _LIT(KOutput_NoPreference, 						"Output_NoPreference");
       
    54 _LIT(KOutput_All, 								"Output_All");
       
    55 _LIT(KOutput_NoOutput, 							"Output_NoOutput");
       
    56 _LIT(KOutput_Private, 							"Output_Private");
       
    57 _LIT(KOutput_Public, 							"Output_Public");
       
    58 /*@}*/
       
    59 
       
    60 const CDataWrapperBase::TEnumEntryTable CT_CAudioOutputData::iEnumOutputOptions[] = 
       
    61 	{ 
       
    62 	{ KOutput_NoPreference,		OUTPUT_NOPREFERENCE.iUid },	
       
    63 	{ KOutput_All,				OUTPUT_ALL.iUid },
       
    64 	{ KOutput_NoOutput,			OUTPUT_NOOUTPUT.iUid },	
       
    65 	{ KOutput_Private,			OUTPUT_PRIVATE.iUid },
       
    66 	{ KOutput_Public,			OUTPUT_PUBLIC.iUid }
       
    67 	};
       
    68 
       
    69 
       
    70 
       
    71 /**
       
    72  * Two phase constructor
       
    73  *
       
    74  * @leave	system wide error
       
    75  */
       
    76 CT_CAudioOutputData* CT_CAudioOutputData::NewL()
       
    77 	{
       
    78 	CT_CAudioOutputData* ret = new (ELeave) CT_CAudioOutputData();
       
    79 	return ret;
       
    80 	}
       
    81 
       
    82 /**
       
    83  * Private constructor. First phase construction
       
    84  */
       
    85 CT_CAudioOutputData::CT_CAudioOutputData()
       
    86 	:
       
    87 	iAudioOutput(NULL),
       
    88 	iSecureOutput(EFalse)
       
    89 	{
       
    90 	}
       
    91 
       
    92 
       
    93 /**
       
    94  * Return a pointer to the object that the data wraps
       
    95  *
       
    96  * @return	pointer to the object that the data wraps
       
    97  */
       
    98 TAny* CT_CAudioOutputData::GetObject()
       
    99 	{
       
   100 	return iAudioOutput;
       
   101 	}
       
   102 
       
   103 /**
       
   104  * Helper method for DoCmdDestructor
       
   105  */
       
   106 void CT_CAudioOutputData::DestroyData()
       
   107 	{
       
   108 	if (iAudioOutput)
       
   109 		{ 
       
   110 		delete iAudioOutput;
       
   111 		iAudioOutput = NULL;
       
   112 		}	
       
   113 	}
       
   114 
       
   115 
       
   116 /**
       
   117  * Process a command read from the Ini file
       
   118  * @param aCommand 			- The command to process
       
   119  * @param aSection			- The section get from the *.ini file of the project T_Wlan
       
   120  * @param aAsyncErrorIndex	- Command index dor async calls to returns errors to
       
   121  * @return TBool			- ETrue if the command is process
       
   122  * @leave					- system wide error
       
   123  */
       
   124 TBool CT_CAudioOutputData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   125 	{
       
   126 	TBool ret = ETrue;
       
   127 	
       
   128 	if (aCommand == KCmdNewL)
       
   129 		{
       
   130 		DoCmdNewL(aSection);
       
   131 		}
       
   132 	else if (aCommand == KCmdDestructor)
       
   133 		{
       
   134 		DoCmdDestructor();
       
   135 		}
       
   136 	else if (aCommand == KCmdAudioOutput)
       
   137 		{
       
   138 		DoCmdAudioOutput();
       
   139 		}
       
   140 	else if (aCommand == KCmdDefaultAudioOutput)
       
   141 		{
       
   142 		DoCmdDefaultAudioOutput();
       
   143 		}
       
   144 	else if (aCommand == KCmdRegisterObserver)
       
   145 		{
       
   146 		DoCmdRegisterObserverL();
       
   147 		}
       
   148 	else if (aCommand == KCmdSecureOutput)
       
   149 		{
       
   150 		DoCmdSecureOutput();
       
   151 		}
       
   152 	else if (aCommand == KCmdSetAudioOutput)
       
   153 		{
       
   154 		DoCmdSetAudioOutputL(aSection);
       
   155 		}
       
   156 	else if (aCommand == KCmdSetSecureOutput)
       
   157 		{
       
   158 		DoCmdSetSecureOutputL(aSection);
       
   159 		}
       
   160 	else if (aCommand == KCmdUnregisterObserver)
       
   161 		{
       
   162 		DoCmdUnregisterObserver();
       
   163 		}
       
   164 	else
       
   165 		{
       
   166 		ERR_PRINTF1(_L("Unknown command."));
       
   167 		ret=EFalse;
       
   168 		}
       
   169 	return ret;
       
   170 	}
       
   171 
       
   172 /**
       
   173  * Create an instance of CAudioOutput
       
   174  * @param aSection  - Section to read param from the ini file
       
   175  * @return none
       
   176  */
       
   177 void CT_CAudioOutputData::DoCmdNewL(const TTEFSectionName& aSection) //quite return
       
   178 	{
       
   179 	DestroyData();
       
   180 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdNewL"));
       
   181 	TPtrC devSoundObject;
       
   182     if( !GetStringFromConfig(aSection, KDevSoundKey, devSoundObject) )
       
   183     	{
       
   184     	ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDevSoundKey);
       
   185     	SetBlockResult(EFail);
       
   186     	}
       
   187     else
       
   188     	{
       
   189 	    CMMFDevSound* DevSoundObject = static_cast<CMMFDevSound*>(GetDataObjectL(devSoundObject));
       
   190 	    iAudioOutput = (CAudioOutput*)DevSoundObject->CustomInterface(KUidAudioOutput);
       
   191 	    INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdNewL"));
       
   192     	}
       
   193     }
       
   194 
       
   195 /**
       
   196  * Destroy an instance of CAudioOutput
       
   197  * @param none
       
   198  * @return none
       
   199  */
       
   200 void CT_CAudioOutputData::DoCmdDestructor()
       
   201 	{
       
   202 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdDestroyData"));
       
   203 	DestroyData();
       
   204 	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdDestroyData"));
       
   205 	}
       
   206 
       
   207 /**
       
   208  * Get the audio Output pref
       
   209  * @param none
       
   210  * @return none
       
   211  */
       
   212 void CT_CAudioOutputData::DoCmdAudioOutput()
       
   213 	{
       
   214 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdAudioOutput"));
       
   215 	audioOutputPref = iAudioOutput->AudioOutput();
       
   216 	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdAudioOutput"));
       
   217 	}
       
   218 
       
   219 /**
       
   220  * Get the default audio output pref
       
   221  * @param none
       
   222  * @return none
       
   223  */
       
   224 void CT_CAudioOutputData::DoCmdDefaultAudioOutput()
       
   225 	{
       
   226 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdDefaultAudioOutput"));
       
   227 	audioOutputPref = iAudioOutput->DefaultAudioOutput();
       
   228 	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdDefaultAudioOutput"));
       
   229 	}
       
   230 
       
   231 /**
       
   232  * Register the observer
       
   233  * @param none
       
   234  * @return none
       
   235  */
       
   236 void CT_CAudioOutputData::DoCmdRegisterObserverL() //quite return
       
   237 	{
       
   238 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdRegisterObserverL"));
       
   239     TRAPD( error, iAudioOutput->RegisterObserverL(*this) );    	    
       
   240     if( error != KErrNone ) 
       
   241         {
       
   242         ERR_PRINTF2(_L("Register observer failed with error %d"), error);
       
   243         SetError(error);
       
   244         }
       
   245     else
       
   246     	{
       
   247     	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdRegisterObserverL"));
       
   248     	}
       
   249     }
       
   250 
       
   251 /**
       
   252  * Secure the output
       
   253  * @param none
       
   254  * @return none
       
   255  */
       
   256 void CT_CAudioOutputData::DoCmdSecureOutput()
       
   257 	{
       
   258 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdSecureOutput"));
       
   259 	iSecureOutput = iAudioOutput->SecureOutput();
       
   260 	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdSecureOutput"));
       
   261 	}
       
   262 
       
   263 /**
       
   264  * Set the audio Output
       
   265  * @param aSection - Section to read param from the ini file
       
   266  * @return none
       
   267  */
       
   268 void CT_CAudioOutputData::DoCmdSetAudioOutputL(const TTEFSectionName& aSection)
       
   269 	{
       
   270 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdSetAudioOutputL"));
       
   271 	TInt parAudioOutput;
       
   272 	if(!GetEnumFromConfig(aSection, KAudioOutputPar, iEnumOutputOptions, parAudioOutput))
       
   273 		{
       
   274 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KAudioOutputPar);
       
   275     	SetBlockResult(EFail); 		
       
   276 		}
       
   277 	else{
       
   278 	    TRAPD(error, iAudioOutput->SetAudioOutputL((CAudioOutput::TAudioOutputPreference)parAudioOutput));
       
   279 	    if( error != KErrNone )
       
   280 	        {
       
   281 	        ERR_PRINTF2(_L("Setting Audio output failed with error %d"), error);
       
   282 	        SetError(error);
       
   283 	        }    
       
   284 	    else
       
   285 	    	{
       
   286 	    	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdSetAudioOutputL"));
       
   287 	    	}
       
   288 		}
       
   289 	}
       
   290 
       
   291 /**
       
   292  * Set the secure output
       
   293  * @param aSection - Section to read param from the ini file
       
   294  * @return none
       
   295  */
       
   296 void CT_CAudioOutputData::DoCmdSetSecureOutputL(const TTEFSectionName& aSection)
       
   297 	{
       
   298 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdSetSecureOutputL"));
       
   299     TBool parSecureOutput;    
       
   300 	if(!GetBoolFromConfig(aSection, KSecureOutputPar, parSecureOutput))
       
   301 		{
       
   302 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSecureOutputPar);
       
   303     	SetBlockResult(EFail);
       
   304     	    		
       
   305 		}
       
   306 	else
       
   307 		{
       
   308 		TRAPD( error, iAudioOutput->SetSecureOutputL(parSecureOutput) );
       
   309 	    if( error != KErrNone ) 
       
   310 	        {
       
   311 	        ERR_PRINTF2(_L("Setting secure output failed with error %d"), error);
       
   312 	        SetError(error);
       
   313 	        }
       
   314 	    else
       
   315 	    	{
       
   316 	    	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdSetSecureOutputL"));
       
   317 	    	}
       
   318 		}
       
   319 	}
       
   320 
       
   321 /**
       
   322  * Unregister the observer
       
   323  * @param none
       
   324  * @return none
       
   325  */
       
   326 void CT_CAudioOutputData::DoCmdUnregisterObserver() 
       
   327 	{
       
   328 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DoCmdUnregisterObserver"));
       
   329 	iAudioOutput->UnregisterObserver(*this);
       
   330 	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DoCmdUnregisterObserver"));
       
   331 	}
       
   332 
       
   333 /**
       
   334  * Shows that the audio output was change
       
   335  * @param aAudioOutput
       
   336  * @param aNewDefault  - The new default value
       
   337  */
       
   338 void CT_CAudioOutputData::DefaultAudioOutputChanged(CAudioOutput& /*aAudioOutput*/, CAudioOutput::TAudioOutputPreference aNewDefault)
       
   339 	{
       
   340 	INFO_PRINTF1(_L("*START*CT_CAudioOutputData::DefaultAudioOutputChanged"));
       
   341 	INFO_PRINTF2(_L("Audio Output changed to %d"), aNewDefault);
       
   342 	INFO_PRINTF1(_L("*END*CT_CAudioOutputData::DefaultAudioOutputChanged"));
       
   343 	}