|
1 /* |
|
2 * Copyright (c) 2002-2009 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: This module contains the implementation of CNWNetworkRegistrationStatusMonitor |
|
15 * class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CNWNetworkRegistrationStatusMonitor.h" |
|
22 #include "CNWMessageHandler.h" |
|
23 #include "NetworkHandlingDomainPSKeys.h" |
|
24 #include "NWPanic.pan" |
|
25 #include "NWLogger.h" |
|
26 #include "CNWNetworkRegistrationStatusReceiver.h" |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ========================================= |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CNWNetworkRegistrationStatusMonitor::CNWNetworkRegistrationStatusMonitor |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ---------------------------------------------------------------------------- |
|
35 // |
|
36 CNWNetworkRegistrationStatusMonitor::CNWNetworkRegistrationStatusMonitor( |
|
37 CNWMessageHandler& aOwner, // ref. to owner class |
|
38 RMobilePhone& aPhone, // ref. to mobile phone |
|
39 TNWInfo& aNetworkInfo, // ref. to network info struct |
|
40 RMmCustomAPI& aCustomAPI ) //ref. to customAPI |
|
41 : CNWNetworkMonitorBase( aOwner, |
|
42 aPhone, |
|
43 aNetworkInfo, |
|
44 aCustomAPI ) |
|
45 { |
|
46 NWLOGSTRING( KNWOBJECT, |
|
47 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
48 CNWNetworkRegistrationStatusMonitor() Begin." ); |
|
49 |
|
50 CActiveScheduler::Add( this ); |
|
51 |
|
52 NWLOGSTRING( KNWOBJECT, |
|
53 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
54 CNWNetworkRegistrationStatusMonitor() End." ); |
|
55 } |
|
56 |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // CNWNetworkRegistrationStatusMonitor::ConstructL |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 void CNWNetworkRegistrationStatusMonitor::ConstructL() |
|
64 { |
|
65 NWLOGSTRING( KNWOBJECT, |
|
66 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
67 ConstructL() Begin." ); |
|
68 |
|
69 RProperty::TType type( RProperty::EInt ); |
|
70 TSecurityPolicy readPolicy( ECapability_None ); |
|
71 TSecurityPolicy writePolicy( ECapabilityWriteDeviceData ); |
|
72 TInt error = iProperty.Define( KPSUidNetworkInfo, |
|
73 KNWRegistrationStatus, |
|
74 type, |
|
75 readPolicy, |
|
76 writePolicy ); |
|
77 |
|
78 if ( (error != KErrNone) && (error != KErrAlreadyExists) ) |
|
79 { |
|
80 NWLOGSTRING2( KNWERROR, |
|
81 "NW: CNWNetworkRegistrationStatusMonitor::ConstructL(), Defining\ |
|
82 property failed, error code = %d .", error ); |
|
83 |
|
84 User::Leave(error); |
|
85 } |
|
86 // Create CNWNetworkRegistrationStatusReceiver object. |
|
87 iNetworkRegistrationReceiver = |
|
88 CNWNetworkRegistrationStatusReceiver::NewL( |
|
89 *this, iPhone, iRegistrationStatus ); |
|
90 |
|
91 NWLOGSTRING( KNWOBJECT, |
|
92 "NW: CNWNetworkRegistrationStatusMonitor::ConstructL(), Attach\ |
|
93 to P&S registration status property." ); |
|
94 |
|
95 // Attach to P&S registration status property |
|
96 User::LeaveIfError( iProperty.Attach( |
|
97 KPSUidNetworkInfo, KNWRegistrationStatus ) ); |
|
98 |
|
99 NWLOGSTRING( KNWOBJECT, |
|
100 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
101 ConstructL() End." ); |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------------------------------- |
|
105 // CNWNetworkRegistrationStatusMonitor::NewL |
|
106 // Two-phased constructor. |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C CNWNetworkRegistrationStatusMonitor* CNWNetworkRegistrationStatusMonitor::NewL( |
|
110 CNWMessageHandler& aOwner, |
|
111 RMobilePhone& aPhone, |
|
112 TNWInfo& aNetworkInfo, |
|
113 RMmCustomAPI& aCustomAPI ) |
|
114 { |
|
115 NWLOGSTRING( KNWOBJECT, |
|
116 "NW: CNWNetworkRegistrationStatusMonitor::NewL() Begin." ); |
|
117 |
|
118 CNWNetworkRegistrationStatusMonitor* self = |
|
119 new( ELeave ) CNWNetworkRegistrationStatusMonitor( aOwner, |
|
120 aPhone, |
|
121 aNetworkInfo, |
|
122 aCustomAPI ); |
|
123 |
|
124 CleanupStack::PushL( self ); |
|
125 self->ConstructL(); |
|
126 CleanupStack::Pop( self ); |
|
127 |
|
128 NWLOGSTRING( KNWOBJECT, |
|
129 "NW: CNWNetworkRegistrationStatusMonitor::NewL() End." ); |
|
130 |
|
131 return self; |
|
132 } |
|
133 |
|
134 |
|
135 // Destructor |
|
136 CNWNetworkRegistrationStatusMonitor::~CNWNetworkRegistrationStatusMonitor() |
|
137 { |
|
138 NWLOGSTRING( KNWOBJECT, |
|
139 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
140 ~CNWNetworkRegistrationStatusMonitor() Begin." ); |
|
141 |
|
142 Cancel(); |
|
143 delete iNetworkRegistrationReceiver; |
|
144 iProperty.Close(); |
|
145 |
|
146 NWLOGSTRING( KNWOBJECT, |
|
147 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
148 ~CNWNetworkRegistrationStatusMonitor() End." ); |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CNWNetworkRegistrationStatusMonitor::DoCancel |
|
153 // Cancels the pending async. command. |
|
154 // (other items were commented in a header). |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 void CNWNetworkRegistrationStatusMonitor::DoCancel() |
|
158 { |
|
159 NWLOGSTRING( KNWREQEND, |
|
160 "NW: CNWNetworkRegistrationStatusMonitor::DoCancel() Begin: Request\ |
|
161 CancelAsyncRequest( EMobilePhoneNotifyNetwork\ |
|
162 RegistrationStatusChange )" ); |
|
163 |
|
164 iPhone.CancelAsyncRequest( |
|
165 EMobilePhoneNotifyNetworkRegistrationStatusChange ); |
|
166 |
|
167 NWLOGSTRING( KNWREQEND, |
|
168 "NW: CNWNetworkRegistrationStatusMonitor::DoCancel() End" ); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CNWNetworkRegistrationStatusMonitor::RunL |
|
173 // Receives the completion of the pending async. command, |
|
174 // saves possible values from async. |
|
175 // Function call and sends notification to CNWSession object. |
|
176 // (other items were commented in a header). |
|
177 // ---------------------------------------------------------------------------- |
|
178 // |
|
179 void CNWNetworkRegistrationStatusMonitor::RunL() |
|
180 { |
|
181 NWLOGSTRING2( KNWREQEND, |
|
182 "NW: CNWNetworkRegistrationStatusMonitor::RunL, \ |
|
183 iStatus = %d", iStatus.Int() ); |
|
184 |
|
185 if ( iStatus == KErrNone ) |
|
186 { |
|
187 if ( !iRegistrationStatus == RMobilePhone::ERegistrationUnknown ) |
|
188 { |
|
189 IssueRequest(); |
|
190 // Cast MMETel types to NW types. |
|
191 UpdateNetworkInfo(); |
|
192 // Update P&S property with registration status |
|
193 UpdateRegistrationStatusProperty(); |
|
194 |
|
195 NWLOGSTRING3( KNWINT, |
|
196 "NW: CNWNetworkRegistrationStatusMonitor::RunL, \ |
|
197 iRegistrationStatus = %d (=ETel) %d (=NW)", |
|
198 iRegistrationStatus, |
|
199 iNWNetworkInfo.iRegistrationStatus ); |
|
200 } |
|
201 else |
|
202 { |
|
203 IssueRequest(); |
|
204 } |
|
205 } |
|
206 // Check if monitor can be restarted. |
|
207 else if ( iStatus != KErrCancel && iStatus != KErrServerTerminated ) |
|
208 { |
|
209 NWLOGSTRING2( KNWERROR, |
|
210 "NW: CNWNetworkRegistrationStatusMonitor::RunL, Unknown error \ |
|
211 situation, iStatus = %d", iStatus.Int() ); |
|
212 IssueRequest(); |
|
213 } |
|
214 else |
|
215 { |
|
216 NWLOGSTRING2( KNWERROR, |
|
217 "NW: CNWNetworkRegistrationStatusMonitor::RunL, Server \ |
|
218 Terminated or request Cancelled, iStatus = %d", iStatus.Int() ); |
|
219 } |
|
220 |
|
221 NWLOGSTRING( KNWREQEND, |
|
222 "NW: CNWNetworkRegistrationStatusMonitor::RunL() End" ); |
|
223 } |
|
224 |
|
225 |
|
226 // ---------------------------------------------------------------------------- |
|
227 // CNWNetworkRegistrationStatusMonitor::IssueRequest |
|
228 // Executes the async. NotifyNetworkRegistrationStatusChange function. |
|
229 // (other items were commented in a header). |
|
230 // ---------------------------------------------------------------------------- |
|
231 // |
|
232 void CNWNetworkRegistrationStatusMonitor::IssueRequest() |
|
233 { |
|
234 NWLOGSTRING( KNWOBJECT, |
|
235 "NW: CNWNetworkRegistrationStatusMonitor::IssueRequest() Begin" ); |
|
236 |
|
237 if ( !IsActive() ) |
|
238 { |
|
239 iPhone.NotifyNetworkRegistrationStatusChange( |
|
240 iStatus, iRegistrationStatus ); |
|
241 SetActive(); |
|
242 |
|
243 if ( !iIsInitialised ) |
|
244 { |
|
245 NWLOGSTRING( KNWREQIN, |
|
246 "NW:CNWNetworkRegistrationStatusMonitor::IssueRequest \ |
|
247 >RMobilePhone::GetNetworkRegistrationStatus" ); |
|
248 iNetworkRegistrationReceiver->IssueRequest(); |
|
249 iIsInitialised = ETrue; |
|
250 } |
|
251 |
|
252 NWLOGSTRING( KNWREQIN, |
|
253 "NW:CNWNetworkRegistrationStatusMonitor::IssueRequest \ |
|
254 > RMobilePhone::NotifyNetworkRegistrationStatusChange" ); |
|
255 |
|
256 } |
|
257 else |
|
258 { |
|
259 NWLOGSTRING( KNWERROR, |
|
260 "NW: CNWNetworkRegistrationStatusMonitor::IssueRequest: \ |
|
261 Already active" ); |
|
262 } |
|
263 |
|
264 NWLOGSTRING( KNWOBJECT, |
|
265 "NW: CNWNetworkRegistrationStatusMonitor::IssueRequest() End" ); |
|
266 } |
|
267 |
|
268 // ---------------------------------------------------------------------------- |
|
269 // CNWNetworkRegistrationStatusMonitor::UpdateNetworkInfo |
|
270 // Castthe MMETel type network info to TNWInfo type. |
|
271 // (other items were commented in a header). |
|
272 // ---------------------------------------------------------------------------- |
|
273 // |
|
274 void CNWNetworkRegistrationStatusMonitor::UpdateNetworkInfo() |
|
275 { |
|
276 NWLOGSTRING( KNWOBJECT, |
|
277 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
278 UpdateNetworkInfo() Begin" ); |
|
279 |
|
280 switch ( iRegistrationStatus ) |
|
281 { |
|
282 case RMobilePhone::ENotRegisteredNoService: |
|
283 { |
|
284 iNWNetworkInfo.iRegistrationStatus = ENWNotRegisteredNoService; |
|
285 break; |
|
286 } |
|
287 case RMobilePhone::ENotRegisteredEmergencyOnly: |
|
288 { |
|
289 iNWNetworkInfo.iRegistrationStatus = ENWNotRegisteredEmergencyOnly; |
|
290 break; |
|
291 } |
|
292 case RMobilePhone::ENotRegisteredSearching: |
|
293 { |
|
294 iNWNetworkInfo.iRegistrationStatus = ENWNotRegisteredSearching; |
|
295 break; |
|
296 } |
|
297 case RMobilePhone::ERegisteredOnHomeNetwork: |
|
298 { |
|
299 iNWNetworkInfo.iRegistrationStatus = ENWRegisteredOnHomeNetwork; |
|
300 break; |
|
301 } |
|
302 case RMobilePhone::ERegisteredBusy: |
|
303 { |
|
304 iNWNetworkInfo.iRegistrationStatus = ENWRegisteredBusy; |
|
305 break; |
|
306 } |
|
307 case RMobilePhone::ERegistrationDenied: |
|
308 { |
|
309 iNWNetworkInfo.iRegistrationStatus = ENWRegistrationDenied; |
|
310 break; |
|
311 } |
|
312 case RMobilePhone::ERegisteredRoaming: |
|
313 { |
|
314 iNWNetworkInfo.iRegistrationStatus = ENWRegisteredRoaming; |
|
315 break; |
|
316 } |
|
317 case RMobilePhone::ERegistrationUnknown: |
|
318 { |
|
319 iNWNetworkInfo.iRegistrationStatus = ENWRegistrationUnknown; |
|
320 break; |
|
321 } |
|
322 default: |
|
323 { |
|
324 iNWNetworkInfo.iRegistrationStatus = ENWRegistrationUnknown; |
|
325 __ASSERT_DEBUG( !iRegistrationStatus, Panic( ENWPanicInvalidStatus ) ); |
|
326 } |
|
327 } |
|
328 |
|
329 NWLOGSTRING( KNWOBJECT, |
|
330 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
331 UpdateNetworkInfo() End" ); |
|
332 } |
|
333 |
|
334 // ---------------------------------------------------------------------------- |
|
335 // CNWNetworkRegistrationStatusMonitor::UpdateRegistrationStatusProperty |
|
336 // Updates Publish & Subscribe with the current registration status. |
|
337 // ---------------------------------------------------------------------------- |
|
338 // |
|
339 void CNWNetworkRegistrationStatusMonitor::UpdateRegistrationStatusProperty() |
|
340 { |
|
341 // KNWNetworkRegistrationStatus values map directly with |
|
342 // TNWRegistrationStatus values |
|
343 NWLOGSTRING2( KNWREQOUT, |
|
344 "NW:CNWNetworkRegistrationStatusMonitor::\ |
|
345 UpdateRegistrationStatusProperty() Begin, rproperty::set \ |
|
346 < status: %d", iNWNetworkInfo.iRegistrationStatus ); |
|
347 |
|
348 TInt err = iProperty.Set( iNWNetworkInfo.iRegistrationStatus ); |
|
349 if ( err != KErrNone ) |
|
350 { |
|
351 NWLOGSTRING2( KNWERROR, |
|
352 "NW:CNWNetworkRegistrationStatusMonitor::\ |
|
353 UpdateRegistrationStatusProperty: rproperty::set error: %d", |
|
354 err ); |
|
355 } |
|
356 iOwner.SendMessage( |
|
357 MNWMessageObserver::ENWMessageNetworkRegistrationStatusChange ); |
|
358 |
|
359 NWLOGSTRING( KNWOBJECT, |
|
360 "NW: CNWNetworkRegistrationStatusMonitor::\ |
|
361 UpdateRegistrationStatusProperty() End" ); |
|
362 } |
|
363 |
|
364 |
|
365 // End of File |