|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Object to monitor the ETel network registration status and |
|
15 // broadcast it to the other components of the LBS sub-system. |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32property.h> |
|
21 #include <etelmm.h> |
|
22 #include <rsshared.h> |
|
23 #include "lbsdevloggermacros.h" |
|
24 #include "netregstatusmonitor.h" |
|
25 |
|
26 using namespace CommsDat; |
|
27 |
|
28 |
|
29 /** |
|
30 */ |
|
31 CNetworkRegistrationStatusMonitor::CNetworkRegistrationStatusMonitor( |
|
32 MNetworkRegistrationStatusObserver& aObserver) : |
|
33 CActive(EPriorityStandard), |
|
34 iPhoneNetRegStatus(RMobilePhone::ENotRegisteredNoService), |
|
35 iCurrentNetRegStatus(RLbsNetworkRegistrationStatus::ENotRegistered), |
|
36 iLastGoodNetRegStatus(RLbsNetworkRegistrationStatus::ENotRegistered), |
|
37 iInitialised(EFalse), |
|
38 iObserver(aObserver) |
|
39 { |
|
40 CActiveScheduler::Add(this); |
|
41 } |
|
42 |
|
43 /** |
|
44 */ |
|
45 CNetworkRegistrationStatusMonitor::~CNetworkRegistrationStatusMonitor() |
|
46 { |
|
47 Cancel(); |
|
48 //Make sure we have finished the initialisation state, before attempting to close these |
|
49 if(iInitialised) |
|
50 { |
|
51 iPhone.Close(); |
|
52 iTelServer.Close(); |
|
53 iLbsNetRegStatus.Close(); |
|
54 } |
|
55 } |
|
56 |
|
57 /** |
|
58 */ |
|
59 CNetworkRegistrationStatusMonitor* CNetworkRegistrationStatusMonitor::NewL(MNetworkRegistrationStatusObserver& aObserver) |
|
60 { |
|
61 CNetworkRegistrationStatusMonitor* self = new (ELeave) CNetworkRegistrationStatusMonitor(aObserver); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 return self; |
|
66 } |
|
67 |
|
68 /** |
|
69 */ |
|
70 void CNetworkRegistrationStatusMonitor::ConstructL() |
|
71 { |
|
72 iConfigurationProperty.Attach(KUidSystemCategory, RootServer::KUidC32StartPropertyKey.iUid); // needs the KEY |
|
73 TInt propertyValue = RootServer::EInitialising; // set to safe state |
|
74 TInt propertyResult = iConfigurationProperty.Get(propertyValue); |
|
75 |
|
76 if(propertyValue < RootServer::EConfigurationComplete) |
|
77 { |
|
78 //Attempt to connect to the ETel Server. This will start C32Start if it has not already been started by the startup routine. |
|
79 User::LeaveIfError(iTelServer.Connect()); |
|
80 iConfigurationProperty.Subscribe(iStatus); |
|
81 SetActive(); |
|
82 } |
|
83 else |
|
84 { |
|
85 //Property already present, continue usual initialisation |
|
86 SetupPhoneL(); |
|
87 iInitialised = ETrue; |
|
88 } |
|
89 } |
|
90 |
|
91 void CNetworkRegistrationStatusMonitor::SetupPhoneL() |
|
92 { |
|
93 // Connect to the Network Registration Status internal LBS bus |
|
94 iLbsNetRegStatus.OpenL(); |
|
95 |
|
96 TRAPD(err, InitialisePhoneL()); |
|
97 if (err == KErrNone) |
|
98 { |
|
99 // Connected to ETel successfully, now get the network |
|
100 // registration status. |
|
101 iPhone.GetNetworkRegistrationStatus(iStatus, iPhoneNetRegStatus); |
|
102 SetActive(); |
|
103 } |
|
104 else |
|
105 { |
|
106 // Couldn't connect to ETel; publish a default value. |
|
107 iLbsNetRegStatus.SetNetworkRegistrationStatus(RLbsNetworkRegistrationStatus::ENotRegistered); |
|
108 } |
|
109 } |
|
110 |
|
111 /** |
|
112 */ |
|
113 void CNetworkRegistrationStatusMonitor::RunL() |
|
114 { |
|
115 User::LeaveIfError(iStatus.Int()); |
|
116 |
|
117 //Check to see whether the initialisation has finished |
|
118 if(iInitialised == EFalse) |
|
119 { |
|
120 TInt propertyValue = RootServer::EInitialising; // set to safe state |
|
121 TInt propertyResult = iConfigurationProperty.Get(propertyValue); |
|
122 |
|
123 if(propertyValue != RootServer::EConfigurationComplete) |
|
124 { |
|
125 iConfigurationProperty.Subscribe(iStatus); |
|
126 SetActive(); |
|
127 } |
|
128 else |
|
129 { |
|
130 iConfigurationProperty.Cancel(); |
|
131 iInitialised = ETrue; |
|
132 |
|
133 SetupPhoneL(); |
|
134 } |
|
135 |
|
136 } |
|
137 else |
|
138 { |
|
139 LBSLOG2(ELogP5, "Current network registration status: %S", &NetRegStatusToDesC(iPhoneNetRegStatus)); |
|
140 |
|
141 // Re-subscribe to monitor any further changes. |
|
142 MonitorNetworkRegistrationStatus(); |
|
143 |
|
144 // Publish the new network registration status to LBS components. |
|
145 switch (iPhoneNetRegStatus) |
|
146 { |
|
147 case RMobilePhone::ERegisteredOnHomeNetwork: |
|
148 { |
|
149 iCurrentNetRegStatus = RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork; |
|
150 break; |
|
151 } |
|
152 case RMobilePhone::ERegisteredRoaming: |
|
153 { |
|
154 iCurrentNetRegStatus = RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork; |
|
155 break; |
|
156 } |
|
157 // All of the following should result in 'not registered' status |
|
158 case RMobilePhone::ENotRegisteredNoService: |
|
159 case RMobilePhone::ENotRegisteredEmergencyOnly: |
|
160 case RMobilePhone::ENotRegisteredSearching: |
|
161 case RMobilePhone::ERegisteredBusy: |
|
162 case RMobilePhone::ERegistrationDenied: |
|
163 case RMobilePhone::ERegistrationUnknown: |
|
164 default: |
|
165 { |
|
166 iCurrentNetRegStatus = RLbsNetworkRegistrationStatus::ENotRegistered; |
|
167 break; |
|
168 } |
|
169 } |
|
170 iLbsNetRegStatus.SetNetworkRegistrationStatus(iCurrentNetRegStatus); |
|
171 |
|
172 if (iCurrentNetRegStatus != RLbsNetworkRegistrationStatus::ENotRegistered) |
|
173 { |
|
174 iLastGoodNetRegStatus = iCurrentNetRegStatus; |
|
175 } |
|
176 |
|
177 LBSLOG2(ELogP5, "Network registration status broadcast to LBS: %S", &LbsNetRegStatusToDesC(iCurrentNetRegStatus)); |
|
178 LBSLOG2(ELogP5, "Last Good Network registration status: %S", &LbsNetRegStatusToDesC(iLastGoodNetRegStatus)); |
|
179 |
|
180 iObserver.OnNetworkRegistrationStatusChange(iCurrentNetRegStatus); |
|
181 } |
|
182 } |
|
183 |
|
184 /** |
|
185 */ |
|
186 void CNetworkRegistrationStatusMonitor::DoCancel() |
|
187 { |
|
188 //Check to see what stage we in are to find out what AO to cancel |
|
189 if(iInitialised) |
|
190 { |
|
191 //We have initialised, so cancel RPhone request |
|
192 iPhone.CancelAsyncRequest(EMobilePhoneNotifyNetworkRegistrationStatusChange); |
|
193 } |
|
194 else |
|
195 { |
|
196 //Still attempting to initialise, so cancel RootServer RProperty request |
|
197 iConfigurationProperty.Cancel(); |
|
198 } |
|
199 } |
|
200 |
|
201 /** |
|
202 */ |
|
203 TInt CNetworkRegistrationStatusMonitor::RunError(TInt /*aError*/) |
|
204 { |
|
205 //TODO: add in a panic here? |
|
206 return KErrNone; |
|
207 } |
|
208 |
|
209 /** |
|
210 */ |
|
211 void CNetworkRegistrationStatusMonitor::MonitorNetworkRegistrationStatus() |
|
212 { |
|
213 iPhone.NotifyNetworkRegistrationStatusChange(iStatus, iPhoneNetRegStatus); |
|
214 SetActive(); |
|
215 } |
|
216 |
|
217 /** |
|
218 */ |
|
219 RLbsNetworkRegistrationStatus::TLbsNetworkRegistrationStatus CNetworkRegistrationStatusMonitor::GetCurrentNetworkRegistrationStatus() |
|
220 { |
|
221 return iCurrentNetRegStatus; |
|
222 } |
|
223 |
|
224 /** |
|
225 */ |
|
226 RLbsNetworkRegistrationStatus::TLbsNetworkRegistrationStatus CNetworkRegistrationStatusMonitor::GetLastGoodNetworkRegistrationStatus() |
|
227 { |
|
228 return iLastGoodNetRegStatus; |
|
229 } |
|
230 |
|
231 /** Retrieves the name of the .tsy to use from CommDB/CommsDat |
|
232 |
|
233 The network gateway is hard-coded to use the .tsy file specified in |
|
234 the ModemBearerEntry which is specified (by index) by the |
|
235 KCDTIdModemPhoneServicesSMS setting in the global settings table. |
|
236 */ |
|
237 void CNetworkRegistrationStatusMonitor::GetCommDbTSYnameL(TDes& aTsyName) |
|
238 { |
|
239 CMDBSession* db = CMDBSession::NewLC(KCDLatestVersion); |
|
240 |
|
241 CMDBField<TUint32>* globalSettingField = new(ELeave) CMDBField<TUint32>(KCDTIdModemPhoneServicesSMS); |
|
242 CleanupStack::PushL(globalSettingField); |
|
243 |
|
244 globalSettingField->SetRecordId(1); |
|
245 globalSettingField->LoadL(*db); |
|
246 TUint32 modemId = *globalSettingField; |
|
247 |
|
248 CMDBField<TDesC>* tsyField = new(ELeave) CMDBField<TDesC>(KCDTIdTsyName); |
|
249 CleanupStack::PushL(tsyField); |
|
250 |
|
251 tsyField->SetRecordId(modemId); |
|
252 tsyField->LoadL(*db); |
|
253 |
|
254 aTsyName = *tsyField; |
|
255 CleanupStack::PopAndDestroy(3, db); // db, tsyField & globalSettingField |
|
256 } |
|
257 |
|
258 /** Finds and opens the phone to be used to monitor the network registration status. |
|
259 |
|
260 @leave Leaves if underlying ETEL.DLL returns error, |
|
261 or if we can't find a suitable Phone or can't open it. |
|
262 */ |
|
263 void CNetworkRegistrationStatusMonitor::InitialisePhoneL() |
|
264 { |
|
265 TInt err(KErrNone); |
|
266 |
|
267 User::LeaveIfError(iTelServer.Connect()); |
|
268 |
|
269 // Read the name of the .tsy to load from CommDB |
|
270 TBuf<KCommsDbSvrMaxFieldLength> tsyName; |
|
271 GetCommDbTSYnameL(tsyName); |
|
272 |
|
273 // Load .tsy into ETel |
|
274 User::LeaveIfError(iTelServer.LoadPhoneModule(tsyName)); |
|
275 |
|
276 // Find available phones; check that the one we requested |
|
277 // to be loaded is there. |
|
278 TInt phoneIndex(0); |
|
279 User::LeaveIfError(iTelServer.EnumeratePhones(phoneIndex)); |
|
280 while(phoneIndex-->0) |
|
281 { |
|
282 TName searchTsyName; |
|
283 // Check whether this phone belongs to loaded TSY |
|
284 if ((iTelServer.GetTsyName(phoneIndex, searchTsyName) == KErrNone) |
|
285 && (searchTsyName.CompareF(tsyName) == KErrNone)) |
|
286 break; |
|
287 } |
|
288 |
|
289 // Open a phone to be used for monitoring the network registration status. |
|
290 RTelServer::TPhoneInfo phoneInfo; |
|
291 User::LeaveIfError(iTelServer.GetPhoneInfo(phoneIndex, phoneInfo)); |
|
292 User::LeaveIfError(iPhone.Open(iTelServer, phoneInfo.iName)); |
|
293 |
|
294 // Check that the phone is ready to be used. |
|
295 RPhone::TStatus status; |
|
296 User::LeaveIfError(iPhone.GetStatus(status)); |
|
297 if(status.iModemDetected != RPhone::EDetectedPresent) |
|
298 { |
|
299 err = iPhone.Initialise(); |
|
300 if(err != KErrNone) |
|
301 { |
|
302 iPhone.Close(); |
|
303 User::Leave(err); |
|
304 } |
|
305 } |
|
306 |
|
307 // Check that we can access the info we want |
|
308 TUint32 networkCaps; |
|
309 User::LeaveIfError(iPhone.GetNetworkCaps(networkCaps)); |
|
310 if (!(networkCaps & RMobilePhone::KCapsGetRegistrationStatus |
|
311 && networkCaps & RMobilePhone::KCapsNotifyRegistrationStatus)) |
|
312 { |
|
313 err = KErrNotSupported; |
|
314 } |
|
315 |
|
316 User::LeaveIfError(err); |
|
317 } |
|
318 |
|
319 #ifdef ENABLE_LBS_DEV_LOGGER |
|
320 /** Logging-only function to return a meaningful description of an enum value. |
|
321 */ |
|
322 const TDesC& CNetworkRegistrationStatusMonitor::NetRegStatusToDesC(RMobilePhone::TMobilePhoneRegistrationStatus iRegStatus) |
|
323 { |
|
324 switch (iRegStatus) |
|
325 { |
|
326 case RMobilePhone::ERegistrationUnknown: |
|
327 { |
|
328 _LIT(KRegistrationUnknown, "ERegistrationUnknown"); |
|
329 return KRegistrationUnknown(); |
|
330 } |
|
331 case RMobilePhone::ENotRegisteredNoService: |
|
332 { |
|
333 _LIT(KNotRegisteredNoService, "ENotRegisteredNoService"); |
|
334 return KNotRegisteredNoService(); |
|
335 } |
|
336 case RMobilePhone::ENotRegisteredEmergencyOnly: |
|
337 { |
|
338 _LIT(KNotRegisteredEmergencyOnly, "ENotRegisteredEmergencyOnly"); |
|
339 return KNotRegisteredEmergencyOnly(); |
|
340 } |
|
341 case RMobilePhone::ENotRegisteredSearching: |
|
342 { |
|
343 _LIT(KNotRegisteredSearching, "ENotRegisteredSearching"); |
|
344 return KNotRegisteredSearching(); |
|
345 } |
|
346 case RMobilePhone::ERegisteredBusy: |
|
347 { |
|
348 _LIT(KRegisteredBusy, "ERegisteredBusy"); |
|
349 return KRegisteredBusy(); |
|
350 } |
|
351 case RMobilePhone::ERegisteredOnHomeNetwork: |
|
352 { |
|
353 _LIT(KRegisteredOnHomeNetwork, "ERegisteredOnHomeNetwork"); |
|
354 return KRegisteredOnHomeNetwork(); |
|
355 } |
|
356 case RMobilePhone::ERegistrationDenied: |
|
357 { |
|
358 _LIT(KRegistrationDenied, "ERegistrationDenied"); |
|
359 return KRegistrationDenied(); |
|
360 } |
|
361 case RMobilePhone::ERegisteredRoaming: |
|
362 { |
|
363 _LIT(KRegisteredRoaming, "ERegisteredRoaming"); |
|
364 return KRegisteredRoaming(); |
|
365 } |
|
366 } |
|
367 |
|
368 _LIT(KUnrecognisedRegistrationStatus, "UnrecognisedRegistrationStatus"); |
|
369 return KUnrecognisedRegistrationStatus(); |
|
370 } |
|
371 |
|
372 /** Logging-only function to return a meaningful description of an enum value. |
|
373 */ |
|
374 const TDesC& CNetworkRegistrationStatusMonitor::LbsNetRegStatusToDesC(RLbsNetworkRegistrationStatus::TLbsNetworkRegistrationStatus iRegStatus) |
|
375 { |
|
376 switch (iRegStatus) |
|
377 { |
|
378 case RLbsNetworkRegistrationStatus::ENetworkRegistrationUnknown: |
|
379 { |
|
380 _LIT(KNetworkRegistrationUnknown, "ENetworkRegistrationUnknown"); |
|
381 return KNetworkRegistrationUnknown(); |
|
382 } |
|
383 case RLbsNetworkRegistrationStatus::ENotRegistered: |
|
384 { |
|
385 _LIT(KNotRegistered, "ENotRegistered"); |
|
386 return KNotRegistered(); |
|
387 } |
|
388 case RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork: |
|
389 { |
|
390 _LIT(KRegisteredHomeNetwork, "ERegisteredHomeNetwork"); |
|
391 return KRegisteredHomeNetwork(); |
|
392 } |
|
393 case RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork: |
|
394 { |
|
395 _LIT(KRegisteredRoamingNetwork, "ERegisteredRoamingNetwork"); |
|
396 return KRegisteredRoamingNetwork(); |
|
397 } |
|
398 } |
|
399 |
|
400 _LIT(KUnrecognisedRegistrationStatus, "UnrecognisedRegistrationStatus"); |
|
401 return KUnrecognisedRegistrationStatus(); |
|
402 } |
|
403 #endif // ENABLE_LBS_DEV_LOGGER |
|
404 |