|
1 /* |
|
2 * Copyright (c) 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: Simple Engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <e32std.h> |
|
24 |
|
25 // own simple |
|
26 #include "simplesipconnection.h" |
|
27 #include "simplecommon.h" |
|
28 #include "simpleenginerequest.h" |
|
29 #include "msimpleconnectionobserver.h" |
|
30 #include "simpleconnection.h" |
|
31 #include "simpleengineutils.h" |
|
32 #include "msimpleenginerequest.h" |
|
33 |
|
34 #ifdef _DEBUG |
|
35 #include "simpledebugutils.h" |
|
36 #endif |
|
37 |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 // |
|
41 |
|
42 // ---------------------------------------------------------- |
|
43 // CSimpleConnection::CSimpleConnection |
|
44 // ---------------------------------------------------------- |
|
45 // |
|
46 CSimpleConnection::CSimpleConnection( MSimpleConnectionObserver& aObserver ) |
|
47 : iState( EInactive ), |
|
48 iObserver( aObserver ), |
|
49 iOpId(0), |
|
50 iRequestList( CSimpleEngineRequest::LinkOffset()) |
|
51 { |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------- |
|
55 // CSimpleConnection::~CSimpleConnection |
|
56 // ---------------------------------------------------------- |
|
57 // |
|
58 CSimpleConnection::~CSimpleConnection() |
|
59 { |
|
60 delete iConnection; |
|
61 DeleteRequests(); |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------- |
|
65 // CSimpleConnection::ConstructL |
|
66 // ---------------------------------------------------------- |
|
67 // |
|
68 void CSimpleConnection::ConstructL( TInt32 aServiceId ) |
|
69 { |
|
70 // Create CSimpleSipConnection entity in simplesiputils.dll |
|
71 iConnection = CSimpleSipConnection::NewL(); |
|
72 // Set operation id ranges |
|
73 iLimitLowerValue = TSimpleEngineUtils::OpIdRange(); |
|
74 iLimitUpperValue = iLimitLowerValue + KRangeSize; |
|
75 iOpId = iLimitLowerValue; |
|
76 |
|
77 // start to listen to status events |
|
78 IncreaseOpId(); |
|
79 CSimpleEngineRequest* req = CSimpleEngineRequest::NewL( |
|
80 *this, MSimpleEngineRequest::EListenEvents, iOpId ); |
|
81 CleanupStack::PushL( req ); |
|
82 if ( aServiceId ) |
|
83 { |
|
84 iConnection->SetServiceId( aServiceId ); |
|
85 } |
|
86 iConnection->DispatchReqL( *req ); |
|
87 iRequestList.AddLast( *req ); |
|
88 CleanupStack::Pop( req ); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------- |
|
92 // CSimpleConnection::NewL |
|
93 // ---------------------------------------------------------- |
|
94 // |
|
95 CSimpleConnection* CSimpleConnection::NewL( |
|
96 MSimpleConnectionObserver& aObserver ) |
|
97 { |
|
98 #ifdef _DEBUG |
|
99 TSimpleLogger::Log(_L("SimpleConnection: NewL" )); |
|
100 #endif |
|
101 CSimpleConnection* self = new (ELeave) CSimpleConnection( aObserver ); |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL( NULL ); |
|
104 CleanupStack::Pop( self ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------- |
|
109 // CSimpleConnection::NewL |
|
110 // ---------------------------------------------------------- |
|
111 // |
|
112 CSimpleConnection* CSimpleConnection::NewL( |
|
113 MSimpleConnectionObserver& aObserver, TInt32 aServiceId ) |
|
114 { |
|
115 #ifdef _DEBUG |
|
116 TSimpleLogger::Log(_L("SimpleConnection: NewL" )); |
|
117 #endif |
|
118 CSimpleConnection* self = new (ELeave) CSimpleConnection( aObserver ); |
|
119 CleanupStack::PushL( self ); |
|
120 self->ConstructL( aServiceId ); |
|
121 CleanupStack::Pop( self ); |
|
122 return self; |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------------- |
|
126 // CSimpleConnection::Connection |
|
127 // ---------------------------------------------------------- |
|
128 // |
|
129 CSimpleSipConnection* CSimpleConnection::Connection() |
|
130 { |
|
131 return iConnection; |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------- |
|
135 // CSimpleConnection::Close |
|
136 // ---------------------------------------------------------- |
|
137 // |
|
138 void CSimpleConnection::Close( ) |
|
139 { |
|
140 delete this; |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------- |
|
144 // CSimpleConnection::LoginL |
|
145 // ---------------------------------------------------------- |
|
146 // |
|
147 TInt CSimpleConnection::LoginL( ) |
|
148 { |
|
149 return LoginL( 0 ); |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------------- |
|
153 // CSimpleConnection::LoginL |
|
154 // ---------------------------------------------------------- |
|
155 // |
|
156 TInt CSimpleConnection::LoginL( TInt aId ) |
|
157 { |
|
158 #ifdef _DEBUG |
|
159 TSimpleLogger::Log(_L("SimpleConnection: LoginL aId=%d" ), aId); |
|
160 #endif |
|
161 // check state |
|
162 if ( iState != EInactive ) |
|
163 { |
|
164 User::Leave(KErrNotReady); |
|
165 } |
|
166 |
|
167 IncreaseOpId(); |
|
168 |
|
169 CSimpleEngineRequest* req = CSimpleEngineRequest::NewL( |
|
170 *this, MSimpleEngineRequest::ERegister, iOpId ); |
|
171 req->SetAux( aId ); |
|
172 CleanupStack::PushL( req ); |
|
173 iConnection->DispatchReqL( *req ); |
|
174 iRequestList.AddLast( *req ); |
|
175 CleanupStack::Pop( req ); |
|
176 SetConnectionStatus( EIdle ); |
|
177 return iOpId; |
|
178 } |
|
179 |
|
180 // ---------------------------------------------------------- |
|
181 // CSimpleConnection::ConnectionStatus |
|
182 // ---------------------------------------------------------- |
|
183 // |
|
184 MSimpleConnection::TSimpleState CSimpleConnection::ConnectionStatus() |
|
185 { |
|
186 #ifdef _DEBUG |
|
187 TSimpleLogger::Log(_L("SimpleConnection: ConnectionStatus returns %d" ), iState); |
|
188 #endif |
|
189 return iState; |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------- |
|
193 // CSimpleConnection::CurrentSIPIdentityL |
|
194 // ---------------------------------------------------------- |
|
195 // |
|
196 TPtrC8 CSimpleConnection::CurrentSIPIdentityL() |
|
197 { |
|
198 return iConnection->CurrentSIPIdentityL(); |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------- |
|
202 // CSimpleConnection::Complete |
|
203 // ---------------------------------------------------------- |
|
204 // |
|
205 void CSimpleConnection::Complete( |
|
206 TInt aOpId, TInt aStatus, MSimpleEngineRequest& aReq ) |
|
207 { |
|
208 #ifdef _DEBUG |
|
209 TSimpleLogger::Log(_L("SimpleConnection: Complete opid=%d status=%d" ), |
|
210 aOpId, aStatus ); |
|
211 #endif |
|
212 // check the SIP state from another DLL |
|
213 TSimpleSipState st = iConnection->SIPState(); |
|
214 MSimpleConnection::TSimpleState oldState = ConnectionStatus(); |
|
215 MSimpleConnection::TSimpleState newState = ConvertState( st ); |
|
216 SetConnectionStatus( newState ); |
|
217 |
|
218 if ( aReq.RequestType() != MSimpleEngineRequest::EListenEvents ) |
|
219 { |
|
220 // delete corresponding request from another DLL too. |
|
221 aReq.ModifyType( MSimpleEngineRequest::EDestroy ); |
|
222 TRAP_IGNORE( iConnection->DispatchReqL( aReq )); |
|
223 // delete request from this DLL. |
|
224 aReq.Destroy(); |
|
225 #ifdef _DEBUG |
|
226 TSimpleLogger::Log(_L("SimpleConnection: call RequestCompleteL opid=%d status=%d" ), |
|
227 aOpId, aStatus ); |
|
228 #endif |
|
229 TRAP_IGNORE( iObserver.RequestCompleteL( aOpId, aStatus ) ); |
|
230 } |
|
231 else |
|
232 { |
|
233 // This is status event |
|
234 if ( oldState != newState ) |
|
235 { |
|
236 #ifdef _DEBUG |
|
237 TSimpleLogger::Log(_L("SimpleConnection: call ConnectionStatusL state=%d" ), |
|
238 newState ); |
|
239 #endif |
|
240 TRAP_IGNORE( iObserver.ConnectionStatusL( newState ) ); |
|
241 } |
|
242 } |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CSimpleConnection::DeleteRequests |
|
247 // ----------------------------------------------------------------------------- |
|
248 void CSimpleConnection::DeleteRequests() |
|
249 { |
|
250 #ifdef _DEBUG |
|
251 TSimpleLogger::Log(_L("SimpleConnection: DeleteRequests" )); |
|
252 #endif |
|
253 // Delete all buffered transaction requests |
|
254 TDblQueIter<CSimpleEngineRequest> rIter( iRequestList ); |
|
255 rIter.SetToFirst(); |
|
256 |
|
257 while ( rIter ) |
|
258 { |
|
259 CSimpleEngineRequest* req = rIter; |
|
260 rIter++; //lint !e1757 |
|
261 req->Destroy(); |
|
262 } |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------------- |
|
266 // CSimpleConnection::IncreaseOpId |
|
267 // ---------------------------------------------------------------------------- |
|
268 void CSimpleConnection::IncreaseOpId( ) |
|
269 { |
|
270 iOpId++; |
|
271 if( iOpId >= iLimitUpperValue ) |
|
272 { |
|
273 iOpId = iLimitLowerValue; |
|
274 } |
|
275 } |
|
276 |
|
277 // ---------------------------------------------------------------------------- |
|
278 // CSimpleConnection::ConvertState |
|
279 // ---------------------------------------------------------------------------- |
|
280 MSimpleConnection::TSimpleState CSimpleConnection::ConvertState( TSimpleSipState aState ) |
|
281 { |
|
282 switch( aState ) |
|
283 { |
|
284 case ESimpleSipIdle: |
|
285 return MSimpleConnection::EIdle; |
|
286 case ESimpleSipActive: |
|
287 return MSimpleConnection::EActive; |
|
288 case ESimpleSipSuspend: |
|
289 return ESuspend; |
|
290 case ESimpleSipInactive: |
|
291 return EInactive; |
|
292 case ESimpleSipUnavailable: |
|
293 default: |
|
294 return EUnavailable; |
|
295 }; //lint !e960 |
|
296 } |
|
297 |
|
298 // ---------------------------------------------------------------------------- |
|
299 // CSimpleConnection::SetConnectionStatus |
|
300 // ---------------------------------------------------------------------------- |
|
301 void CSimpleConnection::SetConnectionStatus( TSimpleState aState ) |
|
302 { |
|
303 #ifdef _DEBUG |
|
304 TSimpleLogger::Log(_L("SimpleConnection: SetConnectionStatus %d" ), aState ); |
|
305 #endif |
|
306 iState = aState; |
|
307 } |
|
308 |