1*c54f35caSApple OSS Distributions /*
2*c54f35caSApple OSS Distributions * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved.
3*c54f35caSApple OSS Distributions *
4*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*c54f35caSApple OSS Distributions *
6*c54f35caSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*c54f35caSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*c54f35caSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*c54f35caSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*c54f35caSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*c54f35caSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*c54f35caSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*c54f35caSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*c54f35caSApple OSS Distributions *
15*c54f35caSApple OSS Distributions * Please obtain a copy of the License at
16*c54f35caSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*c54f35caSApple OSS Distributions *
18*c54f35caSApple OSS Distributions * The Original Code and all software distributed under the License are
19*c54f35caSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*c54f35caSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*c54f35caSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*c54f35caSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*c54f35caSApple OSS Distributions * Please see the License for the specific language governing rights and
24*c54f35caSApple OSS Distributions * limitations under the License.
25*c54f35caSApple OSS Distributions *
26*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*c54f35caSApple OSS Distributions */
28*c54f35caSApple OSS Distributions
29*c54f35caSApple OSS Distributions #include <IOKit/pwr_mgt/IOPMPowerSource.h>
30*c54f35caSApple OSS Distributions #include <IOKit/pwr_mgt/IOPM.h>
31*c54f35caSApple OSS Distributions #include <IOKit/IOMessage.h>
32*c54f35caSApple OSS Distributions #include <IOKit/IOLib.h>
33*c54f35caSApple OSS Distributions #include <os/log.h>
34*c54f35caSApple OSS Distributions
35*c54f35caSApple OSS Distributions #define super IOService
36*c54f35caSApple OSS Distributions
OSDefineMetaClassAndStructors(IOPMPowerSource,IOService)37*c54f35caSApple OSS Distributions OSDefineMetaClassAndStructors(IOPMPowerSource, IOService)
38*c54f35caSApple OSS Distributions
39*c54f35caSApple OSS Distributions // *****************************************************************************
40*c54f35caSApple OSS Distributions // powerSource
41*c54f35caSApple OSS Distributions //
42*c54f35caSApple OSS Distributions // Static initializer for IOPMPowerSource. Returns a new instance of the class
43*c54f35caSApple OSS Distributions // which the caller must attach to the power plane.
44*c54f35caSApple OSS Distributions // *****************************************************************************
45*c54f35caSApple OSS Distributions
46*c54f35caSApple OSS Distributions IOPMPowerSource *IOPMPowerSource::powerSource(void)
47*c54f35caSApple OSS Distributions {
48*c54f35caSApple OSS Distributions IOPMPowerSource *ps = new IOPMPowerSource;
49*c54f35caSApple OSS Distributions
50*c54f35caSApple OSS Distributions if (ps) {
51*c54f35caSApple OSS Distributions ps->init();
52*c54f35caSApple OSS Distributions return ps;
53*c54f35caSApple OSS Distributions }
54*c54f35caSApple OSS Distributions return NULL;
55*c54f35caSApple OSS Distributions }
56*c54f35caSApple OSS Distributions
57*c54f35caSApple OSS Distributions // *****************************************************************************
58*c54f35caSApple OSS Distributions // init
59*c54f35caSApple OSS Distributions //
60*c54f35caSApple OSS Distributions // *****************************************************************************
61*c54f35caSApple OSS Distributions bool
init(void)62*c54f35caSApple OSS Distributions IOPMPowerSource::init(void)
63*c54f35caSApple OSS Distributions {
64*c54f35caSApple OSS Distributions if (!super::init()) {
65*c54f35caSApple OSS Distributions return false;
66*c54f35caSApple OSS Distributions }
67*c54f35caSApple OSS Distributions
68*c54f35caSApple OSS Distributions nextInList = NULL;
69*c54f35caSApple OSS Distributions
70*c54f35caSApple OSS Distributions properties = OSDictionary::withCapacity(10);
71*c54f35caSApple OSS Distributions if (!properties) {
72*c54f35caSApple OSS Distributions return false;
73*c54f35caSApple OSS Distributions }
74*c54f35caSApple OSS Distributions properties->setCapacityIncrement(1);
75*c54f35caSApple OSS Distributions
76*c54f35caSApple OSS Distributions externalConnectedKey = OSSymbol::withCString(kIOPMPSExternalConnectedKey);
77*c54f35caSApple OSS Distributions externalChargeCapableKey = OSSymbol::withCString(kIOPMPSExternalChargeCapableKey);
78*c54f35caSApple OSS Distributions batteryInstalledKey = OSSymbol::withCString(kIOPMPSBatteryInstalledKey);
79*c54f35caSApple OSS Distributions chargingKey = OSSymbol::withCString(kIOPMPSIsChargingKey);
80*c54f35caSApple OSS Distributions warnLevelKey = OSSymbol::withCString(kIOPMPSAtWarnLevelKey);
81*c54f35caSApple OSS Distributions criticalLevelKey = OSSymbol::withCString(kIOPMPSAtCriticalLevelKey);
82*c54f35caSApple OSS Distributions currentCapacityKey = OSSymbol::withCString(kIOPMPSCurrentCapacityKey);
83*c54f35caSApple OSS Distributions maxCapacityKey = OSSymbol::withCString(kIOPMPSMaxCapacityKey);
84*c54f35caSApple OSS Distributions timeRemainingKey = OSSymbol::withCString(kIOPMPSTimeRemainingKey);
85*c54f35caSApple OSS Distributions amperageKey = OSSymbol::withCString(kIOPMPSAmperageKey);
86*c54f35caSApple OSS Distributions voltageKey = OSSymbol::withCString(kIOPMPSVoltageKey);
87*c54f35caSApple OSS Distributions cycleCountKey = OSSymbol::withCString(kIOPMPSCycleCountKey);
88*c54f35caSApple OSS Distributions adapterInfoKey = OSSymbol::withCString(kIOPMPSAdapterInfoKey);
89*c54f35caSApple OSS Distributions locationKey = OSSymbol::withCString(kIOPMPSLocationKey);
90*c54f35caSApple OSS Distributions errorConditionKey = OSSymbol::withCString(kIOPMPSErrorConditionKey);
91*c54f35caSApple OSS Distributions manufacturerKey = OSSymbol::withCString(kIOPMPSManufacturerKey);
92*c54f35caSApple OSS Distributions modelKey = OSSymbol::withCString(kIOPMPSModelKey);
93*c54f35caSApple OSS Distributions serialKey = OSSymbol::withCString(kIOPMPSSerialKey);
94*c54f35caSApple OSS Distributions batteryInfoKey = OSSymbol::withCString(kIOPMPSLegacyBatteryInfoKey);
95*c54f35caSApple OSS Distributions
96*c54f35caSApple OSS Distributions return true;
97*c54f35caSApple OSS Distributions }
98*c54f35caSApple OSS Distributions
99*c54f35caSApple OSS Distributions // *****************************************************************************
100*c54f35caSApple OSS Distributions // free
101*c54f35caSApple OSS Distributions //
102*c54f35caSApple OSS Distributions // *****************************************************************************
103*c54f35caSApple OSS Distributions void
free(void)104*c54f35caSApple OSS Distributions IOPMPowerSource::free(void)
105*c54f35caSApple OSS Distributions {
106*c54f35caSApple OSS Distributions if (properties) {
107*c54f35caSApple OSS Distributions properties->release();
108*c54f35caSApple OSS Distributions }
109*c54f35caSApple OSS Distributions if (externalConnectedKey) {
110*c54f35caSApple OSS Distributions externalConnectedKey->release();
111*c54f35caSApple OSS Distributions }
112*c54f35caSApple OSS Distributions if (externalChargeCapableKey) {
113*c54f35caSApple OSS Distributions externalChargeCapableKey->release();
114*c54f35caSApple OSS Distributions }
115*c54f35caSApple OSS Distributions if (batteryInstalledKey) {
116*c54f35caSApple OSS Distributions batteryInstalledKey->release();
117*c54f35caSApple OSS Distributions }
118*c54f35caSApple OSS Distributions if (chargingKey) {
119*c54f35caSApple OSS Distributions chargingKey->release();
120*c54f35caSApple OSS Distributions }
121*c54f35caSApple OSS Distributions if (warnLevelKey) {
122*c54f35caSApple OSS Distributions warnLevelKey->release();
123*c54f35caSApple OSS Distributions }
124*c54f35caSApple OSS Distributions if (criticalLevelKey) {
125*c54f35caSApple OSS Distributions criticalLevelKey->release();
126*c54f35caSApple OSS Distributions }
127*c54f35caSApple OSS Distributions if (currentCapacityKey) {
128*c54f35caSApple OSS Distributions currentCapacityKey->release();
129*c54f35caSApple OSS Distributions }
130*c54f35caSApple OSS Distributions if (maxCapacityKey) {
131*c54f35caSApple OSS Distributions maxCapacityKey->release();
132*c54f35caSApple OSS Distributions }
133*c54f35caSApple OSS Distributions if (timeRemainingKey) {
134*c54f35caSApple OSS Distributions timeRemainingKey->release();
135*c54f35caSApple OSS Distributions }
136*c54f35caSApple OSS Distributions if (amperageKey) {
137*c54f35caSApple OSS Distributions amperageKey->release();
138*c54f35caSApple OSS Distributions }
139*c54f35caSApple OSS Distributions if (voltageKey) {
140*c54f35caSApple OSS Distributions voltageKey->release();
141*c54f35caSApple OSS Distributions }
142*c54f35caSApple OSS Distributions if (cycleCountKey) {
143*c54f35caSApple OSS Distributions cycleCountKey->release();
144*c54f35caSApple OSS Distributions }
145*c54f35caSApple OSS Distributions if (adapterInfoKey) {
146*c54f35caSApple OSS Distributions adapterInfoKey->release();
147*c54f35caSApple OSS Distributions }
148*c54f35caSApple OSS Distributions if (errorConditionKey) {
149*c54f35caSApple OSS Distributions errorConditionKey->release();
150*c54f35caSApple OSS Distributions }
151*c54f35caSApple OSS Distributions if (manufacturerKey) {
152*c54f35caSApple OSS Distributions manufacturerKey->release();
153*c54f35caSApple OSS Distributions }
154*c54f35caSApple OSS Distributions if (modelKey) {
155*c54f35caSApple OSS Distributions modelKey->release();
156*c54f35caSApple OSS Distributions }
157*c54f35caSApple OSS Distributions if (serialKey) {
158*c54f35caSApple OSS Distributions serialKey->release();
159*c54f35caSApple OSS Distributions }
160*c54f35caSApple OSS Distributions if (locationKey) {
161*c54f35caSApple OSS Distributions locationKey->release();
162*c54f35caSApple OSS Distributions }
163*c54f35caSApple OSS Distributions if (batteryInfoKey) {
164*c54f35caSApple OSS Distributions batteryInfoKey->release();
165*c54f35caSApple OSS Distributions }
166*c54f35caSApple OSS Distributions
167*c54f35caSApple OSS Distributions super::free();
168*c54f35caSApple OSS Distributions }
169*c54f35caSApple OSS Distributions
170*c54f35caSApple OSS Distributions // *****************************************************************************
171*c54f35caSApple OSS Distributions // updateStatus
172*c54f35caSApple OSS Distributions //
173*c54f35caSApple OSS Distributions // Update power source state in IORegistry and message interested clients
174*c54f35caSApple OSS Distributions // notifying them of our change.
175*c54f35caSApple OSS Distributions // *****************************************************************************
176*c54f35caSApple OSS Distributions void
updateStatus(void)177*c54f35caSApple OSS Distributions IOPMPowerSource::updateStatus(void)
178*c54f35caSApple OSS Distributions {
179*c54f35caSApple OSS Distributions OSCollectionIterator *iterator;
180*c54f35caSApple OSS Distributions OSObject *iteratorKey;
181*c54f35caSApple OSS Distributions OSObject *obj;
182*c54f35caSApple OSS Distributions
183*c54f35caSApple OSS Distributions // do nothing if settings haven't changed
184*c54f35caSApple OSS Distributions if (!settingsChangedSinceUpdate) {
185*c54f35caSApple OSS Distributions return;
186*c54f35caSApple OSS Distributions }
187*c54f35caSApple OSS Distributions
188*c54f35caSApple OSS Distributions iterator = OSCollectionIterator::withCollection(properties);
189*c54f35caSApple OSS Distributions if (!iterator) {
190*c54f35caSApple OSS Distributions return;
191*c54f35caSApple OSS Distributions }
192*c54f35caSApple OSS Distributions
193*c54f35caSApple OSS Distributions while ((iteratorKey = iterator->getNextObject())) {
194*c54f35caSApple OSS Distributions OSSymbol *key;
195*c54f35caSApple OSS Distributions
196*c54f35caSApple OSS Distributions key = OSDynamicCast(OSSymbol, iteratorKey);
197*c54f35caSApple OSS Distributions if (!key) {
198*c54f35caSApple OSS Distributions continue;
199*c54f35caSApple OSS Distributions }
200*c54f35caSApple OSS Distributions obj = properties->getObject(key);
201*c54f35caSApple OSS Distributions if (!obj) {
202*c54f35caSApple OSS Distributions continue;
203*c54f35caSApple OSS Distributions }
204*c54f35caSApple OSS Distributions setProperty(key, obj);
205*c54f35caSApple OSS Distributions }
206*c54f35caSApple OSS Distributions iterator->release();
207*c54f35caSApple OSS Distributions
208*c54f35caSApple OSS Distributions settingsChangedSinceUpdate = false;
209*c54f35caSApple OSS Distributions
210*c54f35caSApple OSS Distributions // And up goes the flare
211*c54f35caSApple OSS Distributions IOMessage notifyMessage = kIOPMMessageBatteryStatusHasChanged;
212*c54f35caSApple OSS Distributions #if DEVELOPMENT || DEBUG
213*c54f35caSApple OSS Distributions os_log(OS_LOG_DEFAULT, "notify clients '%u'\n", (unsigned int)notifyMessage);
214*c54f35caSApple OSS Distributions #endif
215*c54f35caSApple OSS Distributions messageClients(notifyMessage);
216*c54f35caSApple OSS Distributions }
217*c54f35caSApple OSS Distributions
218*c54f35caSApple OSS Distributions
219*c54f35caSApple OSS Distributions /*******************************************************************************
220*c54f35caSApple OSS Distributions *
221*c54f35caSApple OSS Distributions * PROTECTED Accessors. All the setters! Yay!
222*c54f35caSApple OSS Distributions *
223*c54f35caSApple OSS Distributions ******************************************************************************/
224*c54f35caSApple OSS Distributions
225*c54f35caSApple OSS Distributions void
setPSProperty(const OSSymbol * key,OSObject * val)226*c54f35caSApple OSS Distributions IOPMPowerSource::setPSProperty(const OSSymbol *key, OSObject *val)
227*c54f35caSApple OSS Distributions {
228*c54f35caSApple OSS Distributions OSObject *lastVal;
229*c54f35caSApple OSS Distributions
230*c54f35caSApple OSS Distributions if (!key || !val) {
231*c54f35caSApple OSS Distributions return;
232*c54f35caSApple OSS Distributions }
233*c54f35caSApple OSS Distributions
234*c54f35caSApple OSS Distributions // Compare new setting with existing setting; update
235*c54f35caSApple OSS Distributions // 'settingsChangedSinceUpdate' if the setting has changed.
236*c54f35caSApple OSS Distributions // If values are OSNumbers, do equality comparison.
237*c54f35caSApple OSS Distributions // Otherwise, just compare pointers.
238*c54f35caSApple OSS Distributions
239*c54f35caSApple OSS Distributions if ((lastVal = properties->getObject(key))) {
240*c54f35caSApple OSS Distributions if (val->isEqualTo(lastVal)) {
241*c54f35caSApple OSS Distributions // settings didn't change
242*c54f35caSApple OSS Distributions } else {
243*c54f35caSApple OSS Distributions // num val is not equal to last val
244*c54f35caSApple OSS Distributions settingsChangedSinceUpdate = true;
245*c54f35caSApple OSS Distributions }
246*c54f35caSApple OSS Distributions } else {
247*c54f35caSApple OSS Distributions // new setting; no last value
248*c54f35caSApple OSS Distributions settingsChangedSinceUpdate = true;
249*c54f35caSApple OSS Distributions }
250*c54f35caSApple OSS Distributions
251*c54f35caSApple OSS Distributions // here's the part where we go crazy.
252*c54f35caSApple OSS Distributions properties->setObject(key, val);
253*c54f35caSApple OSS Distributions }
254*c54f35caSApple OSS Distributions
255*c54f35caSApple OSS Distributions
256*c54f35caSApple OSS Distributions
257*c54f35caSApple OSS Distributions void
setExternalConnected(bool b)258*c54f35caSApple OSS Distributions IOPMPowerSource::setExternalConnected(bool b)
259*c54f35caSApple OSS Distributions {
260*c54f35caSApple OSS Distributions setPSProperty(externalConnectedKey,
261*c54f35caSApple OSS Distributions b ? kOSBooleanTrue : kOSBooleanFalse);
262*c54f35caSApple OSS Distributions }
263*c54f35caSApple OSS Distributions
264*c54f35caSApple OSS Distributions void
setExternalChargeCapable(bool b)265*c54f35caSApple OSS Distributions IOPMPowerSource::setExternalChargeCapable(bool b)
266*c54f35caSApple OSS Distributions {
267*c54f35caSApple OSS Distributions setPSProperty(externalChargeCapableKey,
268*c54f35caSApple OSS Distributions b ? kOSBooleanTrue : kOSBooleanFalse);
269*c54f35caSApple OSS Distributions }
270*c54f35caSApple OSS Distributions
271*c54f35caSApple OSS Distributions void
setBatteryInstalled(bool b)272*c54f35caSApple OSS Distributions IOPMPowerSource::setBatteryInstalled(bool b)
273*c54f35caSApple OSS Distributions {
274*c54f35caSApple OSS Distributions setPSProperty(batteryInstalledKey,
275*c54f35caSApple OSS Distributions b ? kOSBooleanTrue : kOSBooleanFalse);
276*c54f35caSApple OSS Distributions }
277*c54f35caSApple OSS Distributions
278*c54f35caSApple OSS Distributions void
setIsCharging(bool b)279*c54f35caSApple OSS Distributions IOPMPowerSource::setIsCharging(bool b)
280*c54f35caSApple OSS Distributions {
281*c54f35caSApple OSS Distributions setPSProperty(chargingKey,
282*c54f35caSApple OSS Distributions b ? kOSBooleanTrue : kOSBooleanFalse);
283*c54f35caSApple OSS Distributions }
284*c54f35caSApple OSS Distributions
285*c54f35caSApple OSS Distributions void
setAtWarnLevel(bool b)286*c54f35caSApple OSS Distributions IOPMPowerSource::setAtWarnLevel(bool b)
287*c54f35caSApple OSS Distributions {
288*c54f35caSApple OSS Distributions setPSProperty(warnLevelKey,
289*c54f35caSApple OSS Distributions b ? kOSBooleanTrue : kOSBooleanFalse);
290*c54f35caSApple OSS Distributions }
291*c54f35caSApple OSS Distributions
292*c54f35caSApple OSS Distributions void
setAtCriticalLevel(bool b)293*c54f35caSApple OSS Distributions IOPMPowerSource::setAtCriticalLevel(bool b)
294*c54f35caSApple OSS Distributions {
295*c54f35caSApple OSS Distributions setPSProperty(criticalLevelKey,
296*c54f35caSApple OSS Distributions b ? kOSBooleanTrue : kOSBooleanFalse);
297*c54f35caSApple OSS Distributions }
298*c54f35caSApple OSS Distributions
299*c54f35caSApple OSS Distributions
300*c54f35caSApple OSS Distributions void
setCurrentCapacity(unsigned int val)301*c54f35caSApple OSS Distributions IOPMPowerSource::setCurrentCapacity(unsigned int val)
302*c54f35caSApple OSS Distributions {
303*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
304*c54f35caSApple OSS Distributions setPSProperty(currentCapacityKey, n);
305*c54f35caSApple OSS Distributions n->release();
306*c54f35caSApple OSS Distributions }
307*c54f35caSApple OSS Distributions
308*c54f35caSApple OSS Distributions void
setMaxCapacity(unsigned int val)309*c54f35caSApple OSS Distributions IOPMPowerSource::setMaxCapacity(unsigned int val)
310*c54f35caSApple OSS Distributions {
311*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
312*c54f35caSApple OSS Distributions setPSProperty(maxCapacityKey, n);
313*c54f35caSApple OSS Distributions n->release();
314*c54f35caSApple OSS Distributions }
315*c54f35caSApple OSS Distributions
316*c54f35caSApple OSS Distributions void
setTimeRemaining(int val)317*c54f35caSApple OSS Distributions IOPMPowerSource::setTimeRemaining(int val)
318*c54f35caSApple OSS Distributions {
319*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
320*c54f35caSApple OSS Distributions setPSProperty(timeRemainingKey, n);
321*c54f35caSApple OSS Distributions n->release();
322*c54f35caSApple OSS Distributions }
323*c54f35caSApple OSS Distributions
324*c54f35caSApple OSS Distributions void
setAmperage(int val)325*c54f35caSApple OSS Distributions IOPMPowerSource::setAmperage(int val)
326*c54f35caSApple OSS Distributions {
327*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
328*c54f35caSApple OSS Distributions setPSProperty(amperageKey, n);
329*c54f35caSApple OSS Distributions n->release();
330*c54f35caSApple OSS Distributions }
331*c54f35caSApple OSS Distributions
332*c54f35caSApple OSS Distributions void
setVoltage(unsigned int val)333*c54f35caSApple OSS Distributions IOPMPowerSource::setVoltage(unsigned int val)
334*c54f35caSApple OSS Distributions {
335*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
336*c54f35caSApple OSS Distributions setPSProperty(voltageKey, n);
337*c54f35caSApple OSS Distributions n->release();
338*c54f35caSApple OSS Distributions }
339*c54f35caSApple OSS Distributions
340*c54f35caSApple OSS Distributions void
setCycleCount(unsigned int val)341*c54f35caSApple OSS Distributions IOPMPowerSource::setCycleCount(unsigned int val)
342*c54f35caSApple OSS Distributions {
343*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
344*c54f35caSApple OSS Distributions setPSProperty(cycleCountKey, n);
345*c54f35caSApple OSS Distributions n->release();
346*c54f35caSApple OSS Distributions }
347*c54f35caSApple OSS Distributions
348*c54f35caSApple OSS Distributions void
setAdapterInfo(int val)349*c54f35caSApple OSS Distributions IOPMPowerSource::setAdapterInfo(int val)
350*c54f35caSApple OSS Distributions {
351*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
352*c54f35caSApple OSS Distributions setPSProperty(adapterInfoKey, n);
353*c54f35caSApple OSS Distributions n->release();
354*c54f35caSApple OSS Distributions }
355*c54f35caSApple OSS Distributions
356*c54f35caSApple OSS Distributions void
setLocation(int val)357*c54f35caSApple OSS Distributions IOPMPowerSource::setLocation(int val)
358*c54f35caSApple OSS Distributions {
359*c54f35caSApple OSS Distributions OSNumber *n = OSNumber::withNumber(val, 32);
360*c54f35caSApple OSS Distributions setPSProperty(locationKey, n);
361*c54f35caSApple OSS Distributions n->release();
362*c54f35caSApple OSS Distributions }
363*c54f35caSApple OSS Distributions
364*c54f35caSApple OSS Distributions void
setErrorCondition(OSSymbol * s)365*c54f35caSApple OSS Distributions IOPMPowerSource::setErrorCondition(OSSymbol *s)
366*c54f35caSApple OSS Distributions {
367*c54f35caSApple OSS Distributions setPSProperty(errorConditionKey, s);
368*c54f35caSApple OSS Distributions }
369*c54f35caSApple OSS Distributions
370*c54f35caSApple OSS Distributions void
setManufacturer(OSSymbol * s)371*c54f35caSApple OSS Distributions IOPMPowerSource::setManufacturer(OSSymbol *s)
372*c54f35caSApple OSS Distributions {
373*c54f35caSApple OSS Distributions setPSProperty(manufacturerKey, s);
374*c54f35caSApple OSS Distributions }
375*c54f35caSApple OSS Distributions
376*c54f35caSApple OSS Distributions void
setModel(OSSymbol * s)377*c54f35caSApple OSS Distributions IOPMPowerSource::setModel(OSSymbol *s)
378*c54f35caSApple OSS Distributions {
379*c54f35caSApple OSS Distributions setPSProperty(modelKey, s);
380*c54f35caSApple OSS Distributions }
381*c54f35caSApple OSS Distributions
382*c54f35caSApple OSS Distributions void
setSerial(OSSymbol * s)383*c54f35caSApple OSS Distributions IOPMPowerSource::setSerial(OSSymbol *s)
384*c54f35caSApple OSS Distributions {
385*c54f35caSApple OSS Distributions setPSProperty(serialKey, s);
386*c54f35caSApple OSS Distributions }
387*c54f35caSApple OSS Distributions
388*c54f35caSApple OSS Distributions void
setLegacyIOBatteryInfo(OSDictionary * d)389*c54f35caSApple OSS Distributions IOPMPowerSource::setLegacyIOBatteryInfo(OSDictionary *d)
390*c54f35caSApple OSS Distributions {
391*c54f35caSApple OSS Distributions setPSProperty(batteryInfoKey, d);
392*c54f35caSApple OSS Distributions }
393*c54f35caSApple OSS Distributions
394*c54f35caSApple OSS Distributions
395*c54f35caSApple OSS Distributions
396*c54f35caSApple OSS Distributions
397*c54f35caSApple OSS Distributions /*******************************************************************************
398*c54f35caSApple OSS Distributions *
399*c54f35caSApple OSS Distributions * PUBLIC Accessors. All the getters! Boo!
400*c54f35caSApple OSS Distributions *
401*c54f35caSApple OSS Distributions ******************************************************************************/
402*c54f35caSApple OSS Distributions
403*c54f35caSApple OSS Distributions OSObject *
getPSProperty(const OSSymbol * symmie)404*c54f35caSApple OSS Distributions IOPMPowerSource::getPSProperty(const OSSymbol *symmie)
405*c54f35caSApple OSS Distributions {
406*c54f35caSApple OSS Distributions if (!symmie) {
407*c54f35caSApple OSS Distributions return NULL;
408*c54f35caSApple OSS Distributions }
409*c54f35caSApple OSS Distributions return properties->getObject(symmie);
410*c54f35caSApple OSS Distributions }
411*c54f35caSApple OSS Distributions
412*c54f35caSApple OSS Distributions bool
externalConnected(void)413*c54f35caSApple OSS Distributions IOPMPowerSource::externalConnected(void)
414*c54f35caSApple OSS Distributions {
415*c54f35caSApple OSS Distributions return kOSBooleanTrue == properties->getObject(externalConnectedKey);
416*c54f35caSApple OSS Distributions }
417*c54f35caSApple OSS Distributions
418*c54f35caSApple OSS Distributions bool
externalChargeCapable(void)419*c54f35caSApple OSS Distributions IOPMPowerSource::externalChargeCapable(void)
420*c54f35caSApple OSS Distributions {
421*c54f35caSApple OSS Distributions return kOSBooleanTrue == properties->getObject(externalChargeCapableKey);
422*c54f35caSApple OSS Distributions }
423*c54f35caSApple OSS Distributions
424*c54f35caSApple OSS Distributions bool
batteryInstalled(void)425*c54f35caSApple OSS Distributions IOPMPowerSource::batteryInstalled(void)
426*c54f35caSApple OSS Distributions {
427*c54f35caSApple OSS Distributions return kOSBooleanTrue == properties->getObject(batteryInstalledKey);
428*c54f35caSApple OSS Distributions }
429*c54f35caSApple OSS Distributions
430*c54f35caSApple OSS Distributions bool
isCharging(void)431*c54f35caSApple OSS Distributions IOPMPowerSource::isCharging(void)
432*c54f35caSApple OSS Distributions {
433*c54f35caSApple OSS Distributions return kOSBooleanTrue == properties->getObject(chargingKey);
434*c54f35caSApple OSS Distributions }
435*c54f35caSApple OSS Distributions
436*c54f35caSApple OSS Distributions bool
atWarnLevel(void)437*c54f35caSApple OSS Distributions IOPMPowerSource::atWarnLevel(void)
438*c54f35caSApple OSS Distributions {
439*c54f35caSApple OSS Distributions return kOSBooleanTrue == properties->getObject(warnLevelKey);
440*c54f35caSApple OSS Distributions }
441*c54f35caSApple OSS Distributions
442*c54f35caSApple OSS Distributions bool
atCriticalLevel(void)443*c54f35caSApple OSS Distributions IOPMPowerSource::atCriticalLevel(void)
444*c54f35caSApple OSS Distributions {
445*c54f35caSApple OSS Distributions return kOSBooleanTrue == properties->getObject(criticalLevelKey);
446*c54f35caSApple OSS Distributions }
447*c54f35caSApple OSS Distributions
448*c54f35caSApple OSS Distributions unsigned int
currentCapacity(void)449*c54f35caSApple OSS Distributions IOPMPowerSource::currentCapacity(void)
450*c54f35caSApple OSS Distributions {
451*c54f35caSApple OSS Distributions OSNumber *n;
452*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(currentCapacityKey));
453*c54f35caSApple OSS Distributions if (!n) {
454*c54f35caSApple OSS Distributions return 0;
455*c54f35caSApple OSS Distributions } else {
456*c54f35caSApple OSS Distributions return (unsigned int)n->unsigned32BitValue();
457*c54f35caSApple OSS Distributions }
458*c54f35caSApple OSS Distributions }
459*c54f35caSApple OSS Distributions
460*c54f35caSApple OSS Distributions unsigned int
maxCapacity(void)461*c54f35caSApple OSS Distributions IOPMPowerSource::maxCapacity(void)
462*c54f35caSApple OSS Distributions {
463*c54f35caSApple OSS Distributions OSNumber *n;
464*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(maxCapacityKey));
465*c54f35caSApple OSS Distributions if (!n) {
466*c54f35caSApple OSS Distributions return 0;
467*c54f35caSApple OSS Distributions } else {
468*c54f35caSApple OSS Distributions return (unsigned int)n->unsigned32BitValue();
469*c54f35caSApple OSS Distributions }
470*c54f35caSApple OSS Distributions }
471*c54f35caSApple OSS Distributions
472*c54f35caSApple OSS Distributions unsigned int
capacityPercentRemaining(void)473*c54f35caSApple OSS Distributions IOPMPowerSource::capacityPercentRemaining(void)
474*c54f35caSApple OSS Distributions {
475*c54f35caSApple OSS Distributions unsigned int _currentCapacity = currentCapacity();
476*c54f35caSApple OSS Distributions unsigned int _maxCapacity = maxCapacity();
477*c54f35caSApple OSS Distributions if (0 == _maxCapacity) {
478*c54f35caSApple OSS Distributions return 0;
479*c54f35caSApple OSS Distributions } else {
480*c54f35caSApple OSS Distributions return (100 * _currentCapacity) / _maxCapacity;
481*c54f35caSApple OSS Distributions }
482*c54f35caSApple OSS Distributions }
483*c54f35caSApple OSS Distributions
484*c54f35caSApple OSS Distributions int
timeRemaining(void)485*c54f35caSApple OSS Distributions IOPMPowerSource::timeRemaining(void)
486*c54f35caSApple OSS Distributions {
487*c54f35caSApple OSS Distributions OSNumber *n;
488*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(timeRemainingKey));
489*c54f35caSApple OSS Distributions if (!n) {
490*c54f35caSApple OSS Distributions return 0;
491*c54f35caSApple OSS Distributions } else {
492*c54f35caSApple OSS Distributions return (int)n->unsigned32BitValue();
493*c54f35caSApple OSS Distributions }
494*c54f35caSApple OSS Distributions }
495*c54f35caSApple OSS Distributions
496*c54f35caSApple OSS Distributions int
amperage(void)497*c54f35caSApple OSS Distributions IOPMPowerSource::amperage(void)
498*c54f35caSApple OSS Distributions {
499*c54f35caSApple OSS Distributions OSNumber *n;
500*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(amperageKey));
501*c54f35caSApple OSS Distributions if (!n) {
502*c54f35caSApple OSS Distributions return 0;
503*c54f35caSApple OSS Distributions } else {
504*c54f35caSApple OSS Distributions return (int)n->unsigned32BitValue();
505*c54f35caSApple OSS Distributions }
506*c54f35caSApple OSS Distributions }
507*c54f35caSApple OSS Distributions
508*c54f35caSApple OSS Distributions unsigned int
voltage(void)509*c54f35caSApple OSS Distributions IOPMPowerSource::voltage(void)
510*c54f35caSApple OSS Distributions {
511*c54f35caSApple OSS Distributions OSNumber *n;
512*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(voltageKey));
513*c54f35caSApple OSS Distributions if (!n) {
514*c54f35caSApple OSS Distributions return 0;
515*c54f35caSApple OSS Distributions } else {
516*c54f35caSApple OSS Distributions return (unsigned int)n->unsigned32BitValue();
517*c54f35caSApple OSS Distributions }
518*c54f35caSApple OSS Distributions }
519*c54f35caSApple OSS Distributions
520*c54f35caSApple OSS Distributions unsigned int
cycleCount(void)521*c54f35caSApple OSS Distributions IOPMPowerSource::cycleCount(void)
522*c54f35caSApple OSS Distributions {
523*c54f35caSApple OSS Distributions OSNumber *n;
524*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(cycleCountKey));
525*c54f35caSApple OSS Distributions if (!n) {
526*c54f35caSApple OSS Distributions return 0;
527*c54f35caSApple OSS Distributions } else {
528*c54f35caSApple OSS Distributions return (unsigned int)n->unsigned32BitValue();
529*c54f35caSApple OSS Distributions }
530*c54f35caSApple OSS Distributions }
531*c54f35caSApple OSS Distributions
532*c54f35caSApple OSS Distributions int
adapterInfo(void)533*c54f35caSApple OSS Distributions IOPMPowerSource::adapterInfo(void)
534*c54f35caSApple OSS Distributions {
535*c54f35caSApple OSS Distributions OSNumber *n;
536*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(adapterInfoKey));
537*c54f35caSApple OSS Distributions if (!n) {
538*c54f35caSApple OSS Distributions return 0;
539*c54f35caSApple OSS Distributions } else {
540*c54f35caSApple OSS Distributions return (int)n->unsigned32BitValue();
541*c54f35caSApple OSS Distributions }
542*c54f35caSApple OSS Distributions }
543*c54f35caSApple OSS Distributions
544*c54f35caSApple OSS Distributions int
location(void)545*c54f35caSApple OSS Distributions IOPMPowerSource::location(void)
546*c54f35caSApple OSS Distributions {
547*c54f35caSApple OSS Distributions OSNumber *n;
548*c54f35caSApple OSS Distributions n = OSDynamicCast(OSNumber, properties->getObject(locationKey));
549*c54f35caSApple OSS Distributions if (!n) {
550*c54f35caSApple OSS Distributions return 0;
551*c54f35caSApple OSS Distributions } else {
552*c54f35caSApple OSS Distributions return (unsigned int)n->unsigned32BitValue();
553*c54f35caSApple OSS Distributions }
554*c54f35caSApple OSS Distributions }
555*c54f35caSApple OSS Distributions
556*c54f35caSApple OSS Distributions OSSymbol *
errorCondition(void)557*c54f35caSApple OSS Distributions IOPMPowerSource::errorCondition(void)
558*c54f35caSApple OSS Distributions {
559*c54f35caSApple OSS Distributions return OSDynamicCast(OSSymbol, properties->getObject(errorConditionKey));
560*c54f35caSApple OSS Distributions }
561*c54f35caSApple OSS Distributions
562*c54f35caSApple OSS Distributions OSSymbol *
manufacturer(void)563*c54f35caSApple OSS Distributions IOPMPowerSource::manufacturer(void)
564*c54f35caSApple OSS Distributions {
565*c54f35caSApple OSS Distributions return OSDynamicCast(OSSymbol, properties->getObject(manufacturerKey));
566*c54f35caSApple OSS Distributions }
567*c54f35caSApple OSS Distributions
568*c54f35caSApple OSS Distributions OSSymbol *
model(void)569*c54f35caSApple OSS Distributions IOPMPowerSource::model(void)
570*c54f35caSApple OSS Distributions {
571*c54f35caSApple OSS Distributions return OSDynamicCast(OSSymbol, properties->getObject(modelKey));
572*c54f35caSApple OSS Distributions }
573*c54f35caSApple OSS Distributions
574*c54f35caSApple OSS Distributions OSSymbol *
serial(void)575*c54f35caSApple OSS Distributions IOPMPowerSource::serial(void)
576*c54f35caSApple OSS Distributions {
577*c54f35caSApple OSS Distributions return OSDynamicCast(OSSymbol, properties->getObject(serialKey));
578*c54f35caSApple OSS Distributions }
579*c54f35caSApple OSS Distributions
580*c54f35caSApple OSS Distributions OSDictionary *
legacyIOBatteryInfo(void)581*c54f35caSApple OSS Distributions IOPMPowerSource::legacyIOBatteryInfo(void)
582*c54f35caSApple OSS Distributions {
583*c54f35caSApple OSS Distributions return OSDynamicCast(OSDictionary, properties->getObject(batteryInfoKey));
584*c54f35caSApple OSS Distributions }
585