|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32base.h> |
|
20 #include <e32debug.h> |
|
21 #include <e32cons.h> |
|
22 #include <badesca.h> |
|
23 #include <sdpdocument.h> |
|
24 #include <sdporiginfield.h> |
|
25 #include <sdpconnectionfield.h> |
|
26 #include <sdpmediafield.h> |
|
27 #include "nspplugin.h" |
|
28 #include "nsptestconsolesession.h" |
|
29 #include "nsptestasyncservice.h" |
|
30 #include "nsptestconsolecenrep.h" |
|
31 #include "nsptestconsolestream.h" |
|
32 |
|
33 #define __PANIC( aError ) User::Panic( _L( "NSP Test console session" ), aError ) |
|
34 #define PTR_DEL( aPtr ) delete aPtr; aPtr = NULL |
|
35 |
|
36 _LIT8( KOriginField, "o=alice 2890844526 2890844527 IN IP4 131.117.0.4\r\n" ); |
|
37 _LIT8( KConnFieldLocal, "c=IN IP4 10.0.0.6\r\n" ); |
|
38 _LIT8( KConnFieldRemote, "c=IN IP4 192.168.0.6\r\n" ); |
|
39 _LIT8( KAudioMedia, "m=audio 2330 RTP/AVP 96\r\n" ); |
|
40 |
|
41 const TUint KProtocolUdp = 2; |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CNSPTestConsoleSession::NewL |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CNSPTestConsoleSession* CNSPTestConsoleSession::NewL( |
|
48 CNSPPlugin& aApi, CRepository& aCenrep, MAsyncService& aAsync ) |
|
49 { |
|
50 CNSPTestConsoleSession* self = new ( ELeave ) CNSPTestConsoleSession( aApi, aAsync ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL( aCenrep ); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CNSPTestConsoleSession::NewLC |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CNSPTestConsoleSession* CNSPTestConsoleSession::NewLC( |
|
62 CNSPPlugin& aApi, CRepository& aCenrep, MAsyncService& aAsync ) |
|
63 { |
|
64 CNSPTestConsoleSession* self = new ( ELeave ) CNSPTestConsoleSession( aApi, aAsync ); |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL( aCenrep ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CNSPTestConsoleSession::CNSPTestConsoleSession |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CNSPTestConsoleSession::CNSPTestConsoleSession( CNSPPlugin& aApi, MAsyncService& aAsync ) |
|
75 : iApi( aApi ), |
|
76 iAsync( aAsync ) |
|
77 { |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CNSPTestConsoleSession::ConstructL |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CNSPTestConsoleSession::ConstructL( CRepository& aCenrep ) |
|
85 { |
|
86 TUint32 iap; |
|
87 TBuf8<255> buffer; |
|
88 TCenrepReader reader( aCenrep ); |
|
89 |
|
90 reader.ReadIapL( iap ); |
|
91 reader.ReadDomainL( buffer ); |
|
92 |
|
93 iSessionId = iApi.NewSessionL( *this, iap, buffer, KProtocolUdp ); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CNSPTestConsoleSession::~CNSPTestConsoleSession |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CNSPTestConsoleSession::~CNSPTestConsoleSession() |
|
101 { |
|
102 TRAP_IGNORE( iApi.CloseSessionL( iSessionId ) ); |
|
103 PTR_DEL( iOffer ); |
|
104 PTR_DEL( iAnswer ); |
|
105 PTR_DEL( iOutStream ); |
|
106 PTR_DEL( iInStream ); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CNSPTestConsoleSession::Initialized |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CNSPTestConsoleSession::Initialized( TUint aSessionId ) |
|
114 { |
|
115 __ASSERT_ALWAYS( aSessionId == iSessionId, __PANIC( KErrTotalLossOfPrecision ) ); |
|
116 iState = ( EInitializing == iState ? EIdle : |
|
117 (TSessionState) KErrTotalLossOfPrecision ); |
|
118 __ASSERT_ALWAYS( iState > 0, __PANIC( KErrTotalLossOfPrecision ) ); |
|
119 iAsync.Stop(); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CNSPTestConsoleSession::OfferReady |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CNSPTestConsoleSession::OfferReady( TUint aSessionId, CSdpDocument* aOffer ) |
|
127 { |
|
128 __ASSERT_ALWAYS( aSessionId == iSessionId, __PANIC( KErrTotalLossOfPrecision ) ); |
|
129 iState = ( ECreateOffer == iState ? EIdle : |
|
130 ( EDecodeOffer == iState ? EIdle : |
|
131 (TSessionState) KErrTotalLossOfPrecision ) ); |
|
132 StoreOffer( aOffer ); |
|
133 iAsync.Stop(); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CNSPTestConsoleSession::AnswerReady |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CNSPTestConsoleSession::AnswerReady( TUint aSessionId, CSdpDocument* aAnswer ) |
|
141 { |
|
142 __ASSERT_ALWAYS( aSessionId == iSessionId, __PANIC( KErrTotalLossOfPrecision ) ); |
|
143 iState = ( ECreateAnswer == iState ? EDecodeOffer : |
|
144 ( EDecodeAnswer == iState ? EIdle : |
|
145 (TSessionState) KErrTotalLossOfPrecision ) ); |
|
146 StoreAnswer( aAnswer ); |
|
147 iAsync.Stop(); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CNSPTestConsoleSession::UpdateSdp |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CNSPTestConsoleSession::UpdateSdp( TUint aSessionId, CSdpDocument* aOffer ) |
|
155 { |
|
156 __ASSERT_ALWAYS( aSessionId == iSessionId, __PANIC( KErrTotalLossOfPrecision ) ); |
|
157 iState = ( EIdle == iState ? EUpdating : |
|
158 (TSessionState) KErrTotalLossOfPrecision ); |
|
159 StoreOffer( aOffer ); |
|
160 iAsync.Stop(); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CNSPTestConsoleSession::ErrorOccurred |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CNSPTestConsoleSession::ErrorOccurred( TUint aSessionId, TInt aError ) |
|
168 { |
|
169 __ASSERT_ALWAYS( aSessionId == iSessionId, __PANIC( KErrTotalLossOfPrecision ) ); |
|
170 iState = (TSessionState) aError; |
|
171 iAsync.Stop(); |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CNSPTestConsoleSession::IcmpErrorOccurred |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CNSPTestConsoleSession::IcmpErrorOccurred( TUint aSessionId, TInt aError ) |
|
179 { |
|
180 __ASSERT_ALWAYS( aSessionId == iSessionId, __PANIC( KErrTotalLossOfPrecision ) ); |
|
181 iState = (TSessionState) aError; |
|
182 iAsync.Stop(); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CNSPTestConsoleSession::CreateOfferL |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CNSPTestConsoleSession::CreateOfferL( CTestConsoleStream& aOutStream ) |
|
190 { |
|
191 __ASSERT_ALWAYS( &aOutStream, User::Leave( KErrArgument ) ); |
|
192 __ASSERT_ALWAYS( EIdle == iState, User::Leave( KErrTotalLossOfPrecision ) ); |
|
193 iState = ECreateOffer; |
|
194 |
|
195 delete iOffer; |
|
196 iOffer = CSdpDocument::NewL(); |
|
197 iOffer->SetConnectionField( CSdpConnectionField::DecodeL( KConnFieldLocal() ) ); |
|
198 iOffer->SetOriginField( CSdpOriginField::DecodeL( KOriginField() ) ); |
|
199 CSdpMediaField* mediafield = CSdpMediaField::DecodeLC( KAudioMedia() ); |
|
200 iOffer->MediaFields().AppendL( mediafield ); |
|
201 CleanupStack::Pop( mediafield ); |
|
202 aOutStream.EncodeL( *mediafield ); |
|
203 |
|
204 return iApi.CreateOfferL( iSessionId, iOffer ); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CNSPTestConsoleSession::ResolveL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 TInt CNSPTestConsoleSession::ResolveL( |
|
212 CTestConsoleStream& aInStream, CTestConsoleStream& aOutStream ) |
|
213 { |
|
214 __ASSERT_ALWAYS( &aInStream, User::Leave( KErrArgument ) ); |
|
215 __ASSERT_ALWAYS( &aOutStream, User::Leave( KErrArgument ) ); |
|
216 __ASSERT_ALWAYS( EIdle == iState, User::Leave( KErrTotalLossOfPrecision ) ); |
|
217 iState = ECreateAnswer; |
|
218 |
|
219 CSdpMediaField* mediafield = NULL; |
|
220 |
|
221 delete iOffer; |
|
222 iOffer = CSdpDocument::NewL(); |
|
223 iOffer->SetConnectionField( CSdpConnectionField::DecodeL( KConnFieldRemote() ) ); |
|
224 iOffer->SetOriginField( CSdpOriginField::DecodeL( KOriginField() ) ); |
|
225 mediafield = CSdpMediaField::DecodeLC( KAudioMedia() ); |
|
226 iOffer->MediaFields().AppendL( mediafield ); |
|
227 CleanupStack::Pop( mediafield ); |
|
228 aInStream.DecodeL( *mediafield ); |
|
229 |
|
230 delete iAnswer; |
|
231 iAnswer = CSdpDocument::NewL(); |
|
232 iAnswer->SetConnectionField( CSdpConnectionField::DecodeL( KConnFieldLocal() ) ); |
|
233 iAnswer->SetOriginField( CSdpOriginField::DecodeL( KOriginField() ) ); |
|
234 mediafield = CSdpMediaField::DecodeLC( KAudioMedia() ); |
|
235 iAnswer->MediaFields().AppendL( mediafield ); |
|
236 CleanupStack::Pop( mediafield ); |
|
237 aOutStream.EncodeL( *mediafield ); |
|
238 |
|
239 return iApi.ResolveL( iSessionId, iOffer, iAnswer ); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CNSPTestConsoleSession::DecodeAnswerL |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 TInt CNSPTestConsoleSession::DecodeAnswerL( CTestConsoleStream& aInStream ) |
|
247 { |
|
248 __ASSERT_ALWAYS( &aInStream, User::Leave( KErrArgument ) ); |
|
249 __ASSERT_ALWAYS( EIdle == iState, User::Leave( KErrTotalLossOfPrecision ) ); |
|
250 iState = EDecodeAnswer; |
|
251 |
|
252 delete iAnswer; |
|
253 iAnswer = CSdpDocument::NewL(); |
|
254 iAnswer->SetConnectionField( CSdpConnectionField::DecodeL( KConnFieldRemote() ) ); |
|
255 iAnswer->SetOriginField( CSdpOriginField::DecodeL( KOriginField() ) ); |
|
256 CSdpMediaField* mediafield = CSdpMediaField::DecodeLC( KAudioMedia() ); |
|
257 iAnswer->MediaFields().AppendL( mediafield ); |
|
258 CleanupStack::Pop( mediafield ); |
|
259 aInStream.DecodeL( *mediafield ); |
|
260 |
|
261 return iApi.DecodeAnswerL( iSessionId, iAnswer ); |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CNSPTestConsoleSession::UpdateL |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CNSPTestConsoleSession::UpdateL( CTestConsoleStream& aInStream ) |
|
269 { |
|
270 __ASSERT_ALWAYS( &aInStream, User::Leave( KErrArgument ) ); |
|
271 |
|
272 delete iOffer; |
|
273 iOffer = CSdpDocument::NewL(); |
|
274 iOffer->SetConnectionField( CSdpConnectionField::DecodeL( KConnFieldRemote() ) ); |
|
275 iOffer->SetOriginField( CSdpOriginField::DecodeL( KOriginField() ) ); |
|
276 CSdpMediaField* mediafield = CSdpMediaField::DecodeLC( KAudioMedia() ); |
|
277 iOffer->MediaFields().AppendL( mediafield ); |
|
278 CleanupStack::Pop( mediafield ); |
|
279 aInStream.DecodeL( *mediafield ); |
|
280 |
|
281 iApi.UpdateL( iSessionId, iOffer ); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CNSPTestConsoleSession::State |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 CNSPTestConsoleSession::TSessionState CNSPTestConsoleSession::State() const |
|
289 { |
|
290 return iState; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CNSPTestConsoleSession::StoreOutStream |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void CNSPTestConsoleSession::StoreOutStream( CTestConsoleStream* aOutStream ) |
|
298 { |
|
299 if ( iOutStream != aOutStream ) |
|
300 { |
|
301 delete iOutStream; |
|
302 iOutStream = aOutStream; |
|
303 } |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CNSPTestConsoleSession::StoreInStream |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 void CNSPTestConsoleSession::StoreInStream( CTestConsoleStream* aInStream ) |
|
311 { |
|
312 if ( iInStream != aInStream ) |
|
313 { |
|
314 delete iInStream; |
|
315 iInStream = aInStream; |
|
316 } |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CNSPTestConsoleSession::StoreOffer |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CNSPTestConsoleSession::StoreOffer( CSdpDocument* aOffer ) |
|
324 { |
|
325 if ( iOffer != aOffer ) |
|
326 { |
|
327 delete iOffer; |
|
328 iOffer = aOffer; |
|
329 } |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CNSPTestConsoleSession::StoreAnswer |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 void CNSPTestConsoleSession::StoreAnswer( CSdpDocument* aAnswer ) |
|
337 { |
|
338 if ( iAnswer != aAnswer ) |
|
339 { |
|
340 delete iAnswer; |
|
341 iAnswer = aAnswer; |
|
342 } |
|
343 } |
|
344 |