|
1 /* |
|
2 * Copyright (c) 2005-2009 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: Main class for server side sessions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <centralrepository.h> |
|
23 |
|
24 #include "epos_suplterminalipc.h" |
|
25 #include "epos_csuplprotocolmanagerbase.h" |
|
26 #include "epos_suplnetworkipc.h" |
|
27 |
|
28 //#ifdef _DEBUG |
|
29 //#include "epos_cpostrace.h" |
|
30 //#endif |
|
31 |
|
32 #include "epos_csuplserver.h" |
|
33 #include "epos_csuplsubsessionregistry.h" |
|
34 #include "epos_csuplglobal.h" |
|
35 #include "epos_csuplipcsubsession.h" |
|
36 #include "epos_csuplipcsession.h" |
|
37 #include "epos_csuplnetinitiatedsession.h" |
|
38 #include "epos_csuplnetinitiatedregistry.h" |
|
39 #include "epos_csuplconnecttimer.h" |
|
40 #include "epos_mconnecttimerobserver.h" |
|
41 #include "epos_csuplsessionmanager.h" |
|
42 |
|
43 |
|
44 // CONSTANTS |
|
45 //#ifdef _DEBUG |
|
46 _LIT(KTraceFileName, "SUPL_GW::epos_csuplipcsession.cpp"); |
|
47 //#endif |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // C++ default constructor can NOT contain any code, that |
|
52 // might leave. |
|
53 // |
|
54 CSuplIPCSession::CSuplIPCSession(CSuplServer& aServer, CSuplSessionManager& aSessnMgr): |
|
55 iSuplServer(aServer), |
|
56 iSessionManager(aSessnMgr) |
|
57 { |
|
58 } |
|
59 |
|
60 // Destructor |
|
61 CSuplIPCSession::~CSuplIPCSession() |
|
62 { |
|
63 DEBUG_TRACE("CSuplIPCSession::~CSuplIPCSession", __LINE__) |
|
64 delete iSubSessionRegistry; |
|
65 delete iConnectTimer; |
|
66 // The flag iServerShutdown prevents calling the server or its members if |
|
67 // it is already destroyed. |
|
68 if (!iServerShutdown) |
|
69 { |
|
70 if (iDecrementSessions) |
|
71 { |
|
72 iSuplServer.DecrementSessions(); |
|
73 } |
|
74 } |
|
75 } |
|
76 |
|
77 // Two-phased constructor |
|
78 CSuplIPCSession* CSuplIPCSession::NewL(CSuplServer& aServer, CSuplSessionManager& aSessnMgr, TInt aIpcSessionId) |
|
79 { |
|
80 DEBUG_TRACE("CSuplIPCSession::NewL", __LINE__) |
|
81 CSuplIPCSession* self = new (ELeave) |
|
82 CSuplIPCSession(aServer, aSessnMgr); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(aIpcSessionId); |
|
85 CleanupStack::Pop(self); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // EPOC default constructor |
|
90 void CSuplIPCSession::ConstructL(TInt aIpcSessionId) |
|
91 { |
|
92 DEBUG_TRACE("CSuplIPCSession::ConstructL", __LINE__) |
|
93 iSubSessionRegistry = CSuplSubsessionRegistry::NewL(); |
|
94 iConnectTimer = CSuplConnectTimer::NewL(this); |
|
95 // This call will also cancel any server shutdown in progress. |
|
96 iSuplServer.IncrementSessions(); |
|
97 iIpcSessionId = aIpcSessionId; |
|
98 iDecrementSessions = ETrue; |
|
99 |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------- |
|
103 // CSuplIPCSession::ForwardMessageL |
|
104 // |
|
105 // (other items were commented in a header). |
|
106 // --------------------------------------------------------- |
|
107 // |
|
108 void CSuplIPCSession::ForwardMessageL(const RMessage2& aMessage) |
|
109 { |
|
110 DEBUG_TRACE("CSuplIPCSession::ForwardMessageL", __LINE__) |
|
111 |
|
112 if (aMessage.SecureId() != KSuplWapSecureId) |
|
113 if (!aMessage.HasCapability(ECapabilityCommDD)) |
|
114 { |
|
115 DEBUG_TRACE("CSuplServer::Invalid UID", __LINE__) |
|
116 RequestComplete(aMessage, KErrPermissionDenied); |
|
117 } |
|
118 TInt dataSize = aMessage.GetDesLength(0); |
|
119 if(dataSize>0) |
|
120 { |
|
121 iSuplServer.HandleNewNetSessionL(iSessionManager,aMessage); |
|
122 } |
|
123 else |
|
124 { |
|
125 RequestComplete(aMessage,KErrArgument); |
|
126 } |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CSuplIPCSession::ServiceL |
|
131 // |
|
132 // (other items were commented in a header). |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 void CSuplIPCSession::ServiceL(const RMessage2& aMessage) |
|
136 { |
|
137 DEBUG_TRACE("CSuplIPCSession::ServiceL", __LINE__) |
|
138 iMessage = aMessage; |
|
139 switch (aMessage.Function()) |
|
140 { |
|
141 case ESuplTerminalSubssnOpen: |
|
142 { |
|
143 TInt service = aMessage.Int0(); |
|
144 |
|
145 switch( service ) |
|
146 { |
|
147 case 1: |
|
148 { |
|
149 iSuplService = RSuplTerminalSubSession::ESUPL_1_0; |
|
150 break; |
|
151 } |
|
152 case 2: |
|
153 { |
|
154 iSuplService = RSuplTerminalSubSession::ESUPL_2_0; |
|
155 break; |
|
156 } |
|
157 default: |
|
158 { |
|
159 iSuplService = RSuplTerminalSubSession::ESUPL_1_0; |
|
160 break; |
|
161 } |
|
162 } |
|
163 |
|
164 TBool connect=iSuplServer.GetConnectFlag(); |
|
165 TInt connectError=iSessionManager.GetConnectError(); |
|
166 if (connect && connectError==KErrNone) |
|
167 CreateSubSessionL(aMessage, CSUPLProtocolManagerBase::ETerminal, iSuplService ); |
|
168 else |
|
169 { |
|
170 if(connect==FALSE && connectError==KErrNone) |
|
171 { |
|
172 iConnectCount = 0; |
|
173 iReqType = ETerminalConnectOpen; |
|
174 iConnectTimer->Start(250000); |
|
175 } |
|
176 else |
|
177 RequestComplete(aMessage,KErrGeneral); |
|
178 } |
|
179 break; |
|
180 } |
|
181 case ESuplTerminalSubssnClose: |
|
182 { |
|
183 CloseSubsessionL(aMessage); |
|
184 } |
|
185 break; |
|
186 case ESuplNetworkForwardSuplMsg: |
|
187 { |
|
188 TBool connect=iSuplServer.GetConnectFlag(); |
|
189 TInt connectError=iSessionManager.GetConnectError(); |
|
190 if (connect && connectError==KErrNone) |
|
191 ForwardMessageL(aMessage); |
|
192 else |
|
193 { |
|
194 if(!connect && connectError==KErrNone) |
|
195 { |
|
196 iConnectCount = 0; |
|
197 iReqType = ENetworkConnectForwardMessage; |
|
198 iConnectTimer->Start(250000); |
|
199 } |
|
200 else |
|
201 RequestComplete(aMessage,KErrGeneral); |
|
202 } |
|
203 break; |
|
204 } |
|
205 default: |
|
206 ForwardToSubSessionL(aMessage); |
|
207 break; |
|
208 } |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // CSuplIPCSession::NotifyServerShutdown |
|
213 // |
|
214 // (other items were commented in a header). |
|
215 // --------------------------------------------------------- |
|
216 // |
|
217 void CSuplIPCSession::NotifyServerShutdown() |
|
218 { |
|
219 DEBUG_TRACE("CSuplIPCSession::NotifyServerShutdown", __LINE__) |
|
220 iServerShutdown = ETrue; |
|
221 TInt nrOfSubSessions = iSubSessionRegistry->Count(); |
|
222 for (TInt i = 0; i < nrOfSubSessions; i++) |
|
223 { |
|
224 CSuplIPCSubSession * subSession = |
|
225 static_cast <CSuplIPCSubSession *> |
|
226 (iSubSessionRegistry->SubSessionFromIndex(i)); |
|
227 if (subSession) |
|
228 { |
|
229 subSession->NotifyServerShutdown(); |
|
230 } |
|
231 } |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------- |
|
235 // CSuplIPCSession::CloseSubsession |
|
236 // |
|
237 // (other items were commented in a header). |
|
238 // --------------------------------------------------------- |
|
239 // |
|
240 void CSuplIPCSession::CloseSubsessionL(const RMessage2& aMessage) |
|
241 { |
|
242 DEBUG_TRACE("CSuplIPCSession::CloseSubsessionL", __LINE__) |
|
243 |
|
244 TInt handle = aMessage.Int3(); |
|
245 |
|
246 CSuplIPCSubSession* subSession = |
|
247 iSubSessionRegistry->SubSessionFromHandleL(aMessage.Int3()); |
|
248 |
|
249 subSession->DestroySession(iSessionManager); |
|
250 |
|
251 iSubSessionRegistry->CloseSubSession(handle); |
|
252 RequestComplete(aMessage, KErrNone); |
|
253 |
|
254 DEBUG_TRACE("CSuplIPCSession::CloseSubsessionCompletes", __LINE__) |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------- |
|
258 // CSuplIPCSession::CreateSubSessionL |
|
259 // |
|
260 // (other items were commented in a header). |
|
261 // --------------------------------------------------------- |
|
262 // |
|
263 void CSuplIPCSession::CreateSubSessionL( |
|
264 const RMessage2& aMessage, |
|
265 CSUPLProtocolManagerBase::TSuplReqType aReqType, |
|
266 RSuplTerminalSubSession::TSuplServiceType aSuplService |
|
267 ) |
|
268 { |
|
269 DEBUG_TRACE("CSuplIPCSession::CreateSubSessionL", __LINE__) |
|
270 // Create SUPL session object |
|
271 CSuplIPCSubSession* subSession = CSuplIPCSubSession::NewLC( |
|
272 iSessionManager, |
|
273 aReqType, |
|
274 iIpcSessionId, |
|
275 aSuplService); |
|
276 if(!subSession) |
|
277 { |
|
278 CleanupStack::PopAndDestroy(); |
|
279 RequestComplete(aMessage, KErrGeneral); |
|
280 return; |
|
281 } |
|
282 TInt subSessionHandle = iSubSessionRegistry->AddInstanceL(subSession); |
|
283 CleanupStack::Pop(subSession); // Now owned by registry |
|
284 |
|
285 // Set the client subsession identifier. |
|
286 TPckg<TInt> handlePackage(subSessionHandle); |
|
287 TInt err = SuplGlobal::Write(aMessage, 3, handlePackage); |
|
288 if (err) |
|
289 { |
|
290 iSubSessionRegistry->CloseSubSession(subSessionHandle); |
|
291 User::Leave(err); |
|
292 } |
|
293 RequestComplete(aMessage, KErrNone); |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------- |
|
297 // CSuplIPCSession::ForwardToSubSessionL |
|
298 // |
|
299 // (other items were commented in a header). |
|
300 // --------------------------------------------------------- |
|
301 // |
|
302 void CSuplIPCSession::ForwardToSubSessionL(const RMessage2& aMessage) |
|
303 { |
|
304 DEBUG_TRACE("CSuplIPCSession::ForwardtoSubSessionL", __LINE__) |
|
305 CSuplIPCSubSession* subSession = |
|
306 iSubSessionRegistry->SubSessionFromHandleL(aMessage.Int3()); |
|
307 |
|
308 if (!subSession) |
|
309 { |
|
310 User::Leave(KErrNotSupported); |
|
311 } |
|
312 |
|
313 subSession->ServiceL(aMessage); |
|
314 } |
|
315 |
|
316 // --------------------------------------------------------- |
|
317 // CSuplIPCSession::RequestComplete |
|
318 // |
|
319 // (other items were commented in a header). |
|
320 // --------------------------------------------------------- |
|
321 // |
|
322 void CSuplIPCSession::RequestComplete(const RMessage2& aMessage, TInt aCompleteCode) |
|
323 { |
|
324 DEBUG_TRACE("CSuplIPCSession::RequestComplete", __LINE__) |
|
325 if (!aMessage.IsNull()) |
|
326 { |
|
327 aMessage.Complete(aCompleteCode); |
|
328 } |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------- |
|
332 // CSuplIPCSession::RequestComplete |
|
333 // |
|
334 // (other items were commented in a header). |
|
335 // --------------------------------------------------------- |
|
336 // |
|
337 void CSuplIPCSession::CompleteConnectTimerL() |
|
338 { |
|
339 DEBUG_TRACE("CSuplIPCSession::CompleteConnectTimerL", __LINE__) |
|
340 TBool connect=iSuplServer.GetConnectFlag(); |
|
341 |
|
342 if (connect) |
|
343 { |
|
344 if (iReqType == ETerminalConnectOpen) |
|
345 { |
|
346 CreateSubSessionL(iMessage, CSUPLProtocolManagerBase::ETerminal, iSuplService); |
|
347 } |
|
348 else if (iReqType == ENetworkConnectForwardMessage) |
|
349 { |
|
350 ForwardMessageL(iMessage); |
|
351 } |
|
352 return; |
|
353 } |
|
354 TInt connectError=iSessionManager.GetConnectError(); |
|
355 if(connectError!=KErrNone) |
|
356 { |
|
357 RequestComplete(iMessage,KErrGeneral); |
|
358 return; |
|
359 } |
|
360 iConnectCount++; |
|
361 if (iConnectCount == 10) |
|
362 { |
|
363 RequestComplete(iMessage,KErrServerBusy); |
|
364 return; |
|
365 } |
|
366 iConnectTimer->Start(250000); |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------- |
|
370 // CSuplIPCSession::ProtocolHUnloaded |
|
371 // |
|
372 // (other items were commented in a header). |
|
373 // --------------------------------------------------------- |
|
374 // |
|
375 void CSuplIPCSession::ProtocolHUnloaded() |
|
376 { |
|
377 DEBUG_TRACE("CSuplIPCSession::ProtocolHUnloaded", __LINE__) |
|
378 TInt subSessioncount = iSubSessionRegistry->Count(); |
|
379 |
|
380 for(TInt loop=0; loop < subSessioncount;loop++) |
|
381 { |
|
382 DEBUG_TRACE("CSuplIPCSession::ProtocolHUnloaded Iterating", __LINE__) |
|
383 CSuplIPCSubSession* subSession = iSubSessionRegistry->SubSessionFromIndex(loop); |
|
384 subSession->ProtocolHUnloaded(); |
|
385 } |
|
386 } |
|
387 |
|
388 // End of File |