|
1 /* |
|
2 * Copyright (c) 2005-2006 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: mussipobserver is SIP API observer class for the MUS availability plug-in. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "musunittesting.h" |
|
21 #include "musavasipconnectionobserver.h" |
|
22 #include "musavasipconnectionadapter.h" |
|
23 #include "musavasipdefaulthandler.h" |
|
24 #include "musavasip.h" |
|
25 #include "muslogger.h" |
|
26 |
|
27 #include <e32std.h> |
|
28 #include <sipconnectionobserver.h> |
|
29 #include <sipservertransaction.h> |
|
30 #include <sipinvitedialogassoc.h> |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // Two-phased constructor. |
|
37 // ----------------------------------------------------------------------------- |
|
38 CMusAvaSipConnectionObserver* CMusAvaSipConnectionObserver::NewL() |
|
39 { |
|
40 CMusAvaSipConnectionObserver* self = |
|
41 new( ELeave ) CMusAvaSipConnectionObserver(); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 // Destructor |
|
50 CMusAvaSipConnectionObserver::~CMusAvaSipConnectionObserver() |
|
51 { |
|
52 delete iDefaultHandler; |
|
53 iObservers.Reset(); |
|
54 iObservers.Close(); |
|
55 } |
|
56 |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // A SIP request outside a dialog has been received from the network. |
|
60 // ----------------------------------------------------------------------------- |
|
61 void CMusAvaSipConnectionObserver::IncomingRequest( |
|
62 CSIPServerTransaction* aTransaction ) |
|
63 { |
|
64 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
65 { |
|
66 TInt retval( KErrNotFound ); |
|
67 retval = iObservers[i]->IncomingRequest( aTransaction ); |
|
68 if( retval == KErrNone) |
|
69 { |
|
70 return; |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // A SIP request within a dialog has been received from the network. |
|
78 // ----------------------------------------------------------------------------- |
|
79 void CMusAvaSipConnectionObserver::IncomingRequest( |
|
80 CSIPServerTransaction* aTransaction, |
|
81 CSIPDialog& aSIPDialog ) |
|
82 |
|
83 { |
|
84 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
85 { |
|
86 TInt retval( KErrNotFound ); |
|
87 retval = iObservers[i]->IncomingRequest( aTransaction, aSIPDialog ); |
|
88 if( retval == KErrNone) |
|
89 { |
|
90 return; |
|
91 } |
|
92 } |
|
93 } |
|
94 |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // A SIP response that is within a dialog association or creates a |
|
98 // dialog association. |
|
99 // ----------------------------------------------------------------------------- |
|
100 void CMusAvaSipConnectionObserver::IncomingResponse( |
|
101 CSIPClientTransaction& aTransaction ) |
|
102 { |
|
103 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
104 { |
|
105 TInt retval( KErrNotFound ); |
|
106 retval = iObservers[i]->IncomingResponse( aTransaction ); |
|
107 if( retval == KErrNone) |
|
108 { |
|
109 return; |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // A SIP response that is within a dialog association or creates a |
|
117 // dialog association. |
|
118 // ----------------------------------------------------------------------------- |
|
119 void CMusAvaSipConnectionObserver::IncomingResponse( |
|
120 CSIPClientTransaction& aTransaction, |
|
121 CSIPDialogAssocBase& aDialogAssoc) |
|
122 { |
|
123 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
124 { |
|
125 TInt retval( KErrNotFound ); |
|
126 retval = iObservers[i]->IncomingResponse( aTransaction, aDialogAssoc ); |
|
127 if( retval == KErrNone) |
|
128 { |
|
129 return; |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // Multiple SIP responses have been received to the single INVITE. |
|
137 // ----------------------------------------------------------------------------- |
|
138 void CMusAvaSipConnectionObserver::IncomingResponse( |
|
139 CSIPClientTransaction& aTransaction, |
|
140 CSIPInviteDialogAssoc* aDialogAssoc ) |
|
141 { |
|
142 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
143 { |
|
144 TInt retval( KErrNotFound ); |
|
145 retval = iObservers[i]->IncomingResponse( aTransaction, aDialogAssoc ); |
|
146 if( retval == KErrNone) |
|
147 { |
|
148 return; |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // SIP stack has completed UAC core INVITE transaction. |
|
156 // ----------------------------------------------------------------------------- |
|
157 void CMusAvaSipConnectionObserver::InviteCompleted( |
|
158 CSIPClientTransaction& aTransaction ) |
|
159 { |
|
160 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
161 { |
|
162 TInt retval( KErrNotFound ); |
|
163 retval = iObservers[i]->InviteCompleted( aTransaction ); |
|
164 if( retval == KErrNone) |
|
165 { |
|
166 return; |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // A SIP response creating a registration binding or an error response |
|
174 // that is related to an existing refreshed registration binding has |
|
175 // been received from the network. |
|
176 // ----------------------------------------------------------------------------- |
|
177 void CMusAvaSipConnectionObserver::IncomingResponse( |
|
178 CSIPClientTransaction& aTransaction, |
|
179 CSIPRegistrationBinding& aRegistration ) |
|
180 { |
|
181 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
182 { |
|
183 TInt retval( KErrNotFound ); |
|
184 retval = iObservers[i]->IncomingResponse( aTransaction, aRegistration ); |
|
185 if( retval == KErrNone) |
|
186 { |
|
187 return; |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // An asynchronous error has occurred in the stack related to the |
|
195 // request indicated by the given transaction. |
|
196 // ----------------------------------------------------------------------------- |
|
197 void CMusAvaSipConnectionObserver::ErrorOccured( |
|
198 TInt aError, |
|
199 CSIPTransactionBase& aTransaction ) |
|
200 { |
|
201 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
202 { |
|
203 TInt retval( KErrNotFound ); |
|
204 retval = iObservers[i]->ErrorOccured( aError, aTransaction ); |
|
205 if( retval == KErrNone) |
|
206 { |
|
207 return; |
|
208 } |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // An asynchronous error has occurred in the stack related to the |
|
215 // request indicated by the given transaction. |
|
216 // ----------------------------------------------------------------------------- |
|
217 void CMusAvaSipConnectionObserver::ErrorOccured( |
|
218 TInt aError, |
|
219 CSIPClientTransaction& aTransaction, |
|
220 CSIPRegistrationBinding& aRegistration ) |
|
221 { |
|
222 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
223 { |
|
224 TInt retval( KErrNotFound ); |
|
225 retval = iObservers[i]->ErrorOccured( aError, aTransaction, aRegistration ); |
|
226 if( retval == KErrNone) |
|
227 { |
|
228 return; |
|
229 } |
|
230 } |
|
231 } |
|
232 |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // An asynchronous error has occured related to a request within an |
|
236 // existing dialog. |
|
237 // ----------------------------------------------------------------------------- |
|
238 void CMusAvaSipConnectionObserver::ErrorOccured( |
|
239 TInt aError, |
|
240 CSIPTransactionBase& aSIPTransactionBase, |
|
241 CSIPDialogAssocBase& aSIPDialogAssociation ) |
|
242 { |
|
243 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
244 { |
|
245 TInt retval( KErrNotFound ); |
|
246 retval = iObservers[i]->ErrorOccured( aError, |
|
247 aSIPTransactionBase, |
|
248 aSIPDialogAssociation ); |
|
249 if( retval == KErrNone) |
|
250 { |
|
251 return; |
|
252 } |
|
253 } |
|
254 } |
|
255 |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // An asynchronous error has occured related to a refresh. |
|
259 // ----------------------------------------------------------------------------- |
|
260 void CMusAvaSipConnectionObserver::ErrorOccured( TInt aError, |
|
261 CSIPRefresh& aSIPRefresh ) |
|
262 { |
|
263 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
264 { |
|
265 TInt retval( KErrNotFound ); |
|
266 retval = iObservers[i]->ErrorOccured( aError, aSIPRefresh ); |
|
267 if( retval == KErrNone) |
|
268 { |
|
269 return; |
|
270 } |
|
271 } |
|
272 } |
|
273 |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // An asynchronous error has occured related to a periodical refresh |
|
277 // that relates to a registration. |
|
278 // ----------------------------------------------------------------------------- |
|
279 void CMusAvaSipConnectionObserver::ErrorOccured( |
|
280 TInt aError, |
|
281 CSIPRegistrationBinding& aRegistration ) |
|
282 { |
|
283 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
284 { |
|
285 TInt retval( KErrNotFound ); |
|
286 retval = iObservers[i]->ErrorOccured( aError, aRegistration ); |
|
287 if( retval == KErrNone) |
|
288 { |
|
289 return; |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // An asynchronous error has occured related to a periodical refresh |
|
297 // that belongs to SIP dialog association. |
|
298 // ----------------------------------------------------------------------------- |
|
299 void CMusAvaSipConnectionObserver::ErrorOccured( |
|
300 TInt aError, |
|
301 CSIPDialogAssocBase& aSIPDialogAssociation ) |
|
302 { |
|
303 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
304 { |
|
305 TInt retval( KErrNotFound ); |
|
306 retval = iObservers[i]->ErrorOccured( aError, aSIPDialogAssociation ); |
|
307 if( retval == KErrNone) |
|
308 { |
|
309 return; |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // Invite was canceled with the CANCEL |
|
317 // ----------------------------------------------------------------------------- |
|
318 void CMusAvaSipConnectionObserver::InviteCanceled( |
|
319 CSIPServerTransaction& aTransaction ) |
|
320 { |
|
321 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
322 { |
|
323 TInt retval( KErrNotFound ); |
|
324 retval = iObservers[i]->InviteCanceled( aTransaction ); |
|
325 if( retval == KErrNone) |
|
326 { |
|
327 return; |
|
328 } |
|
329 } |
|
330 } |
|
331 |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // Is called when the connection state changes |
|
335 // ----------------------------------------------------------------------------- |
|
336 void CMusAvaSipConnectionObserver::ConnectionStateChanged ( |
|
337 CSIPConnection::TState aState ) |
|
338 { |
|
339 for( TInt i=0; i<iObservers.Count(); i++ ) |
|
340 { |
|
341 TInt retval( KErrNotFound ); |
|
342 retval = iObservers[i]->ConnectionStateChanged( aState ); |
|
343 if( retval == KErrNone) |
|
344 { |
|
345 return; |
|
346 } |
|
347 } |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // C++ default constructor. |
|
352 // ----------------------------------------------------------------------------- |
|
353 CMusAvaSipConnectionObserver::CMusAvaSipConnectionObserver() |
|
354 { |
|
355 } |
|
356 |
|
357 |
|
358 // ----------------------------------------------------------------------------- |
|
359 // Symbian 2nd phase constructor. |
|
360 // ----------------------------------------------------------------------------- |
|
361 void CMusAvaSipConnectionObserver::ConstructL() |
|
362 { |
|
363 iDefaultHandler = new( ELeave ) CMusAvaSipDefaultHandler(); |
|
364 iObservers.AppendL( iDefaultHandler ); |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 // ----------------------------------------------------------------------------- |
|
370 void CMusAvaSipConnectionObserver::AddObserverL( |
|
371 MMusAvaSipConnectionAdapter& aAdapter, |
|
372 TInt aIndex ) |
|
373 { |
|
374 TInt index = iObservers.Find( &aAdapter ); |
|
375 |
|
376 if( index == KErrNotFound ) |
|
377 { |
|
378 TInt count = iObservers.Count(); |
|
379 if ( aIndex > KErrNotFound && aIndex < iObservers.Count() ) |
|
380 { |
|
381 iObservers.InsertL( &aAdapter, aIndex ); |
|
382 } |
|
383 else |
|
384 { |
|
385 iObservers.InsertL( &aAdapter, count-1 ); |
|
386 } |
|
387 } |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 // ----------------------------------------------------------------------------- |
|
393 void CMusAvaSipConnectionObserver::RemoveObserver( MMusAvaSipConnectionAdapter& aAdapter ) |
|
394 { |
|
395 TInt index = iObservers.Find( &aAdapter ); |
|
396 |
|
397 if( index != KErrNotFound ) |
|
398 { |
|
399 iObservers.Remove( index ); |
|
400 } |
|
401 } |
|
402 |