|
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: Cell Id implementaion in SUPL PSY. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <centralrepository.h> |
|
22 #include <commdb.h> |
|
23 |
|
24 #include "suplpsylogging.h" |
|
25 #include "suplpsycellidhandler.h" |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS OF CSuplPsyCellIdHandler =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CSuplPsyCellIdHandler::CSuplPsyCellIdHandler,constuctor |
|
32 // (other items were commented in a header). |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 |
|
36 CSuplPsyCellIdHandler::CSuplPsyCellIdHandler( MBasicCellIDListener& aObserver ) |
|
37 : CActive( EPriorityStandard ), |
|
38 iNetworkInfoPkg( iNetworkInfo ), |
|
39 iObserver( aObserver ), |
|
40 iNetworkType( EUnknown ), |
|
41 iCellIdInfo( NULL ) |
|
42 { |
|
43 CActiveScheduler::Add( this ); |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CSuplPsyCellIdHandler::ConstructL,two phase constuctor |
|
48 // (other items were commented in a header). |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CSuplPsyCellIdHandler::ConstructL() |
|
52 { |
|
53 TRACESTRING( "CSuplPsyCellIdHandler::ConstructL start" ) |
|
54 iIsInitilized = EFalse; |
|
55 User::LeaveIfError( ConnectToETelL() ); |
|
56 iIsInitilized = ETrue; |
|
57 TRACESTRING( "CSuplPsyCellIdHandler::ConstructL end" ) |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CSuplPsyCellIdHandler::NewL,two phase constuctor |
|
62 // (other items were commented in a header). |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CSuplPsyCellIdHandler* CSuplPsyCellIdHandler::NewL( MBasicCellIDListener& aObserver ) |
|
66 { |
|
67 CSuplPsyCellIdHandler* self = new( ELeave ) CSuplPsyCellIdHandler( aObserver ); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CSuplPsyCellIdHandler::DoCancel |
|
77 // (other items were commented in a header). |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CSuplPsyCellIdHandler::DoCancel() |
|
81 { |
|
82 TRACESTRING( "CSuplPsyCellIdHandler::DoCancel start" ) |
|
83 iPhone.CancelAsyncRequest( EMobilePhoneGetCurrentNetwork ); |
|
84 TRACESTRING( "CSuplPsyCellIdHandler::DoCancel end" ) |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler,Destructor |
|
89 // (other items were commented in a header). |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler() |
|
93 { |
|
94 TRACESTRING( "CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler start" ) |
|
95 Cancel(); |
|
96 iPhone.Close(); |
|
97 if ( iIsInitilized ) |
|
98 { |
|
99 iTelServer.UnloadPhoneModule(iTsyName); |
|
100 } |
|
101 |
|
102 iTelServer.Close(); |
|
103 |
|
104 TRACESTRING( "CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler end" ) |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CSuplPsyCellIdHandler::GetCellID,For retriving the cell id information |
|
109 // (other items were commented in a header). |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CSuplPsyCellIdHandler::GetCellID( TCellIdInfo& aCellIdInfo ) |
|
113 { |
|
114 TRACESTRING("CSuplPsyCellIdHandler::GetCellID start") |
|
115 if( IsActive() ) |
|
116 { |
|
117 return; |
|
118 } |
|
119 iCellIdInfo = &aCellIdInfo; |
|
120 iPhone.GetCurrentNetwork( iStatus, iNetworkInfoPkg, iLocationInfo ); |
|
121 SetActive(); |
|
122 TRACESTRING("CSuplPsyCellIdHandler::GetCellID end") |
|
123 } |
|
124 |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CSuplPsyCellIdHandler::NetworkType |
|
128 // (other items were commented in a header). |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 CSuplPsyCellIdHandler::TNetworkTypeInfo CSuplPsyCellIdHandler::NetworkType() const |
|
132 { |
|
133 return iNetworkType; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CSuplPsyCellIdHandler::RunL |
|
138 // (other items were commented in a header). |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CSuplPsyCellIdHandler::RunL() |
|
142 { |
|
143 TRACESTRING("CSuplPsyCellIdHandler::RunL start") |
|
144 |
|
145 TInt err = iStatus.Int(); |
|
146 TRACESTRING2("Request Completed with Error Code: %d",err ) |
|
147 |
|
148 if ( err == KErrNone ) |
|
149 { |
|
150 HandleCellInfoL(); |
|
151 } |
|
152 else |
|
153 { |
|
154 iObserver.BasicCellIDRequestCompletedL( KErrNotFound ); |
|
155 } |
|
156 TRACESTRING("CSuplPsyCellIdHandler::RunL end") |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CSuplPsyCellIdHandler::HandleCellInfoL(), |
|
161 // (other items were commented in a header). |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CSuplPsyCellIdHandler::HandleCellInfoL() |
|
165 { |
|
166 TRACESTRING("CSuplPsyCellIdHandler::HandleCellInfoL start") |
|
167 |
|
168 |
|
169 switch (iNetworkInfo.iMode) |
|
170 { |
|
171 case RMobilePhone::ENetworkModeGsm: |
|
172 { |
|
173 TRACESTRING("GSM Network") |
|
174 //For GSM Cell Information |
|
175 iNetworkType = EGSM; |
|
176 |
|
177 TInt MCC=0; |
|
178 TInt64 MNC=0; |
|
179 TLex LexMCC(iNetworkInfo.iCountryCode); |
|
180 TLex LexMNC(iNetworkInfo.iNetworkId); |
|
181 |
|
182 LexMCC.Val(MCC); |
|
183 LexMNC.Val(MNC); |
|
184 TUint LAC = iLocationInfo.iLocationAreaCode; |
|
185 TUint CellId = iLocationInfo.iCellId; |
|
186 |
|
187 iCellIdInfo->iMCC = MCC; |
|
188 iCellIdInfo->iMNC = MNC; |
|
189 iCellIdInfo->iCid = CellId; |
|
190 iCellIdInfo->iLac = LAC; |
|
191 |
|
192 TRACESTRING("Observers notified for GSM CellId information") |
|
193 iObserver.BasicCellIDRequestCompletedL(KErrNone); |
|
194 break; |
|
195 } |
|
196 case RMobilePhone::ENetworkModeWcdma: |
|
197 { |
|
198 TRACESTRING("WCDMA Network") |
|
199 //For WCDMA Cell Information |
|
200 iNetworkType = EWCDMA; |
|
201 |
|
202 TInt MCC=0; |
|
203 TInt64 MNC=0; |
|
204 TLex LexMCC(iNetworkInfo.iCountryCode); |
|
205 TLex LexMNC(iNetworkInfo.iNetworkId); |
|
206 LexMCC.Val(MCC); |
|
207 LexMNC.Val(MNC); |
|
208 TUint CellId = iLocationInfo.iCellId; |
|
209 |
|
210 iCellIdInfo->iMNC = MNC; |
|
211 iCellIdInfo->iMCC = MCC; |
|
212 iCellIdInfo->iCid = CellId; |
|
213 |
|
214 TRACESTRING("Observers notified for WCDMA CellId information") |
|
215 iObserver.BasicCellIDRequestCompletedL(KErrNone); |
|
216 break; |
|
217 } |
|
218 default: |
|
219 { |
|
220 |
|
221 #ifdef _WINS_ |
|
222 |
|
223 iNetworkType = EGSM; |
|
224 |
|
225 TInt MCC=0; |
|
226 TInt64 MNC=0; |
|
227 TLex LexMCC(iNetworkInfo.iCountryCode); |
|
228 TLex LexMNC(iNetworkInfo.iNetworkId); |
|
229 |
|
230 LexMCC.Val(MCC); |
|
231 LexMNC.Val(MNC); |
|
232 TUint LAC = iLocationInfo.iLocationAreaCode; |
|
233 TUint CellId = iLocationInfo.iCellId; |
|
234 |
|
235 iCellIdInfo->iMCC = MCC; |
|
236 iCellIdInfo->iMNC = MNC; |
|
237 iCellIdInfo->iCid = CellId; |
|
238 iCellIdInfo->iLac = LAC; |
|
239 |
|
240 TRACESTRING("Observers notified for GSM CellId information") |
|
241 iObserver.BasicCellIDRequestCompletedL(KErrNone); |
|
242 #else |
|
243 |
|
244 TRACESTRING("Unknown Network") |
|
245 iNetworkType = EUnknown; |
|
246 |
|
247 TRACESTRING("Observers notified with error for unknown network") |
|
248 iObserver.BasicCellIDRequestCompletedL(KErrNotFound); |
|
249 #endif |
|
250 break; |
|
251 } |
|
252 } |
|
253 TRACESTRING("CSuplPsyCellIdHandler::HandleCellInfoL end") |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CSuplPsyCellIdHandler::RunError, Will be called by framework,if RunL leaves. |
|
258 // (other items were commented in a header). |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CSuplPsyCellIdHandler::RunError(TInt /*aError*/) |
|
262 { |
|
263 TRAP_IGNORE(iObserver.BasicCellIDRequestCompletedL(KErrNotFound)); |
|
264 return KErrNone; |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CSuplPsyCellIdHandler::ConnectToETelL |
|
269 // Connects to Telephony server & RMobilePhone |
|
270 // Returns System wide error,if any occurs |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 TInt CSuplPsyCellIdHandler::ConnectToETelL() |
|
274 { |
|
275 TInt err = iTelServer.Connect(); |
|
276 if(err != KErrNone) |
|
277 { |
|
278 TRACESTRING2("Failed to connect with Error Code: %d",err ) |
|
279 return err; |
|
280 } |
|
281 |
|
282 CCommsDatabase* const db = CCommsDatabase::NewL(EDatabaseTypeUnspecified); |
|
283 CleanupStack::PushL(db); |
|
284 |
|
285 TUint32 modemId = 0; |
|
286 db->GetGlobalSettingL(TPtrC(MODEM_PHONE_SERVICES_SMS), modemId); |
|
287 CCommsDbTableView* const view = db->OpenViewMatchingUintLC(TPtrC(MODEM), TPtrC(COMMDB_ID), |
|
288 modemId); |
|
289 err = view->GotoFirstRecord(); |
|
290 if(err != KErrNone) |
|
291 { |
|
292 CleanupStack::PopAndDestroy(2,db); |
|
293 return err; |
|
294 } |
|
295 |
|
296 view->ReadTextL(TPtrC(MODEM_TSY_NAME), iTsyName); |
|
297 err = iTelServer.LoadPhoneModule(iTsyName); |
|
298 if(err != KErrNone) |
|
299 { |
|
300 CleanupStack::PopAndDestroy(2,db); |
|
301 return err; |
|
302 } |
|
303 |
|
304 |
|
305 // For the phone information |
|
306 RTelServer::TPhoneInfo info; |
|
307 |
|
308 iTelServer.GetPhoneInfo(0, info); |
|
309 err = iPhone.Open(iTelServer, info.iName); |
|
310 CleanupStack::PopAndDestroy(2,db); |
|
311 if(err != KErrNone) |
|
312 { |
|
313 return err; |
|
314 } |
|
315 return err; |
|
316 } |
|
317 // End of File |