|
1 /* |
|
2 * Copyright (c) 2007-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 |
|
19 // INCLUDE FILES |
|
20 #include "BatteryInfoObserver.h" |
|
21 |
|
22 // ======== define patchable constants ====== |
|
23 // Note: patchable constant cannot be defined in the source file it is referred to. |
|
24 #ifdef __EABI__ |
|
25 // for HWRM support. 1 indicate HWRM is available. 0 indicate it is unavailable |
|
26 EXPORT_C extern const TInt32 KHWRMIsSupported = 0; |
|
27 #endif |
|
28 |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 CBatteryInfoObserver* CBatteryInfoObserver::NewL( CHWRMPower& aPower, |
|
33 MBatteryInfoNotifier& aBatteryInfoNotifier ) |
|
34 { |
|
35 CBatteryInfoObserver* self = CBatteryInfoObserver::NewLC( aPower, |
|
36 aBatteryInfoNotifier ); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CBatteryInfoObserver* CBatteryInfoObserver::NewLC( CHWRMPower& aPower, |
|
42 MBatteryInfoNotifier& aBatteryInfoNotifier ) |
|
43 { |
|
44 CBatteryInfoObserver* self = new ( ELeave ) CBatteryInfoObserver( aPower, |
|
45 aBatteryInfoNotifier ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CBatteryInfoObserver::~CBatteryInfoObserver() |
|
52 { |
|
53 if ( iPeriodic ) |
|
54 { |
|
55 iPeriodic->Cancel(); |
|
56 delete iPeriodic; |
|
57 } |
|
58 Cancel(); |
|
59 } |
|
60 |
|
61 void CBatteryInfoObserver::ConstructL() |
|
62 { |
|
63 iPeriodic = CPeriodic::NewL( EPriorityNormal ); |
|
64 // Start the timer with 2 minute interval |
|
65 iPeriodic->Start( TTimeIntervalMicroSeconds32(KHalfSecond), |
|
66 TTimeIntervalMicroSeconds32(KTwoMins), |
|
67 TCallBack(CBatteryInfoObserver::RunTimer, |
|
68 this )); |
|
69 } |
|
70 |
|
71 CBatteryInfoObserver::CBatteryInfoObserver( CHWRMPower& aPower, |
|
72 MBatteryInfoNotifier& aBatteryInfoNotifier ) : |
|
73 CActive( EPriorityStandard ), |
|
74 iPower( aPower ), |
|
75 iBatteryInfoNotifier( aBatteryInfoNotifier ) |
|
76 { |
|
77 CActiveScheduler::Add(this); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CBatteryInfoObserver::RunL |
|
82 // Handles CBatteryInfoObserver::GetBatteryInfo request completion event. |
|
83 // |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CBatteryInfoObserver::RunL() |
|
87 { |
|
88 iBatteryInfoNotifier.NotifyBatteryInfo( iStatus.Int(), iBatteryData ); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CBatteryInfoObserver::DoCancel |
|
93 // Cancellation of an outstanding request |
|
94 // |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CBatteryInfoObserver::DoCancel() |
|
98 { |
|
99 //no cancel for GetBatteryInfo |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CBatteryInfoObserver::GetBatteryInfo |
|
104 // Get battery info from HWRM. |
|
105 // |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CBatteryInfoObserver::GetBatteryInfo() |
|
109 { |
|
110 //Check if active |
|
111 if ( !IsActive() ) |
|
112 { |
|
113 iPower.GetBatteryInfo( iStatus, iBatteryData ); |
|
114 SetActive(); |
|
115 } |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CBatteryInfoObserver::RunTimer |
|
120 // Execute GetBatteryInfo() |
|
121 // |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CBatteryInfoObserver::RunTimer( TAny* aObject ) |
|
125 { |
|
126 ( ( CBatteryInfoObserver* ) aObject )->GetBatteryInfo(); |
|
127 return KErrNone; |
|
128 } |
|
129 |
|
130 // End of File |