|
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: Server session class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ---------------------------------------------------------------------------- |
|
21 // INCLUDE FILES |
|
22 // ---------------------------------------------------------------------------- |
|
23 // |
|
24 #include "CNcnSession.h" |
|
25 #include "NcnCommsDefs.h" |
|
26 #include "CNcnUnpackDescrArray.h" |
|
27 #include "MNcnNotificationObserver.h" |
|
28 #include <MNcnNotification.h> |
|
29 |
|
30 // CONSTANTS |
|
31 /// Unnamed namespace for local definitions |
|
32 namespace { |
|
33 |
|
34 |
|
35 } // namespace |
|
36 |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CNcnSession::CNcnSession |
|
40 // |
|
41 // Constructor. |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CNcnSession::CNcnSession( MNcnNotificationObserver& aObserver ) |
|
45 : iObserver( aObserver ) |
|
46 { |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CNcnSession::ConstructL |
|
51 // |
|
52 // Symbian 2nd phase constructor. |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 void CNcnSession::ConstructL() |
|
56 { |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CNcnSession::~CNcnSession |
|
61 // |
|
62 // Destructor. |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CNcnSession::~CNcnSession() |
|
66 { |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CNcnSession::NewL |
|
71 // |
|
72 // Symbian two-phased construction. |
|
73 // ---------------------------------------------------------------------------- |
|
74 // |
|
75 CNcnSession* CNcnSession::NewL( MNcnNotificationObserver& aObserver ) |
|
76 { |
|
77 CNcnSession* self = |
|
78 new( ELeave ) CNcnSession( aObserver ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop(); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CNcnSession::ServiceL |
|
87 // |
|
88 // ServiceL method from CSession2. |
|
89 // ---------------------------------------------------------------------------- |
|
90 // |
|
91 void CNcnSession::ServiceL( const RMessage2& aMessage ) |
|
92 { |
|
93 // If this method leaves default ServiceError implementation will |
|
94 // complete the message using the leave value. |
|
95 |
|
96 // However, we have to reset our member variable in any case so |
|
97 // we can't rely on this functionality, hence the trap below |
|
98 |
|
99 if( IsRequestPending() ) |
|
100 { |
|
101 PanicClient( aMessage, EPanicNcnRequestActive ); |
|
102 } |
|
103 |
|
104 // set current request message |
|
105 SetRequestMessage( aMessage ); |
|
106 |
|
107 // handle service inside a trap so we can |
|
108 // reset our message member if service leaves |
|
109 TRAPD( error, HandleServiceL( aMessage ) ); |
|
110 |
|
111 // complete & reset current message |
|
112 CompleteRequestMessage( error ); |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------------------------------- |
|
116 // CNcnSession::HandleServiceL |
|
117 // ---------------------------------------------------------------------------- |
|
118 // |
|
119 void CNcnSession::HandleServiceL( const RMessage2& aMessage ) |
|
120 { |
|
121 switch ( aMessage.Function() ) |
|
122 { |
|
123 case ENewInternalMessages1: |
|
124 { |
|
125 ServiceNewInternalMessages1L( aMessage ); |
|
126 break; |
|
127 } |
|
128 case ENewInternalMessages2: |
|
129 { |
|
130 ServiceNewInternalMessages2L( aMessage ); |
|
131 break; |
|
132 } |
|
133 case EInternalMarkUnread1: |
|
134 { |
|
135 ServiceInternalMarkUnread1L( aMessage ); |
|
136 break; |
|
137 } |
|
138 case EInternalMarkUnread2: |
|
139 { |
|
140 ServiceInternalMarkUnread2L( aMessage ); |
|
141 break; |
|
142 } |
|
143 case EInternalCancelMarkUnread: |
|
144 { |
|
145 CancelRequest(); |
|
146 break; |
|
147 } |
|
148 case ENewMessages1: |
|
149 { |
|
150 ServiceNewMessages1L( aMessage ); |
|
151 break; |
|
152 } |
|
153 case EMarkUnread1: |
|
154 { |
|
155 ServiceMarkUnread1L( aMessage ); |
|
156 break; |
|
157 } |
|
158 default: |
|
159 { |
|
160 User::Leave( KErrNotSupported ); |
|
161 break; |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // CNcnSession::CompleteRequestMessage |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 void CNcnSession::CompleteRequestMessage( TInt aError ) |
|
171 { |
|
172 // if request message is set complete it with error code |
|
173 if( !iRequestMessage.IsNull() ) |
|
174 { |
|
175 iRequestMessage.Complete( aError ); |
|
176 } |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------- |
|
180 // CNcnSession::SetRequestMessage |
|
181 // ---------------------------------------------------------------------------- |
|
182 // |
|
183 void CNcnSession::SetRequestMessage( const RMessage2& aMessage ) |
|
184 { |
|
185 iRequestMessage = aMessage; |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // CNcnSession::IsRequestPending |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 TBool CNcnSession::IsRequestPending() const |
|
193 { |
|
194 return !iRequestMessage.IsNull(); |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // CNcnSession::CancelRequest |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 void CNcnSession::CancelRequest() |
|
202 { |
|
203 // complete pending request with KErrCancel |
|
204 CompleteRequestMessage( KErrCancel ); |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------------------------------- |
|
208 // CNcnSession::PanicClient |
|
209 // ---------------------------------------------------------------------------- |
|
210 // |
|
211 void CNcnSession::PanicClient( const RMessage2& aMessage, TNcnSessionPanic aPanic ) |
|
212 { |
|
213 _LIT( KPanicCategory, "ncnsession" ); |
|
214 aMessage.Panic( KPanicCategory, aPanic ); |
|
215 } |
|
216 |
|
217 void CNcnSession::ServiceNewInternalMessages1L( const RMessage2& aMessage ) |
|
218 { |
|
219 TNcnNotifMessageType type = |
|
220 static_cast <TNcnNotifMessageType> ( aMessage.Int0() ); |
|
221 iObserver.HandleNewInternalMessagesL( type ); |
|
222 } |
|
223 |
|
224 void CNcnSession::ServiceNewInternalMessages2L( const RMessage2& aMessage ) |
|
225 { |
|
226 TNcnNotifMessageType type = |
|
227 static_cast <TNcnNotifMessageType> ( aMessage.Int0() ); |
|
228 TMsvId mailBox = static_cast <TMsvId> ( aMessage.Int1() ); |
|
229 CNcnUnpackDescrArray* packedInfo = CNcnUnpackDescrArray::NewLC(); |
|
230 packedInfo->UnpackL( aMessage, 2 ); |
|
231 iObserver.HandleNewInternalMessagesL( type, mailBox, *packedInfo ); |
|
232 CleanupStack::PopAndDestroy( packedInfo ); |
|
233 } |
|
234 |
|
235 void CNcnSession::ServiceInternalMarkUnread1L( const RMessage2& aMessage ) |
|
236 { |
|
237 TNcnUnreadRequestType type = |
|
238 static_cast <TNcnUnreadRequestType> ( aMessage.Int0() ); |
|
239 iObserver.HandleInternalMarkUnreadL( type ); |
|
240 } |
|
241 |
|
242 void CNcnSession::ServiceInternalMarkUnread2L( const RMessage2& aMessage ) |
|
243 { |
|
244 TNcnUnreadRequestType type = |
|
245 static_cast <TNcnUnreadRequestType> ( aMessage.Int0() ); |
|
246 |
|
247 TMsvId mailBox = static_cast <TMsvId> ( aMessage.Int1() ); |
|
248 iObserver.HandleInternalMarkUnreadL( type, mailBox ); |
|
249 } |
|
250 |
|
251 void CNcnSession::ServiceNewMessages1L( const RMessage2& aMessage ) |
|
252 { |
|
253 TMsvId mailBox = static_cast <TMsvId> ( aMessage.Int0() ); |
|
254 MNcnNotification::TIndicationType indicationType = |
|
255 static_cast <MNcnNotification::TIndicationType> ( aMessage.Int1() ); |
|
256 CNcnUnpackDescrArray* packedInfo = CNcnUnpackDescrArray::NewLC(); |
|
257 packedInfo->UnpackL( aMessage, 2 ); |
|
258 iObserver.HandleNewMessagesL( mailBox, indicationType, *packedInfo ); |
|
259 CleanupStack::PopAndDestroy( packedInfo ); |
|
260 } |
|
261 |
|
262 void CNcnSession::ServiceMarkUnread1L( const RMessage2& aMessage ) |
|
263 { |
|
264 TMsvId mailBox = static_cast <TMsvId> ( aMessage.Int0() ); |
|
265 iObserver.HandleMarkUnreadL( mailBox ); |
|
266 } |
|
267 |
|
268 // End of file |