|
1 /* |
|
2 * Copyright (c) 2004 - 2007 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: Container for ETel session and subsessions. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #pragma CTC SKIP |
|
20 // INCLUDE FILES |
|
21 #include "CVtCtlSessionContainer.h" |
|
22 #include "CVtCtlLineMonitor.h" |
|
23 #include "CVtCtlVideoCall.h" |
|
24 #include <mmtsy_names.h> |
|
25 #include <cvtlogger.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // Retrials for connecting to ETel server |
|
30 const TInt KVtCtlETelConnectRetrials = 5; |
|
31 |
|
32 // Granularity |
|
33 const TInt KVtCtlMaxCalls = 5; |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CVtCtlSessionContainer::CVtCtlSessionContainer |
|
39 // C++ constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CVtCtlSessionContainer::CVtCtlSessionContainer( |
|
44 MVtCtlCallStatusObserver& aObserver ) : |
|
45 iCalls( KVtCtlMaxCalls ), |
|
46 iObserver( aObserver ) |
|
47 { |
|
48 __VTPRINTENTER( "CVtCtlSessionContainer.CVtCtlSessionContainer" ) |
|
49 __VTPRINTEXIT( "CVtCtlSessionContainer.CVtCtlSessionContainer" ) |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CVtCtlSessionContainer::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 /***************************************************** |
|
58 * Series 60 Customer / ETel |
|
59 * Series 60 ETel API |
|
60 *****************************************************/ |
|
61 void CVtCtlSessionContainer::ConstructL() |
|
62 { |
|
63 __VTPRINTENTER( "CVtCtlSessionContainer.ConstructL" ) |
|
64 TInt retries( KVtCtlETelConnectRetrials ); |
|
65 TInt err( KErrNone ); |
|
66 while ( retries-- && |
|
67 iServer.Handle() == KNullHandle ) |
|
68 { |
|
69 err = iServer.Connect(); |
|
70 } |
|
71 User::LeaveIfError( err ); |
|
72 User::LeaveIfError( iServer.LoadPhoneModule( KMmTsyModuleName() ) ); |
|
73 User::LeaveIfError( iPhone.Open( iServer, KMmTsyPhoneName() ) ); |
|
74 User::LeaveIfError( iLine.Open( iPhone, KMmTsyDataLineName() ) ); |
|
75 |
|
76 iLineMonitor = new ( ELeave ) CVtCtlLineMonitor( iLine, *this ); |
|
77 iLineMonitor->Start(); |
|
78 |
|
79 RMobileCall::TMobileCallStatus lineStatus; |
|
80 User::LeaveIfError( iLine.GetMobileLineStatus( lineStatus ) ); |
|
81 if ( lineStatus != RMobileCall::EStatusIdle ) |
|
82 { |
|
83 __VTPRINT( DEBUG_SESSION | DEBUG_CONSTRUCT, |
|
84 "VtCtl:SesConL line active" ) |
|
85 TInt calls( 0 ); |
|
86 User::LeaveIfError( iLine.EnumerateCall( calls ) ); |
|
87 while ( calls-- ) |
|
88 { |
|
89 RLine::TCallInfo callInfo; |
|
90 iLine.GetCallInfo( calls, callInfo ); |
|
91 if ( InitCallL( callInfo.iCallName ) ) |
|
92 { |
|
93 __VTPRINT( DEBUG_SESSION | DEBUG_CONSTRUCT, |
|
94 "VtCtl:SesConL call found and created" ) |
|
95 calls = 0; |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 __VTPRINTEXIT( "CVtCtlSessionContainer.ConstructL" ) |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CVtCtlSessionContainer::NewL |
|
105 // Two-phased constructor. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CVtCtlSessionContainer* CVtCtlSessionContainer::NewL( |
|
109 MVtCtlCallStatusObserver& aObserver ) |
|
110 { |
|
111 __VTPRINTENTER( "CVtCtlSessionContainer.NewL" ) |
|
112 CVtCtlSessionContainer* self = |
|
113 new ( ELeave ) CVtCtlSessionContainer( aObserver ); |
|
114 |
|
115 CleanupStack::PushL( self ); |
|
116 self->ConstructL(); |
|
117 CleanupStack::Pop(); |
|
118 |
|
119 __VTPRINTEXIT( "CVtCtlSessionContainer.NewL" ) |
|
120 return self; |
|
121 } |
|
122 |
|
123 |
|
124 // Destructor |
|
125 CVtCtlSessionContainer::~CVtCtlSessionContainer() |
|
126 { |
|
127 __VTPRINTENTER( "CVtCtlSessionContainer.~" ) |
|
128 |
|
129 TInt count( iCalls.Count() ); |
|
130 CVtCtlVideoCall* call = NULL; |
|
131 while ( count-- ) |
|
132 { |
|
133 call = iCalls[count]; |
|
134 delete call; |
|
135 } |
|
136 iCalls.Close(); |
|
137 delete iLineMonitor; |
|
138 iLine.Close(); |
|
139 iPhone.Close(); |
|
140 iServer.UnloadPhoneModule( KMmTsyModuleName() ); |
|
141 iServer.Close(); |
|
142 __VTPRINTEXIT( "CVtCtlSessionContainer.~" ) |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CVtCtlSessionContainer::HandleLineEventL |
|
147 // Handle new call on data line |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CVtCtlSessionContainer::HandleLineEventL( |
|
151 const TLineEvent aEvent, |
|
152 TDesC& aCallName ) |
|
153 { |
|
154 __VTPRINTENTER( "CVtCtlSessionContainer.HandleLineEventL" ) |
|
155 if ( aEvent == ELineEventCallAdded ) |
|
156 { |
|
157 CVtCtlVideoCall* call = FindCall( aCallName ); |
|
158 if ( call == NULL ) |
|
159 { |
|
160 InitCallL( aCallName ); |
|
161 } |
|
162 } |
|
163 __VTPRINTEXITR( "CVtCtlSessionContainer.HandleLineEventL event=%d", |
|
164 aEvent ) |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CVtCtlSessionContainer::HandleLineEventL |
|
169 // |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 /***************************************************** |
|
173 * Series 60 Customer / ETel |
|
174 * Series 60 ETel API |
|
175 *****************************************************/ |
|
176 void CVtCtlSessionContainer::HandleLineEventL( |
|
177 const TLineEvent aEvent, |
|
178 const RMobileCall::TMobileCallStatus aStatus ) |
|
179 { |
|
180 __VTPRINTENTER( "CVtCtlSessionContainer.HandleLineEventL" ) |
|
181 __VTPRINT3( DEBUG_SESSION, "SesCont.LineEvent2 event=%d,status=%d", |
|
182 (TInt) aEvent, |
|
183 (TInt) aStatus ) |
|
184 if ( aEvent == ELineEventStatusChange && |
|
185 ( aStatus == RMobileCall::EStatusRinging || |
|
186 aStatus == RMobileCall::EStatusDialling ) ) |
|
187 { |
|
188 TInt calls( 0 ); |
|
189 iLine.EnumerateCall( calls ); |
|
190 while ( calls-- ) |
|
191 { |
|
192 RLine::TCallInfo callInfo; |
|
193 TInt err( iLine.GetCallInfo( calls, callInfo ) ); |
|
194 // ensure we're opening correct call |
|
195 if ( err == KErrNone && |
|
196 ( callInfo.iStatus == RCall::EStatusDialling || |
|
197 callInfo.iStatus == RCall::EStatusRinging ) ) |
|
198 { |
|
199 calls = 0; // break |
|
200 CVtCtlVideoCall* call = FindCall( callInfo.iCallName ); |
|
201 if ( call == NULL ) |
|
202 { |
|
203 InitCallL( callInfo.iCallName ); |
|
204 } |
|
205 } |
|
206 } |
|
207 } |
|
208 __VTPRINTEXIT( "CVtCtlSessionContainer.HandleLineEventL" ) |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CVtCtlSessionContainer::HandleCallStatusChangeL |
|
213 // passes call status change event to observer |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CVtCtlSessionContainer::HandleCallStatusChangeL( |
|
217 TVtCtlSessionId aId, |
|
218 MVtCtlCallControl::TVtCtlState aStatus, |
|
219 MVtCtlCallControl::TVtCtlState aPreviousStatus ) |
|
220 { |
|
221 __VTPRINTENTER( "CVtCtlSessionContainer.HandleCallStatusChangeL" ) |
|
222 iObserver.HandleCallStatusChangeL( aId, aStatus, aPreviousStatus ); |
|
223 if ( aStatus == MVtCtlCallControl::EIdle ) |
|
224 { |
|
225 DestructCall( aId ); |
|
226 } |
|
227 __VTPRINTEXIT( "CVtCtlSessionContainer.HandleCallStatusChangeL" ) |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CVtCtlSessionContainer::FindCall |
|
232 // Finds call by name |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 /***************************************************** |
|
236 * Series 60 Customer / ETel |
|
237 * Series 60 ETel API |
|
238 *****************************************************/ |
|
239 CVtCtlVideoCall* CVtCtlSessionContainer::FindCall( TDesC& aCallName ) const |
|
240 { |
|
241 __VTPRINTENTER( "CVtCtlSessionContainer.FindCall" ) |
|
242 TInt count( iCalls.Count() ); |
|
243 CVtCtlVideoCall* call = NULL; |
|
244 while ( count-- ) |
|
245 { |
|
246 call = iCalls[count]; |
|
247 const RMobileCall::TMobileCallInfoV1& mobileInfo = call->MobileInfo(); |
|
248 if ( aCallName == mobileInfo.iCallName ) |
|
249 { |
|
250 count = 0; // break |
|
251 } |
|
252 else |
|
253 { |
|
254 call = NULL; |
|
255 } |
|
256 } |
|
257 __VTPRINT2( DEBUG_SESSION | DEBUG_DETAIL, |
|
258 "SesCont.FindCall by name --> %d",(TInt)call ) |
|
259 __VTPRINTEXIT( "CVtCtlSessionContainer.FindCall" ) |
|
260 return call; |
|
261 } |
|
262 |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CVtCtlSessionContainer::FindCall |
|
266 // Finds call by id. |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 CVtCtlVideoCall* CVtCtlSessionContainer::FindCall( TVtCtlSessionId aId ) const |
|
270 { |
|
271 __VTPRINTENTER( "CVtCtlSessionContainer.FindCall" ) |
|
272 TInt count( iCalls.Count() ); |
|
273 CVtCtlVideoCall* call = NULL; |
|
274 if ( aId == KActiveSessionId && count == 1 ) |
|
275 { |
|
276 call = iCalls[0]; |
|
277 count = 0; |
|
278 } |
|
279 while ( count-- ) |
|
280 { |
|
281 call = iCalls[count]; |
|
282 const CVtCtlVideoCall::TVtCtlCallInfo& info = |
|
283 call->CallInfo(); |
|
284 if ( aId == info.iId ) |
|
285 { |
|
286 count = 0; // break |
|
287 } |
|
288 else |
|
289 { |
|
290 call = NULL; |
|
291 } |
|
292 } |
|
293 __VTPRINT2( DEBUG_SESSION | DEBUG_DETAIL, |
|
294 "SesCont.FindCall by id --> %d",(TInt)call ) |
|
295 __VTPRINTEXIT( "CVtCtlSessionContainer.FindCall" ) |
|
296 return call; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CVtCtlSessionContainer::Sessions |
|
301 // Returns sessions. |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 TInt CVtCtlSessionContainer::GetSessions( RVtCtlSessionIdArray& aArray ) const |
|
305 { |
|
306 __VTPRINTENTER( "CVtCtlSessionContainer.GetSessions" ) |
|
307 const TInt count( iCalls.Count() ); |
|
308 for ( TInt ii = 0; ii < count; ii++ ) |
|
309 { |
|
310 TInt err( aArray.Append( iCalls[ii]->CallInfo().iId ) ); |
|
311 if ( err != KErrNone ) |
|
312 { |
|
313 __VTPRINTEXIT( "CVtCtlSessionContainer.GetSessions" ) |
|
314 return err; |
|
315 } |
|
316 } |
|
317 __VTPRINTEXIT( "CVtCtlSessionContainer.GetSessions" ) |
|
318 return count; |
|
319 } |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CVtCtlSessionContainer::DestructCall |
|
323 // Destructs call |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void CVtCtlSessionContainer::DestructCall( TVtCtlSessionId aId ) |
|
327 { |
|
328 __VTPRINTENTER( "CVtCtlSessionContainer.DestructCall" ) |
|
329 TInt count( iCalls.Count() ); |
|
330 CVtCtlVideoCall* call = NULL; |
|
331 while ( count-- ) |
|
332 { |
|
333 call = iCalls[count]; |
|
334 const CVtCtlVideoCall::TVtCtlCallInfo& info = |
|
335 call->CallInfo(); |
|
336 if ( aId == info.iId ) |
|
337 { |
|
338 delete call; |
|
339 iCalls.Remove( count ); |
|
340 count = 0; // break |
|
341 } |
|
342 } |
|
343 __VTPRINTEXIT( "CVtCtlSessionContainer.DestructCall" ) |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CVtCtlSessionContainer::CheckCallTypeL |
|
348 // Checks call type |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 /***************************************************** |
|
352 * Series 60 Customer / ETel |
|
353 * Series 60 ETel API |
|
354 *****************************************************/ |
|
355 TBool CVtCtlSessionContainer::CheckCallTypeL( |
|
356 RMobileCall& aCall, |
|
357 const TName& aName ) |
|
358 { |
|
359 __VTPRINTENTER( "CVtCtlSessionContainer.CheckCallTypeL" ) |
|
360 User::LeaveIfError( aCall.OpenExistingCall( iLine, aName ) ); |
|
361 TBool typeOk( EFalse ); |
|
362 RMobileCall::TMobileCallDataCapsV1 caps; |
|
363 RMobileCall::TMobileCallDataCapsV1Pckg pckg( caps ); |
|
364 User::LeaveIfError( aCall.GetMobileDataCallCaps( pckg ) ); |
|
365 __VTPRINT3( DEBUG_SESSION | DEBUG_DETAIL, |
|
366 "SesCont.ChkCall speedCaps=%d,protCaps=%d", |
|
367 caps.iSpeedCaps, caps.iProtocolCaps ) |
|
368 if ( caps.iProtocolCaps & RMobileCall::KCapsIsdnMultimedia ) |
|
369 { |
|
370 typeOk = ETrue; |
|
371 } |
|
372 else |
|
373 { |
|
374 aCall.Close(); |
|
375 } |
|
376 __VTPRINTEXIT( "CVtCtlSessionContainer.CheckCallTypeL" ) |
|
377 return typeOk; |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CVtCtlSessionContainer::InitCallL |
|
382 // Initializes call if it is video call. |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 /***************************************************** |
|
386 * Series 60 Customer / ETel |
|
387 * Series 60 ETel API |
|
388 *****************************************************/ |
|
389 TBool CVtCtlSessionContainer::InitCallL( const TName& aCallName ) |
|
390 { |
|
391 __VTPRINTENTER( "CVtCtlSessionContainer.InitCallL" ) |
|
392 RMobileCall* mobilecall = new ( ELeave ) RMobileCall; |
|
393 CleanupStack::PushL( mobilecall ); |
|
394 |
|
395 // check that type is multimedia call |
|
396 const TBool callTypeOk = CheckCallTypeL( *mobilecall, aCallName ); |
|
397 if ( callTypeOk ) |
|
398 { |
|
399 __VTPRINT( DEBUG_SESSION | DEBUG_DETAIL, |
|
400 "SesCont.InitCall ok" ) |
|
401 TVtCtlSessionId id = iSessionIds.Create(); |
|
402 CVtCtlVideoCall* call = CVtCtlVideoCall::NewL( |
|
403 iLine, id, *this ); |
|
404 CleanupStack::PushL( call ); |
|
405 User::LeaveIfError( iCalls.Append( call ) ); |
|
406 call->InitializeCallL( *mobilecall ); // takes ownership |
|
407 const CVtCtlVideoCall::TVtCtlCallInfo& callInfo = call->CallInfo(); |
|
408 iObserver.HandleCallStatusChangeL( |
|
409 id, callInfo.iStatus, callInfo.iPreviousStatus ); |
|
410 CleanupStack::Pop(2); // mobilecall, call |
|
411 } |
|
412 else |
|
413 { |
|
414 CleanupStack::PopAndDestroy(); // mobilecall |
|
415 } |
|
416 __VTPRINTEXIT( "CVtCtlSessionContainer.InitCallL" ) |
|
417 return callTypeOk; |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // CVtCtlSessionContainer::TVtCtlSessionIdentities::TVtCtlSessionIdentities |
|
422 // C++ constructor |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 CVtCtlSessionContainer::TVtCtlSessionIdentities::TVtCtlSessionIdentities() |
|
426 : iCurrentId( 0 ) |
|
427 { |
|
428 __VTPRINTENTER( "TVtCtlSessionIdentities.TVtCtlSessionIdentities" ) |
|
429 __VTPRINTEXIT( "TVtCtlSessionIdentities.TVtCtlSessionIdentities" ) |
|
430 } |
|
431 |
|
432 // ----------------------------------------------------------------------------- |
|
433 // CVtCtlSessionContainer::TVtCtlSessionIdentities::Create |
|
434 // Increment session id. |
|
435 // ----------------------------------------------------------------------------- |
|
436 // |
|
437 TVtCtlSessionId CVtCtlSessionContainer::TVtCtlSessionIdentities::Create() |
|
438 { |
|
439 __VTPRINTENTER( "TVtCtlSessionIdentities.Create" ) |
|
440 __VTPRINTEXIT( "TVtCtlSessionIdentities.Create" ) |
|
441 return ++iCurrentId; |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // CVtCtlSessionContainer::TVtCtlSessionIdentities::Current |
|
446 // Return current session id. |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 TVtCtlSessionId CVtCtlSessionContainer::TVtCtlSessionIdentities::Current() const |
|
450 { |
|
451 __VTPRINTENTER( "TVtCtlSessionIdentities.Current" ) |
|
452 __VTPRINTEXIT( "TVtCtlSessionIdentities.Current" ) |
|
453 return iCurrentId; |
|
454 } |
|
455 #pragma CTC ENDSKIP |
|
456 // End of File |
|
457 |