|
1 /* |
|
2 * Copyright (c) 2002-2007 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: CConnMonEventHandler is a hidden active object to receive |
|
15 * notifications on behalf of a client application. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <rconnmon.h> |
|
20 |
|
21 #include "ConnMonDef.h" |
|
22 #include "ConnMonCli.h" |
|
23 #include "log.h" |
|
24 |
|
25 // ============================ LOCAL FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // Panic |
|
29 // Panics the client in case of programming error. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 void Panic( TInt aPanic ) |
|
33 { |
|
34 _LIT( KPanicCategory, "ConnectionMonitor Client" ); |
|
35 User::Panic( KPanicCategory, aPanic ); |
|
36 } |
|
37 |
|
38 |
|
39 // ============================ MEMBER FUNCTIONS =============================== |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CConnMonEventHandler::CConnMonEventHandler |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CConnMonEventHandler::CConnMonEventHandler( |
|
46 MConnectionMonitorObserver* aObserver, |
|
47 RConnectionMonitor& aSession ) |
|
48 : |
|
49 CActive( EConnMonPriorityNormal ), |
|
50 iSession( aSession ), |
|
51 iObserver( aObserver ), |
|
52 iBuf( NULL, 0, 0 ) |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CConnMonEventHandler::Construct |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CConnMonEventHandler::Construct() |
|
61 { |
|
62 CActiveScheduler::Add( this ); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // Destructor |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CConnMonEventHandler::~CConnMonEventHandler() |
|
70 { |
|
71 Cancel(); |
|
72 delete iConnMonEvent; |
|
73 |
|
74 iObserver = NULL; |
|
75 } |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CConnMonEventHandler::ReceiveNotification |
|
80 // Request a new event from Connection Monitor server. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CConnMonEventHandler::ReceiveNotification() |
|
84 { |
|
85 if ( iPause ) |
|
86 { |
|
87 return; |
|
88 } |
|
89 |
|
90 if ( IsActive() ) |
|
91 { |
|
92 Cancel(); |
|
93 } |
|
94 |
|
95 // Must be passed as a descriptor |
|
96 iEventInfo.Reset(); |
|
97 iBuf.Set( reinterpret_cast<TUint8*>( &iEventInfo ), |
|
98 sizeof( TEventInfo ), |
|
99 sizeof( TEventInfo ) ); |
|
100 |
|
101 iSession.ReceiveEvent( iBuf, iExtraBuf, iStatus ); |
|
102 SetActive(); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CConnMonEventHandler::Pause |
|
107 // Pauses receiving events. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CConnMonEventHandler::Pause() |
|
111 { |
|
112 iPause = ETrue; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CConnMonEventHandler::Continue |
|
117 // Continues receiving events. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CConnMonEventHandler::Continue( MConnectionMonitorObserver* aObserver ) |
|
121 { |
|
122 iPause = EFalse; |
|
123 iObserver = aObserver; |
|
124 ReceiveNotification(); |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CConnMonEventHandler::ReceiveNotification |
|
129 // Receives the new event from Connection Monitor server and passes it to the |
|
130 // client interface. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CConnMonEventHandler::RunL() |
|
134 { |
|
135 if ( KErrServerBusy == iStatus.Int() ) |
|
136 { |
|
137 // Message slot was reserved |
|
138 // Try again |
|
139 LOGIT("Client [%d]: CConnMonEventHandler::RunL() KErrServerBusy, trying again") |
|
140 ReceiveNotification(); |
|
141 } |
|
142 else if ( KErrNone == iStatus.Int() ) |
|
143 { |
|
144 // A new event has arrived |
|
145 switch ( iEventInfo.iEventType ) |
|
146 { |
|
147 case EConnMonCreateConnection : |
|
148 iConnMonEvent = new (ELeave) CConnMonCreateConnection( |
|
149 iEventInfo.iConnectionId ); |
|
150 break; |
|
151 |
|
152 case EConnMonDeleteConnection : |
|
153 iConnMonEvent = new (ELeave) CConnMonDeleteConnection( |
|
154 iEventInfo.iConnectionId, |
|
155 iEventInfo.iData, |
|
156 iEventInfo.iData2, |
|
157 iEventInfo.iData3 ); |
|
158 break; |
|
159 |
|
160 case EConnMonDownlinkDataThreshold : |
|
161 iConnMonEvent = new (ELeave) CConnMonDownlinkDataThreshold( |
|
162 iEventInfo.iConnectionId, |
|
163 iEventInfo.iSubConnectionId, |
|
164 iEventInfo.iData ); |
|
165 break; |
|
166 |
|
167 case EConnMonUplinkDataThreshold : |
|
168 iConnMonEvent = new (ELeave) CConnMonUplinkDataThreshold( |
|
169 iEventInfo.iConnectionId, |
|
170 iEventInfo.iSubConnectionId, |
|
171 iEventInfo.iData ); |
|
172 break; |
|
173 |
|
174 case EConnMonNetworkStatusChange : |
|
175 iConnMonEvent = new (ELeave) CConnMonNetworkStatusChange( |
|
176 iEventInfo.iConnectionId, |
|
177 iEventInfo.iData ); |
|
178 break; |
|
179 |
|
180 case EConnMonConnectionStatusChange : |
|
181 iConnMonEvent = new (ELeave) CConnMonConnectionStatusChange( |
|
182 iEventInfo.iConnectionId, |
|
183 iEventInfo.iSubConnectionId, |
|
184 iEventInfo.iData ); |
|
185 break; |
|
186 |
|
187 case EConnMonConnectionActivityChange : |
|
188 iConnMonEvent = new (ELeave) CConnMonConnectionActivityChange( |
|
189 iEventInfo.iConnectionId, |
|
190 iEventInfo.iSubConnectionId, |
|
191 iEventInfo.iData ); |
|
192 break; |
|
193 |
|
194 case EConnMonNetworkRegistrationChange : |
|
195 iConnMonEvent = new (ELeave) CConnMonNetworkRegistrationChange( |
|
196 iEventInfo.iConnectionId, |
|
197 iEventInfo.iData ); |
|
198 break; |
|
199 |
|
200 case EConnMonBearerChange : |
|
201 iConnMonEvent = new (ELeave) CConnMonBearerChange( |
|
202 iEventInfo.iConnectionId, |
|
203 iEventInfo.iData ); |
|
204 break; |
|
205 |
|
206 case EConnMonSignalStrengthChange : |
|
207 iConnMonEvent = new (ELeave) CConnMonSignalStrengthChange( |
|
208 iEventInfo.iConnectionId, |
|
209 iEventInfo.iData ); |
|
210 break; |
|
211 |
|
212 case EConnMonBearerAvailabilityChange : |
|
213 iConnMonEvent = new (ELeave) CConnMonBearerAvailabilityChange( |
|
214 iEventInfo.iConnectionId, |
|
215 iEventInfo.iData ); |
|
216 break; |
|
217 |
|
218 case EConnMonIapAvailabilityChange : |
|
219 iConnMonEvent = new (ELeave) CConnMonIapAvailabilityChange( |
|
220 iEventInfo.iConnectionId, |
|
221 reinterpret_cast<const TConnMonIapInfo*>( iExtraBuf.Ptr() ) ); |
|
222 break; |
|
223 |
|
224 case EConnMonTransmitPowerChange : |
|
225 iConnMonEvent = new (ELeave) CConnMonTransmitPowerChange( |
|
226 iEventInfo.iConnectionId, |
|
227 iEventInfo.iData ); |
|
228 break; |
|
229 |
|
230 case EConnMonSNAPsAvailabilityChange : |
|
231 iConnMonEvent = new (ELeave) CConnMonSNAPsAvailabilityChange( |
|
232 iEventInfo.iConnectionId, iEventInfo.iData, |
|
233 reinterpret_cast< const TConnMonSNAPInfo* >( iExtraBuf.Ptr() ) ); |
|
234 break; |
|
235 |
|
236 case EConnMonNewWLANNetworkDetected : |
|
237 iConnMonEvent = new (ELeave) CConnMonNewWLANNetworkDetected( |
|
238 iEventInfo.iConnectionId ); |
|
239 break; |
|
240 |
|
241 case EConnMonOldWLANNetworkLost : |
|
242 iConnMonEvent = new (ELeave) CConnMonOldWLANNetworkLost( |
|
243 iEventInfo.iConnectionId ); |
|
244 break; |
|
245 |
|
246 case EConnMonPacketDataUnavailable : |
|
247 iConnMonEvent = new (ELeave) CConnMonPacketDataUnavailable( |
|
248 iEventInfo.iConnectionId ); |
|
249 break; |
|
250 |
|
251 case EConnMonPacketDataAvailable : |
|
252 iConnMonEvent = new (ELeave) CConnMonPacketDataAvailable( |
|
253 iEventInfo.iConnectionId ); |
|
254 break; |
|
255 |
|
256 case EConnMonBearerInfoChange : |
|
257 iConnMonEvent = new (ELeave) CConnMonBearerInfoChange( |
|
258 iEventInfo.iConnectionId, |
|
259 iEventInfo.iData ); |
|
260 break; |
|
261 |
|
262 case EConnMonBearerGroupChange : |
|
263 iConnMonEvent = new (ELeave) CConnMonBearerGroupChange( |
|
264 iEventInfo.iConnectionId, |
|
265 iEventInfo.iData2, |
|
266 iEventInfo.iData3, |
|
267 iEventInfo.iData ); |
|
268 break; |
|
269 |
|
270 default: |
|
271 if ( iEventInfo.iEventType >= EConnMonPluginEventBase ) |
|
272 { |
|
273 // Size of the data is in 'iEventInfo.iData2' |
|
274 iConnMonEvent = new (ELeave) CConnMonGenericEvent( |
|
275 iEventInfo.iEventType, |
|
276 iEventInfo.iConnectionId, |
|
277 reinterpret_cast<TAny*>( &( iEventInfo.iData ) ) ); |
|
278 } |
|
279 else |
|
280 { |
|
281 iConnMonEvent = new (ELeave) CConnMonEventBase( |
|
282 iEventInfo.iEventType, |
|
283 iEventInfo.iConnectionId ); |
|
284 } |
|
285 } |
|
286 |
|
287 // Deliver the event to client handler |
|
288 TRAPD( leaveCode, |
|
289 iObserver->EventL( reinterpret_cast<CConnMonEventBase&>( *iConnMonEvent ) ) ); |
|
290 |
|
291 delete iConnMonEvent; |
|
292 iConnMonEvent = NULL; |
|
293 |
|
294 LOGIT6("Client [%d]: GOT EVENT: type %d, id %d, data1 %d, data2 %d, data3 %d", |
|
295 &iSession, |
|
296 iEventInfo.iEventType, |
|
297 iEventInfo.iConnectionId, |
|
298 iEventInfo.iData, |
|
299 iEventInfo.iData2, |
|
300 iEventInfo.iData3 ) |
|
301 |
|
302 // Initiate the next receive |
|
303 ReceiveNotification(); |
|
304 |
|
305 // If leave occurs in EventL, log and ignore |
|
306 if ( leaveCode ) |
|
307 { |
|
308 LOGIT2("Client [%d]: CConnMonEventHandler::RunL() iObserver->EventL() call left <%d>", |
|
309 &iSession, leaveCode) |
|
310 } |
|
311 } |
|
312 else |
|
313 { |
|
314 LOGIT2("Client [%d]: CConnMonEventHandler::RunL() failed <%d>", &iSession, iStatus.Int()) |
|
315 } |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CConnMonEventHandler::DoCancel |
|
320 // Cancels the request from Connection Monitor server. |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CConnMonEventHandler::DoCancel() |
|
324 { |
|
325 if ( IsActive() ) |
|
326 { |
|
327 iSession.CancelReceiveEvent(); |
|
328 } |
|
329 } |
|
330 |
|
331 // End-of-file |