|
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 |
|
19 #include <centralrepository.h> |
|
20 #include <btserversdkcrkeys.h> |
|
21 #include <SettingsInternalCRKeys.h> |
|
22 #include <HWRMVibraSDKCRKeys.h> |
|
23 #include <HWRMLightDomainCRKeys.h> |
|
24 #include <AknFepInternalCRKeys.h> |
|
25 #include <SysUtilDomainCRKeys.h> |
|
26 |
|
27 #include <UikonInternalPSKeys.h> |
|
28 #include <NetworkHandlingDomainPSKeys.h> |
|
29 #include <HWRMDomainPSKeys.h> |
|
30 #include <hwrmpowerstatesdkpskeys.h> |
|
31 #include <IR_SOCK.H> |
|
32 |
|
33 #include "activerequests.h" |
|
34 #include "sysinfoservice.h" |
|
35 #include "entitykeys.h" |
|
36 #include "SysInfoUtils.h" |
|
37 |
|
38 using namespace SysInfo; |
|
39 _LIT(KDriveSeperator,":\\"); |
|
40 const TInt KMaxDriveLength = 5; |
|
41 |
|
42 // -------------------------------------------------------------------- |
|
43 // CCenrepNotifier::CCenrepNotifier() |
|
44 // C++ default constructor. |
|
45 // -------------------------------------------------------------------- |
|
46 // |
|
47 CCenrepNotifier::CCenrepNotifier(TSysRequest::TRequestType aReqType, |
|
48 TInt32 aTransID, TCommand aCommand, |
|
49 ISystemObserver* aObsrver) |
|
50 :CActiveRequest(aReqType,aTransID,aObsrver), |
|
51 iCommand(aCommand) |
|
52 { |
|
53 } |
|
54 |
|
55 // -------------------------------------------------------------------- |
|
56 // CCenrepNotifier::~CCenrepNotifier() |
|
57 // Destructor. |
|
58 // -------------------------------------------------------------------- |
|
59 // |
|
60 CCenrepNotifier::~CCenrepNotifier() |
|
61 { |
|
62 Cancel(); |
|
63 delete iCenrep; |
|
64 delete iEntity; |
|
65 delete iKey; |
|
66 } |
|
67 |
|
68 // -------------------------------------------------------------------- |
|
69 // CCenrepNotifier::NewL() |
|
70 // Two-phased constructor, returns instance of this class. |
|
71 // -------------------------------------------------------------------- |
|
72 // |
|
73 CCenrepNotifier* CCenrepNotifier::NewL(const TSysRequest& aRequest, |
|
74 TCommand aCommand) |
|
75 { |
|
76 CCenrepNotifier* self; |
|
77 self = new (ELeave) CCenrepNotifier(aRequest.RequestType(), |
|
78 aRequest.TransactionID(), |
|
79 aCommand,aRequest.Observer()); |
|
80 |
|
81 CleanupStack::PushL(self); |
|
82 self->ConstructL(aRequest); |
|
83 CleanupStack::Pop(self); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------- |
|
88 // CCenrepNotifier::ConstructL() |
|
89 // 2nd Phase constructor to allocate required resources for this obj. |
|
90 // -------------------------------------------------------------------- |
|
91 // |
|
92 void CCenrepNotifier::ConstructL(const TSysRequest& aRequest) |
|
93 { |
|
94 //supportes only notifications. |
|
95 if(TSysRequest::ENotification != RequestType()) |
|
96 User::Leave(KErrNotSupported); |
|
97 |
|
98 // Identify repository uid and key. |
|
99 switch (iCommand) |
|
100 { |
|
101 case EPridictiveText: |
|
102 iRepositoryUid = KCRUidAknFep; |
|
103 iRepositoryKey = KAknFepPredTxtFlag; |
|
104 break; |
|
105 |
|
106 case EInputLanguage: |
|
107 iRepositoryUid = KCRUidAknFep; |
|
108 iRepositoryKey = KAknFepInputTxtLang; |
|
109 break; |
|
110 |
|
111 case EBlueTooth: |
|
112 iRepositoryUid = KCRUidBluetoothPowerState; |
|
113 iRepositoryKey = KBTPowerState; |
|
114 break; |
|
115 |
|
116 case EVibra: |
|
117 iRepositoryUid = KCRUidVibraCtrl; |
|
118 iRepositoryKey = KVibraCtrlProfileVibraEnabled; |
|
119 break; |
|
120 |
|
121 case EKeyLock: |
|
122 iRepositoryUid = KCRUidSecuritySettings; |
|
123 iRepositoryKey = KSettingsAutolockStatus; |
|
124 break; |
|
125 |
|
126 default: |
|
127 User::Leave(KErrNotFound); |
|
128 } |
|
129 |
|
130 // create repository instance. |
|
131 iCenrep = CRepository::NewL(iRepositoryUid); |
|
132 // Make local copy of SA. |
|
133 iEntity = aRequest.Entity().AllocL(); |
|
134 iKey = aRequest.Key().AllocL(); |
|
135 } |
|
136 |
|
137 // -------------------------------------------------------------------- |
|
138 // CCenrepNotifier::Request() |
|
139 // Issues notification request. |
|
140 // -------------------------------------------------------------------- |
|
141 // |
|
142 TInt CCenrepNotifier::Request () |
|
143 { |
|
144 if( !IsActive() ) |
|
145 { |
|
146 iCenrep->NotifyRequest(iRepositoryKey, iStatus); |
|
147 SetActive (); |
|
148 } |
|
149 return KErrNone; |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------- |
|
153 // CCenrepNotifier::RunL() |
|
154 // Gets called in event of request completion or error situation. |
|
155 // -------------------------------------------------------------------- |
|
156 // |
|
157 void CCenrepNotifier::RunL() |
|
158 { |
|
159 TInt Error(iStatus.Int()); |
|
160 |
|
161 if (KErrNone <= Error) |
|
162 { |
|
163 // Re-Issue request |
|
164 Request (); |
|
165 Error = iCenrep->Get(iRepositoryKey,iValue); |
|
166 //Create CSysData |
|
167 CStatus* Status = CStatus::NewL(iValue); |
|
168 // Calling Observer response method. |
|
169 TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity, *iKey, Status, |
|
170 TransactionID(),RequestType(),Error)); |
|
171 } |
|
172 else |
|
173 { |
|
174 TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity, *iKey, NULL, |
|
175 TransactionID(),RequestType(),Error)); |
|
176 |
|
177 ActiveStore::RemoveRequest(TransactionID()); |
|
178 } |
|
179 } |
|
180 |
|
181 // -------------------------------------------------------------------- |
|
182 // CCenrepNotifier::DoCancel() |
|
183 // Cancel ongoing request. |
|
184 // -------------------------------------------------------------------- |
|
185 // |
|
186 void CCenrepNotifier::DoCancel() |
|
187 { |
|
188 iCenrep->NotifyCancel(iRepositoryKey); |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------- |
|
192 // CPubSubNotifier::CPubSubNotifier() |
|
193 // C++ default constructor. |
|
194 // -------------------------------------------------------------------- |
|
195 // |
|
196 CPubSubNotifier::CPubSubNotifier(TSysRequest::TRequestType aReqType, |
|
197 TInt32 aTransID, TCommand aCommand, |
|
198 ISystemObserver* aObsrver) |
|
199 :CActiveRequest(aReqType,aTransID,aObsrver), |
|
200 iValue(EUnknown), iCommand(aCommand) |
|
201 { |
|
202 } |
|
203 |
|
204 // -------------------------------------------------------------------- |
|
205 // CPubSubNotifier::~CPubSubNotifier() |
|
206 // Destructor. |
|
207 // -------------------------------------------------------------------- |
|
208 // |
|
209 CPubSubNotifier::~CPubSubNotifier() |
|
210 { |
|
211 Cancel(); |
|
212 iProperty.Close(); |
|
213 delete iEntity; |
|
214 delete iKey; |
|
215 } |
|
216 |
|
217 // -------------------------------------------------------------------- |
|
218 // CPubSubNotifier::NewL() |
|
219 // Two-phased constructor, returns instance of this class. |
|
220 // -------------------------------------------------------------------- |
|
221 // |
|
222 CPubSubNotifier* CPubSubNotifier::NewL(const TSysRequest& aRequest, |
|
223 TCommand aCommand) |
|
224 { |
|
225 CPubSubNotifier* self; |
|
226 self = new (ELeave) CPubSubNotifier( aRequest.RequestType(), |
|
227 aRequest.TransactionID(), |
|
228 aCommand,aRequest.Observer() ); |
|
229 |
|
230 CleanupStack::PushL(self); |
|
231 self->ConstructL (aRequest); |
|
232 CleanupStack::Pop(self); |
|
233 return self; |
|
234 } |
|
235 |
|
236 // -------------------------------------------------------------------- |
|
237 // CPubSubNotifier::ConstructL() |
|
238 // 2nd Phase constructor to allocate required resources for this obj. |
|
239 // -------------------------------------------------------------------- |
|
240 // |
|
241 void CPubSubNotifier::ConstructL (const TSysRequest& aRequest) |
|
242 { |
|
243 //supportes only notifications. |
|
244 if(TSysRequest::ENotification != RequestType()) |
|
245 User::Leave(KErrNotSupported); |
|
246 |
|
247 // Identify publish subscribe category uid and key based on command. |
|
248 switch (iCommand) |
|
249 { |
|
250 case ERegistrationStatus: |
|
251 iPropertyUid = KPSUidNetworkInfo; |
|
252 iPropertyKey = KNWRegistrationStatus; |
|
253 break; |
|
254 |
|
255 case ENetworkMode: |
|
256 iPropertyUid = KPSUidNetworkInfo; |
|
257 iPropertyKey = KNWTelephonyNetworkMode; |
|
258 break; |
|
259 |
|
260 case EChargingStatus: |
|
261 iPropertyUid = KPSUidHWRMPowerState; |
|
262 iPropertyKey = KHWRMChargingStatus; |
|
263 break; |
|
264 |
|
265 case EFlipStatus: |
|
266 iPropertyUid = KPSUidHWRM; |
|
267 iPropertyKey = KHWRMFlipStatus; |
|
268 break; |
|
269 |
|
270 case EGripStatus: |
|
271 iPropertyUid = KPSUidHWRM; |
|
272 iPropertyKey = KHWRMGripStatus; |
|
273 break; |
|
274 |
|
275 case EInfraRed: |
|
276 iPropertyUid = KIrdaPropertyCategory; |
|
277 iPropertyKey = KIrdaStatus; |
|
278 break; |
|
279 |
|
280 case EMemoryCard: |
|
281 iPropertyUid = KPSUidUikon; |
|
282 iPropertyKey = KUikMMCInserted; |
|
283 break; |
|
284 |
|
285 default: |
|
286 User::Leave(KErrNotFound); |
|
287 } |
|
288 |
|
289 User::LeaveIfError (iProperty.Attach(iPropertyUid,iPropertyKey)); |
|
290 // Make local copy of SA. |
|
291 iEntity = aRequest.Entity().AllocL(); |
|
292 iKey = aRequest.Key().AllocL(); |
|
293 } |
|
294 |
|
295 // -------------------------------------------------------------------- |
|
296 // CPubSubNotifier::Request() |
|
297 // Issues notification request. |
|
298 // -------------------------------------------------------------------- |
|
299 // |
|
300 TInt CPubSubNotifier::Request() |
|
301 { |
|
302 if( !IsActive() ) |
|
303 { |
|
304 iProperty.Subscribe(iStatus); |
|
305 SetActive (); |
|
306 } |
|
307 return KErrNone; |
|
308 } |
|
309 |
|
310 // -------------------------------------------------------------------- |
|
311 // CPubSubNotifier::RunL() |
|
312 // Gets called in event of request completion or error situation. |
|
313 // -------------------------------------------------------------------- |
|
314 // |
|
315 void CPubSubNotifier::RunL() |
|
316 { |
|
317 //get error. |
|
318 TInt Error(iStatus.Int()); |
|
319 TInt value = 0; |
|
320 |
|
321 if (KErrNone <= Error) |
|
322 { |
|
323 // Re-Issue request |
|
324 Request(); |
|
325 // read value. |
|
326 iProperty.Get(value); |
|
327 switch (iCommand) |
|
328 { |
|
329 case EChargingStatus: |
|
330 // ChargeStatus need to be mapped to one these states Charging, |
|
331 // NotCharging and Unknown |
|
332 if ( EChargingStatusCharging == value || |
|
333 EChargingStatusAlmostComplete == value || |
|
334 EChargingStatusChargingContinued == value ) |
|
335 value = ECharging; |
|
336 |
|
337 else if( EChargingStatusNotConnected == value || |
|
338 EChargingStatusNotCharging == value || |
|
339 EChargingStatusChargingComplete == value) |
|
340 value = ENotCharging; |
|
341 |
|
342 else |
|
343 value = EUnknown; |
|
344 break; |
|
345 |
|
346 case EInfraRed: |
|
347 // IRStatus need to be mapped to one these states |
|
348 // ON, OFF, UNKNOWN. |
|
349 if ( TIrdaStatusCodes::EIrLoaded == value || |
|
350 TIrdaStatusCodes::EIrDiscoveredPeer == value || |
|
351 TIrdaStatusCodes::EIrBlocked == value || |
|
352 TIrdaStatusCodes::EIrLostPeer == value || |
|
353 TIrdaStatusCodes::EIrDisconnected == value ) |
|
354 value = EOn; |
|
355 else if( TIrdaStatusCodes::EIrUnloaded == value ) |
|
356 value = EOff; |
|
357 else |
|
358 value = EUnknown; |
|
359 break; |
|
360 |
|
361 case EFlipStatus: |
|
362 case EGripStatus: |
|
363 if (value == EPSHWRMFlipOpen) |
|
364 value = EOpen; |
|
365 else if (value == EPSHWRMFlipClosed) |
|
366 value = EClosed; |
|
367 else |
|
368 value = EUnknown; |
|
369 break; |
|
370 |
|
371 case ERegistrationStatus: |
|
372 case ENetworkMode : |
|
373 case EMemoryCard: |
|
374 break; |
|
375 |
|
376 default: |
|
377 Error= KErrGeneral; |
|
378 } |
|
379 |
|
380 if((value != iValue)) |
|
381 { |
|
382 iValue = value; |
|
383 //Create output CSysData |
|
384 CStatus* Status = CStatus::NewL(iValue); |
|
385 //Calling Observer Handle. |
|
386 TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity, *iKey, Status, |
|
387 TransactionID(),RequestType(),Error)); |
|
388 } |
|
389 } |
|
390 else |
|
391 { |
|
392 TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity, *iKey, NULL, |
|
393 TransactionID(),RequestType(),Error)); |
|
394 |
|
395 ActiveStore::RemoveRequest(TransactionID()); |
|
396 } |
|
397 |
|
398 } |
|
399 |
|
400 // -------------------------------------------------------------------- |
|
401 // CPubSubNotifier::DoCancel() |
|
402 // Cancel ongoing request. |
|
403 // -------------------------------------------------------------------- |
|
404 // |
|
405 void CPubSubNotifier::DoCancel() |
|
406 { |
|
407 iProperty.Cancel(); |
|
408 } |
|
409 |
|
410 // -------------------------------------------------------------------- |
|
411 // CCriticalMemNotifier::CCriticalMemNotifier() |
|
412 // C++ default constructor. |
|
413 // -------------------------------------------------------------------- |
|
414 // |
|
415 CCriticalMemNotifier::CCriticalMemNotifier(TSysRequest::TRequestType aReqType, |
|
416 TInt32 aTransID,ISystemObserver* aObsrver) |
|
417 :CActiveRequest(aReqType,aTransID,aObsrver) |
|
418 { |
|
419 } |
|
420 |
|
421 // -------------------------------------------------------------------- |
|
422 // CCriticalMemNotifier::~CCriticalMemNotifier() |
|
423 // Destructor. |
|
424 // -------------------------------------------------------------------- |
|
425 // |
|
426 CCriticalMemNotifier::~CCriticalMemNotifier() |
|
427 { |
|
428 Cancel(); |
|
429 iFs.Close(); |
|
430 } |
|
431 |
|
432 // -------------------------------------------------------------------- |
|
433 // CCriticalMemNotifier::NewL() |
|
434 // Two-phased constructor, returns instance of this class. |
|
435 // -------------------------------------------------------------------- |
|
436 // |
|
437 CCriticalMemNotifier* CCriticalMemNotifier::NewL(const TSysRequest& aRequest) |
|
438 { |
|
439 CCriticalMemNotifier* self; |
|
440 self = new (ELeave) CCriticalMemNotifier(aRequest.RequestType(), |
|
441 aRequest.TransactionID(),aRequest.Observer()); |
|
442 |
|
443 CleanupStack::PushL(self); |
|
444 self->ConstructL (aRequest); |
|
445 CleanupStack::Pop(self); |
|
446 |
|
447 return self; |
|
448 } |
|
449 |
|
450 // -------------------------------------------------------------------- |
|
451 // CCriticalMemNotifier::ConstructL() |
|
452 // 2nd Phase constructor to allocate required resources for this obj. |
|
453 // -------------------------------------------------------------------- |
|
454 // |
|
455 void CCriticalMemNotifier::ConstructL(const TSysRequest& aRequest) |
|
456 { |
|
457 //supportes only notifications. |
|
458 if(TSysRequest::ENotification != RequestType()) |
|
459 User::Leave(KErrNotSupported); |
|
460 |
|
461 CDriveInfo* DrvInfo=NULL; |
|
462 //Input validation. |
|
463 if( aRequest.SystemData() && |
|
464 CSysData::EDriveInfo == aRequest.SystemData()->DataType() ) |
|
465 DrvInfo = (CDriveInfo*)aRequest.SystemData(); |
|
466 else |
|
467 User::Leave(KErrArgument); |
|
468 |
|
469 iDrvNumber = DrvInfo->DriveNumber(); |
|
470 iCriticalFreeMemory = DrvInfo->CriticalSpace(); |
|
471 |
|
472 CleanupClosePushL(iFs); |
|
473 User::LeaveIfError(iFs.Connect()); |
|
474 |
|
475 // If Critical Memory not specified assume system defaults. |
|
476 if( -1 == iCriticalFreeMemory ) |
|
477 { |
|
478 TVolumeInfo VolumeInfo; |
|
479 User::LeaveIfError(iFs.Volume(VolumeInfo,iDrvNumber)); |
|
480 if(EMediaRam == VolumeInfo.iDrive.iType) |
|
481 RepositoryUtil::GetRepositoryKeyL(KCRUidDiskLevel, |
|
482 KRamDiskCriticalLevel, iCriticalFreeMemory); |
|
483 else |
|
484 RepositoryUtil::GetRepositoryKeyL(KCRUidDiskLevel, |
|
485 KDiskCriticalThreshold, iCriticalFreeMemory); |
|
486 } |
|
487 CleanupStack::Pop(&iFs); |
|
488 } |
|
489 |
|
490 // -------------------------------------------------------------------- |
|
491 // CCriticalMemNotifier::Request() |
|
492 // Issues notification request. |
|
493 // -------------------------------------------------------------------- |
|
494 // |
|
495 TInt CCriticalMemNotifier::Request () |
|
496 { |
|
497 if( !IsActive() ) |
|
498 { |
|
499 iFs.NotifyDiskSpace(iCriticalFreeMemory,iDrvNumber,iStatus); |
|
500 SetActive(); |
|
501 } |
|
502 return KErrNone; |
|
503 } |
|
504 |
|
505 // -------------------------------------------------------------------- |
|
506 // CCriticalMemNotifier::RunL() |
|
507 // Gets called in event of request completion or error situation. |
|
508 // -------------------------------------------------------------------- |
|
509 // |
|
510 void CCriticalMemNotifier::RunL() |
|
511 { |
|
512 TInt error(iStatus.Int()); |
|
513 |
|
514 if(KErrNone <= error) |
|
515 { |
|
516 //Re-Issue request. |
|
517 Request(); |
|
518 |
|
519 //Specify the Drive number in output CSysData. |
|
520 TBuf<KMaxDriveLength> drv; |
|
521 drv.FillZ(); |
|
522 drv.Append('A'+iDrvNumber); |
|
523 drv.Append(KDriveSeperator); |
|
524 CStringData* drive = CStringData::NewL(drv); |
|
525 |
|
526 TVolumeInfo VolumeInfo; |
|
527 iFs.Volume(VolumeInfo,iDrvNumber); |
|
528 |
|
529 //Call Observer handle. |
|
530 if(VolumeInfo.iFree <= iCriticalFreeMemory) |
|
531 TRAP_IGNORE(SystemObserver()->HandleResponseL(KMemory, KCriticalMemory, |
|
532 drive,TransactionID(),RequestType(),error)); |
|
533 } |
|
534 else |
|
535 { |
|
536 TRAP_IGNORE(SystemObserver()->HandleResponseL(KMemory, KCriticalMemory, |
|
537 NULL,TransactionID(),RequestType(),error)); |
|
538 ActiveStore::RemoveRequest(TransactionID()); |
|
539 } |
|
540 |
|
541 } |
|
542 |
|
543 // -------------------------------------------------------------------- |
|
544 // CPubSubNotifier::DoCancel() |
|
545 // Cancel ongoing request. |
|
546 // -------------------------------------------------------------------- |
|
547 // |
|
548 void CCriticalMemNotifier::DoCancel() |
|
549 { |
|
550 iFs.NotifyDiskSpaceCancel(iStatus); |
|
551 } |
|
552 |
|
553 // End of file |