]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMPowerSource.cpp
xnu-792.17.14.tar.gz
[apple/xnu.git] / iokit / Kernel / IOPMPowerSource.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <IOKit/pwr_mgt/IOPMPowerSource.h>
30
31 #define super OSObject
32
33 OSDefineMetaClassAndStructors(IOPMPowerSource, OSObject)
34
35 // **********************************************************************************
36 // init
37 //
38 // **********************************************************************************
39 bool IOPMPowerSource::init (unsigned short whichBatteryIndex)
40 {
41 if (!super::init ())
42 return false;
43
44 bBatteryIndex = whichBatteryIndex;
45 nextInList = 0;
46
47 return true;
48 }
49
50 // **********************************************************************************
51 // capacityPercentRemaining
52 //
53 // **********************************************************************************
54 unsigned long IOPMPowerSource::capacityPercentRemaining (void)
55 {
56 unsigned long percentage = 0;
57
58 if (bMaxCapacity > 0)
59 percentage = (bCurCapacity * 100) / bMaxCapacity;
60
61 // always return a non-zero value unless the real capacity IS zero.
62 if (percentage == 0 && bCurCapacity > 0)
63 percentage = 1;
64
65 return percentage;
66 }
67
68 // **********************************************************************************
69 // atWarnLevel
70 //
71 // **********************************************************************************
72 bool IOPMPowerSource::atWarnLevel (void)
73 {
74 return bFlags & kBatteryAtWarn;
75 }
76
77 // **********************************************************************************
78 // acConnected
79 //
80 // **********************************************************************************
81 bool IOPMPowerSource::acConnected (void)
82 {
83 return bFlags & kACInstalled;
84 }
85
86 // **********************************************************************************
87 // depleted
88 //
89 // **********************************************************************************
90 bool IOPMPowerSource::depleted (void)
91 {
92 return bFlags & kBatteryDepleted;
93 }
94
95 // **********************************************************************************
96 // isInstalled
97 //
98 // **********************************************************************************
99 bool IOPMPowerSource::isInstalled (void)
100 {
101 return bFlags & kBatteryInstalled;
102 }
103
104 // **********************************************************************************
105 // isCharging
106 //
107 // **********************************************************************************
108 bool IOPMPowerSource::isCharging (void)
109 {
110 return bFlags & kBatteryCharging;
111 }
112
113 // **********************************************************************************
114 // timeRemaining
115 //
116 // **********************************************************************************
117 unsigned long IOPMPowerSource::timeRemaining (void)
118 {
119 return bTimeRemaining;
120 }
121
122 // **********************************************************************************
123 // maxCapacity
124 //
125 // **********************************************************************************
126 unsigned long IOPMPowerSource::maxCapacity (void)
127 {
128 return bMaxCapacity;
129 }
130
131 // **********************************************************************************
132 // curCapacity
133 //
134 // **********************************************************************************
135 unsigned long IOPMPowerSource::curCapacity (void)
136 {
137 return bCurCapacity;
138 }
139
140 // **********************************************************************************
141 // currentDrawn
142 //
143 // **********************************************************************************
144 long IOPMPowerSource::currentDrawn (void)
145 {
146 return bCurrent;
147 }
148
149 // **********************************************************************************
150 // voltage
151 //
152 // **********************************************************************************
153
154 unsigned long IOPMPowerSource::voltage (void)
155 {
156 return bVoltage;
157 }
158
159 // **********************************************************************************
160 // updateStatus
161 //
162 // **********************************************************************************
163
164 void IOPMPowerSource::updateStatus (void)
165 {
166
167 }
168
169
170
171
172