|
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 event listener implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cvtengmdtrmessagelistener.h" |
|
22 #include "VtEngUtils.h" |
|
23 #include "CVtEngSettings.h" |
|
24 #include "CVtEngEventManager.h" |
|
25 #include "cvtengmediatorservice.h" |
|
26 |
|
27 #include <cvtlogger.h> |
|
28 #include <videotelcontrolmediatorapi.h> |
|
29 #include <mediatorcommandresponder.h> |
|
30 #include <mediatordomainuids.h> |
|
31 #include <mediatoreventsfromtelephonyapi.h> |
|
32 #include <vtinternalmediatorapi.h> |
|
33 |
|
34 // CONSTANTS |
|
35 |
|
36 // mediator command timeout |
|
37 static const TInt KVtEngMdtrCmdTimeout = 500000; |
|
38 |
|
39 // array granularity is 2 (enable mic, disable mic commands) |
|
40 static const TInt KVtEngMdtrCmdArrayGranularity = 2; |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CVtEngMdtrMessageListener::NewL |
|
46 // Two-phased constructor. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CVtEngMdtrMessageListener* CVtEngMdtrMessageListener::NewL( |
|
50 CVtEngUtility& aUtils ) |
|
51 { |
|
52 __VTPRINTENTER( "CVtEngMdtrMessageListener.NewL" ) |
|
53 CVtEngMdtrMessageListener* self = new( ELeave ) |
|
54 CVtEngMdtrMessageListener( aUtils ); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL( ); |
|
57 CleanupStack::Pop(); |
|
58 __VTPRINTEXIT( "CVtEngMdtrMessageListener.NewL" ) |
|
59 return self; |
|
60 } |
|
61 |
|
62 // Destructor |
|
63 CVtEngMdtrMessageListener::~CVtEngMdtrMessageListener() |
|
64 { |
|
65 // ignore error in unregistering |
|
66 if ( iMediatorResponder ) |
|
67 { |
|
68 iMediatorResponder->UnregisterCommand( |
|
69 KMediatorVideoTelephonyDomain, |
|
70 KCatPhoneToVideotelCommands, |
|
71 iCommandList ); |
|
72 iCommandList.Close(); |
|
73 iMediatorResponder->UnregisterCommand( |
|
74 KMediatorVideoTelephonyDomain, |
|
75 KCatVideotelInternalCommands, |
|
76 EVtMediatorReleaseDataport ); |
|
77 |
|
78 delete iMediatorResponder; |
|
79 } |
|
80 |
|
81 |
|
82 // ignore error in unregistering |
|
83 if ( iMediatorEvents ) |
|
84 { |
|
85 iMediatorEvents->UnsubscribeEvent( KMediatorVideoTelephonyDomain, |
|
86 KCatVideotelInternalEvents, |
|
87 EVtMediatorEventVideoCallInformation ); |
|
88 delete iMediatorEvents; |
|
89 } |
|
90 |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CVtEngMdtrMessageListener::MediatorCommandL |
|
95 // Receives mediator command and passes it to service object |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CVtEngMdtrMessageListener::MediatorCommandL( |
|
99 TUid /*aDomain*/, |
|
100 TUid aCategory, |
|
101 TInt aCommandId, |
|
102 TVersion /*aVersion*/, |
|
103 const TDesC8& /*aData*/ ) |
|
104 { |
|
105 __VTPRINTENTER( "CVtEngMdtrMessageListener.MediatorCommandL" ) |
|
106 // service object destroys itself after sending command response |
|
107 CVtEngMediatorService::StartLD( *iMediatorResponder, iUtils, aCategory, aCommandId ); |
|
108 __VTPRINTEXIT( "CVtEngMdtrMessageListener.MediatorCommandL" ) |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CVtEngMdtrMessageListener::CancelMediatorCommand |
|
113 // Cancallation of mediator command. no-op, just returns response. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CVtEngMdtrMessageListener::CancelMediatorCommand( |
|
117 TUid /*aDomain*/, |
|
118 TUid /*aCategory*/, |
|
119 TInt /*aCommandId*/ ) |
|
120 { |
|
121 __VTPRINTENTER( "CVtEngMdtrMessageListener.CancelMediatorCommand" ) |
|
122 // No-op |
|
123 __VTPRINTEXIT( "CVtEngMdtrMessageListener.CancelMediatorCommand" ) |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CVtEngMdtrEventListener::MediatorEventL |
|
128 // Receives mediator event from VT Mediator Plugin. The event |
|
129 // contains CLI and/or Dataport name. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CVtEngMdtrMessageListener::MediatorEventL( TUid /*aDomain*/, |
|
133 TUid aCategory, |
|
134 TInt aEventId, |
|
135 const TDesC8& aData ) |
|
136 { |
|
137 __VTPRINTENTER( "CVtEngMdtrMessageListener.MediatorEventL" ) |
|
138 if ( aCategory == KCatVideotelInternalEvents && |
|
139 aEventId == EVtMediatorEventVideoCallInformation ) |
|
140 { |
|
141 TVtMediatorInfoPackage package; |
|
142 package.Copy( aData ); |
|
143 TVtVideoTelephonyCallInformation data = package(); |
|
144 __VTPRINT2( DEBUG_GEN, " VT call info data validity value=%d", |
|
145 data.iEventDataValidity) |
|
146 // if message contains dataport name save it |
|
147 CVtEngSettings& settings = iUtils.Settings(); |
|
148 if ( data.iEventDataValidity & |
|
149 TVtVideoTelephonyCallInformation::EDataportValid ) |
|
150 { |
|
151 //__VTPRINT(DEBUG_GEN, " Dataport is ready") |
|
152 settings.SetDataportInfoL( data.iDataport ); |
|
153 } |
|
154 // if message contains CLI info handle it (save and notify if state |
|
155 // allows) |
|
156 if ( data.iEventDataValidity & |
|
157 TVtVideoTelephonyCallInformation::EDisplayTextValid ) |
|
158 { |
|
159 MVtEngSessionInfo::TCLI cli; |
|
160 cli.iCallId = data.iCallId; |
|
161 cli.iName = data.iDisplayText.Left( cli.iName.MaxLength() ); |
|
162 cli.iVoiceCallPossible = data.iVoiceCallPossible; |
|
163 settings.SetCLI( cli ); |
|
164 |
|
165 // ready == call is answered (allows setting app to foreground) |
|
166 if ( IsReadyForCLIEvent() ) |
|
167 { |
|
168 // send event about CLI availability |
|
169 CVtEngEventManager::NotifyEvent( KVtEngCLIAvailable ); |
|
170 } |
|
171 else |
|
172 { |
|
173 // Wait until connected state is reached (see HandleVtEventL) |
|
174 __VTPRINT( DEBUG_GEN, |
|
175 "CVtEngMdtrMessageListener defer CLI event" ) |
|
176 iUtils.EventManager().AddObserverL( this ); |
|
177 } |
|
178 } |
|
179 } |
|
180 __VTPRINTEXIT( "CVtEngMdtrMessageListener.MediatorEventL" ) |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CVtEngMdtrMessageListener::HandleVtEventL |
|
185 // |
|
186 // Handles defered CLI event dispatching (to UI). CLI event was defered because |
|
187 // engine state was not suitable in MediatorEventL which then started observing |
|
188 // state changes. |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CVtEngMdtrMessageListener::HandleVtEventL( TInt aEvent ) |
|
192 { |
|
193 __VTPRINTENTER( "CVtEngMdtrMessageListener.HandleVtEventL" ) |
|
194 if ( aEvent == KVtEngSessionStateChanged && |
|
195 IsReadyForCLIEvent() ) // <- ready == call is answered |
|
196 { |
|
197 iUtils.EventManager().RemoveObserver( this ); |
|
198 __VTPRINT( DEBUG_GEN, |
|
199 "CVtEngMdtrMessageListener dispatch defered CLI event" ) |
|
200 CVtEngEventManager::NotifyEvent( KVtEngCLIAvailable ); |
|
201 } |
|
202 |
|
203 __VTPRINTEXIT( "CVtEngMdtrMessageListener.HandleVtEventL" ) |
|
204 } |
|
205 |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CVtEngMdtrMessageListener::ConstructL |
|
209 // Symbian 2nd phase constructor can leave. |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CVtEngMdtrMessageListener::ConstructL() |
|
213 { |
|
214 __VTPRINTENTER( "CVtEngMdtrMessageListener.ConstructL" ) |
|
215 |
|
216 // for sending command responses |
|
217 iMediatorResponder = CMediatorCommandResponder::NewL( this ); |
|
218 |
|
219 // for receiving events from VT Mediator Plugin (dataport/CLI info) |
|
220 iMediatorEvents = CMediatorEventConsumer::NewL( this ); |
|
221 |
|
222 TCapabilitySet capSet; |
|
223 capSet.SetEmpty(); |
|
224 // for audio control |
|
225 capSet.AddCapability( ECapabilityWriteDeviceData ); |
|
226 |
|
227 // define common attributes for all commands that engine is responsible for |
|
228 MediatorService::TCommand command; |
|
229 command.iCaps = capSet; |
|
230 command.iVersion = TVersion( |
|
231 KPhoneToVideotelCmdVersionMajor, |
|
232 KPhoneToVideotelCmdVersionMinor, |
|
233 KPhoneToVideotelCmdVersionBuild ); |
|
234 command.iTimeout = KVtEngMdtrCmdTimeout; |
|
235 |
|
236 // enable microphone command |
|
237 command.iCommandId = EVtCmdUnmute; |
|
238 iCommandList.Append( command ); |
|
239 |
|
240 // disable microphone command |
|
241 command.iCommandId = EVtCmdMute; |
|
242 iCommandList.Append( command ); |
|
243 |
|
244 // register VT events that are raised by VT Mediator Plugin. |
|
245 // !!! Note !!!! |
|
246 // event subscription must be done before command registration because |
|
247 // command registration triggers raising the event in the plugin. Different |
|
248 // order would cause the engine to miss the event. |
|
249 const TVersion commandVersion( |
|
250 KVideotelMdtrCommandsVersionMajor, |
|
251 KVideotelMdtrCommandsVersionMinor, |
|
252 KVideotelMdtrCommandsVersionBuild ); |
|
253 //capSet.SetEmpty(); |
|
254 //capSet.AddCapability( ECapabilityPowerMgmt ); |
|
255 |
|
256 iMediatorResponder->RegisterCommand( |
|
257 KMediatorVideoTelephonyDomain, |
|
258 KCatVideotelInternalCommands, |
|
259 EVtMediatorReleaseDataport, |
|
260 commandVersion, |
|
261 capSet, |
|
262 KVtEngMdtrCmdTimeout ); |
|
263 |
|
264 const TVersion eventVersion( |
|
265 KTelephonyEventsVersionMajor, |
|
266 KTelephonyEventsVersionMinor, |
|
267 KTelephonyEventsVersionBuild ); |
|
268 |
|
269 TInt res = iMediatorEvents->SubscribeEvent( KMediatorVideoTelephonyDomain, |
|
270 KCatVideotelInternalEvents, |
|
271 EVtMediatorEventVideoCallInformation, |
|
272 eventVersion ); |
|
273 |
|
274 if ( res == KErrNone ) |
|
275 { |
|
276 // register Mediator commands that we handle |
|
277 res = iMediatorResponder->RegisterCommand( |
|
278 KMediatorVideoTelephonyDomain, |
|
279 KCatPhoneToVideotelCommands, |
|
280 iCommandList ); |
|
281 |
|
282 } |
|
283 __VTPRINTEXITR( "CVtEngMdtrMessageListener.ConstructL res=%d",res ) |
|
284 // registering must not fail |
|
285 User::LeaveIfError( res ); |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CVtEngMdtrMessageListener::CVtEngMdtrMessageListener |
|
290 // C++ default constructor can NOT contain any code, that |
|
291 // might leave. |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 CVtEngMdtrMessageListener::CVtEngMdtrMessageListener( CVtEngUtility& aUtils) |
|
295 : iUtils( aUtils ), iCommandList( KVtEngMdtrCmdArrayGranularity ) |
|
296 { |
|
297 __VTPRINTENTER( "CVtEngMdtrMessageListener.CVtEngMdtrMessageListener" ) |
|
298 __VTPRINTEXIT( "CVtEngMdtrMessageListener.CVtEngMdtrMessageListener" ) |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CVtEngMdtrMessageListener::IsReadyForCLIEvent |
|
303 // Checks if engine state is appropriate to send CLI event. |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 TBool CVtEngMdtrMessageListener::IsReadyForCLIEvent() const |
|
307 { |
|
308 __VTPRINTENTER( "CVtEngMdtrMessageListener.IsReadyForCLIEvent" ) |
|
309 const MVtEngSessionInfo::TSessionState state = |
|
310 iUtils.StateManager()->SessionState(); |
|
311 const TBool isReady = |
|
312 ( state == MVtEngSessionInfo::EConnected || |
|
313 state == MVtEngSessionInfo::ENegotiating || |
|
314 state == MVtEngSessionInfo::EOpen ); |
|
315 __VTPRINTEXITR( "CVtEngMdtrMessageListener.IsReadyForCLIEvent %d>", |
|
316 isReady ) |
|
317 return isReady; |
|
318 } |
|
319 |
|
320 // End of File |
|
321 |