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