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