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