|
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_crestrictedaudiooutputdata.h" |
|
21 |
|
22 /*@{*/ |
|
23 //Command literals |
|
24 _LIT(KCmdNewL, "NewL"); |
|
25 _LIT(KCmdDestructor, "~"); |
|
26 _LIT(KCmdAppendAllowedOutput, "AppendAllowedOutput"); |
|
27 _LIT(KCmdRemoveAllowedOutput, "RemoveAllowedOutput"); |
|
28 _LIT(KCmdGetAllowedOutput, "GetAllowedOutput"); |
|
29 _LIT(KCmdGetAllowedOutputCount, "GetAllowedOutputCount"); |
|
30 _LIT(KCmdReset, "Reset"); |
|
31 _LIT(KCmdCommit, "Commit"); |
|
32 /*@}*/ |
|
33 |
|
34 /*@{*/ |
|
35 //INI Section name literals |
|
36 _LIT(KOutput, "Output"); |
|
37 _LIT(KIndex, "Index"); |
|
38 _LIT(KDevSoundInstanceName, "DevSoundInstanceName"); |
|
39 /*@}*/ |
|
40 |
|
41 /*@{*/ |
|
42 //Enumeration Literals |
|
43 _LIT(KEAllowAllAudio, "EAllowAllAudio"); |
|
44 _LIT(KEAllowAudioAnalog, "EAllowAudioAnalog"); |
|
45 _LIT(KEAllowAudioFMTransmitter, "EAllowAudioFMTransmitter"); |
|
46 _LIT(KEAllowAudioBtHFPHSP, "EAllowAudioBtHFPHSP"); |
|
47 _LIT(KEAllowAudioBtA2DP, "EAllowAudioBtA2DP"); |
|
48 _LIT(KEAllowAudioUplink, "EAllowAudioUplink"); |
|
49 _LIT(KEAllowAudioUsb, "EAllowAudioUsb"); |
|
50 _LIT(KEAllowAudioRecording, "EAllowAudioRecording"); |
|
51 _LIT(KEAllowVisualization, "EAllowVisualization"); |
|
52 /*@}*/ |
|
53 |
|
54 const CDataWrapperBase::TEnumEntryTable CT_CRestrictedAudioOutputData::iEnumAllowedOutputPreference[]= |
|
55 { |
|
56 { KEAllowAllAudio, CRestrictedAudioOutput::EAllowAllAudio}, |
|
57 { KEAllowAudioAnalog, CRestrictedAudioOutput::EAllowAudioAnalog}, |
|
58 { KEAllowAudioFMTransmitter, CRestrictedAudioOutput::EAllowAudioFMTransmitter}, |
|
59 { KEAllowAudioBtHFPHSP, CRestrictedAudioOutput::EAllowAudioBtHFPHSP}, |
|
60 { KEAllowAudioBtA2DP, CRestrictedAudioOutput::EAllowAudioBtA2DP}, |
|
61 { KEAllowAudioUplink, CRestrictedAudioOutput::EAllowAudioUplink}, |
|
62 { KEAllowAudioUsb, CRestrictedAudioOutput::EAllowAudioUsb}, |
|
63 { KEAllowAudioRecording, CRestrictedAudioOutput::EAllowAudioRecording}, |
|
64 { KEAllowVisualization, CRestrictedAudioOutput::EAllowVisualization} |
|
65 }; |
|
66 |
|
67 /** |
|
68 * Public destructor |
|
69 */ |
|
70 CT_CRestrictedAudioOutputData::~CT_CRestrictedAudioOutputData() |
|
71 { |
|
72 DestroyData(); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Two phase constructor |
|
77 * |
|
78 * @leave system wide error |
|
79 */ |
|
80 CT_CRestrictedAudioOutputData* CT_CRestrictedAudioOutputData::NewL() |
|
81 { |
|
82 CT_CRestrictedAudioOutputData* ret = new (ELeave) CT_CRestrictedAudioOutputData(); |
|
83 return ret; |
|
84 } |
|
85 |
|
86 /** |
|
87 * Return a pointer to the object that the data wraps |
|
88 * |
|
89 * @return pointer to the object that the data wraps |
|
90 */ |
|
91 TAny* CT_CRestrictedAudioOutputData::GetObject() |
|
92 { |
|
93 return iRestrictedAudioOutput; |
|
94 } |
|
95 |
|
96 /** |
|
97 * Helper destructor |
|
98 */ |
|
99 void CT_CRestrictedAudioOutputData::DestroyData() |
|
100 { |
|
101 if (iRestrictedAudioOutput) |
|
102 { |
|
103 delete iRestrictedAudioOutput; |
|
104 iRestrictedAudioOutput = NULL; |
|
105 } |
|
106 } |
|
107 /** |
|
108 * Process a command read from the Ini file |
|
109 * @param aCommand The command to process |
|
110 * @param aSection The section get from the *.ini file of the project T_Wlan |
|
111 * @param aAsyncErrorIndex Command index dor async calls to returns errors to |
|
112 * @return TBool ETrue if the command is process |
|
113 * @leave system wide error |
|
114 */ |
|
115 TBool CT_CRestrictedAudioOutputData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
116 { |
|
117 TBool ret = ETrue; |
|
118 |
|
119 if (aCommand == KCmdNewL) |
|
120 { |
|
121 DoCmdNewL(aSection); |
|
122 } |
|
123 else if (aCommand == KCmdDestructor) |
|
124 { |
|
125 DoCmdDestructor(); |
|
126 } |
|
127 else if (aCommand == KCmdAppendAllowedOutput) |
|
128 { |
|
129 DoCmdAppendAllowedOutput(aSection); |
|
130 } |
|
131 else if (aCommand == KCmdRemoveAllowedOutput) |
|
132 { |
|
133 DoCmdRemoveAllowedOutput(aSection); |
|
134 } |
|
135 else if (aCommand == KCmdGetAllowedOutput) |
|
136 { |
|
137 DoCmdGetAllowedOutput(aSection); |
|
138 } |
|
139 else if (aCommand == KCmdGetAllowedOutputCount) |
|
140 { |
|
141 DoCmdGetAllowedOutputCount(); |
|
142 } |
|
143 else if (aCommand == KCmdReset) |
|
144 { |
|
145 DoCmdReset(); |
|
146 } |
|
147 else if (aCommand == KCmdCommit) |
|
148 { |
|
149 DoCmdCommit(); |
|
150 } |
|
151 else |
|
152 { |
|
153 ERR_PRINTF1(_L("Unknown command")); |
|
154 ret=EFalse; |
|
155 } |
|
156 |
|
157 return ret; |
|
158 } |
|
159 |
|
160 /** |
|
161 * Create a new instance of CRestrictedAudioOutput |
|
162 * @param aSection - Section to read from the ini file |
|
163 * @return void |
|
164 */ |
|
165 void CT_CRestrictedAudioOutputData::DoCmdNewL(const TTEFSectionName& aSection) |
|
166 { |
|
167 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdNewL()")); |
|
168 DestroyData(); |
|
169 TPtrC devSoundInstanceName; |
|
170 if (!GetStringFromConfig(aSection, KDevSoundInstanceName, devSoundInstanceName)) |
|
171 { |
|
172 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDevSoundInstanceName); |
|
173 SetBlockResult(EFail); |
|
174 } |
|
175 else |
|
176 { |
|
177 CMMFDevSound* mMFDevSound = static_cast<CMMFDevSound*>(GetDataObjectL(devSoundInstanceName)); |
|
178 TInt error; |
|
179 if ( !iRestrictedAudioOutput ) |
|
180 { |
|
181 if ( mMFDevSound ) |
|
182 { |
|
183 CleanupStack::PushL(mMFDevSound); |
|
184 iRestrictedAudioOutput = (CRestrictedAudioOutput*)mMFDevSound->CustomInterface(KUidRestrictedAudioOutput); |
|
185 if ( iRestrictedAudioOutput == NULL ) |
|
186 { |
|
187 ERR_PRINTF1(_L("Failed to create RestrictedAudioOutput")); |
|
188 error = KErrNotFound; |
|
189 SetError(error); |
|
190 } |
|
191 else |
|
192 { |
|
193 INFO_PRINTF1(_L("RestrictedAudioOutput created")); |
|
194 CleanupStack::Pop(mMFDevSound); |
|
195 } |
|
196 } |
|
197 else |
|
198 { |
|
199 ERR_PRINTF1(_L("DevSound not ready")); |
|
200 error = KErrNotReady; |
|
201 SetError(error); |
|
202 } |
|
203 } |
|
204 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdNewL()")); |
|
205 } |
|
206 } |
|
207 |
|
208 /** |
|
209 * Delete an instance of CRestrictedAudioOutput |
|
210 * @param |
|
211 * @return void |
|
212 */ |
|
213 void CT_CRestrictedAudioOutputData::DoCmdDestructor() |
|
214 { |
|
215 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdDestructor()")); |
|
216 DestroyData(); |
|
217 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdDestructor()")); |
|
218 } |
|
219 |
|
220 /** |
|
221 * Appends an allowed output to the existing list. |
|
222 * @param aSection - The section to read from the ini file |
|
223 * @return void |
|
224 */ |
|
225 void CT_CRestrictedAudioOutputData::DoCmdAppendAllowedOutput(const TTEFSectionName& aSection) |
|
226 { |
|
227 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdAppendAllowedOutput()")); |
|
228 TInt output; |
|
229 if ( !GetEnumFromConfig(aSection, KOutput, iEnumAllowedOutputPreference, output) ) |
|
230 { |
|
231 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KOutput); |
|
232 SetBlockResult(EFail); |
|
233 } |
|
234 else |
|
235 { |
|
236 TInt error; |
|
237 error = iRestrictedAudioOutput->AppendAllowedOutput((CRestrictedAudioOutput::TAllowedOutputPreference) output); |
|
238 |
|
239 if ( (error!=KErrNone) && (error!=KErrAlreadyExists) ) |
|
240 { |
|
241 ERR_PRINTF2(_L("Error in appending allowed output. Error: %d"), error); |
|
242 SetError(error); |
|
243 } |
|
244 else |
|
245 { |
|
246 INFO_PRINTF2(_L("Allowed output 0x%x appended"), (CRestrictedAudioOutput::TAllowedOutputPreference) output); |
|
247 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdAppendAllowedOutput()")); |
|
248 } |
|
249 } |
|
250 } |
|
251 |
|
252 /** |
|
253 * Removes an allowed output from the existing list. |
|
254 * @param aSection - The section to read from the ini file |
|
255 * @return void |
|
256 */ |
|
257 void CT_CRestrictedAudioOutputData::DoCmdRemoveAllowedOutput(const TTEFSectionName& aSection) |
|
258 { |
|
259 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdRemoveAllowedOutput()")); |
|
260 TInt output; |
|
261 if(!GetEnumFromConfig(aSection, KOutput, iEnumAllowedOutputPreference, output)) |
|
262 { |
|
263 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KOutput); |
|
264 SetBlockResult(EFail); |
|
265 } |
|
266 else |
|
267 { |
|
268 TInt error; |
|
269 error = iRestrictedAudioOutput->RemoveAllowedOutput((CRestrictedAudioOutput::TAllowedOutputPreference) output); |
|
270 if (error != KErrNone) |
|
271 { |
|
272 ERR_PRINTF2(_L("Error in removing allowed output. Error: %d"), error); |
|
273 SetError(error); |
|
274 } |
|
275 else |
|
276 { |
|
277 INFO_PRINTF2(_L("Allowed output 0x%x removed"), (CRestrictedAudioOutput::TAllowedOutputPreference) output); |
|
278 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdRemoveAllowedOutput()")); |
|
279 } |
|
280 } |
|
281 } |
|
282 |
|
283 /** |
|
284 * Gets a reference to an allowed output located at a specified position |
|
285 * within the list. |
|
286 * @param aSection - The section to read from the ini file |
|
287 * @return void |
|
288 */ |
|
289 void CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutput(const TTEFSectionName& aSection) |
|
290 { |
|
291 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutput()")); |
|
292 TInt index; |
|
293 if ( !GetIntFromConfig(aSection, KIndex, index) ) |
|
294 { |
|
295 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KIndex); |
|
296 SetBlockResult(EFail); |
|
297 } |
|
298 else |
|
299 { |
|
300 TInt error; |
|
301 CRestrictedAudioOutput::TAllowedOutputPreference allowedOutput; |
|
302 error = iRestrictedAudioOutput->GetAllowedOutput(index, allowedOutput); |
|
303 if ( error != KErrNone ) |
|
304 { |
|
305 ERR_PRINTF2(_L("Error in getting allowed output. Error: %d"), error); |
|
306 SetError(error); |
|
307 } |
|
308 else |
|
309 { |
|
310 switch (allowedOutput) |
|
311 { |
|
312 case CRestrictedAudioOutput::EAllowAllAudio: |
|
313 INFO_PRINTF1(_L("AllowAllAudio")); |
|
314 break; |
|
315 case CRestrictedAudioOutput::EAllowAudioAnalog: |
|
316 INFO_PRINTF1(_L("AllowAudioAnalog")); |
|
317 break; |
|
318 case CRestrictedAudioOutput::EAllowAudioFMTransmitter: |
|
319 INFO_PRINTF1(_L("AllowAudioFMTransmitter")); |
|
320 break; |
|
321 case CRestrictedAudioOutput::EAllowAudioBtHFPHSP: |
|
322 INFO_PRINTF1(_L("AllowAudioBtHFPHSP")); |
|
323 break; |
|
324 case CRestrictedAudioOutput::EAllowAudioBtA2DP: |
|
325 INFO_PRINTF1(_L("AllowAudioBtA2DP")); |
|
326 break; |
|
327 case CRestrictedAudioOutput::EAllowAudioUplink: |
|
328 INFO_PRINTF1(_L("AllowAudioUplink")); |
|
329 break; |
|
330 case CRestrictedAudioOutput::EAllowAudioUsb: |
|
331 INFO_PRINTF1(_L("AllowAudioUsb")); |
|
332 break; |
|
333 case CRestrictedAudioOutput::EAllowAudioRecording: |
|
334 INFO_PRINTF1(_L("AllowAudioRecording")); |
|
335 break; |
|
336 case CRestrictedAudioOutput::EAllowVisualization: |
|
337 INFO_PRINTF1(_L("AllowVisualization")); |
|
338 break; |
|
339 default: |
|
340 INFO_PRINTF2(_L("Unknown output 0x%x"), allowedOutput); |
|
341 } |
|
342 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutput()")); |
|
343 } |
|
344 } |
|
345 } |
|
346 |
|
347 |
|
348 /** |
|
349 * Gets the number of allowed objects in the array. * |
|
350 * @param |
|
351 * @return void |
|
352 */ |
|
353 void CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutputCount() |
|
354 { |
|
355 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutputCount()")); |
|
356 TInt error, size; |
|
357 error = iRestrictedAudioOutput->GetAllowedOutputCount(size); |
|
358 if(error != KErrNone) |
|
359 { |
|
360 ERR_PRINTF2(_L("Error in getting allowed output count. Error: %d"), error); |
|
361 SetError(error); |
|
362 } |
|
363 else |
|
364 { |
|
365 INFO_PRINTF2(_L("Allowed output count: %d"), size); |
|
366 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdGetAllowedOutputCount()")); |
|
367 } |
|
368 } |
|
369 |
|
370 /** |
|
371 * Empties the list, so that it is ready to be reused. |
|
372 * |
|
373 * @param |
|
374 * @return void |
|
375 */ |
|
376 void CT_CRestrictedAudioOutputData::DoCmdReset() |
|
377 { |
|
378 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdReset()")); |
|
379 TInt error; |
|
380 error = iRestrictedAudioOutput->Reset(); |
|
381 if (error!=KErrNone) |
|
382 { |
|
383 ERR_PRINTF2(_L("Error in reset. Error: %d"), error); |
|
384 SetError(error); |
|
385 } |
|
386 else |
|
387 { |
|
388 INFO_PRINTF1(_L("Reset successfully")); |
|
389 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdReset()")); |
|
390 } |
|
391 } |
|
392 |
|
393 |
|
394 /** |
|
395 * Applies settings cached locally and commits. |
|
396 * |
|
397 * This function can only be called when the DevSound instance is in Idle OR |
|
398 * Stopped state. |
|
399 * @param |
|
400 * @return |
|
401 */ |
|
402 |
|
403 void CT_CRestrictedAudioOutputData::DoCmdCommit() |
|
404 { |
|
405 INFO_PRINTF1(_L("*START*CT_CRestrictedAudioOutputData::DoCmdCommit()")); |
|
406 TInt error; |
|
407 error = iRestrictedAudioOutput->Commit(); |
|
408 if (error != KErrNone) |
|
409 { |
|
410 ERR_PRINTF2(_L("Error in Commit. Error: %d"), error); |
|
411 SetError(error); |
|
412 } |
|
413 else |
|
414 { |
|
415 INFO_PRINTF1(_L("Commit successfully")); |
|
416 INFO_PRINTF1(_L("*END*CT_CRestrictedAudioOutputData::DoCmdCommit()")); |
|
417 } |
|
418 } |