|
1 /* |
|
2 * Copyright (c) 2002 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: Presence Server sub-session handler implementation |
|
15 * All clients sub-session related request are handler here |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32std.h> |
|
23 #include "CPEngSubSession.h" |
|
24 #include "TPEngServerMessages.h" |
|
25 #include "TPEngServerCommon.h" |
|
26 |
|
27 #include "MPEngServer.h" |
|
28 #include "RPEngMessage.h" |
|
29 #include "CPEngSessionSlotId.h" |
|
30 #include "CPEngCSPSessManager.h" |
|
31 |
|
32 |
|
33 namespace |
|
34 { |
|
35 void LeaveIfNotAttachedL( TBool aAttached ) |
|
36 { |
|
37 if ( !aAttached ) |
|
38 { |
|
39 User::Leave( KErrNotReady ); |
|
40 } |
|
41 } |
|
42 |
|
43 void LeaveIfAttachedL( TBool aAttached ) |
|
44 { |
|
45 if ( aAttached ) |
|
46 { |
|
47 User::Leave( KErrAlreadyExists ); |
|
48 } |
|
49 } |
|
50 } |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CPEngSubSession::CPEngSubSession |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CPEngSubSession::CPEngSubSession( |
|
61 TInt32 aSessionId ) |
|
62 : iSessionId( aSessionId ) |
|
63 { |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CPEngSubSession::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CPEngSubSession::ConstructL( |
|
72 MPEngServer& aServer, |
|
73 const RPEngMessage& aMessage ) |
|
74 { |
|
75 // app Id |
|
76 iType = aMessage.Function(); |
|
77 iAppId = aMessage.ReadOneDescriptor16L( KMessageSlot1 ); |
|
78 |
|
79 // Read session id from the message |
|
80 HBufC8* sessIdBuff = aMessage.ReadOneDescriptor8LC( KMessageSlot0 ); |
|
81 CPEngSessionSlotId* sessId = CPEngSessionSlotId::NewLC(); |
|
82 sessId->UnPackL( * sessIdBuff ); |
|
83 |
|
84 // get Session manager from the server |
|
85 CPEngCSPSessManager* sessMan = aServer.CSPSessionManagerLC( *sessId ); |
|
86 |
|
87 // if this is transaction sub session, check app Id validity |
|
88 if ( iType == EMainSessCreateTransactionSubSession ) |
|
89 { |
|
90 sessMan->AppIdActiveL( *iAppId ); |
|
91 } |
|
92 // open reference to the CPS holder |
|
93 sessMan->OpenL( *this ); |
|
94 iSessionManager = sessMan; |
|
95 CleanupStack::PopAndDestroy( 3 ); // sessMan, sessId, sessIdBuff |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CPEngSubSession::NewL |
|
100 // Two-phased constructor. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CPEngSubSession* CPEngSubSession::NewL( |
|
104 MPEngServer& aServer, |
|
105 const RPEngMessage& aMessage, |
|
106 TInt32 aSessionId ) |
|
107 { |
|
108 CPEngSubSession* self = NewLC( aServer, aMessage, aSessionId ); |
|
109 |
|
110 CleanupStack::Pop(); // self |
|
111 |
|
112 return self; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CPEngSubSession::NewLC |
|
117 // Two-phased constructor. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 CPEngSubSession* CPEngSubSession::NewLC( |
|
121 MPEngServer& aServer, |
|
122 const RPEngMessage& aMessage, |
|
123 TInt32 aSessionId ) |
|
124 { |
|
125 CPEngSubSession* self = new( ELeave ) CPEngSubSession( aSessionId ); |
|
126 |
|
127 CleanupClosePushL( *self ); |
|
128 self->ConstructL( aServer, aMessage ); |
|
129 return self; |
|
130 } |
|
131 |
|
132 // Destructor |
|
133 CPEngSubSession::~CPEngSubSession() |
|
134 { |
|
135 // decrease count of state machine |
|
136 if ( iSessionManager ) |
|
137 { |
|
138 iSessionManager->CancelAllSubSessionRquests( iSessionId, iHandle ); |
|
139 iSessionManager->Close( this ); // normal reference |
|
140 if ( iAppIdAttached ) |
|
141 { |
|
142 // remove appId reference |
|
143 iSessionManager->DetachAppId( *iAppId ); |
|
144 } |
|
145 } |
|
146 delete iAppId; |
|
147 delete iRequestResult; |
|
148 } |
|
149 |
|
150 // ============================================================================= |
|
151 // =========== New Functions of the MPengSubSession class ====================== |
|
152 // ============================================================================= |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CPEngSubSession::StoreRequestResponse() |
|
156 // Store request response for the sub-session |
|
157 // (other items were commented in a header). |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CPEngSubSession::StoreRequestResponse( |
|
161 HBufC8* aResponse ) |
|
162 { |
|
163 delete iRequestResult; |
|
164 iRequestResult = aResponse; |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CPEngSubSession::AppId() |
|
169 // Application Id of the sub-session |
|
170 // (other items were commented in a header). |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 TDesC& CPEngSubSession::AppId() |
|
174 { |
|
175 return *iAppId; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CPEngSubSession::HandleLogInL() |
|
180 // Handler successful application Id login |
|
181 // (other items were commented in a header). |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CPEngSubSession::HandleLogInL() |
|
185 { |
|
186 // remove normal reference by the app Id reference |
|
187 iSessionManager->AttachAppIdL( *iAppId ); |
|
188 iAppIdAttached = ETrue; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CPEngSubSession::HandleLogOut() |
|
193 // Handler successful application Id logOut |
|
194 // (other items were commented in a header). |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CPEngSubSession::HandleLogOut() |
|
198 { |
|
199 if ( iAppIdAttached ) |
|
200 { |
|
201 iSessionManager->DetachAppId( *iAppId ); |
|
202 iAppIdAttached = EFalse; |
|
203 } |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CPEngSubSession::DisconnectAppId() |
|
208 // Disconnect Application Id |
|
209 // (other items were commented in a header). |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CPEngSubSession::DisconnectAppId( |
|
213 const TDesC& aAppId ) |
|
214 { |
|
215 if ( iAppId->Compare( aAppId ) != KErrNone ) |
|
216 { |
|
217 // not our app Id |
|
218 return; |
|
219 } |
|
220 iAppIdAttached = EFalse; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CPEngSubSession::DisconnectAppId() |
|
225 // Handle CSP closing |
|
226 // (other items were commented in a header). |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CPEngSubSession::CSPSessionClosed() |
|
230 { |
|
231 iAppIdAttached = EFalse; |
|
232 } |
|
233 |
|
234 // ============================================================================= |
|
235 // =============== Functions of the main class ================================= |
|
236 // ============================================================================= |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CPEngSubSession::DispatchMessageL() |
|
240 // Dispatch message from the client |
|
241 // (other items were commented in a header). |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 TBool CPEngSubSession::DispatchMessageL( |
|
245 const RPEngMessage& aMessage, |
|
246 TInt aRequest ) |
|
247 { |
|
248 TBool completeMessage( ETrue ); |
|
249 switch ( aRequest ) |
|
250 { |
|
251 // Storage Related Requests |
|
252 case ESubSessCancelRequest: |
|
253 { |
|
254 iSessionManager->CancelAsynchronousRequest( aMessage, |
|
255 iSessionId, |
|
256 iHandle ); |
|
257 break; |
|
258 } |
|
259 |
|
260 // Holder client |
|
261 case ESubSessLogIn: |
|
262 { |
|
263 iSessionManager->HandleLogInRequestL( aMessage, |
|
264 *this, |
|
265 iSessionId, |
|
266 iHandle ); |
|
267 completeMessage = EFalse; |
|
268 break; |
|
269 } |
|
270 |
|
271 case ESubSessForceLogOut: |
|
272 { |
|
273 LeaveIfNotAttachedL( iAppIdAttached ); |
|
274 iSessionManager->HandleForceLogOutRequestL( aMessage, |
|
275 *this, |
|
276 iSessionId, |
|
277 iHandle ); |
|
278 completeMessage = EFalse; |
|
279 break; |
|
280 } |
|
281 |
|
282 case ESubSessAttachHolder: |
|
283 { |
|
284 LeaveIfAttachedL( iAppIdAttached ); |
|
285 iSessionManager->AttachAppIdL( *iAppId ); |
|
286 iAppIdAttached = ETrue; |
|
287 break; |
|
288 } |
|
289 |
|
290 case ESubSessAttachWithProcessName: |
|
291 { |
|
292 LeaveIfAttachedL( iAppIdAttached ); |
|
293 HBufC* processName = aMessage.ReadOneDescriptor16LC( |
|
294 KMessageSlot0 ); |
|
295 |
|
296 iSessionManager->ActivateProcessL( *iAppId, *processName ); |
|
297 iAppIdAttached = ETrue; |
|
298 CleanupStack::PopAndDestroy(); // processName |
|
299 break; |
|
300 } |
|
301 |
|
302 case ESubSessDetachHolder: |
|
303 { |
|
304 LeaveIfNotAttachedL( iAppIdAttached ); |
|
305 iSessionManager->HandleDetachAppIdL( aMessage, |
|
306 *this, |
|
307 iSessionId, |
|
308 iHandle ); |
|
309 completeMessage = EFalse; |
|
310 break; |
|
311 } |
|
312 |
|
313 case ESubSessLeaveAlive: |
|
314 { |
|
315 LeaveIfNotAttachedL( iAppIdAttached ); |
|
316 HBufC* processName = aMessage.ReadOneDescriptor16LC( |
|
317 KMessageSlot0 ); |
|
318 |
|
319 iSessionManager->ReserveProcessL( *iAppId, *processName ); |
|
320 iAppIdAttached = EFalse; |
|
321 CleanupStack::PopAndDestroy(); // processName |
|
322 break; |
|
323 } |
|
324 |
|
325 case ESubSessGetServiceTree: |
|
326 case ESubSessGetLogInData: |
|
327 { |
|
328 iSessionManager->HandleSynchronousRequestL( aMessage, |
|
329 iSessionId, |
|
330 iHandle ); |
|
331 break; |
|
332 } |
|
333 |
|
334 // Transfer client |
|
335 case ESubSessUpdateData: |
|
336 { |
|
337 iSessionManager->HandleAsynchronousRequestL( aMessage, |
|
338 *this, |
|
339 iSessionId, |
|
340 iHandle ); |
|
341 completeMessage = EFalse; |
|
342 break; |
|
343 } |
|
344 |
|
345 case ESubSessFetchUpdateRqstResult: |
|
346 { |
|
347 FetchRequestresultL( aMessage ); |
|
348 break; |
|
349 } |
|
350 |
|
351 default: |
|
352 { |
|
353 PanicClient( aMessage, EPECBadRequest ); |
|
354 break; |
|
355 } |
|
356 } |
|
357 // check if message can be completed |
|
358 completeMessage &= aMessage.MessageValid(); |
|
359 return completeMessage; |
|
360 } |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CPEngSubSession::SetSubSesionHandle() |
|
364 // Set Sub-session handle ID for the Session |
|
365 // (other items were commented in a header). |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 void CPEngSubSession::SetSubSesionHandle( |
|
369 TInt aHandle ) |
|
370 { |
|
371 iHandle = aHandle; |
|
372 } |
|
373 |
|
374 // ============================================================================= |
|
375 // =============== Private Functions from base class =========================== |
|
376 // ============================================================================= |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CPEngSubSession::PanicClient() |
|
380 // Panic client |
|
381 // (other items were commented in a header). |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 void CPEngSubSession::PanicClient( |
|
385 const RPEngMessage& aMessage, |
|
386 const TInt aPanic ) const |
|
387 { |
|
388 aMessage.Panic( KSessionName, aPanic ); |
|
389 } |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // CPEngSubSession::FetchRequestresultL() |
|
393 // Fetch result of last asynchronous request |
|
394 // (other items were commented in a header). |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void CPEngSubSession::FetchRequestresultL( |
|
398 const RPEngMessage& aMessage ) |
|
399 { |
|
400 if ( !iRequestResult ) |
|
401 { |
|
402 User::Leave( KErrNotFound ); |
|
403 } |
|
404 aMessage.WriteOneDescriptorL( KMessageSlot0, *iRequestResult ); |
|
405 delete iRequestResult; |
|
406 iRequestResult = NULL; |
|
407 } |
|
408 |
|
409 // End of File |