|
1 /* |
|
2 * Copyright (c) 2005 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: Admin Sub-session class of the Storage Server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include "CPEngAdminSubSession.h" |
|
23 #include "PEngStorageServerCommon.h" |
|
24 |
|
25 #include "CPEngStorageFolder.h" |
|
26 #include "CPEngSessionSlotState.h" |
|
27 #include "CPEngSessionSlotEvent.h" |
|
28 #include "PEngPresenceEngineConsts2.h" |
|
29 |
|
30 #include "MPEngStorageServer.h" |
|
31 #include "RPEngMessage.h" |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CPEngAdminSubSession::CPEngAdminSubSession |
|
38 // C++ default constructor can NOT contain any code, that might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPEngAdminSubSession::CPEngAdminSubSession( |
|
42 MPEngStorageServer& aServer, |
|
43 TInt32 aSessionId ) |
|
44 : iSessionId( aSessionId ), |
|
45 iServer( aServer ) |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CPEngAdminSubSession::ConstructL |
|
53 // Symbian 2nd phase constructor can leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CPEngAdminSubSession::ConstructL( |
|
57 const RPEngMessage& aMessage ) |
|
58 { |
|
59 iStorageFolder = iServer.StorageFolderL( aMessage ); |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPEngAdminSubSession::NewL |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CPEngAdminSubSession* CPEngAdminSubSession::NewL( |
|
69 MPEngStorageServer& aServer, |
|
70 const RPEngMessage& aMessage, |
|
71 TInt32 aSessionId ) |
|
72 { |
|
73 CPEngAdminSubSession* self = NewLC( aServer, aMessage, aSessionId ); |
|
74 |
|
75 CleanupStack::Pop(); // self |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CPEngAdminSubSession::NewLC |
|
83 // Two-phased constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CPEngAdminSubSession* CPEngAdminSubSession::NewLC( |
|
87 MPEngStorageServer& aServer, |
|
88 const RPEngMessage& aMessage, |
|
89 TInt32 aSessionId ) |
|
90 { |
|
91 CPEngAdminSubSession* self = new( ELeave ) CPEngAdminSubSession( |
|
92 aServer, |
|
93 aSessionId ); |
|
94 |
|
95 CleanupClosePushL( *self ); |
|
96 self->ConstructL( aMessage ); |
|
97 return self; |
|
98 } |
|
99 |
|
100 |
|
101 // Destructor |
|
102 CPEngAdminSubSession::~CPEngAdminSubSession() |
|
103 { |
|
104 // decrease count of the storage Folder |
|
105 TRAP_IGNORE( NotifySessionSlotCloseL() ); |
|
106 if ( iStorageFolder ) |
|
107 { |
|
108 // notify globally |
|
109 iStorageFolder->CancelSubSessionRequests( iSessionId, iHandle ); |
|
110 iStorageFolder->Close(); |
|
111 } |
|
112 } |
|
113 |
|
114 |
|
115 |
|
116 // ============================================================================= |
|
117 // =============== Functions from base class =================================== |
|
118 // ============================================================================= |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CPEngAdminSubSession::DispatchMessageL() |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 TBool CPEngAdminSubSession::DispatchMessageL( |
|
125 const RPEngMessage& aMessage, |
|
126 TInt aRequest ) |
|
127 { |
|
128 TBool completeMessage( ETrue ); |
|
129 switch ( aRequest ) |
|
130 { |
|
131 // ================ Admin sub client requests ======================== |
|
132 /*********************************************************************/ |
|
133 /* Admin sub session requests */ |
|
134 /*********************************************************************/ |
|
135 |
|
136 // Notify new global event |
|
137 case EAdminSubSessNotifyNewEvent: |
|
138 { |
|
139 NotifyGlobalEventL( aMessage ); |
|
140 break; |
|
141 } |
|
142 |
|
143 // Check if passed App Id is registered for passed Session Slot |
|
144 case EAdminSubSessCheckAppIdRegistration: |
|
145 { |
|
146 CheckAppIdRegistrationL( aMessage ); |
|
147 break; |
|
148 } |
|
149 |
|
150 case EAdminSubSessNotifyError: |
|
151 { |
|
152 NotifyError( aMessage ); |
|
153 break; |
|
154 } |
|
155 |
|
156 default: |
|
157 { |
|
158 PanicClient( aMessage, ESSBadRequest ); |
|
159 break; |
|
160 } |
|
161 } |
|
162 // check if message can be completed |
|
163 completeMessage &= aMessage.MessageValid(); |
|
164 return completeMessage; |
|
165 } |
|
166 |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CPEngAdminSubSession::SetSubSesionHandle() |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CPEngAdminSubSession::SetSubSesionHandle( |
|
173 TInt aHandle ) |
|
174 { |
|
175 iHandle = aHandle; |
|
176 } |
|
177 |
|
178 |
|
179 // ============================================================================= |
|
180 // =============== Private Functions from base class =========================== |
|
181 // ============================================================================= |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CPEngAdminSubSession::PanicClient() |
|
185 // Panic client |
|
186 // (other items were commented in a header). |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CPEngAdminSubSession::PanicClient( |
|
190 const RPEngMessage& aMessage, |
|
191 const TInt aPanic ) const |
|
192 { |
|
193 aMessage.Panic( KStorageSessionName, aPanic ); |
|
194 } |
|
195 |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CPEngAdminSubSession::NotifyGlobalEventL() |
|
199 // Notify about new global event |
|
200 // (other items were commented in a header). |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CPEngAdminSubSession::NotifyGlobalEventL( |
|
204 const RPEngMessage& aMessage ) |
|
205 { |
|
206 // Try to unpack the event |
|
207 CPEngSessionSlotEvent* newEvent = CPEngSessionSlotEvent::NewLC(); |
|
208 HBufC8* evetBuff = aMessage.ReadOneDescriptor8LC( KMessageSlot0 ); |
|
209 newEvent->UnpackEventL( *evetBuff ); |
|
210 // update state |
|
211 iStorageFolder->SessionSlotState().UpdateAndCommitStateL( *newEvent ); |
|
212 iStorageFolder->CommiteStateUpdate(); |
|
213 iServer.NotifyGlobalEvent( *evetBuff ); |
|
214 CleanupStack::PopAndDestroy( 2 ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CPEngAdminSubSession::CheckAppIdRegistrationL() |
|
219 // Notify Error to listeners |
|
220 // (other items were commented in a header). |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CPEngAdminSubSession::NotifyError( |
|
224 const RPEngMessage& aMessage ) |
|
225 { |
|
226 iServer.NotifyError( aMessage.Int0() ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CPEngAdminSubSession::CheckAppIdRegistrationL() |
|
231 // Check application registration |
|
232 // (other items were commented in a header). |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CPEngAdminSubSession::CheckAppIdRegistrationL( |
|
236 const RPEngMessage& aMessage ) |
|
237 { |
|
238 HBufC* appId = aMessage.ReadOneDescriptor16LC( KMessageSlot0 ); |
|
239 iStorageFolder->SessionSlotState().ApplicationRegisteredL( *appId ); |
|
240 CleanupStack::PopAndDestroy(); // appId |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CPEngAdminSubSession::NotifySessionSlotCloseL() |
|
245 // Notify Global Session slot close |
|
246 // (other items were commented in a header). |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CPEngAdminSubSession::NotifySessionSlotCloseL() |
|
250 { |
|
251 // Construct new Session slot event |
|
252 if ( !iStorageFolder ) |
|
253 { |
|
254 return; |
|
255 } |
|
256 iStorageFolder->SessionSlotState().SetSessionSlotStateClosed(); |
|
257 iStorageFolder->CommiteStateUpdate(); |
|
258 CPEngSessionSlotEvent* newEvent = CPEngSessionSlotEvent::NewLC(); |
|
259 newEvent->SetSessionSlotId( |
|
260 &( iStorageFolder->SessionSlotState().SessionSlotId() ), |
|
261 EFalse ); |
|
262 HBufC8* eventBuff = newEvent->PackEventLC(); |
|
263 iServer.NotifyGlobalEvent( *eventBuff ); |
|
264 CleanupStack::PopAndDestroy( 2 ); // eventBuff, newEvent |
|
265 } |
|
266 |
|
267 // End of File |