X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/5d5c5d0d5b79ade9a973d55186ffda2638ba2b6e..99c3a10404e5d1ef94397ab4df5a8b74711fc4d3:/iokit/Kernel/IOPMPowerSource.cpp diff --git a/iokit/Kernel/IOPMPowerSource.cpp b/iokit/Kernel/IOPMPowerSource.cpp index 1c4b0670c..614f4caa3 100644 --- a/iokit/Kernel/IOPMPowerSource.cpp +++ b/iokit/Kernel/IOPMPowerSource.cpp @@ -1,31 +1,29 @@ /* * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. The rights granted to you under the - * License may not be used to create, or enable the creation or - * redistribution of, unlawful or unlicensed copies of an Apple operating - * system, or to circumvent, violate, or enable the circumvention or - * violation of, any terms of an Apple operating system software license - * agreement. - * - * Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and * limitations under the License. - * - * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #include @@ -134,6 +132,9 @@ void IOPMPowerSource::updateStatus (void) OSObject *iteratorKey; OSObject *obj; + // do nothing if settings haven't changed + if(!settingsChangedSinceUpdate) return; + iterator = OSCollectionIterator::withCollection(properties); if(!iterator) return; @@ -148,6 +149,8 @@ void IOPMPowerSource::updateStatus (void) } iterator->release(); + settingsChangedSinceUpdate = false; + // And up goes the flare messageClients(kIOPMMessageBatteryStatusHasChanged); } @@ -159,125 +162,132 @@ void IOPMPowerSource::updateStatus (void) * ******************************************************************************/ +void IOPMPowerSource::setPSProperty(const OSSymbol *key, OSObject *val) +{ + OSObject *lastVal; + + if(!key || !val) return; + + // Compare new setting with existing setting; update + // 'settingsChangedSinceUpdate' if the setting has changed. + // If values are OSNumbers, do equality comparison. + // Otherwise, just compare pointers. + + if( (lastVal = properties->getObject(key)) ) { + if(val->isEqualTo(lastVal)) { + // settings didn't change + } else { + // num val is not equal to last val + settingsChangedSinceUpdate = true; + } + } else { + // new setting; no last value + settingsChangedSinceUpdate = true; + } + + // here's the part where we go crazy. + properties->setObject(key, val); +} + + + void IOPMPowerSource::setExternalConnected(bool b) { - properties->setObject( - externalConnectedKey, - b ? kOSBooleanTrue:kOSBooleanFalse); + setPSProperty(externalConnectedKey, + b ? kOSBooleanTrue : kOSBooleanFalse); } void IOPMPowerSource::setExternalChargeCapable(bool b) { - properties->setObject( - externalChargeCapableKey, - b ? kOSBooleanTrue:kOSBooleanFalse); + setPSProperty(externalChargeCapableKey, + b ? kOSBooleanTrue : kOSBooleanFalse); } void IOPMPowerSource::setBatteryInstalled(bool b) { - properties->setObject( - batteryInstalledKey, - b ? kOSBooleanTrue:kOSBooleanFalse); + setPSProperty(batteryInstalledKey, + b ? kOSBooleanTrue : kOSBooleanFalse); } void IOPMPowerSource::setIsCharging(bool b) { - properties->setObject( - chargingKey, - b ? kOSBooleanTrue:kOSBooleanFalse); + setPSProperty(chargingKey, + b ? kOSBooleanTrue : kOSBooleanFalse); } void IOPMPowerSource::setAtWarnLevel(bool b) { - properties->setObject( - warnLevelKey, - b ? kOSBooleanTrue:kOSBooleanFalse); + setPSProperty(warnLevelKey, + b ? kOSBooleanTrue : kOSBooleanFalse); } void IOPMPowerSource::setAtCriticalLevel(bool b) { - properties->setObject( - criticalLevelKey, - b ? kOSBooleanTrue:kOSBooleanFalse); + setPSProperty(criticalLevelKey, + b ? kOSBooleanTrue : kOSBooleanFalse); } void IOPMPowerSource::setCurrentCapacity(unsigned int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - currentCapacityKey, - n); + setPSProperty(currentCapacityKey, n); n->release(); } void IOPMPowerSource::setMaxCapacity(unsigned int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - maxCapacityKey, - n); + setPSProperty(maxCapacityKey, n); n->release(); } void IOPMPowerSource::setTimeRemaining(int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - timeRemainingKey, - n); + setPSProperty(timeRemainingKey, n); n->release(); } void IOPMPowerSource::setAmperage(int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - amperageKey, - n); + setPSProperty(amperageKey, n); n->release(); } void IOPMPowerSource::setVoltage(unsigned int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - voltageKey, - n); + setPSProperty(voltageKey, n); n->release(); } void IOPMPowerSource::setCycleCount(unsigned int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - cycleCountKey, - n); + setPSProperty(cycleCountKey, n); n->release(); } void IOPMPowerSource::setAdapterInfo(int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - adapterInfoKey, - n); + setPSProperty(adapterInfoKey, n); n->release(); } void IOPMPowerSource::setLocation(int val) { OSNumber *n = OSNumber::withNumber(val, 32); - properties->setObject( - locationKey, - n); + setPSProperty(locationKey, n); n->release(); } void IOPMPowerSource::setErrorCondition(OSSymbol *s) { - properties->setObject(errorConditionKey, s); + setPSProperty(errorConditionKey, s); } void IOPMPowerSource::setManufacturer(OSSymbol *s) { - properties->setObject(manufacturerKey, s); + setPSProperty(manufacturerKey, s); } void IOPMPowerSource::setModel(OSSymbol *s) { - properties->setObject(modelKey, s); + setPSProperty(modelKey, s); } void IOPMPowerSource::setSerial(OSSymbol *s) { - properties->setObject(serialKey, s); + setPSProperty(serialKey, s); } void IOPMPowerSource::setLegacyIOBatteryInfo(OSDictionary *d) { - properties->setObject(batteryInfoKey, d); + setPSProperty(batteryInfoKey, d); } @@ -289,6 +299,11 @@ void IOPMPowerSource::setLegacyIOBatteryInfo(OSDictionary *d) { * ******************************************************************************/ +OSObject *IOPMPowerSource::getPSProperty(const OSSymbol *symmie) { + if(!symmie) return NULL; + return properties->getObject(symmie); +} + bool IOPMPowerSource::externalConnected(void) { return (kOSBooleanTrue == properties->getObject(externalConnectedKey)); }