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