|
1 /* |
|
2 * Copyright (c) 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: Session class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <sdpdocument.h> |
|
19 #include "nspsessionobserver.h" |
|
20 #include "nspsession.h" |
|
21 #include "nspevents.h" |
|
22 #include "nspcontrollerif.h" |
|
23 #include "nspmediastreamcontainer.h" |
|
24 #include "nspstatemachine.h" |
|
25 #include "nspactionset.h" |
|
26 #include "nspstatebase.h" |
|
27 #include "nspcontentparser.h" |
|
28 #include "nspdefs.h" |
|
29 |
|
30 const TUint KConstProtocolTcp = 1; |
|
31 const TUint KConstProtocolUdp = 2; |
|
32 const TUint KDefaultGranularity = 5; |
|
33 |
|
34 #define CONV_PROTOCOL_L( aProtocol ) \ |
|
35 (TUint) User::LeaveIfError( \ |
|
36 KConstProtocolTcp == aProtocol ? (TInt)KProtocolInetTcp : \ |
|
37 ( KConstProtocolUdp == aProtocol ? (TInt)KProtocolInetUdp : KErrNotFound ) ) |
|
38 |
|
39 #define LOGEVENT( aEvent ) \ |
|
40 switch( aEvent )\ |
|
41 {\ |
|
42 case MNATFWConnectivityObserver::ESessionCreated:{ NSPLOG_STR( "CNSPSession::EventOccured, event:ESessionCreated" ); break; }\ |
|
43 case MNATFWConnectivityObserver::ELocalCandidateFound:{ NSPLOG_STR( "CNSPSession::EventOccured, event:ELocalCandidateFound" ); break; }\ |
|
44 case MNATFWConnectivityObserver::EFetchingCompleted:{ NSPLOG_STR( "CNSPSession::EventOccured, event:EFetchingCompleted" ); break; }\ |
|
45 case MNATFWConnectivityObserver::EReceivingActivated:{ NSPLOG_STR( "CNSPSession::EventOccured, event:EReceivingActivated" ); break; }\ |
|
46 case MNATFWConnectivityObserver::EReceivingDeactivated:{ NSPLOG_STR( "CNSPSession::EventOccured, event:EReceivingDeactivated" ); break; }\ |
|
47 case MNATFWConnectivityObserver::ESendingActivated:{ NSPLOG_STR( "CNSPSession::EventOccured, event:ESendingActivated" ); break; }\ |
|
48 case MNATFWConnectivityObserver::ESendingDeactivated:{ NSPLOG_STR( "CNSPSession::EventOccured, event:ESendingDeactivated" ); break; }\ |
|
49 case MNATFWConnectivityObserver::ECandidatePairFound:{ NSPLOG_STR( "CNSPSession::EventOccured, event:ECandidatePairFound" ); break; }\ |
|
50 case MNATFWConnectivityObserver::EConnChecksCompleted:{ NSPLOG_STR( "CNSPSession::EventOccured, event:EConnChecksCompleted" ); break; }\ |
|
51 case MNATFWConnectivityObserver::EGeneralError:{ NSPLOG_STR( "CNSPSession::EventOccured, event:EGeneralError" ); break; }\ |
|
52 case MNATFWConnectivityObserver::EAllEvents:{ NSPLOG_STR( "CNSPSession::EventOccured, event:EAllEvents" ); break; }\ |
|
53 default:{ NSPLOG_STR( "CNSPSession::EventOccured, event:Unknown" ); break; }\ |
|
54 } |
|
55 |
|
56 // ======== MEMBER FUNCTIONS ======== |
|
57 // --------------------------------------------------------------------------- |
|
58 // CNSPSession::CNSPSession |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CNSPSession::CNSPSession( MNSPControllerIF& aController, |
|
62 MNSPSessionObserver& aSessionObserver ) |
|
63 : iController( aController ), |
|
64 iSessionObserver( aSessionObserver ) |
|
65 { |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CNSPSession::ConstructL |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CNSPSession::ConstructL( TUint32 aIapId, const TDesC8& aDomain, |
|
74 TUint aProtocol ) |
|
75 { |
|
76 NSPLOG_STR( "CNSPSession::ConstructL(), Entry" ) |
|
77 |
|
78 iSessionId = iController.CreateSessionL( aIapId, aDomain ); |
|
79 iSessionData = CNSPSessionData::NewL(); |
|
80 iStreamContainer = CNSPMediaStreamContainer::NewL( |
|
81 iController, iSessionId, CONV_PROTOCOL_L( aProtocol ) ); |
|
82 iStateMachine = CNSPStateMachine::NewL(); |
|
83 iProtocolsArray = new (ELeave) CDesC8ArrayFlat( KDefaultGranularity ); |
|
84 |
|
85 NSPLOG_STR( "CNSPSession::ConstructL(), Exit" ) |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CNSPSession::NewL |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CNSPSession* CNSPSession::NewL( MNSPControllerIF& aController, |
|
94 MNSPSessionObserver& aSessionObserver, TUint32 aIapId, |
|
95 const TDesC8& aDomain, TUint aProtocol ) |
|
96 { |
|
97 CNSPSession* self = CNSPSession::NewLC( aController, aSessionObserver, |
|
98 aIapId, aDomain, aProtocol ); |
|
99 CleanupStack::Pop( self ); |
|
100 return self; |
|
101 } |
|
102 |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CNSPSession::NewLC |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 CNSPSession* CNSPSession::NewLC( MNSPControllerIF& aController, |
|
109 MNSPSessionObserver& aSessionObserver, TUint32 aIapId, |
|
110 const TDesC8& aDomain, TUint aProtocol ) |
|
111 { |
|
112 CNSPSession* self = new ( ELeave ) CNSPSession( aController, |
|
113 aSessionObserver ); |
|
114 CleanupStack::PushL( self ); |
|
115 self->ConstructL( aIapId, aDomain, aProtocol ); |
|
116 return self; |
|
117 } |
|
118 |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CNSPSession::~CNSPSession |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 CNSPSession::~CNSPSession() |
|
125 { |
|
126 NSPLOG_STR( "CNSPSession::~CNSPSession(), Entry" ) |
|
127 |
|
128 delete iSessionData; |
|
129 delete iStreamContainer; |
|
130 delete iStateMachine; |
|
131 delete iProtocolsArray; |
|
132 TRAP_IGNORE( iController.CloseSessionL( iSessionId ) ); |
|
133 |
|
134 NSPLOG_STR( "CNSPSession::~CNSPSession(), Exit" ) |
|
135 } |
|
136 |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CNSPSession::CreateOfferL |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 TNatReturnStatus CNSPSession::CreateOfferL( CSdpDocument*& aOffer ) |
|
143 { |
|
144 NSPLOG_STR( "CNSPSession::CreateOfferL(), Entry" ) |
|
145 |
|
146 __ASSERT_ALWAYS( aOffer, User::Leave( KErrArgument ) ); |
|
147 |
|
148 NSP_INPUT_OFFER( *aOffer ) |
|
149 |
|
150 TNSPStateMachineEvent event( KErrNone, aOffer, NULL, |
|
151 TNSPStateMachineEvent::ECreateOffer, *this ); |
|
152 |
|
153 iStateMachine->ProcessL( event ); |
|
154 |
|
155 NSP_OUTPUT_OFFER( event.Status(), *aOffer ) |
|
156 |
|
157 NSPLOG_STR( "CNSPSession::CreateOfferL(), Exit" ) |
|
158 |
|
159 return event.Status(); |
|
160 } |
|
161 |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CNSPSession::ResolveL |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 TNatReturnStatus CNSPSession::ResolveL( |
|
168 CSdpDocument*& aOffer, CSdpDocument*& aAnswer ) |
|
169 { |
|
170 NSPLOG_STR( "CNSPSession::ResolveL(), Entry" ) |
|
171 |
|
172 __ASSERT_ALWAYS( aOffer, User::Leave( KErrArgument ) ); |
|
173 __ASSERT_ALWAYS( aAnswer, User::Leave( KErrArgument ) ); |
|
174 |
|
175 NSP_INPUT_OFFER( *aOffer ) |
|
176 NSP_INPUT_ANSWER( *aAnswer ) |
|
177 |
|
178 TNSPStateMachineEvent event( KErrNone, aOffer, aAnswer, |
|
179 TNSPStateMachineEvent::EResolve, *this ); |
|
180 |
|
181 iStateMachine->ProcessL( event ); |
|
182 |
|
183 NSP_OUTPUT_OFFER( event.Status(), *aOffer ) |
|
184 NSP_OUTPUT_ANSWER( event.Status(), *aAnswer ) |
|
185 |
|
186 NSPLOG_STR( "CNSPSession::ResolveL(), Exit" ) |
|
187 |
|
188 return event.Status(); |
|
189 } |
|
190 |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CNSPSession::DecodeAnswerL |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 TNatReturnStatus CNSPSession::DecodeAnswerL( CSdpDocument*& aAnswer ) |
|
197 { |
|
198 NSPLOG_STR( "CNSPSession::DecodeAnswerL(), Entry" ) |
|
199 |
|
200 __ASSERT_ALWAYS( aAnswer, User::Leave( KErrArgument ) ); |
|
201 |
|
202 NSP_INPUT_ANSWER_L( *aAnswer ) |
|
203 |
|
204 TNSPStateMachineEvent event( KErrNone, NULL, aAnswer, |
|
205 TNSPStateMachineEvent::EDecodeAnswer, *this ); |
|
206 |
|
207 iStateMachine->ProcessL( event ); |
|
208 |
|
209 NSP_OUTPUT_ANSWER_L( event.Status(), *aAnswer ) |
|
210 |
|
211 NSPLOG_STR( "CNSPSession::DecodeAnswerL(), Exit" ) |
|
212 |
|
213 return event.Status(); |
|
214 } |
|
215 |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CNSPSession::UpdateL |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CNSPSession::UpdateL( CSdpDocument*& aOffer ) |
|
222 { |
|
223 NSPLOG_STR( "CNSPSession::UpdateL(), Entry" ) |
|
224 |
|
225 __ASSERT_ALWAYS( aOffer, User::Leave( KErrArgument ) ); |
|
226 |
|
227 NSP_INPUT_OFFER( *aOffer ) |
|
228 |
|
229 TNSPStateMachineEvent event( KErrNone, aOffer, NULL, |
|
230 TNSPStateMachineEvent::EUpdate, *this ); |
|
231 |
|
232 iStateMachine->ProcessL( event ); |
|
233 |
|
234 NSP_OUTPUT_OFFER( event.Status(), *aOffer ) |
|
235 |
|
236 NSPLOG_STR( "CNSPSession::UpdateL(), Exit" ) |
|
237 } |
|
238 |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CNSPSession::CloseSessionL |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 TNatReturnStatus CNSPSession::CloseSessionL() |
|
245 { |
|
246 NSPLOG_STR( "CNSPSession::CloseSessionL(), Entry" ) |
|
247 |
|
248 TNSPStateMachineEvent event( KErrNone, NULL, NULL, |
|
249 TNSPStateMachineEvent::ECloseSession, *this ); |
|
250 |
|
251 iStateMachine->ProcessL( event ); |
|
252 |
|
253 NSPLOG_STR( "CNSPSession::CloseSessionL(), Exit" ) |
|
254 |
|
255 return event.Status(); |
|
256 } |
|
257 |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CNSPSession::EventOccured |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 TEventReturnStatus CNSPSession::EventOccured( TUint aStreamId, |
|
264 MNATFWConnectivityObserver::TNATFWConnectivityEvent aEvent, |
|
265 TInt aError, TAny* aData ) |
|
266 { |
|
267 NSPLOG_STR( "CNSPSession::EventOccured(), Entry" ) |
|
268 LOGEVENT( aEvent ) |
|
269 NSPLOG_INT( "CNSPSession::EventOccured, aError:", aError ) |
|
270 |
|
271 __ASSERT_ALWAYS( iStateMachine, __PANIC( KErrNotFound ) ); |
|
272 |
|
273 TNSPStateMachineMediaEvent event( aStreamId, aEvent, aData, aError, |
|
274 NULL, NULL, TNSPStateMachineEvent::ENat, *this ); |
|
275 |
|
276 TRAPD( error, iStateMachine->ProcessL( event ) ); |
|
277 |
|
278 NSPLOG_INT( "CNSPSession::EventOccured, error:", error ) |
|
279 NSPLOG_INT( "CNSPSession::EventOccured, event.Status():", event.Status() ) |
|
280 |
|
281 event.Status() = ( KErrNone == error ? event.Status() : error ); |
|
282 event.CallbackType() = ( NSP_ERROR( event.Status() ) ? |
|
283 TEventReturnStatus::EError : event.CallbackType() ); |
|
284 |
|
285 // If event.iOffer or event.iAnswer is not NULL, it means that ownership |
|
286 // was transferred inside iStateMachine->ProcessL(). |
|
287 // If there was an error we have to free the memory here, |
|
288 // since it won't be handled anywhere else |
|
289 if ( event.CallbackType() == TEventReturnStatus::EError ) |
|
290 { |
|
291 delete event.iOffer; |
|
292 event.iOffer = NULL; |
|
293 |
|
294 delete event.iAnswer; |
|
295 event.iAnswer = NULL; |
|
296 } |
|
297 |
|
298 return static_cast<TEventReturnStatus>( event ); |
|
299 } |
|
300 |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CNSPSession::UpdateSdpAsyncL |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CNSPSession::UpdateSdpAsyncL( CSdpDocument* aDocument ) |
|
307 { |
|
308 NSPLOG_STR( "CNSPSession::Update(), Entry" ) |
|
309 |
|
310 __ASSERT_ALWAYS( aDocument, User::Leave( KErrArgument ) ); |
|
311 |
|
312 NSP_OUTPUT_UPDATESDP( KNatReady, *aDocument ) |
|
313 |
|
314 iController.OrderUpdateSdpL( iSessionId, aDocument ); |
|
315 |
|
316 NSPLOG_STR( "CNSPSession::Update(), Exit" ) |
|
317 } |
|
318 |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CNSPSession::SessionId |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 TUint CNSPSession::SessionId() const |
|
325 { |
|
326 return iSessionId; |
|
327 } |
|
328 |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // CNSPSession::Data |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 CNSPSessionData& CNSPSession::Data() |
|
335 { |
|
336 return *iSessionData; |
|
337 } |
|
338 |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // CNSPSession::Container |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 CNSPMediaStreamContainer& CNSPSession::Container() |
|
345 { |
|
346 return *iStreamContainer; |
|
347 } |
|
348 |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // CNSPSession::Plugins |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 CDesC8Array& CNSPSession::Plugins() |
|
355 { |
|
356 return *iProtocolsArray; |
|
357 } |
|
358 |
|
359 |
|
360 // --------------------------------------------------------------------------- |
|
361 // CNSPSession::RemoveIce |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 void CNSPSession::RemoveIce( CDesC8Array& aDesArray ) const |
|
365 { |
|
366 iController.RemoveIce( aDesArray ); |
|
367 } |
|
368 |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // CNSPSession::IsIce |
|
372 // --------------------------------------------------------------------------- |
|
373 // |
|
374 TBool CNSPSession::IsIce( const TDesC8& aProtocol ) const |
|
375 { |
|
376 return iController.IsIce( aProtocol ); |
|
377 } |
|
378 |
|
379 |
|
380 // --------------------------------------------------------------------------- |
|
381 // CNSPSession::Parser |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 const CNSPContentParser& CNSPSession::Parser() const |
|
385 { |
|
386 return iController.ContentParser(); |
|
387 } |
|
388 |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // CNSPSession::Role |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 CNSPSession::TSdpRole& CNSPSession::Role() |
|
395 { |
|
396 return iRole; |
|
397 } |
|
398 |
|
399 |
|
400 // --------------------------------------------------------------------------- |
|
401 // CNSPSession::SessionObserver |
|
402 // --------------------------------------------------------------------------- |
|
403 // |
|
404 MNSPSessionObserver& CNSPSession::SessionObserver() const |
|
405 { |
|
406 return iSessionObserver; |
|
407 } |
|
408 |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // CNSPSession::Actions |
|
412 // --------------------------------------------------------------------------- |
|
413 // |
|
414 TNSPActionSet CNSPSession::Actions() |
|
415 { |
|
416 return TNSPActionSet( *this ); |
|
417 } |
|
418 |
|
419 |
|
420 // --------------------------------------------------------------------------- |
|
421 // CNSPSession::SetSessionParam |
|
422 // --------------------------------------------------------------------------- |
|
423 // |
|
424 TInt CNSPSession::SetSessionParam( CNSPPlugin::TNSPSessionParamKey aParamKey, |
|
425 TUint aParamValue ) |
|
426 { |
|
427 NSPLOG_STR( "CNSPSession::SetSessionParam, Entry" ) |
|
428 |
|
429 TInt status = KErrNone; |
|
430 |
|
431 switch( aParamKey ) |
|
432 { |
|
433 case CNSPPlugin::ENSPResourseReservationStatusKey: |
|
434 { |
|
435 status = KErrNotSupported; |
|
436 break; |
|
437 } |
|
438 |
|
439 case CNSPPlugin::ENSPMediaTypeOfServiceKey: |
|
440 { |
|
441 status = iStreamContainer->SetMediaTos( aParamValue ); |
|
442 break; |
|
443 } |
|
444 |
|
445 default: |
|
446 { |
|
447 status = KErrNotFound; |
|
448 break; |
|
449 } |
|
450 } |
|
451 |
|
452 NSPLOG_INT( "CNSPSession::SetSessionParam, Exit, status:", status ) |
|
453 return status; |
|
454 } |
|
455 |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // CNSPSession::GetSessionParam |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 TInt CNSPSession::GetSessionParam( CNSPPlugin::TNSPSessionParamKey aParamKey ) |
|
462 { |
|
463 NSPLOG_STR( "CNSPSession::GetSessionParam, Entry" ) |
|
464 |
|
465 TInt value = KErrNone; |
|
466 |
|
467 switch( aParamKey ) |
|
468 { |
|
469 case CNSPPlugin::ENSPResourseReservationStatusKey: |
|
470 { |
|
471 if ( iSessionData->UseIce() ) |
|
472 { |
|
473 Proceed( TNSPStateMachineEvent::EReservationStatus, value ); |
|
474 |
|
475 value = ( KNatAsync == value ? |
|
476 CNSPPlugin::ENSPResourcesNotReserved : |
|
477 ( KNatReady == value ? |
|
478 CNSPPlugin::ENSPResourcesReserved : value ) ); |
|
479 } |
|
480 else |
|
481 { |
|
482 value = CNSPPlugin::ENSPResourcesReserved; |
|
483 } |
|
484 |
|
485 break; |
|
486 } |
|
487 |
|
488 case CNSPPlugin::ENSPMediaTypeOfServiceKey: |
|
489 { |
|
490 value = iStreamContainer->MediaTos(); |
|
491 break; |
|
492 } |
|
493 |
|
494 default: |
|
495 { |
|
496 value = KErrNotFound; |
|
497 break; |
|
498 } |
|
499 } |
|
500 |
|
501 NSPLOG_INT( "CNSPSession::GetSessionParam, Exit, value:", value ) |
|
502 return value; |
|
503 } |
|
504 |
|
505 |
|
506 // --------------------------------------------------------------------------- |
|
507 // CNSPSession::SetUseIce |
|
508 // --------------------------------------------------------------------------- |
|
509 // |
|
510 void CNSPSession::SetUseIce( TBool aUseIce ) |
|
511 { |
|
512 __ASSERT_ALWAYS( iSessionData, __PANIC( KErrNotFound ) ); |
|
513 iSessionData->SetUseIce( aUseIce ); |
|
514 } |
|
515 |
|
516 |
|
517 // --------------------------------------------------------------------------- |
|
518 // CNSPSession::Proceed |
|
519 // --------------------------------------------------------------------------- |
|
520 // |
|
521 void CNSPSession::Proceed( TInt aRequest, TNatReturnStatus& aStatus ) |
|
522 { |
|
523 __ASSERT_ALWAYS( iStateMachine, __PANIC( KErrNotFound ) ); |
|
524 __ASSERT_ALWAYS( iSessionData, __PANIC( KErrNotFound ) ); |
|
525 __ASSERT_ALWAYS( iStreamContainer, __PANIC( KErrNotFound ) ); |
|
526 |
|
527 TNSPStateMachineEvent event( KErrNone, NULL, NULL, |
|
528 (TNSPStateMachineEvent::TRequest) aRequest, *this ); |
|
529 |
|
530 TRAPD( error, iStateMachine->ProcessL( event ) ); |
|
531 |
|
532 aStatus = ( KErrNone == error ? event.Status() : error ); |
|
533 } |
|
534 |
|
535 |
|
536 // end of file |