|
1 /* |
|
2 * Copyright (c) 2005-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: Provide interface for the client requestin availability class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "musunittesting.h" |
|
22 #include "musavainviteresponder.h" |
|
23 #include "musavainvitehandler.h" |
|
24 #include "musavasharedobject.h" |
|
25 #include "muslogger.h" |
|
26 #include "musavasip.h" |
|
27 #include "musavasettingsimp.h" |
|
28 #include "sipservertransaction.h" |
|
29 #include <sipstrings.h> |
|
30 #include <sipstrconsts.h> |
|
31 |
|
32 |
|
33 CMusAvaInviteHandler* CMusAvaInviteHandler::NewL( |
|
34 MMusAvaAvailabilityObserver& aObserver, |
|
35 CMusAvaSettingsImp& aSettings ) |
|
36 { |
|
37 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::NewL()" ) |
|
38 CMusAvaInviteHandler* self = CMusAvaInviteHandler::NewLC( |
|
39 aObserver, |
|
40 aSettings ); |
|
41 CleanupStack::Pop( self ); |
|
42 |
|
43 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::NewL()" ) |
|
44 return self; |
|
45 } |
|
46 |
|
47 |
|
48 CMusAvaInviteHandler* CMusAvaInviteHandler::NewLC( |
|
49 MMusAvaAvailabilityObserver& aObserver, |
|
50 CMusAvaSettingsImp& aSettings ) |
|
51 { |
|
52 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::NewLC()" ) |
|
53 CMusAvaInviteHandler* self = new( ELeave ) CMusAvaInviteHandler( |
|
54 aObserver, |
|
55 aSettings ); |
|
56 |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 |
|
60 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::NewLC()" ) |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 CMusAvaInviteHandler::~CMusAvaInviteHandler() |
|
66 { |
|
67 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::~CMusAvaInviteHandler()" ) |
|
68 iResponders.ResetAndDestroy(); |
|
69 if ( iSharedObj ) |
|
70 { |
|
71 iSharedObj->DeleteSingleton(); |
|
72 } |
|
73 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::~CMusAvaInviteHandler()" ) |
|
74 } |
|
75 |
|
76 |
|
77 CMusAvaInviteHandler::CMusAvaInviteHandler( |
|
78 MMusAvaAvailabilityObserver& aObserver, |
|
79 CMusAvaSettingsImp& aSettings ) |
|
80 :CMusAvaAvailability( aObserver ), |
|
81 iSettings( aSettings ) |
|
82 { |
|
83 } |
|
84 |
|
85 |
|
86 void CMusAvaInviteHandler::ConstructL() |
|
87 { |
|
88 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::ConstructL()" ) |
|
89 iSharedObj = CMusAvaSharedObject::GetSingletonL(); |
|
90 iSharedObj->MusAvaSip().AddAdapterL( ( MMusAvaSipConnectionAdapter& ) *this ); |
|
91 iSharedObj->MusAvaSip().AddAdapterL( ( MMusAvaSipAdapter& ) *this ); |
|
92 // set this only for static availability modules |
|
93 iState = MMusAvaObserver::EMusAvaStatusAvailable ; |
|
94 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::ConstructL()" ) |
|
95 } |
|
96 |
|
97 |
|
98 // ------------------------------------------------------------------------- |
|
99 // A SIP request outside a dialog has been received from the network. |
|
100 // ------------------------------------------------------------------------- |
|
101 // |
|
102 TInt CMusAvaInviteHandler::IncomingRequest (CSIPServerTransaction* |
|
103 aTransaction) |
|
104 { |
|
105 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::IncomingRequest (CSIPServerTransaction* aTransaction)" ) |
|
106 if( aTransaction->Type() == SIPStrings::StringF( SipStrConsts::EInvite ) ) |
|
107 { |
|
108 TRAPD ( err, InvitationReceivedL( aTransaction ) ) |
|
109 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::IncomingRequest()" ) |
|
110 if ( err != KErrNone ) |
|
111 { |
|
112 delete aTransaction; |
|
113 } |
|
114 return KErrNone; |
|
115 } |
|
116 else |
|
117 { |
|
118 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::IncomingRequest(KErrNotFound)" ) |
|
119 return KErrNotFound; |
|
120 } |
|
121 } |
|
122 |
|
123 |
|
124 // ------------------------------------------------------------------------- |
|
125 // Starts the loopy execution. |
|
126 // ------------------------------------------------------------------------- |
|
127 // |
|
128 void CMusAvaInviteHandler::DoExecuteL() |
|
129 { |
|
130 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::ExecutePatternL()" ) |
|
131 // set status available |
|
132 SetState( MMusAvaObserver::EMusAvaStatusAvailable ); |
|
133 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::ExecutePatternL()" ) |
|
134 } |
|
135 |
|
136 |
|
137 // ------------------------------------------------------------------------- |
|
138 // Stops the loop. |
|
139 // ------------------------------------------------------------------------- |
|
140 // |
|
141 void CMusAvaInviteHandler::Stop() |
|
142 { |
|
143 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::StopPatternL()" ) |
|
144 iResponders.ResetAndDestroy(); |
|
145 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::StopPatternL()" ) |
|
146 } |
|
147 |
|
148 |
|
149 // ------------------------------------------------------------------------- |
|
150 // CMusAvaInviteHandler::Name |
|
151 // ------------------------------------------------------------------------- |
|
152 // |
|
153 MMusAvaObserver::TAvailabilityName CMusAvaInviteHandler::Name() |
|
154 { |
|
155 return MMusAvaObserver::EMusAvaInviteHandler; |
|
156 } |
|
157 |
|
158 // ------------------------------------------------------------------------- |
|
159 // This function is called when a SIP invite is received. |
|
160 // ------------------------------------------------------------------------- |
|
161 // |
|
162 void CMusAvaInviteHandler::InvitationReceivedL( |
|
163 CSIPServerTransaction* aTransaction ) |
|
164 { |
|
165 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::InvitationReceivedL()" ) |
|
166 |
|
167 // create a new responder instance |
|
168 CMusAvaInviteResponder* responder = CMusAvaInviteResponder::NewLC( |
|
169 aTransaction, *this ); |
|
170 TRAPD( err, responder->AnswerL() ); |
|
171 if( err != KErrNone ) |
|
172 { |
|
173 CleanupStack::PopAndDestroy( responder ); |
|
174 MUS_LOG1( "mus: [MUSAVA] InvitationReceivedL( aTransaction )\ |
|
175 err #%d", err ) |
|
176 } |
|
177 else |
|
178 { |
|
179 TRAP( err, iResponders.AppendL( responder ) ); |
|
180 if ( err != KErrNone ) |
|
181 { |
|
182 CleanupStack::PopAndDestroy( responder ); |
|
183 } |
|
184 else |
|
185 { |
|
186 CleanupStack::Pop( responder ); |
|
187 } |
|
188 InvitationAnsweredLD(); |
|
189 } |
|
190 |
|
191 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::InvitationReceivedL()" ) |
|
192 } |
|
193 |
|
194 |
|
195 // ------------------------------------------------------------------------- |
|
196 // This function is called when SIP invite is properly responded. |
|
197 // ------------------------------------------------------------------------- |
|
198 // |
|
199 void CMusAvaInviteHandler::InvitationAnsweredLD() |
|
200 { |
|
201 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::InvitationAnsweredLD()" ) |
|
202 |
|
203 // look for that responder instance from the array |
|
204 if ( iResponders.Count() ) |
|
205 { |
|
206 for ( TInt i = 0; i < iResponders.Count(); i++ ) |
|
207 { |
|
208 CMusAvaInviteResponder* responder = ( iResponders )[ i ]; |
|
209 if( responder->ResponseComplete() ) |
|
210 { |
|
211 MUS_LOG( "mus: [MUSAVA] Remove responder" ) |
|
212 delete responder; |
|
213 iResponders.Remove( i ); |
|
214 } |
|
215 } |
|
216 } |
|
217 |
|
218 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::InvitationAnsweredLD()" ) |
|
219 } |
|
220 |
|
221 |
|
222 // ------------------------------------------------------------------------- |
|
223 // CMusAvaInviteHandler::ApplicationState |
|
224 // ------------------------------------------------------------------------- |
|
225 // |
|
226 MMusAvaSettingsObserver::TApplicationState |
|
227 CMusAvaInviteHandler::ApplicationState() |
|
228 { |
|
229 return iSettings.ApplicationState(); |
|
230 } |
|
231 |
|
232 |
|
233 // ------------------------------------------------------------------------- |
|
234 // CMusAvaInviteHandler::IncomingRequest |
|
235 // ------------------------------------------------------------------------- |
|
236 // |
|
237 TInt CMusAvaInviteHandler::IncomingRequest( |
|
238 TUint32 /*aIapId*/, |
|
239 CSIPServerTransaction* aTransaction ) |
|
240 { |
|
241 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::IncomingRequest()" ) |
|
242 TInt retval = IncomingRequest( aTransaction ); |
|
243 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::IncomingRequest()" ) |
|
244 return retval; |
|
245 } |
|
246 |
|
247 |
|
248 // ------------------------------------------------------------------------- |
|
249 // CMusAvaInviteHandler::TimedOut |
|
250 // ------------------------------------------------------------------------- |
|
251 // |
|
252 TInt CMusAvaInviteHandler::TimedOut(CSIPServerTransaction& /*aTransaction*/ ) |
|
253 { |
|
254 MUS_LOG( "mus: [MUSAVA] -> CMusAvaInviteHandler::ConstructL()" ) |
|
255 MUS_LOG( "mus: [MUSAVA] <- CMusAvaInviteHandler::ConstructL()" ) |
|
256 return KErrNotSupported; |
|
257 } |