|
1 /* |
|
2 * Copyright (c) 2004 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: Connection mode handler implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <E32Std.h> |
|
20 #include "CCnUiConnModeHandler.h" |
|
21 #include "CnUiPanics.h" |
|
22 |
|
23 |
|
24 |
|
25 // ================= GLOBAL FUNCTIONS ======================= |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CreateConnModeHandlerL() |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 GLREF_C MCnUiConnModeHandler* CreateConnModeHandlerL() |
|
31 { |
|
32 return CCnUiConnModeHandler::NewL(); |
|
33 } |
|
34 |
|
35 |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 // Two-phased constructor. |
|
39 CCnUiConnModeHandler* CCnUiConnModeHandler::NewL() |
|
40 { |
|
41 CCnUiConnModeHandler* self = new ( ELeave ) CCnUiConnModeHandler; |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 // Destructor |
|
50 CCnUiConnModeHandler::~CCnUiConnModeHandler() |
|
51 { |
|
52 //Cancel any outstanding request |
|
53 CancelRegisteringAsSSClient(); |
|
54 CancelConnectionModeNotify(); |
|
55 } |
|
56 |
|
57 |
|
58 // C++ default constructor can NOT contain any code, that |
|
59 // might leave. |
|
60 // |
|
61 CCnUiConnModeHandler::CCnUiConnModeHandler() |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 // Symbian OS default constructor can leave. |
|
67 void CCnUiConnModeHandler::ConstructL() |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CCnUiConnModeHandler::SendUserSelectionL() |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CCnUiConnModeHandler::SendUserSelectionL( TIMPSUserConnectionSelection aUserSelection, |
|
77 TIMPSConnectionClient aClient ) |
|
78 { |
|
79 TIMPSConnectionModeEvent event = EIMPSCMEUnknown; |
|
80 switch ( aUserSelection ) |
|
81 { |
|
82 case EUserLevelLogin: |
|
83 { |
|
84 event = EIMPSCMEUserLevelLogin; |
|
85 break; |
|
86 } |
|
87 |
|
88 case EUserLevelLogout: |
|
89 { |
|
90 event = EIMPSCMEUserLevelLogout; |
|
91 break; |
|
92 } |
|
93 |
|
94 case EUserLevelAAConnectionStart: |
|
95 { |
|
96 event = EIMPSCMEUserLevelAAConnectionStart; |
|
97 break; |
|
98 } |
|
99 |
|
100 default: |
|
101 { |
|
102 User::Leave( KErrArgument ); |
|
103 break; |
|
104 } |
|
105 } |
|
106 |
|
107 CCnUiGroupChannel* loginLogoutChannel = |
|
108 CCnUiGroupChannel::NewLC( aClient, |
|
109 ECnUiLoginLogoutEventChannel ); |
|
110 loginLogoutChannel->WriteL( event ); |
|
111 CleanupStack::PopAndDestroy( loginLogoutChannel ); //loginLogoutChannel |
|
112 } |
|
113 |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CCnUiConnModeHandler::RegisterAsSignificantSchedulingClientL() |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 TInt CCnUiConnModeHandler::RegisterAsSignificantSchedulingClientL( TIMPSConnectionClient aClient ) |
|
120 { |
|
121 if ( iSSReqistration ) |
|
122 { |
|
123 return KErrInUse; |
|
124 } |
|
125 |
|
126 iSSReqistration = CCnUiGroupChannel::NewL( aClient, |
|
127 ECnUiSSClientReqistrationChannel ); |
|
128 iSSReqistration->SignalL(); |
|
129 return KErrNone; |
|
130 } |
|
131 |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CCnUiConnModeHandler::CancelRegisteringAsSSClient() |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CCnUiConnModeHandler::CancelRegisteringAsSSClient() |
|
138 { |
|
139 if ( iSSReqistration ) |
|
140 { |
|
141 iSSReqistration->CancelSignal(); |
|
142 delete iSSReqistration; |
|
143 iSSReqistration = NULL; |
|
144 } |
|
145 } |
|
146 |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CCnUiConnModeHandler::ConnectionModeL() |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 TIMPSConnectionModeEvent CCnUiConnModeHandler::ConnectionModeL( |
|
153 TIMPSConnectionClient aClient, |
|
154 TIMPSConnectionModeEvent aModeEventCateqory ) |
|
155 { |
|
156 TInt cateqorizedEvent = EIMPSCMEUnknown; |
|
157 |
|
158 if ( aModeEventCateqory == EIMPSCMEUserLevelSelectionEventGroup ) |
|
159 { |
|
160 //client wants the login logout event value |
|
161 //retrieve value from channel & verify its range |
|
162 |
|
163 CCnUiGroupChannel* loginLogoutChannel = |
|
164 CCnUiGroupChannel::NewLC( aClient, |
|
165 ECnUiLoginLogoutEventChannel ); |
|
166 TInt lastEventValue = KErrNotFound; |
|
167 loginLogoutChannel->Read( lastEventValue ); |
|
168 CleanupStack::PopAndDestroy( loginLogoutChannel ); //loginLogoutChannel |
|
169 |
|
170 if ( LoginLogoutModeCategoryEvent( lastEventValue ) ) |
|
171 { |
|
172 cateqorizedEvent = lastEventValue; |
|
173 } |
|
174 } |
|
175 |
|
176 |
|
177 else if ( aModeEventCateqory == EIMPSCMESSClientEventGroup ) |
|
178 { |
|
179 //client wants the SS Client Start/Stop event |
|
180 //retrieve the client registration count channel |
|
181 |
|
182 CCnUiGroupChannel* reqistrationChannel = |
|
183 CCnUiGroupChannel::NewLC( aClient, |
|
184 ECnUiSSClientReqistrationChannel ); |
|
185 TInt clientReqistrationCount = KErrNotFound; |
|
186 reqistrationChannel->Read( clientReqistrationCount ); |
|
187 CleanupStack::PopAndDestroy( reqistrationChannel ); //reqistrationChannel |
|
188 |
|
189 if ( clientReqistrationCount == 0 ) //0 client currently registered ==> last stopped |
|
190 { |
|
191 cateqorizedEvent = EIMPSCMELastSSClientStop; |
|
192 } |
|
193 |
|
194 else if ( clientReqistrationCount > 0 ) //more than 0 currently registered clients |
|
195 { |
|
196 cateqorizedEvent = EIMPSCMEFirstSSClientStart; |
|
197 } |
|
198 } |
|
199 |
|
200 return static_cast<TIMPSConnectionModeEvent> ( cateqorizedEvent ); |
|
201 } |
|
202 |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CCnUiConnModeHandler::NotifyConnectionModeChangesL() |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CCnUiConnModeHandler::NotifyConnectionModeChangesL( MCnUiConnModeObserver* aObserver, |
|
209 TIMPSConnectionClient aClientToNotify ) |
|
210 { |
|
211 __ASSERT_ALWAYS( !iConnModeObserver, User::Leave( KErrInUse ) ); |
|
212 __ASSERT_ALWAYS( aObserver, User::Leave( KErrArgument ) ); |
|
213 |
|
214 TRAPD( err, DoStartNotifyL( aClientToNotify ) ); |
|
215 if ( err != KErrNone ) |
|
216 { |
|
217 CancelConnectionModeNotify(); |
|
218 User::Leave( err ); |
|
219 } |
|
220 |
|
221 //store observer information |
|
222 iConnModeObserver = aObserver; |
|
223 iObserverClient = aClientToNotify; |
|
224 } |
|
225 |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CCnUiConnModeHandler::CancelConnectionModeNotify() |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CCnUiConnModeHandler::CancelConnectionModeNotify() |
|
232 { |
|
233 delete iLoginLogoutEventChannelListener; |
|
234 delete iSSReqistrationChannelListener; |
|
235 |
|
236 iLoginLogoutEventChannelListener = NULL; |
|
237 iSSReqistrationChannelListener = NULL; |
|
238 |
|
239 iConnModeObserver = NULL; |
|
240 iSSClientCountPrev = KErrNotFound; |
|
241 } |
|
242 |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CCnUiConnModeHandler::HandleNotifyL() |
|
246 // from MCnUiGroupChannelListener |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CCnUiConnModeHandler::HandleChannelMsg( TInt aGroupId, |
|
250 TGCChannelID aChannelId, |
|
251 TInt aChannelMsg ) |
|
252 { |
|
253 if ( iObserverClient != aGroupId ) |
|
254 { |
|
255 return; |
|
256 } |
|
257 |
|
258 if ( aChannelId == ECnUiLoginLogoutEventChannel ) |
|
259 { |
|
260 //login/logout related event |
|
261 TIMPSConnectionModeEvent event = static_cast<TIMPSConnectionModeEvent>( aChannelMsg ); |
|
262 if ( LoginLogoutModeCategoryEvent( event ) ) |
|
263 { |
|
264 iConnModeObserver->HandleConnModeChange( iObserverClient, event ) ; |
|
265 } |
|
266 } |
|
267 |
|
268 else if ( aChannelId == ECnUiSSClientReqistrationChannel ) |
|
269 { |
|
270 //SSClient start/stop event - actually a signal count |
|
271 |
|
272 //If client count increased from zero to 1 ==> first client started |
|
273 if ( ( iSSClientCountPrev == 0 ) && ( aChannelMsg == 1 ) ) |
|
274 { |
|
275 iConnModeObserver->HandleConnModeChange( iObserverClient, EIMPSCMEFirstSSClientStart ); |
|
276 iSSClientCountPrev = aChannelMsg; |
|
277 } |
|
278 |
|
279 //If client count decreased to zero ==> last client stopped |
|
280 else if ( ( iSSClientCountPrev > 0 ) && ( aChannelMsg == 0 ) ) |
|
281 { |
|
282 iConnModeObserver->HandleConnModeChange( iObserverClient, EIMPSCMELastSSClientStop ); |
|
283 iSSClientCountPrev = aChannelMsg; |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CCnUiConnModeHandler::DoStartNotifyL() |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CCnUiConnModeHandler::DoStartNotifyL( TIMPSConnectionClient aClientToNotify ) |
|
294 { |
|
295 //start the channel notifier for login/logout related events |
|
296 iLoginLogoutEventChannelListener = CCnUiGroupChannel::NewL( aClientToNotify, |
|
297 ECnUiLoginLogoutEventChannel ); |
|
298 iLoginLogoutEventChannelListener->ListenL( this ); |
|
299 |
|
300 //start the channel notifier for client start/stops |
|
301 iSSReqistrationChannelListener = CCnUiGroupChannel::NewL( aClientToNotify, |
|
302 ECnUiSSClientReqistrationChannel ); |
|
303 iSSReqistrationChannelListener->ListenL( this ); |
|
304 |
|
305 |
|
306 TInt clientReqistrationCount = KErrNotFound; |
|
307 iSSReqistrationChannelListener->Read( clientReqistrationCount ); |
|
308 |
|
309 //if there is a positive registration count, use it. |
|
310 //Else default pre count to 0 |
|
311 if ( clientReqistrationCount >= 0 ) |
|
312 { |
|
313 iSSClientCountPrev = clientReqistrationCount; |
|
314 } |
|
315 else |
|
316 { |
|
317 iSSClientCountPrev = 0; |
|
318 } |
|
319 } |
|
320 |
|
321 |
|
322 |
|
323 // ----------------------------------------------------------------------------- |
|
324 // CCnUiConnModeHandler::LoginLogoutModeCategoryEvent() |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 TBool CCnUiConnModeHandler::LoginLogoutModeCategoryEvent( TInt aEvent ) |
|
328 { |
|
329 switch ( aEvent ) |
|
330 { |
|
331 //FLOW TROUGH |
|
332 case EIMPSCMEUserLevelLogout: |
|
333 case EIMPSCMEUserLevelLogin: |
|
334 case EIMPSCMEUserLevelAAConnectionStart: |
|
335 { |
|
336 //known events |
|
337 return ETrue; |
|
338 // no break needed because of return |
|
339 } |
|
340 |
|
341 default: |
|
342 { |
|
343 //unknown event |
|
344 break; |
|
345 } |
|
346 } |
|
347 |
|
348 return EFalse; |
|
349 } |
|
350 |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CCnUiConnModeHandler::SSClientStartStopEvent() |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 TBool CCnUiConnModeHandler::SSClientStartStopCategoryEvent( TInt aEvent ) |
|
357 { |
|
358 switch ( aEvent ) |
|
359 { |
|
360 //FLOW TROUGH |
|
361 case EIMPSCMEFirstSSClientStart: |
|
362 case EIMPSCMELastSSClientStop: |
|
363 { |
|
364 //known events |
|
365 return ETrue; |
|
366 // no break needed because of return |
|
367 } |
|
368 |
|
369 default: |
|
370 { |
|
371 //unknown event for this category |
|
372 break; |
|
373 } |
|
374 } |
|
375 |
|
376 return EFalse; |
|
377 } |
|
378 |
|
379 |
|
380 |
|
381 // End of File |
|
382 |