1 /* |
|
2 * Copyright (c) 2008 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: Mediator command sender implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cvtengmdtrcommandsender.h" |
|
22 #include "CVtEngEventManager.h" |
|
23 #include "VtEngUtils.h" |
|
24 #include "CVtEngSettings.h" |
|
25 #include "CVtEngOperation.h" |
|
26 #include "vtengcommands.h" |
|
27 #include "CVtEngStateManager.h" |
|
28 #include "VtEngPanic.h" |
|
29 #include <mediatorcommandinitiator.h> |
|
30 #include <mediatordomainuids.h> |
|
31 #include <mediatorcommandstotelephonyapi.h> |
|
32 #include <mediatoraudiocommandstotelephonyapi.h> |
|
33 #include <videoteltophonecommandsapi.h> |
|
34 #include <cvtlogger.h> |
|
35 |
|
36 |
|
37 /** |
|
38 * Three state classes for handling audio mute/unmute commands towards mediator when mute state |
|
39 * is changed locally faster than mediator gives response. |
|
40 |
|
41 |
|
42 IDLE <-------------------------| |
|
43 | | |
|
44 NotifyOutgoingAudioState( x ) / mediator.Send( x ) | |
|
45 | | |
|
46 v | |
|
47 |--------------------------------------> SENDING -- CommandResponseL ---| |
|
48 | | |
|
49 | NotifyOutgoingAudioState( y ) / saveCommand( y ) |
|
50 | | |
|
51 | v |
|
52 |- CommandResponseL( x ) / Send( y ) ---- BUFFERED |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 */ |
|
58 NONSHARABLE_CLASS( TVtMdtrStateIdle ) : public CBase |
|
59 { |
|
60 public: |
|
61 TVtMdtrStateIdle( CVtEngMdtrCommandSender& aSender, CMediatorCommandInitiator& aMediator ); |
|
62 virtual void SendL( TUid aDomain, TUid aCategory, TInt aCommand ); |
|
63 virtual void CommandResponseL( TUid aDomain, TUid aCategory, TInt aCommand, TInt aStatus ); |
|
64 |
|
65 TInt DoSend( TUid aDomain, TUid aCategory, TInt aCommand ); |
|
66 |
|
67 CVtEngMdtrCommandSender& iSender; |
|
68 CMediatorCommandInitiator& iMediator; |
|
69 }; |
|
70 |
|
71 NONSHARABLE_CLASS( TVtMdtrStateSending ) : public TVtMdtrStateIdle |
|
72 { |
|
73 public: |
|
74 TVtMdtrStateSending( CVtEngMdtrCommandSender& aSender, CMediatorCommandInitiator& aMediator ); |
|
75 void SendL( TUid aDomain, TUid aCategory, TInt aCommand ); |
|
76 void CommandResponseL( TUid aDomain, TUid aCategory, TInt aCommand, TInt aStatus ); |
|
77 }; |
|
78 |
|
79 NONSHARABLE_CLASS( TVtMdtrStateBuffered ) : public TVtMdtrStateIdle |
|
80 { |
|
81 public: |
|
82 TVtMdtrStateBuffered( CVtEngMdtrCommandSender& aSender, CMediatorCommandInitiator& aMediator ); |
|
83 void SendL( TUid aDomain, TUid aCategory, TInt aCommand ); |
|
84 void CommandResponseL( TUid aDomain, TUid aCategory, TInt aCommand, TInt aStatus ); |
|
85 |
|
86 TUid iDomain; |
|
87 TUid iCategory; |
|
88 TInt iCommand; |
|
89 }; |
|
90 |
|
91 |
|
92 // CONSTANTS |
|
93 // ============================ MEMBER FUNCTIONS =============================== |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CVtEngMdtrCommandListener::NewL |
|
97 // Two-phased constructor. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CVtEngMdtrCommandSender* CVtEngMdtrCommandSender::NewL( CVtEngUtility& aUtils ) |
|
101 { |
|
102 __VTPRINTENTER( "CVtEngMdtrCommandSender.NewL" ) |
|
103 CVtEngMdtrCommandSender* self = new ( ELeave ) |
|
104 CVtEngMdtrCommandSender( aUtils ); |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL( ); |
|
107 CleanupStack::Pop(); |
|
108 |
|
109 __VTPRINTEXIT( "CVtEngMdtrCommandSender.NewL" ) |
|
110 return self; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CVtEngMdtrCommandListener::~CVtEngMdtrCommandSender |
|
115 // destructor |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 CVtEngMdtrCommandSender::~CVtEngMdtrCommandSender() |
|
119 { |
|
120 iUtils.EventManager().RemoveObserver( this ); |
|
121 delete iMediatorInitiator; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CVtEngMdtrCommandListener::EndCall |
|
126 // Sends end call command via Mediator |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CVtEngMdtrCommandSender::EndCall( ) |
|
130 { |
|
131 __VTPRINTENTER( "CVtEngMdtrCommandSender.EndCall" ) |
|
132 const TVersion KTelephonyCmdVersion( |
|
133 KTelephonyCommandsVersionMajor, |
|
134 KTelephonyCommandsVersionMinor, |
|
135 KTelephonyCommandsVersionBuild ); |
|
136 const TInt res = |
|
137 iMediatorInitiator->IssueCommand( |
|
138 KMediatorTelephonyDomain, |
|
139 KCatCommandsToTelephony, |
|
140 EPhoneCmdEndActiveCall, |
|
141 KTelephonyCmdVersion, |
|
142 KNullDesC8() ); |
|
143 |
|
144 __VTPRINTEXITR( "CVtEngMdtrCommandSender.EndCall res=%d", res ) |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CVtEngMdtrCommandListener::VoiceFallback |
|
149 // Sends voice fallback command to telephony via Mediator |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CVtEngMdtrCommandSender::VoiceFallback() |
|
153 { |
|
154 __VTPRINTENTER( "CVtEngMdtrCommandSender.VoiceFallback" ) |
|
155 const TVersion KVtToPhoneCmdVersion( |
|
156 KVideoTelToPhoneCmdVersionMajor, |
|
157 KVideoTelToPhoneCmdVersionMinor, |
|
158 KVideoTelToPhoneCmdVersionBuild ); |
|
159 #ifdef _DEBUG |
|
160 TInt err = |
|
161 #endif |
|
162 iMediatorInitiator->IssueCommand( |
|
163 KMediatorTelephonyDomain, |
|
164 KCatVideoTelToPhoneCommands, |
|
165 EVtCmdFallback, |
|
166 KVtToPhoneCmdVersion, |
|
167 KNullDesC8() ); |
|
168 // response is not awaited |
|
169 __VTPRINTEXITR( "CVtEngMdtrCommandSender.VoiceFallback %d>", err ) |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CVtEngMdtrCommandListener::SwitchToVoiceL |
|
174 // Sends switch to voice command to telephony via Mediator |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CVtEngMdtrCommandSender::SwitchToVoiceL( CVtEngOperation& aOperation ) |
|
178 { |
|
179 __VTPRINTENTER( "CVtEngMdtrCommandSender.SwitchToVoiceL" ) |
|
180 iOperation = &aOperation; |
|
181 // add this as observer. Mediator command is sent when idle state |
|
182 // is reached (i.e. Protocol has released dataport and it can be recovered |
|
183 // by telephony) |
|
184 iUtils.EventManager().AddObserverL( this ); |
|
185 // let current state handle actual request |
|
186 iUtils.StateManager()->HandleOperationL( aOperation ); |
|
187 __VTPRINTEXIT( "CVtEngMdtrCommandSender.SwitchToVoiceL" ) |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CVtEngMdtrCommandListener::NotifyOutgoingAudioState |
|
192 // Sends microphone state to telephony via Mediator |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CVtEngMdtrCommandSender::NotifyOutgoingAudioState( |
|
196 const TBool aMicEnabled ) |
|
197 { |
|
198 __VTPRINTENTER( "CVtEngMdtrCommandSender.NotifyOutgoingAudioState" ) |
|
199 |
|
200 const TInt command = ( aMicEnabled ) |
|
201 ? EAudioCmdUnmute : EAudioCmdMute; |
|
202 #ifdef _DEBUG |
|
203 TRAPD( res, iSenderState->SendL( |
|
204 KMediatorTelephonyDomain, |
|
205 KCatAudioCommandsToTelephony, |
|
206 command ) ); |
|
207 #else |
|
208 TRAP_IGNORE(iSenderState->SendL( |
|
209 KMediatorTelephonyDomain, |
|
210 KCatAudioCommandsToTelephony, |
|
211 command ) ); |
|
212 #endif |
|
213 |
|
214 __VTPRINTEXITR( "CVtEngMdtrCommandSender.NotifyOutgoingAudioState %d", res ) |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CVtEngMdtrCommandListener::SetSenderState |
|
219 // sets new mediator sender state for audio command |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CVtEngMdtrCommandSender::SetSenderState( TVtMdtrStateIdle& aNewState ) |
|
223 { |
|
224 __VTPRINTENTER( "CVtEngMdtrCommandSender.SetSenderState" ) |
|
225 __VTPRINT2( DEBUG_GEN, " delete old state %x", (TInt) iSenderState ) |
|
226 __ASSERT_DEBUG( iSenderState != &aNewState, |
|
227 Panic( EVtEngPanicWrongMediatorSenderState ) ); |
|
228 delete iSenderState; |
|
229 iSenderState = &aNewState; |
|
230 __VTPRINTEXITR( "CVtEngMdtrCommandSender.SetSenderState %x", (TInt) iSenderState ) |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CVtEngMdtrCommandListener::CommandResponseL |
|
235 // Mediator framework callback |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CVtEngMdtrCommandSender::CommandResponseL( TUid aDomain, |
|
239 TUid aCategory, |
|
240 TInt aCommandId, |
|
241 TInt aStatus, |
|
242 const TDesC8& /*aData*/ ) |
|
243 { |
|
244 __VTPRINTENTER( "CVtEngMdtrCommandSender.CommandResponseL" ) |
|
245 switch ( aCommandId ) |
|
246 { |
|
247 case EAudioCmdUnmute: |
|
248 case EAudioCmdMute: |
|
249 iSenderState->CommandResponseL( aDomain, aCategory, aCommandId, aStatus ); |
|
250 break; |
|
251 default: |
|
252 // ignored for other commands (so far) |
|
253 break; |
|
254 } |
|
255 __VTPRINT2( DEBUG_GEN, " mediator command id=%d", aCommandId ) |
|
256 __VTPRINTEXITR( "CVtEngMdtrCommandSender.CommandResponseL res=%d", aStatus ) |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CVtEngMdtrCommandListener::HandleVtEventL |
|
261 // Handles state change event associated with "switch to voice" and "TerminateSession" command |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CVtEngMdtrCommandSender::HandleVtEventL( TInt aEvent ) |
|
265 { |
|
266 __VTPRINTENTER( "CVtEngMdtrCommandSender.HandleVtEventL" ) |
|
267 #ifdef _DEBUG |
|
268 TInt err = KErrNone; |
|
269 #endif |
|
270 if ( aEvent == KVtEngSessionStateChanged && |
|
271 iOperation && iOperation->Command() == KVtEngSwitchToVoice ) |
|
272 { |
|
273 const TVersion KVtToPhoneCmdVersion( |
|
274 KVideoTelToPhoneCmdVersionMajor, |
|
275 KVideoTelToPhoneCmdVersionMinor, |
|
276 KVideoTelToPhoneCmdVersionBuild ); |
|
277 |
|
278 iUtils.EventManager().RemoveObserver( this ); |
|
279 // send command (ignore possible error - no way to recover from it) |
|
280 #ifdef _DEBUG |
|
281 err = |
|
282 #endif |
|
283 iMediatorInitiator->IssueCommand( |
|
284 //KMediatorVideoTelephonyDomain, |
|
285 KMediatorTelephonyDomain, |
|
286 KCatVideoTelToPhoneCommands, |
|
287 EVtCmdSwitchToVoice, |
|
288 KVtToPhoneCmdVersion, |
|
289 KNullDesC8() ); |
|
290 iOperation->HandleOpComplete( KErrNone ); |
|
291 iOperation = NULL; |
|
292 } |
|
293 __VTPRINTEXITR( "CVtEngMdtrCommandSender.HandleVtEventL %d", err ) |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CVtEngMdtrCommandListener:: |
|
298 // c++ constructor |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 CVtEngMdtrCommandSender::CVtEngMdtrCommandSender( CVtEngUtility& aUtils ) : |
|
302 iUtils( aUtils ) |
|
303 { |
|
304 __VTPRINTENTER( "CVtEngMdtrCommandSender.CVtEngMdtrCommandSender" ) |
|
305 __VTPRINTEXIT( "CVtEngMdtrCommandSender.CVtEngMdtrCommandSender" ) |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CVtEngMdtrCommandListener::ConstructL |
|
310 // |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CVtEngMdtrCommandSender::ConstructL() |
|
314 { |
|
315 __VTPRINTENTER( "CVtEngMdtrCommandSender.ConstructL" ) |
|
316 iMediatorInitiator = CMediatorCommandInitiator::NewL( this ); |
|
317 |
|
318 // set initial mediator command sender state |
|
319 iSenderState = new ( ELeave ) TVtMdtrStateIdle( *this, *iMediatorInitiator ); |
|
320 __VTPRINTEXIT( "CVtEngMdtrCommandSender.ConstructL" ) |
|
321 } |
|
322 |
|
323 TVtMdtrStateIdle::TVtMdtrStateIdle( CVtEngMdtrCommandSender& aSender, CMediatorCommandInitiator& aMediator ) |
|
324 : iSender( aSender), iMediator( aMediator ) |
|
325 { |
|
326 __VTPRINTENTER( "TVtMdtrStateIdle.ctr" ) |
|
327 __VTPRINTEXITR( "TVtMdtrStateIdle.ctr %x", (TInt) this ) |
|
328 } |
|
329 |
|
330 void TVtMdtrStateIdle::SendL( TUid aDomain, TUid aCategory, TInt aCommand ) |
|
331 { |
|
332 __VTPRINTENTER( "TVtMdtrStateIdle.SendL" ) |
|
333 TVtMdtrStateIdle* nextState = NULL; |
|
334 const TInt res = DoSend( aDomain, aCategory, aCommand ); |
|
335 if ( res == KErrInUse ) |
|
336 { |
|
337 nextState = new ( ELeave ) TVtMdtrStateBuffered( iSender, iMediator ); |
|
338 CleanupStack::PushL( nextState ); |
|
339 nextState->SendL( aDomain, aCategory, aCommand ); |
|
340 CleanupStack::Pop( nextState ); |
|
341 } |
|
342 else |
|
343 { |
|
344 nextState = new ( ELeave ) TVtMdtrStateSending( iSender, iMediator ); |
|
345 } |
|
346 iSender.SetSenderState( *nextState ); |
|
347 __VTPRINTEXIT( "TVtMdtrStateIdle.SendL" ) |
|
348 } |
|
349 |
|
350 TInt TVtMdtrStateIdle::DoSend( TUid aDomain, TUid aCategory, TInt aCommand ) |
|
351 { |
|
352 __VTPRINTENTER( "TVtMdtrStateIdle.DoSend" ) |
|
353 const TVersion KVtToPhoneCmdVersion( |
|
354 KVideoTelToPhoneCmdVersionMajor, |
|
355 KVideoTelToPhoneCmdVersionMinor, |
|
356 KVideoTelToPhoneCmdVersionBuild ); |
|
357 |
|
358 TInt res = iMediator.IssueCommand( |
|
359 aDomain, |
|
360 aCategory, |
|
361 aCommand, |
|
362 KVtToPhoneCmdVersion, |
|
363 KNullDesC8() ); |
|
364 __VTPRINTEXITR( "TVtMdtrStateIdle.DoSend res=%d", res ) |
|
365 return res; |
|
366 } |
|
367 |
|
368 void TVtMdtrStateIdle::CommandResponseL( TUid /*aDomain*/, TUid /*aCategory*/, TInt /*aCommand*/, TInt /*aStatus*/ ) |
|
369 { |
|
370 __VTPRINTENTER( "TVtMdtrStateIdle.CommandResponseL" ) |
|
371 // base class method should never be possible to call |
|
372 __VTPRINTEXIT( "TVtMdtrStateIdle.CommandResponseL" ) |
|
373 } |
|
374 |
|
375 TVtMdtrStateSending::TVtMdtrStateSending( CVtEngMdtrCommandSender& aSender, CMediatorCommandInitiator& aMediator ) |
|
376 : TVtMdtrStateIdle( aSender, aMediator ) |
|
377 { |
|
378 __VTPRINTENTER( "TVtMdtrStateSending.ctr" ) |
|
379 __VTPRINTEXITR( "TVtMdtrStateSending.ctr %x", (TInt) this ) |
|
380 } |
|
381 |
|
382 void TVtMdtrStateSending::SendL( TUid aDomain, TUid aCategory, TInt aCommand ) |
|
383 { |
|
384 __VTPRINTENTER( "TVtMdtrStateSending.SendL" ) |
|
385 TVtMdtrStateIdle* buffered = new ( ELeave )TVtMdtrStateBuffered( iSender, iMediator ); |
|
386 CleanupStack::PushL( buffered ); |
|
387 buffered->SendL( aDomain, aCategory, aCommand ); |
|
388 CleanupStack::Pop( buffered ); |
|
389 iSender.SetSenderState( *buffered ); |
|
390 __VTPRINTEXIT( "TVtMdtrStateSending.SendL" ) |
|
391 } |
|
392 |
|
393 void TVtMdtrStateSending::CommandResponseL( TUid aDomain, TUid aCategory, TInt aCommand, TInt aStatus ) |
|
394 { |
|
395 __VTPRINTENTER( "TVtMdtrStateSending.CommandResponseL" ) |
|
396 __VTPRINT2( DEBUG_GEN, " command=%d", aCommand ) |
|
397 __VTPRINT2( DEBUG_GEN, " response=%d", aStatus ) |
|
398 TVtMdtrStateIdle* idle = new ( ELeave ) TVtMdtrStateIdle( iSender, iMediator ); |
|
399 iSender.SetSenderState( *idle ); |
|
400 __VTPRINTEXIT( "TVtMdtrStateSending.CommandResponseL" ) |
|
401 } |
|
402 |
|
403 TVtMdtrStateBuffered::TVtMdtrStateBuffered( CVtEngMdtrCommandSender& aSender, CMediatorCommandInitiator& aMediator ) |
|
404 : TVtMdtrStateIdle( aSender, aMediator ) |
|
405 { |
|
406 __VTPRINTENTER( "TVtMdtrStateBuffered.ctr" ) |
|
407 __VTPRINTEXITR( "TVtMdtrStateBuffered.ctr %x", (TInt) this ) |
|
408 } |
|
409 |
|
410 void TVtMdtrStateBuffered::SendL( TUid aDomain, TUid aCategory, TInt aCommand ) |
|
411 { |
|
412 __VTPRINTENTER( "TVtMdtrStateBuffered.SendL" ) |
|
413 |
|
414 iDomain = aDomain; |
|
415 iCategory = aCategory; |
|
416 iCommand = aCommand; |
|
417 // iCommand is sent in CommandResponseL |
|
418 __VTPRINTEXIT( "TVtMdtrStateBuffered.SendL" ) |
|
419 } |
|
420 |
|
421 void TVtMdtrStateBuffered::CommandResponseL( TUid aDomain, TUid aCategory, TInt aCommand, TInt aStatus ) |
|
422 { |
|
423 __VTPRINTENTER( "TVtMdtrStateBuffered.CommandResponseL" ) |
|
424 const TVersion KVtToPhoneCmdVersion( |
|
425 KVideoTelToPhoneCmdVersionMajor, |
|
426 KVideoTelToPhoneCmdVersionMinor, |
|
427 KVideoTelToPhoneCmdVersionBuild ); |
|
428 TBool nextStateIdle = ETrue; |
|
429 TInt res = KErrNone; |
|
430 if ( aCommand != iCommand ) |
|
431 { |
|
432 res = iMediator.IssueCommand( |
|
433 KMediatorTelephonyDomain, |
|
434 KCatAudioCommandsToTelephony, |
|
435 iCommand, |
|
436 KVtToPhoneCmdVersion, |
|
437 KNullDesC8() ); |
|
438 if ( res == KErrNone ) |
|
439 { |
|
440 nextStateIdle = EFalse; |
|
441 } |
|
442 } |
|
443 TVtMdtrStateIdle* nextState = NULL; |
|
444 if ( nextStateIdle ) |
|
445 { |
|
446 __VTPRINT2( DEBUG_GEN, " failed to send buffered command with error=%d", res ) |
|
447 nextState = new ( ELeave ) TVtMdtrStateIdle( iSender, iMediator ); |
|
448 } |
|
449 else |
|
450 { |
|
451 nextState = new ( ELeave ) TVtMdtrStateSending( iSender, iMediator ); |
|
452 CleanupStack::PushL( nextState ); |
|
453 nextState->SendL( iDomain, iCategory, iCommand ); |
|
454 CleanupStack::Pop( nextState ); |
|
455 } |
|
456 iSender.SetSenderState( *nextState ); |
|
457 __VTPRINTEXIT( "TVtMdtrStateBuffered.CommandResponseL" ) |
|
458 } |
|
459 |
|
460 // End of File |
|