|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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: class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <etel.h> |
|
19 #include <etelmm.h> |
|
20 #include <MmTsy_names.h> |
|
21 |
|
22 #include "sysinfoservice.h" |
|
23 #include "sysnetworkrequest.h" |
|
24 #include "entitykeys.h" |
|
25 #include "sysrequest.h" |
|
26 #include "SysInfoUtils.h" |
|
27 |
|
28 // -------------------------------------------------------------------- |
|
29 // CNetwork::CNetwork() |
|
30 // C++ default constructor. |
|
31 // -------------------------------------------------------------------- |
|
32 // |
|
33 CNetwork::CNetwork( TSysRequest::TRequestType aReqType, TInt32 aTransID, |
|
34 TInt aNetworkInfoType, ISystemObserver* aObsrver ) |
|
35 :CActiveRequest(aReqType,aTransID,aObsrver), |
|
36 iNetworkInfoType((TNetInfoType)aNetworkInfoType), |
|
37 iNetworkInfoBuf(iNetworkInfo), iIsThresholdSet(EFalse) |
|
38 { |
|
39 } |
|
40 |
|
41 // -------------------------------------------------------------------- |
|
42 // CNetwork::~CNetwork() |
|
43 // Destructor |
|
44 // -------------------------------------------------------------------- |
|
45 // |
|
46 CNetwork::~CNetwork() |
|
47 { |
|
48 Cancel(); |
|
49 iMobilePhone.Close(); |
|
50 iTelServer.Close(); |
|
51 delete iEntity; |
|
52 delete iKey; |
|
53 } |
|
54 |
|
55 // -------------------------------------------------------------------- |
|
56 // CNetwork::NewL() |
|
57 // Two-phased constructor, returns instance of this class. |
|
58 // -------------------------------------------------------------------- |
|
59 // |
|
60 CNetwork* CNetwork::NewL( const TSysRequest& aRequest,TInt aNetworkInfoType ) |
|
61 { |
|
62 CNetwork* self; |
|
63 self = new (ELeave) CNetwork(aRequest.RequestType(), aRequest.TransactionID(), |
|
64 aNetworkInfoType, aRequest.Observer() ); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(aRequest); |
|
67 CleanupStack::Pop(self); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // -------------------------------------------------------------------- |
|
72 // CNetwork::ConstructL() |
|
73 // 2nd Phase constructor to allocate required resources for this obj. |
|
74 // -------------------------------------------------------------------- |
|
75 // |
|
76 void CNetwork::ConstructL(const TSysRequest& aRequest) |
|
77 { |
|
78 //For Network signal strength and battery user can specify threshold. |
|
79 if( TSysRequest::ENotification == RequestType() && |
|
80 (ESignalStrength == iNetworkInfoType || |
|
81 EBatteryStrength == iNetworkInfoType) ) |
|
82 { |
|
83 const CSysData* Input = aRequest.SystemData(); |
|
84 // check if any input parameter |
|
85 if(Input) |
|
86 { |
|
87 //perform parameter validation. |
|
88 if( CSysData::EStatus != Input->DataType()) |
|
89 User::Leave(KErrArgument); |
|
90 //get threshold value. |
|
91 iThreshold = ((CStatus*)Input)->Status(); |
|
92 iIsThresholdSet = ETrue; |
|
93 } |
|
94 } |
|
95 |
|
96 //Create a handle to RMobile |
|
97 User::LeaveIfError(RPhoneInstance::Connect( iTelServer,iMobilePhone )); |
|
98 |
|
99 // Make local copy of SA. |
|
100 iEntity = aRequest.Entity().AllocL(); |
|
101 iKey = aRequest.Key().AllocL(); |
|
102 } |
|
103 |
|
104 // -------------------------------------------------------------------- |
|
105 // CNetwork::Request() |
|
106 // Issues network request. |
|
107 // -------------------------------------------------------------------- |
|
108 // |
|
109 TInt CNetwork::Request() |
|
110 { |
|
111 TSysRequest::TRequestType ReqType = RequestType(); |
|
112 |
|
113 if( !IsActive() ) |
|
114 { |
|
115 // Issue request based on request type. |
|
116 if(TSysRequest::EASyncONESHOT == ReqType) |
|
117 { |
|
118 switch(iNetworkInfoType) |
|
119 { |
|
120 case ESignalStrength: |
|
121 iMobilePhone.GetSignalStrength(iStatus,iSignalStrength,iBar); |
|
122 break; |
|
123 // HomeNetwork info require ReadDeviceData, which is not user grantable permission, and |
|
124 // is currently not supported. |
|
125 #ifdef _REQUIRE_READDEVICEDATA_ |
|
126 case EHomeNetworkInfo: |
|
127 iMobilePhone.GetHomeNetwork( iStatus, iNetworkInfoBuf ); |
|
128 break; |
|
129 #endif |
|
130 case ECurrentNetworkInfo: |
|
131 iMobilePhone.GetCurrentNetwork(iStatus,iNetworkInfoBuf,iArea); |
|
132 break; |
|
133 |
|
134 case EBatteryStrength: |
|
135 iMobilePhone.GetBatteryInfo(iStatus,iBatteryInfo); |
|
136 break; |
|
137 |
|
138 default: |
|
139 return KErrNotFound; |
|
140 } |
|
141 } |
|
142 else //Notification. |
|
143 { |
|
144 switch(iNetworkInfoType) |
|
145 { |
|
146 case ESignalStrength: |
|
147 iMobilePhone.NotifySignalStrengthChange(iStatus,iSignalStrength,iBar); |
|
148 break; |
|
149 |
|
150 case ECurrentNetworkInfo: |
|
151 case ELocationAreaCode: |
|
152 case ECellId: |
|
153 iMobilePhone.NotifyCurrentNetworkChange(iStatus,iNetworkInfoBuf,iArea); |
|
154 break; |
|
155 |
|
156 case EBatteryStrength: |
|
157 iMobilePhone.NotifyBatteryInfoChange(iStatus,iBatteryInfo); |
|
158 break; |
|
159 |
|
160 default: |
|
161 return KErrNotFound; |
|
162 } |
|
163 } |
|
164 SetActive (); |
|
165 } |
|
166 return KErrNone; |
|
167 } |
|
168 |
|
169 // -------------------------------------------------------------------- |
|
170 // CNetwork::RunL() |
|
171 // Gets called in event of request completion or error situation. |
|
172 // -------------------------------------------------------------------- |
|
173 // |
|
174 void CNetwork::RunL() |
|
175 { |
|
176 TSysRequest::TRequestType ReqType = RequestType(); |
|
177 CSysData* OutputParam = NULL; |
|
178 TInt32 transId = this->TransactionID(); |
|
179 TInt error( iStatus.Int() ); |
|
180 |
|
181 if(KErrNone == error) |
|
182 { |
|
183 switch(iNetworkInfoType) |
|
184 { |
|
185 case ESignalStrength: |
|
186 //if threshold not specified. notify every change. |
|
187 if( !iIsThresholdSet ) |
|
188 OutputParam = CStatus::NewL(iSignalStrength); |
|
189 else if( (iSignalStrength > iThreshold) ) |
|
190 OutputParam = CStatus::NewL(iSignalStrength); |
|
191 break; |
|
192 |
|
193 case EHomeNetworkInfo: |
|
194 case ECurrentNetworkInfo: |
|
195 OutputParam = CNetworkInfo::NewL(iNetworkInfo,iArea); |
|
196 break; |
|
197 |
|
198 case ELocationAreaCode: |
|
199 if( iArea.iAreaKnown && iLocationAreaCodeOld != iArea.iLocationAreaCode ) |
|
200 { |
|
201 OutputParam = CStatus::NewL(iArea.iLocationAreaCode); |
|
202 iLocationAreaCodeOld = iArea.iLocationAreaCode; |
|
203 } |
|
204 break; |
|
205 |
|
206 case ECellId: |
|
207 if( iArea.iAreaKnown && iCellIdOld != iArea.iCellId ) |
|
208 { |
|
209 OutputParam = CStatus::NewL(iArea.iCellId); |
|
210 iCellIdOld = iArea.iCellId; |
|
211 } |
|
212 break; |
|
213 |
|
214 case EBatteryStrength: |
|
215 //if threshold not specified. notify every change. |
|
216 if( !iIsThresholdSet ) |
|
217 OutputParam = CStatus::NewL(iBatteryInfo.iChargeLevel); |
|
218 else if( (iSignalStrength <= iThreshold) ) |
|
219 OutputParam = CStatus::NewL(iBatteryInfo.iChargeLevel); |
|
220 break; |
|
221 |
|
222 default: |
|
223 break; |
|
224 } |
|
225 |
|
226 //In case notification Re-Issue Request. |
|
227 if (TSysRequest::ENotification == ReqType) |
|
228 Request(); |
|
229 |
|
230 //Notify only if threshold reached. |
|
231 if(OutputParam) |
|
232 TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity,*iKey,OutputParam,transId,RequestType(),error)); |
|
233 |
|
234 } |
|
235 //If error |
|
236 else |
|
237 { |
|
238 TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity,*iKey,NULL,transId,RequestType(),error)); |
|
239 ActiveStore::RemoveRequest(TransactionID()); |
|
240 } |
|
241 |
|
242 //If its a ONSHOT Requeust remove this from active store. |
|
243 if (TSysRequest::EASyncONESHOT == ReqType) |
|
244 ActiveStore::RemoveRequest(transId); |
|
245 } |
|
246 |
|
247 // -------------------------------------------------------------------- |
|
248 // CNetwork::DoCancel() |
|
249 // cancels ongoing network request. |
|
250 // -------------------------------------------------------------------- |
|
251 // |
|
252 void CNetwork::DoCancel() |
|
253 { |
|
254 TSysRequest::TRequestType ReqType = RequestType(); |
|
255 |
|
256 //Cancel request based on type of request. |
|
257 if(TSysRequest::EASyncONESHOT == ReqType) |
|
258 { |
|
259 switch(iNetworkInfoType) |
|
260 { |
|
261 case ESignalStrength: |
|
262 iMobilePhone.CancelAsyncRequest(EMobilePhoneGetSignalStrength); |
|
263 break; |
|
264 |
|
265 case EHomeNetworkInfo: |
|
266 iMobilePhone.CancelAsyncRequest(EMobilePhoneGetHomeNetwork); |
|
267 break; |
|
268 |
|
269 case ECurrentNetworkInfo: |
|
270 case ELocationAreaCode: |
|
271 case ECellId: |
|
272 iMobilePhone.CancelAsyncRequest(EMobilePhoneGetNetworkRegistrationStatus); |
|
273 break; |
|
274 |
|
275 case EBatteryStrength: |
|
276 iMobilePhone.CancelAsyncRequest(EMobilePhoneGetBatteryInfo); |
|
277 break; |
|
278 |
|
279 default: |
|
280 break; |
|
281 } |
|
282 } |
|
283 //Notification |
|
284 else |
|
285 { |
|
286 switch(iNetworkInfoType) |
|
287 { |
|
288 case ESignalStrength: |
|
289 iMobilePhone.CancelAsyncRequest(EMobilePhoneNotifySignalStrengthChange); |
|
290 break; |
|
291 |
|
292 case EHomeNetworkInfo: |
|
293 iMobilePhone.CancelAsyncRequest(EMobilePhoneGetHomeNetwork); |
|
294 break; |
|
295 |
|
296 case ECurrentNetworkInfo: |
|
297 case ELocationAreaCode: |
|
298 case ECellId: |
|
299 iMobilePhone.CancelAsyncRequest(EMobilePhoneNotifyCurrentNetworkChange); |
|
300 break; |
|
301 |
|
302 case EBatteryStrength: |
|
303 iMobilePhone.CancelAsyncRequest(EMobilePhoneNotifyBatteryInfoChange); |
|
304 break; |
|
305 |
|
306 default: |
|
307 break; |
|
308 } |
|
309 } |
|
310 } |
|
311 |
|
312 //End of File. |