|
1 /* |
|
2 * Copyright (c) 2006-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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "irdebug.h" |
|
20 #include "irnwinfoobserver.h" |
|
21 #include "irui.h" |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // Function : CIRNwInfoObserver |
|
25 // Function is the default constructor, sets the CActive priority |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CIRNwInfoObserver::CIRNwInfoObserver():CActive (EPriorityLow), |
|
29 iCurrentNetworkInfoV1Pckg(iCurrentNetworkInfo), |
|
30 iHomeOperatorInfoPckg(iHomeOperatorInfo) |
|
31 { |
|
32 IRLOG_DEBUG( "CIRNwInfoObserver::CIRNwInfoObserver" ); |
|
33 //no implementation |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Function : ConstructL |
|
38 // Function does all the initializations |
|
39 // Two phase constructor |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 void CIRNwInfoObserver::ConstructL(CIRUi* aUi) |
|
43 { |
|
44 IRLOG_DEBUG( "CIRNwInfoObserver::ConstructL - Entering" ); |
|
45 iUi = aUi; |
|
46 iNwInfoObserver = CTelephony::NewL(); |
|
47 CActiveScheduler::Add(this); |
|
48 iCurrentNetwork = ETrue; |
|
49 iHomeNetworkType = EFalse; |
|
50 iFirstTime = ETrue; |
|
51 IRLOG_DEBUG( "CIRNwInfoObserver::ConstructL - Exiting." ); |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Function : NewL |
|
56 // Function returns an instance of CIRNwInfoObserver |
|
57 // Two phase constructor |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CIRNwInfoObserver* CIRNwInfoObserver::NewL(CIRUi* aUi) |
|
61 { |
|
62 IRLOG_DEBUG( "CIRNwInfoObserver::NewL - Entering" ); |
|
63 CIRNwInfoObserver* self = CIRNwInfoObserver::NewLC(aUi); |
|
64 CleanupStack::Pop(self); |
|
65 IRLOG_DEBUG( "CIRNwInfoObserver::NewL - Exiting." ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Function : NewLC |
|
71 // Function returns an instance of CIRNwInfoObserver |
|
72 // Two phase constructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CIRNwInfoObserver* CIRNwInfoObserver::NewLC(CIRUi* aUi) |
|
76 { |
|
77 IRLOG_DEBUG( "CIRNwInfoObserver::NewLC - Entering" ); |
|
78 CIRNwInfoObserver* self = new (ELeave) CIRNwInfoObserver; |
|
79 CleanupStack::PushL(self); |
|
80 self->ConstructL(aUi); |
|
81 IRLOG_DEBUG( "CIRNwInfoObserver::NewLC - Exiting." ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Function : ~CIRNwInfoObserver |
|
87 // Default destructor calls Cancel function which cancel the active request |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 |
|
91 CIRNwInfoObserver::~CIRNwInfoObserver() |
|
92 { |
|
93 IRLOG_DEBUG( "CIRNwInfoObserver::~CIRNwInfoObserver - Entering" ); |
|
94 Cancel(); |
|
95 delete iNwInfoObserver; |
|
96 IRLOG_DEBUG( "CIRNwInfoObserver::~CIRNwInfoObserver - Exiting" ); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // Function : IRStartNwMonitor |
|
101 // Function to start network monitoring |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 |
|
105 void CIRNwInfoObserver::IRStartNwMonitor() |
|
106 { |
|
107 IRLOG_DEBUG( "CIRNwInfoObserver::IRStartNwMonitor - Entering" ); |
|
108 if( !IsActive() ) |
|
109 { |
|
110 //get the network status for the first time |
|
111 iNwInfoObserver->GetCurrentNetworkInfo(iStatus, |
|
112 iCurrentNetworkInfoV1Pckg); |
|
113 SetActive(); |
|
114 } |
|
115 |
|
116 IRLOG_DEBUG( "CIRNwInfoObserver::IRStartNwMonitor - Exiting." ); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Function : IssueRequest |
|
121 // Issue request |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 |
|
125 void CIRNwInfoObserver::IssueRequest() |
|
126 { |
|
127 IRLOG_DEBUG( "CIRNwInfoObserver::IssueRequest - Entering" ); |
|
128 if( iCurrentNetwork ) |
|
129 { |
|
130 if( !IsActive() ) |
|
131 { |
|
132 //notify if current operator changes |
|
133 iNwInfoObserver->NotifyChange(iStatus, |
|
134 CTelephony::ECurrentNetworkInfoChange, |
|
135 iCurrentNetworkInfoV1Pckg); |
|
136 SetActive(); |
|
137 } |
|
138 } |
|
139 if( iHomeNetworkType ) |
|
140 { |
|
141 if( !IsActive() ) |
|
142 { |
|
143 //notify if home operator changes |
|
144 iNwInfoObserver->NotifyChange(iStatus, |
|
145 CTelephony::ENetworkRegistrationStatusChange, |
|
146 iHomeOperatorInfoPckg); |
|
147 SetActive(); |
|
148 } |
|
149 } |
|
150 IRLOG_DEBUG( "CIRNwInfoObserver::IssueRequest - Exiting." ); |
|
151 } |
|
152 |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // Function : DoCancel |
|
156 // Function stops getting the battery info if it is active |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CIRNwInfoObserver::DoCancel() |
|
160 { |
|
161 IRLOG_DEBUG( "CIRNwInfoObserver::DoCancel - Entering" ); |
|
162 if( IsActive() ) |
|
163 { |
|
164 //cancel the out standing requests if any |
|
165 iNwInfoObserver->CancelAsync(CTelephony::ECurrentNetworkInfoChangeCancel); |
|
166 iNwInfoObserver->CancelAsync(CTelephony::ENetworkRegistrationStatusChangeCancel); |
|
167 iNwInfoObserver->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel); |
|
168 iNwInfoObserver->CancelAsync(CTelephony::EGetNetworkRegistrationStatusCancel); |
|
169 } |
|
170 IRLOG_DEBUG( "CIRNwInfoObserver::DoCancel - Exiting" ); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // Function : RunL |
|
175 // RunL of the nwinfoobserver |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void CIRNwInfoObserver::RunL() |
|
179 { |
|
180 IRLOG_DEBUG( "CIRNwInfoObserver::RunL - Entering" ); |
|
181 if(KErrNone == iStatus.Int()) |
|
182 { |
|
183 if( iCurrentNetwork ) |
|
184 { |
|
185 //if the request was to find the current network |
|
186 //(changes) then the value is updated |
|
187 #ifdef _WINS_ |
|
188 iCurrentNetworkMCC.Zero(); |
|
189 iCurrentNetworkMNC.Zero(); |
|
190 iUi->UpdateCurrentNetwork |
|
191 (iCurrentNetworkMCC,iCurrentNetworkMNC); |
|
192 #else |
|
193 iCurrentNetworkMCC = iCurrentNetworkInfo.iCountryCode; |
|
194 iCurrentNetworkMNC = iCurrentNetworkInfo.iNetworkId; |
|
195 //updating mcc+mnc value |
|
196 iUi->UpdateCurrentNetwork |
|
197 (iCurrentNetworkMCC,iCurrentNetworkMNC); |
|
198 #endif |
|
199 |
|
200 iHomeNetworkType = ETrue; |
|
201 iCurrentNetwork = EFalse; |
|
202 if( iFirstTime ) |
|
203 { |
|
204 //if first time we have check the |
|
205 //current operator is home operator |
|
206 iNwInfoObserver->GetNetworkRegistrationStatus |
|
207 (iStatus,iHomeOperatorInfoPckg); |
|
208 SetActive(); |
|
209 iFirstTime = EFalse; |
|
210 } |
|
211 else |
|
212 { |
|
213 //else issue request is called for notifying |
|
214 //home operator change |
|
215 IssueRequest(); |
|
216 } |
|
217 } |
|
218 else if( iHomeNetworkType ) |
|
219 { |
|
220 //home operator (or the change in home operator is |
|
221 //notified. |
|
222 #ifdef _WINS_ |
|
223 iHomeNetworkMCC.Zero(); |
|
224 iHomeNetworkMNC.Zero(); |
|
225 iUi->UpdateHomeNetwork(iHomeNetworkMCC,iHomeNetworkMNC); |
|
226 #else |
|
227 //if operator is not same as home operator it is not updated |
|
228 if (CTelephony::ERegisteredOnHomeNetwork |
|
229 == iHomeOperatorInfo.iRegStatus) |
|
230 { |
|
231 //if registration status shows that user is registered in |
|
232 //home network and not in roaming status, the current operator |
|
233 //is updated |
|
234 iHomeNetworkMCC = iCurrentNetworkMCC; |
|
235 iHomeNetworkMNC = iCurrentNetworkMNC; |
|
236 iUi->UpdateHomeNetwork(iHomeNetworkMCC,iHomeNetworkMNC); |
|
237 } |
|
238 #endif |
|
239 //issue request to find the current network change |
|
240 iHomeNetworkType = EFalse; |
|
241 iCurrentNetwork = ETrue; |
|
242 IssueRequest(); |
|
243 } |
|
244 else |
|
245 { |
|
246 return; |
|
247 } |
|
248 } |
|
249 else |
|
250 { |
|
251 //if any error network is updated to zero |
|
252 iCurrentNetworkMCC.Zero(); |
|
253 iCurrentNetworkMNC.Zero(); |
|
254 iUi->UpdateCurrentNetwork(iCurrentNetworkMCC,iCurrentNetworkMNC); |
|
255 iHomeNetworkMCC.Zero(); |
|
256 iHomeNetworkMNC.Zero(); |
|
257 iUi->UpdateHomeNetwork(iHomeNetworkMCC,iHomeNetworkMNC); |
|
258 } |
|
259 IRLOG_DEBUG( "CIRNwInfoObserver::RunL - Exiting." ); |
|
260 return; |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // Function : RunError |
|
265 // Function which handles RunL error |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 TInt CIRNwInfoObserver::RunError(TInt aError) |
|
269 { |
|
270 IRLOG_DEBUG( "CIRNwInfoObserver::RunError" ); |
|
271 return aError; |
|
272 } |
|
273 |
|
274 |