OSObject *iteratorKey;
OSObject *obj;
+ // do nothing if settings haven't changed
+ if(!settingsChangedSinceUpdate) return;
+
iterator = OSCollectionIterator::withCollection(properties);
if(!iterator) return;
}
iterator->release();
+ settingsChangedSinceUpdate = false;
+
// And up goes the flare
messageClients(kIOPMMessageBatteryStatusHasChanged);
}
*
******************************************************************************/
+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);
}
*
******************************************************************************/
+OSObject *IOPMPowerSource::getPSProperty(const OSSymbol *symmie) {
+ if(!symmie) return NULL;
+ return properties->getObject(symmie);
+}
+
bool IOPMPowerSource::externalConnected(void) {
return (kOSBooleanTrue == properties->getObject(externalConnectedKey));
}