|
1 /* |
|
2 * Copyright (c) 2008 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: The Conmon Active object listening for the Network unavalibility |
|
15 events and launches the Auto-restart exe |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // USER INCLUDES |
|
21 #include "nsmldsnetmon.h" |
|
22 #include <nsmldebug.h> |
|
23 |
|
24 //Constants |
|
25 const TInt KNsmlDsAutoStartTimeoutKey = 4; // 0x0000004 defined in DS cenrep |
|
26 const TUid KRepositoryId = { 0x2000CF7E }; |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // StaticDoStopDSSession() |
|
30 // Global function to handle the timeout |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 |
|
34 static TInt StaticLaunchAutoRestartL(TAny *aPtr) |
|
35 { |
|
36 CNsmlDSNetmon* srv = (CNsmlDSNetmon*) aPtr; |
|
37 //Stop the DS Session |
|
38 return srv->LaunchAutoRestartL(); |
|
39 } |
|
40 |
|
41 // ============================== MEMBER FUNCTIONS ============================ |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CNsmlDSNetmon::NewL |
|
45 // Two Phase Construction |
|
46 // ---------------------------------------------------------------------------- |
|
47 CNsmlDSNetmon* CNsmlDSNetmon::NewL(CNSmlDSAgent& aDSAgent) |
|
48 { |
|
49 CNsmlDSNetmon* self = new (ELeave) CNsmlDSNetmon; |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aDSAgent); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // CNsmlDSNetmon::CNsmlDSNetmon |
|
58 // Constructor |
|
59 // ---------------------------------------------------------------------------- |
|
60 CNsmlDSNetmon::CNsmlDSNetmon() : CActive(CActive::EPriorityStandard) |
|
61 { |
|
62 CActiveScheduler::Add(this); |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // CNsmlDSNetmon::ConstructL |
|
67 // Second phase constructor |
|
68 // ---------------------------------------------------------------------------- |
|
69 void CNsmlDSNetmon::ConstructL(CNSmlDSAgent& aDSAgent) |
|
70 { |
|
71 DBG_FILE(_S8("CNsmlDSNetmon::ConstructL() begins")); |
|
72 |
|
73 // Initial state |
|
74 iState = ERegister; |
|
75 iDSAgent=&aDSAgent; |
|
76 IssueRequest(); |
|
77 |
|
78 //Auto_Restart |
|
79 iDSAgent->iPacketDataUnAvailable = EFalse; |
|
80 |
|
81 iRoamingStatus = 0; |
|
82 |
|
83 iAutoRestartTimer = NULL; |
|
84 |
|
85 DBG_FILE(_S8("CNsmlDSNetmon::ConstructL() ends")); |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // CNsmlDSNetmon::~CNsmlDSNetmon |
|
90 // Destructor |
|
91 // ---------------------------------------------------------------------------- |
|
92 CNsmlDSNetmon::~CNsmlDSNetmon() |
|
93 { |
|
94 DBG_FILE(_S8("CNsmlDSNetmon::~CNsmlDSNetmon() begins")); |
|
95 |
|
96 Cancel(); |
|
97 Complete(); |
|
98 |
|
99 if ( iAutoRestartTimer ) |
|
100 { |
|
101 iAutoRestartTimer->Cancel(); |
|
102 delete iAutoRestartTimer; |
|
103 iAutoRestartTimer = NULL; |
|
104 } |
|
105 |
|
106 DBG_FILE(_S8("CNsmlDSNetmon::~CNsmlDSNetmon() ends")); |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CNsmlDSNetmon::DoCancel |
|
111 // ---------------------------------------------------------------------------- |
|
112 void CNsmlDSNetmon::DoCancel() |
|
113 { |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // CNsmlDSNetmon::RunL |
|
118 // ---------------------------------------------------------------------------- |
|
119 void CNsmlDSNetmon::RunL() |
|
120 { |
|
121 switch ( iState ) |
|
122 { |
|
123 case ERegister: |
|
124 RegisterL(); |
|
125 break; |
|
126 |
|
127 case EComplete: |
|
128 Complete(); |
|
129 break; |
|
130 |
|
131 default: |
|
132 break; |
|
133 } |
|
134 } |
|
135 |
|
136 // ---------------------------------------------------------------------------- |
|
137 // CNsmlDSNetmon::RunError |
|
138 // ---------------------------------------------------------------------------- |
|
139 TInt CNsmlDSNetmon::RunError ( TInt aError ) |
|
140 { |
|
141 return aError; |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // CNsmlDSNetmon::RegisterL |
|
146 // ---------------------------------------------------------------------------- |
|
147 void CNsmlDSNetmon::RegisterL() |
|
148 { |
|
149 DBG_FILE(_S8("CNsmlDSNetmon::RegisterL() Begins")); |
|
150 |
|
151 // Register for events |
|
152 iConnectionMonitor.ConnectL(); |
|
153 iConnectionMonitor.NotifyEventL(*this); |
|
154 |
|
155 TInt err = iConnectionMonitor.SetUintAttribute( EBearerIdAll, |
|
156 0, |
|
157 KSignalStrengthThreshold, |
|
158 1 ); |
|
159 //Check whether the Users' Network is in Roaming |
|
160 iRoamingStatus = 0; |
|
161 TRequestStatus gprsstatus; |
|
162 |
|
163 iConnectionMonitor.GetIntAttribute(EBearerIdGPRS, |
|
164 0, |
|
165 KNetworkRegistration, |
|
166 iRoamingStatus, |
|
167 gprsstatus); |
|
168 |
|
169 User::WaitForRequest(gprsstatus); |
|
170 |
|
171 TRequestStatus wcdmastatus; |
|
172 if(iRoamingStatus == 0) |
|
173 { |
|
174 iConnectionMonitor.GetIntAttribute(EBearerIdWCDMA, |
|
175 0, |
|
176 KNetworkRegistration, |
|
177 iRoamingStatus, |
|
178 wcdmastatus); |
|
179 |
|
180 User::WaitForRequest(wcdmastatus); |
|
181 } |
|
182 DBG_FILE_CODE(iRoamingStatus, _S8("CNsmlDSNetmon::RegisterL(), The Roaming Status is:")); |
|
183 |
|
184 |
|
185 DBG_FILE(_S8("CNsmlDSNetmon::RegisterL() ends")); |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // CNsmlDSNetmon::Complete |
|
190 // ---------------------------------------------------------------------------- |
|
191 void CNsmlDSNetmon::Complete() |
|
192 { |
|
193 DBG_FILE(_S8("CNsmlDSNetmon::Complete() begins")); |
|
194 |
|
195 // Un-register for events |
|
196 iConnectionMonitor.CancelNotifications(); |
|
197 iConnectionMonitor.Close(); |
|
198 |
|
199 |
|
200 DBG_FILE(_S8("CNsmlDSNetmon::Complete() end")); |
|
201 } |
|
202 |
|
203 // ---------------------------------------------------------------------------- |
|
204 // CNsmlDSNetmon::EventL |
|
205 // ---------------------------------------------------------------------------- |
|
206 void CNsmlDSNetmon::EventL ( const CConnMonEventBase& aEvent ) |
|
207 { |
|
208 DBG_FILE(_S8("CNsmlDSNetmon::EventL() Begins")); |
|
209 |
|
210 DBG_FILE_CODE(aEvent.ConnectionId(), _S8("The Connection ID is:")); |
|
211 DBG_FILE_CODE(aEvent.EventType(), _S8("The Event Type is:")); |
|
212 |
|
213 const CConnMonNetworkStatusChange * eventNetworkStatus; |
|
214 eventNetworkStatus = ( const CConnMonNetworkStatusChange* ) &aEvent; |
|
215 |
|
216 const CConnMonConnectionStatusChange* eventConnectionStatus; |
|
217 eventConnectionStatus = ( const CConnMonConnectionStatusChange* ) &aEvent; |
|
218 |
|
219 DBG_FILE_CODE(eventNetworkStatus->NetworkStatus(), _S8("The Network Status is:")); |
|
220 DBG_FILE_CODE(eventConnectionStatus->ConnectionStatus(), _S8("The Connection Status is:")); |
|
221 |
|
222 //Fix for BPSS-7GBGV7 |
|
223 if( iDSAgent->IsSyncClientInitiated() && |
|
224 (iDSAgent->iNetmonAPBearerType == EApBearerTypeGPRS || |
|
225 iDSAgent->iNetmonAPBearerType == EApBearerTypeCDMA) ) |
|
226 |
|
227 { |
|
228 switch(aEvent.ConnectionId()) |
|
229 { |
|
230 case EBearerIdGPRS: |
|
231 case EBearerIdWCDMA: |
|
232 { |
|
233 switch(aEvent.EventType()) |
|
234 { |
|
235 case EConnMonNetworkStatusChange: |
|
236 { |
|
237 switch(eventNetworkStatus->NetworkStatus()) |
|
238 { |
|
239 //Network Down Scenario |
|
240 case EConnMonStatusNotAvailable: |
|
241 //General to Offline Scenario |
|
242 case EConnMonStatusUnattached: |
|
243 //Incoming Voice Call Scenario |
|
244 case EConnMonStatusSuspended: |
|
245 { |
|
246 //Launch NetMon |
|
247 StartTimerL(); |
|
248 } |
|
249 break; |
|
250 |
|
251 //Network Up Scenario |
|
252 case EConnMonStatusActive: |
|
253 { |
|
254 //Kill NetMon |
|
255 StopTimer(); |
|
256 } |
|
257 break; |
|
258 } |
|
259 |
|
260 } |
|
261 break; |
|
262 |
|
263 //Offline to General Scenario |
|
264 case EConnMonPacketDataAvailable: |
|
265 { |
|
266 //Kill Netmon |
|
267 StopTimer(); |
|
268 } |
|
269 break; |
|
270 } |
|
271 } |
|
272 break; |
|
273 |
|
274 default: |
|
275 DBG_FILE(_S8("CNsmlDSNetmon::EventL() In the Default Case")); |
|
276 if( eventConnectionStatus->ConnectionStatus() == KConnectionClosed ) |
|
277 { |
|
278 //Launch NetMon |
|
279 StartTimerL(); |
|
280 } |
|
281 break; |
|
282 |
|
283 } |
|
284 } |
|
285 |
|
286 DBG_FILE(_S8("CNsmlDSNetmon::EventL() Ends")); |
|
287 } |
|
288 |
|
289 // ---------------------------------------------------------------------------- |
|
290 // CNsmlDSNetmon::StartTimerL |
|
291 // ---------------------------------------------------------------------------- |
|
292 void CNsmlDSNetmon::StartTimerL() |
|
293 { |
|
294 if(!iDSAgent->iPacketDataUnAvailable) |
|
295 { |
|
296 DBG_FILE(_S8("CNsmlDSNetmon::EventL() Packet Data is not Available")); |
|
297 |
|
298 iDSAgent->iPacketDataUnAvailable = ETrue; |
|
299 |
|
300 TInt timeout = ReadTimeoutFromCenrepL(); |
|
301 |
|
302 if(timeout <= 0) |
|
303 { |
|
304 DBG_FILE(_S8("CNsmlDSNetmon::EventL() Timer Value is not Valid Launching the Netmon")); |
|
305 LaunchAutoRestartL(); |
|
306 } |
|
307 |
|
308 else |
|
309 { |
|
310 DBG_FILE(_S8("CNsmlDSNetmon::EventL() Starting the Timer")); |
|
311 |
|
312 iPacketDataUnAvailableTime.HomeTime(); |
|
313 |
|
314 if ( iAutoRestartTimer ) |
|
315 { |
|
316 iAutoRestartTimer->Cancel(); |
|
317 delete iAutoRestartTimer; |
|
318 iAutoRestartTimer = NULL; |
|
319 } |
|
320 iAutoRestartTimer = CPeriodic::NewL (EPriorityNormal) ; |
|
321 iAutoRestartTimer->Start ( |
|
322 TTimeIntervalMicroSeconds32( timeout ) |
|
323 , TTimeIntervalMicroSeconds32( timeout ) |
|
324 , TCallBack(StaticLaunchAutoRestartL,this) ) ; |
|
325 } |
|
326 |
|
327 } |
|
328 } |
|
329 // ---------------------------------------------------------------------------- |
|
330 // CNsmlDSNetmon::StopTimer |
|
331 // ---------------------------------------------------------------------------- |
|
332 void CNsmlDSNetmon::StopTimer() |
|
333 { |
|
334 if(iDSAgent->iPacketDataUnAvailable) |
|
335 { |
|
336 DBG_FILE(_S8("CNsmlDSNetmon::EventL() Packet Data is Available")); |
|
337 |
|
338 iDSAgent->iPacketDataUnAvailable = EFalse; |
|
339 |
|
340 iPacketDataAvailableTime.HomeTime(); |
|
341 TTimeIntervalSeconds duration; |
|
342 iPacketDataAvailableTime.SecondsFrom(iPacketDataUnAvailableTime,duration); |
|
343 |
|
344 if ( iAutoRestartTimer ) |
|
345 { |
|
346 iAutoRestartTimer->Cancel(); |
|
347 delete iAutoRestartTimer; |
|
348 iAutoRestartTimer = NULL; |
|
349 } |
|
350 //if(duration.Int() >= (5 * 60)) |
|
351 //{ |
|
352 //Invoke the NETMON exe and Kill the session |
|
353 // iDSAgent->LaunchAutoRestartL(KErrNone); |
|
354 //} |
|
355 } |
|
356 } |
|
357 |
|
358 // ---------------------------------------------------------------------------- |
|
359 // CNsmlDSNetmon::LaunchAutoRestart |
|
360 // ---------------------------------------------------------------------------- |
|
361 TBool CNsmlDSNetmon::LaunchAutoRestartL() |
|
362 { |
|
363 iDSAgent->LaunchAutoRestartL(KErrNone); |
|
364 return ETrue; |
|
365 } |
|
366 |
|
367 |
|
368 // ---------------------------------------------------------------------------- |
|
369 // CNsmlDSNetmon::IssueRequest |
|
370 // ---------------------------------------------------------------------------- |
|
371 void CNsmlDSNetmon::IssueRequest() |
|
372 { |
|
373 TRequestStatus* status = &iStatus; |
|
374 User::RequestComplete(status, KErrNone); |
|
375 SetActive(); |
|
376 } |
|
377 |
|
378 // ---------------------------------------------------------------------------- |
|
379 // CNsmlDSNetmon::IsRoaming |
|
380 // ---------------------------------------------------------------------------- |
|
381 TBool CNsmlDSNetmon::IsRoaming() |
|
382 { |
|
383 if(iRoamingStatus == ENetworkRegistrationRoaming) |
|
384 return ETrue; |
|
385 else |
|
386 return EFalse; |
|
387 } |
|
388 |
|
389 // ---------------------------------------------------------------------------- |
|
390 // CNsmlDSNetmon::ReadTimeoutFromCenrepL |
|
391 // ---------------------------------------------------------------------------- |
|
392 TInt CNsmlDSNetmon::ReadTimeoutFromCenrepL() |
|
393 { |
|
394 DBG_FILE(_S8("CNsmlDSNetmon::ReadTimeoutFromCenrepL() begins")); |
|
395 |
|
396 TInt timeoutInMinutes = 0; |
|
397 |
|
398 // Read the value from cenrep |
|
399 CRepository* repository = CRepository::NewLC(KRepositoryId); |
|
400 TInt err = repository->Get(KNsmlDsAutoStartTimeoutKey, timeoutInMinutes); |
|
401 User::LeaveIfError(err); |
|
402 CleanupStack::PopAndDestroy(repository); |
|
403 |
|
404 TInt timeout = timeoutInMinutes * 60 * 1000000; |
|
405 |
|
406 DBG_FILE(_S8("CNsmlDSNetmon::ReadTimeoutFromCenrepL() ends")); |
|
407 |
|
408 return timeout; |
|
409 } |
|
410 |
|
411 |
|
412 // End of file |
|
413 |