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