author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 09:49:03 +0300 | |
changeset 41 | 3a6b55c6390c |
parent 28 | 075425b8d9a4 |
permissions | -rw-r--r-- |
24 | 1 |
/* |
2 |
* Copyright (c) 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// System includes |
|
19 |
#include <etelmm.h> |
|
20 |
#include <commsdattypesv1_1.h> |
|
21 |
||
22 |
// User includes |
|
23 |
#include "cradionetworkinfolistener.h" |
|
24 |
#include "mradiosettingssetter.h" |
|
25 |
#include "cradioenginelogger.h" |
|
26 |
||
27 |
using namespace CommsDat; |
|
28 |
||
29 |
// ======== MEMBER FUNCTIONS ======== |
|
30 |
||
31 |
||
32 |
// --------------------------------------------------------------------------- |
|
33 |
// |
|
34 |
// --------------------------------------------------------------------------- |
|
35 |
// |
|
36 |
CRadioNetworkInfoListener* CRadioNetworkInfoListener::NewL( MRadioSettingsSetter& aSetter, |
|
37 |
MRadioNetworkChangeObserver* aObserver ) |
|
38 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
39 |
LEVEL3( LOG_METHOD_AUTO ); |
24 | 40 |
CRadioNetworkInfoListener* self = new ( ELeave ) CRadioNetworkInfoListener( aSetter, aObserver ); |
41 |
CleanupStack::PushL( self ); |
|
42 |
self->ConstructL(); |
|
43 |
CleanupStack::Pop( self ); |
|
44 |
return self; |
|
45 |
} |
|
46 |
||
47 |
// --------------------------------------------------------------------------- |
|
48 |
// |
|
49 |
// --------------------------------------------------------------------------- |
|
50 |
// |
|
51 |
CRadioNetworkInfoListener::CRadioNetworkInfoListener( MRadioSettingsSetter& aSetter, |
|
52 |
MRadioNetworkChangeObserver* aObserver ) |
|
53 |
: CActive( CActive::EPriorityHigh ) |
|
54 |
, iSetter( aSetter ) |
|
55 |
, iObserver( aObserver ) |
|
56 |
, iSubscriberIdPckg( iSubscriberId ) |
|
57 |
, iNetworkInfoPckg( iNetworkInfo ) |
|
58 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
59 |
LEVEL3( LOG_METHOD_AUTO ); |
24 | 60 |
CActiveScheduler::Add( this ); |
61 |
} |
|
62 |
||
63 |
// --------------------------------------------------------------------------- |
|
64 |
// |
|
65 |
// --------------------------------------------------------------------------- |
|
66 |
// |
|
67 |
void CRadioNetworkInfoListener::ConstructL() |
|
68 |
{ |
|
69 |
LOG_METHOD_AUTO; |
|
70 |
#ifndef __WINS__ |
|
71 |
iTelephony = CTelephony::NewL(); |
|
72 |
||
73 |
// Initialize the default network id and country code directly from CommsDat, as CTelephony cannot be used in synchronous mode |
|
74 |
// and using it in async mode will cause problems in core initialisation, and too much complexity! |
|
75 |
||
76 |
// Get default TSY from database. |
|
77 |
||
78 |
CMDBSession* db = CMDBSession::NewL( CMDBSession::LatestVersion()); |
|
79 |
CleanupStack::PushL( db ); |
|
80 |
||
81 |
CMDBRecordSet<CCDModemBearerRecord>* set = new ( ELeave ) CMDBRecordSet<CCDModemBearerRecord>( KCDTIdModemBearerRecord ); |
|
82 |
CleanupStack::PushL( set ); |
|
83 |
||
84 |
set->LoadL( *db ); |
|
85 |
||
86 |
TInt index = 0; |
|
87 |
CCDModemBearerRecord* record = static_cast<CCDModemBearerRecord*>( set->iRecords[index++]); |
|
88 |
||
89 |
if ( record->iTsyName.IsNull() && set->iRecords.Count() > index ) // the first item is normally only a template |
|
90 |
{ |
|
91 |
record = static_cast<CCDModemBearerRecord*>( set->iRecords[index++]); |
|
92 |
} |
|
93 |
||
94 |
TPtrC name( static_cast<const TDesC&>( record->iTsyName )); |
|
95 |
TBuf<50> tsyName; |
|
96 |
tsyName.Copy( name ); |
|
97 |
||
98 |
LOG_FORMAT( "CRadioNetworkInfoListener::ConstructL, TSY name: %S", &tsyName ); |
|
99 |
CleanupStack::PopAndDestroy( set ); |
|
100 |
CleanupStack::PopAndDestroy( db ); |
|
101 |
||
102 |
RTelServer telServer; |
|
103 |
CleanupClosePushL( telServer ); |
|
104 |
RMobilePhone mobilePhone; |
|
105 |
CleanupClosePushL( mobilePhone ); |
|
106 |
||
107 |
// Open phone |
|
108 |
User::LeaveIfError( telServer.Connect()); |
|
109 |
||
110 |
// TSY module gets automatically unloaded when tel.Close() is called ( and tel is is CU-stack ), |
|
111 |
// so loaded TSY is also leave-safe |
|
112 |
User::LeaveIfError( telServer.LoadPhoneModule( tsyName )); |
|
113 |
||
114 |
// Get number of phones. |
|
115 |
TInt phones( 0 ); |
|
116 |
User::LeaveIfError( telServer.EnumeratePhones( phones )); |
|
117 |
LOG_FORMAT( "CRadioNetworkInfoListener::ConstructL, Number of phones=%d", phones ); |
|
118 |
||
119 |
// Get phone info of first legal phone. |
|
120 |
TInt legalPhoneIndex = KErrNotFound; |
|
121 |
RTelServer::TPhoneInfo phoneInfo; |
|
41
3a6b55c6390c
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
122 |
for ( TInt i=0; i<phones && legalPhoneIndex == KErrNotFound; ++i ) |
24 | 123 |
{ |
124 |
if ( telServer.GetPhoneInfo( i, phoneInfo ) == KErrNone ) |
|
125 |
{ |
|
126 |
if ( phoneInfo.iNetworkType == RTelServer::ENetworkTypeMobileDigital ) |
|
127 |
{ |
|
128 |
legalPhoneIndex = i; |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
User::LeaveIfError( legalPhoneIndex ); |
|
133 |
||
134 |
// Open legal phone. |
|
135 |
User::LeaveIfError( mobilePhone.Open( telServer, phoneInfo.iName )); |
|
136 |
||
137 |
TUint32 networkCaps; |
|
138 |
User::LeaveIfError( mobilePhone.GetNetworkCaps( networkCaps )); |
|
139 |
TUint32 identityCaps; |
|
140 |
User::LeaveIfError( mobilePhone.GetIdentityCaps( identityCaps )); |
|
141 |
// Check if we are allowed to get network info. |
|
142 |
if ( networkCaps & RMobilePhone::KCapsGetCurrentNetwork ) |
|
143 |
{ |
|
144 |
// Gather initial information synchronically. |
|
145 |
RMobilePhone::TMobilePhoneLocationAreaV1 location; |
|
146 |
||
147 |
RMobilePhone::TMobilePhoneNetworkInfoV1 networkInfo; |
|
148 |
RMobilePhone::TMobilePhoneNetworkInfoV1Pckg networkInfoPckg( networkInfo ); |
|
149 |
||
150 |
mobilePhone.GetCurrentNetwork( iStatus, networkInfoPckg, location ); |
|
151 |
User::WaitForRequest( iStatus ); |
|
152 |
||
153 |
CTelephony::TNetworkInfoV1 telephonyNetworkInfo; |
|
154 |
if ( iStatus == KErrNone ) |
|
155 |
{ |
|
156 |
telephonyNetworkInfo.iMode = static_cast<CTelephony::TNetworkMode>( networkInfo.iMode ); |
|
157 |
telephonyNetworkInfo.iCountryCode = networkInfo.iCountryCode; |
|
158 |
telephonyNetworkInfo.iCdmaSID = networkInfo.iCdmaSID; |
|
159 |
telephonyNetworkInfo.iNetworkId = networkInfo.iNetworkId; |
|
160 |
} |
|
161 |
else |
|
162 |
{ |
|
163 |
telephonyNetworkInfo.iCountryCode = iSetter.CountryCode(); |
|
164 |
telephonyNetworkInfo.iNetworkId = iSetter.NetworkId(); |
|
165 |
} |
|
166 |
iNetworkInfoPckg() = telephonyNetworkInfo; |
|
167 |
} |
|
168 |
else |
|
169 |
{ |
|
170 |
// Leave if we are not allowed to get network info. |
|
171 |
// Other action could also be considered!!!! |
|
172 |
User::Leave( KErrNotSupported ); |
|
173 |
} |
|
174 |
||
175 |
CleanupStack::PopAndDestroy( 2, &telServer ); |
|
176 |
#endif |
|
177 |
// At the end, update the local variables by simulating the "netid changed" event. |
|
178 |
RunL(); |
|
179 |
} |
|
180 |
||
181 |
// --------------------------------------------------------------------------- |
|
182 |
// |
|
183 |
// --------------------------------------------------------------------------- |
|
184 |
// |
|
185 |
CRadioNetworkInfoListener::~CRadioNetworkInfoListener() |
|
186 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
187 |
LEVEL3( LOG_METHOD_AUTO ); |
24 | 188 |
Cancel(); |
189 |
||
190 |
#ifndef __WINS__ |
|
191 |
delete iTelephony; |
|
192 |
#endif |
|
193 |
} |
|
194 |
||
195 |
// --------------------------------------------------------------------------- |
|
196 |
// |
|
197 |
// --------------------------------------------------------------------------- |
|
198 |
// |
|
199 |
TInt CRadioNetworkInfoListener::CompoundNetworkId() const |
|
200 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
201 |
LEVEL3( LOG_METHOD_AUTO ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
202 |
LOG_FORMAT( "Returning iCompoundNetworkId: %d", iCompoundNetworkId ); |
24 | 203 |
return iCompoundNetworkId; |
204 |
} |
|
205 |
||
206 |
// --------------------------------------------------------------------------- |
|
207 |
// |
|
208 |
// --------------------------------------------------------------------------- |
|
209 |
// |
|
210 |
TPtrC CRadioNetworkInfoListener::SubscriberId() const |
|
211 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
212 |
LEVEL3( LOG_METHOD_AUTO ); |
24 | 213 |
TPtrC id = iSubscriberId.iSubscriberId; |
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
214 |
LOG_FORMAT( "SubscriberId: %S", &id ); |
24 | 215 |
return id; |
216 |
} |
|
217 |
||
218 |
// --------------------------------------------------------------------------- |
|
219 |
// |
|
220 |
// --------------------------------------------------------------------------- |
|
221 |
// |
|
222 |
TPtrC CRadioNetworkInfoListener::CountryCode() const |
|
223 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
224 |
LEVEL3( LOG_METHOD_AUTO ); |
24 | 225 |
TPtrC countryCode = iSetter.CountryCode(); |
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
226 |
LOG_FORMAT( "CountryCode: %S", &countryCode ); |
24 | 227 |
return countryCode; |
228 |
} |
|
229 |
||
230 |
// --------------------------------------------------------------------------- |
|
231 |
// |
|
232 |
// --------------------------------------------------------------------------- |
|
233 |
// |
|
234 |
void CRadioNetworkInfoListener::SaveNetworkInfoL() |
|
235 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
236 |
LEVEL3( LOG_METHOD_AUTO ); |
24 | 237 |
#ifdef __WINS__ |
238 |
iNetworkInfo.iCountryCode.Copy( _L("244") ); |
|
239 |
iNetworkInfo.iNetworkId.Zero(); |
|
240 |
#endif |
|
241 |
||
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
242 |
LOG_FORMAT( "iNetworkInfo.iCountryCode = %S", |
24 | 243 |
&iNetworkInfo.iCountryCode ); |
244 |
||
245 |
User::LeaveIfError( iSetter.SetCountryCode( iNetworkInfo.iCountryCode ) ); |
|
246 |
||
247 |
// The compound network identifier is composed of the current network identifier and country code. |
|
248 |
TBuf<KDefaultRealWidth> compoundNetworkId; |
|
249 |
compoundNetworkId.Append( iSetter.CountryCode() ); |
|
250 |
if ( iNetworkInfo.iNetworkId.Length() < 2 ) |
|
251 |
{ |
|
252 |
// Network identifier has only one digit, in which case it must be prepended with a zero. |
|
253 |
compoundNetworkId.AppendNum( 0 ); |
|
254 |
} |
|
255 |
||
256 |
compoundNetworkId.Append( iNetworkInfo.iNetworkId ); |
|
257 |
||
258 |
TLex lex( compoundNetworkId ); |
|
259 |
User::LeaveIfError( lex.Val( iCompoundNetworkId ) ); |
|
260 |
||
261 |
if ( iCompoundNetworkId != 0 && iPreviousCompoundNetworkId != iCompoundNetworkId ) |
|
262 |
{ |
|
263 |
if ( iPreviousCompoundNetworkId != 0 && iObserver ) |
|
264 |
{ |
|
265 |
iObserver->NetworkIdChanged(); |
|
266 |
} |
|
267 |
iPreviousCompoundNetworkId = iCompoundNetworkId; |
|
268 |
} |
|
269 |
} |
|
270 |
||
271 |
// --------------------------------------------------------------------------- |
|
272 |
// |
|
273 |
// --------------------------------------------------------------------------- |
|
274 |
// |
|
275 |
void CRadioNetworkInfoListener::DoCancel() |
|
276 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
277 |
LEVEL3( LOG_METHOD_AUTO ); |
24 | 278 |
#ifndef __WINS__ |
279 |
iTelephony->CancelAsync( CTelephony::ECurrentNetworkInfoChangeCancel ); |
|
280 |
#endif |
|
281 |
} |
|
282 |
||
283 |
// --------------------------------------------------------------------------- |
|
284 |
// |
|
285 |
// --------------------------------------------------------------------------- |
|
286 |
// |
|
287 |
void CRadioNetworkInfoListener::RunL() |
|
288 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
289 |
LEVEL3( LOG_METHOD_AUTO ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
290 |
LEVEL3( LOG_FORMAT( "iStatus.Int() = %d", iStatus.Int() ) ); |
24 | 291 |
#ifndef __WINS__ |
292 |
iTelephony->NotifyChange( iStatus, CTelephony::ECurrentNetworkInfoChange, iNetworkInfoPckg ); |
|
293 |
SetActive(); |
|
294 |
#endif |
|
295 |
SaveNetworkInfoL(); |
|
296 |
} |