summaryrefslogtreecommitdiffstats
path: root/src/hardware_battery.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-04-15 17:42:29 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-04-15 17:42:29 -0500
commit3ec8230e9f10645de684b5e03471e293481183d7 (patch)
tree0a9f15fcc62fb8a0e84eb8270ff30262274f3f4c /src/hardware_battery.cpp
parent82806a03ea419871940eb3c03c792f3ea15734d9 (diff)
downloadtdepowersave-3ec8230e9f10645de684b5e03471e293481183d7.tar.gz
tdepowersave-3ec8230e9f10645de684b5e03471e293481183d7.zip
Initial migration off of HAL
Diffstat (limited to 'src/hardware_battery.cpp')
-rw-r--r--src/hardware_battery.cpp531
1 files changed, 232 insertions, 299 deletions
diff --git a/src/hardware_battery.cpp b/src/hardware_battery.cpp
index b9809e8..21dc5c9 100644
--- a/src/hardware_battery.cpp
+++ b/src/hardware_battery.cpp
@@ -26,38 +26,54 @@
#include "hardware_battery.h"
-/*! The default constructor of the class Battery. */
-Battery::Battery(dbusHAL* _dbus_HAL) : dbus_HAL(_dbus_HAL) {
- kdDebugFuncIn(trace);
-
- udi = TQString();
- initialized = false;
-
- initDefault();
- init(NULL);
-
- kdDebugFuncOut(trace);
-}
+// FOR REFERENCE
+// udi = '/org/freedesktop/Hal/devices/bme'
+// info.addons = { 'hald-addon-bme' } (string list)
+// maemo.charger.type = 'host 500 mA' (string)
+// maemo.charger.connection_status = 'connected' (string)
+// maemo.rechargeable.charging_status = 'on' (string)
+// maemo.rechargeable.positive_rate = true (bool)
+// battery.present = true (bool)
+// info.product = 'Battery (BME-HAL)' (string)
+// info.subsystem = 'unknown' (string)
+// battery.is_rechargeable = true (bool)
+// info.udi = '/org/freedesktop/Hal/devices/bme' (string)
+// battery.charge_level.unit = 'bars' (string)
+// battery.remaining_time = 7200 (0x1c20) (int)
+// battery.type = 'pda' (string)
+// battery.charge_level.percentage = 71 (0x47) (int)
+// battery.charge_level.design = 8 (0x8) (int)
+// battery.charge_level.capacity_state = 'ok' (string)
+// battery.rechargeable.is_discharging = false (bool)
+// battery.charge_level.last_full = 7 (0x7) (int)
+// battery.reporting.design = 1258 (0x4ea) (int)
+// battery.reporting.last_full = 867 (0x363) (int)
+// battery.reporting.current = 903 (0x387) (int)
+// battery.voltage.unit = 'mV' (string)
+// battery.voltage.design = 4200 (0x1068) (int)
+// info.category = 'battery' (string)
+// battery.voltage.current = 3947 (0xf6b) (int)
+// battery.remaining_time.calculate_per_time = false (bool)
+// info.parent = '/org/freedesktop/Hal/devices/computer' (string)
+// battery.charge_level.current = 7 (0x7) (int)
+// battery.rechargeable.is_charging = true (bool)
+// info.capabilities = { 'battery' } (string list)
+// battery.reporting.unit = 'mAh' (string)
/*! The default constructor of the class Battery. */
-Battery::Battery( dbusHAL* _dbus_HAL, TQString _udi ) : dbus_HAL(_dbus_HAL), udi(_udi) {
+Battery::Battery( TQString _udi ) {
if (trace) kdDebug() << funcinfo << "IN , udi: " << udi << endl;
-
- initialized = false;
- initDefault();
- init(NULL);
+ m_hwdevices = KGlobal::hardwareDevices();
- kdDebugFuncOut(trace);
-}
+ udi = _udi;
-/*! The default constructor of the class Battery. */
-Battery::Battery() {
- kdDebugFuncIn(trace);
+ connect(m_hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(updateProperty(TDEGenericDevice*)));
+
initialized = false;
initDefault();
- udi = TQString();
+ init();
kdDebugFuncOut(trace);
}
@@ -94,26 +110,18 @@ void Battery::initDefault() {
}
//! initialize this battery object with values from HAL
-void Battery::init(dbusHAL* _dbus_HAL) {
+void Battery::init() {
kdDebugFuncIn(trace);
- if (_dbus_HAL != NULL)
- dbus_HAL = _dbus_HAL;
-
// read battery information from HAL
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- //couldnt connect to HAL
- state=BAT_HAL_ERROR;
+ if (resetUdi(udi)) {
+ //udi is valid
+ recheck(); //fills all values
+ //ready here for now
} else {
- if (resetUdi(udi)) {
- //udi is valid
- recheck(); //fills all values
- //ready here for now
- } else {
- //udi is invalid or is no battery
- state=BAT_HAL_ERROR;
- kdWarning() << "Warning: Battery::init cannot make use of udi " << udi << endl;
- }
+ //udi is invalid or is no battery
+ state=BAT_HAL_ERROR;
+ kdWarning() << "Warning: Battery::init cannot make use of udi " << udi << endl;
}
initialized = true;
@@ -127,10 +135,11 @@ void Battery::init(dbusHAL* _dbus_HAL) {
void Battery::minRecheck() {
kdDebugFuncIn(trace);
- //first check whether HAL is available
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
//grr... no luck
- kdError() << "Battery::recheck couldn't connect to HAL" << endl;
+ kdError() << "Battery::recheck couldn't find battery" << endl;
kdDebugFuncOut(trace);
return;
}
@@ -160,10 +169,11 @@ void Battery::minRecheck() {
void Battery::recheck() {
kdDebugFuncIn(trace);
- //first check whether HAL is available
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
//grr... no luck
- kdError() << "Battery::recheck couldn't connect to HAL" << endl;
+ kdError() << "Battery::recheck couldn't find battery" << endl;
kdDebugFuncOut(trace);
return;
}
@@ -203,44 +213,40 @@ bool Battery::checkBatteryPresent () {
kdDebugFuncIn(trace);
bool _present = false;
-
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkBatteryPresent couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
- if (dbus_HAL->halGetPropertyBool(udi,"battery.present", &_present)) {
- if (_present != present) {
- present = _present;
-
- // force depending changes
- if (_present) {
- // should be now present
- recheck();
- }
- if (!_present) {
- //Uhhh, battery is not present, so we need to reset battery to default.
- initDefault();
- checkBatteryType();
- state = BAT_NONE;
- }
-
- if (initialized) {
- emit changedBatteryPresent();
- emit changedBattery();
- }
+ _present = bdevice->installed();
+ if (_present != present) {
+ present = _present;
+
+ // force depending changes
+ if (_present) {
+ // should be now present
+ recheck();
+ }
+ if (!_present) {
+ //Uhhh, battery is not present, so we need to reset battery to default.
+ initDefault();
+ checkBatteryType();
+ state = BAT_NONE;
}
- // also query the serial ... no need to do this in a extra place
- dbus_HAL->halGetPropertyString(udi, "battery.serial", &serial);
-
- } else {
- //query was not successfull
- kdDebug() << "Query of battery.present of " << udi << " wasn't successfull." << endl;
- //..but we assume its there try on
- present = true;
+ if (initialized) {
+ emit changedBatteryPresent();
+ emit changedBattery();
+ }
}
+
+ // also query the serial ... no need to do this in a extra place
+ serial = bdevice->serialNumber();
kdDebugFuncOut(trace);
return true;
@@ -258,12 +264,22 @@ bool Battery::checkBatteryType () {
TQString tmp_qstring;
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkBatteryType couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
+ // FIXME
+ // How can we get battery type from TDE HW library (i.e. how to get type from sysfs)?
+ // For now just report any batteries as primary...
+ type = BAT_PRIMARY;
+ return true;
+
+#if 0
if (dbus_HAL->halGetPropertyString(udi,"battery.type", &tmp_qstring)) {
if (tmp_qstring.compare("primary") == 0) {
type = BAT_PRIMARY;
@@ -290,6 +306,7 @@ bool Battery::checkBatteryType () {
kdDebugFuncOut(trace);
return false;
}
+#endif
}
//! to check battery.technology
@@ -303,9 +320,12 @@ bool Battery::checkBatteryTechnology () {
kdDebugFuncIn(trace);
TQString tmp_qstring;
-
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkBatteryTechnology couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -316,20 +336,14 @@ bool Battery::checkBatteryTechnology () {
return false;
}
- if (dbus_HAL->halGetPropertyString(udi,"battery.technology", &tmp_qstring)) {
- if (!tmp_qstring.isEmpty()) {
- technology = TQString(tmp_qstring);
- } else {
- technology = TQString("UNKNOWN");
- }
- kdDebugFuncOut(trace);
- return true;
+ tmp_qstring = bdevice->technology();
+ if (!tmp_qstring.isEmpty()) {
+ technology = TQString(tmp_qstring);
} else {
- //query was not successfull, but this property is optional
technology = TQString("UNKNOWN");
- kdDebugFuncOut(trace);
- return false;
}
+ kdDebugFuncOut(trace);
+ return true;
}
@@ -344,9 +358,12 @@ bool Battery::checkCapacityState () {
kdDebugFuncIn(trace);
TQString tmp_qstring;
-
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkCapacityState couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -357,16 +374,20 @@ bool Battery::checkCapacityState () {
return false;
}
- if (dbus_HAL->halGetPropertyString(udi, "battery.charge_level.capacity_state", &tmp_qstring)) {
- capacity_state = TQString(tmp_qstring);
- kdDebugFuncOut(trace);
- return true;
- } else {
- //query was not successfull, but this property is optional
- capacity_state = TQString();
- kdDebugFuncOut(trace);
- return false;
+ capacity_state = "unknown";
+ TDEBatteryStatus::TDEBatteryStatus batteryStatus = bdevice->status();
+ if (batteryStatus == TDEBatteryStatus::Charging) {
+ capacity_state = "charging";
+ }
+ if (batteryStatus == TDEBatteryStatus::Discharging) {
+ capacity_state = "discharging";
}
+ if (batteryStatus == TDEBatteryStatus::Full) {
+ capacity_state = "full";
+ }
+
+ kdDebugFuncOut(trace);
+ return true;
}
@@ -379,9 +400,12 @@ bool Battery::checkCapacityState () {
*/
bool Battery::checkChargeLevelCurrent () {
kdDebugFuncIn(trace);
-
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkChargeLevelCurrent couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -392,20 +416,15 @@ bool Battery::checkChargeLevelCurrent () {
return false;
}
- if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.current", &charge_level_current)) {
- if (charge_level_current < 0) {
- //overflow?
- charge_level_current = 0;
- }
- kdDebugFuncOut(trace);
- return true;
- } else {
- //query was not successfull (is mandatory)
- kdError() << "Couldn't request charge_level.current for udi: " << udi << endl;
- state = BAT_NONE;
- kdDebugFuncOut(trace);
- return false;
+ // FIXME VERIFY CORRECTNESS
+ // what does kpowersave expect to see in charge_level_current (battery.charge_level.current)?
+ charge_level_current = bdevice->energy();
+ if (charge_level_current < 0) {
+ //overflow?
+ charge_level_current = 0;
}
+ kdDebugFuncOut(trace);
+ return true;
}
@@ -419,8 +438,11 @@ bool Battery::checkChargeLevelCurrent () {
bool Battery::checkChargeLevelLastfull () {
kdDebugFuncIn(trace);
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkChargeLevelLastfull couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -431,20 +453,15 @@ bool Battery::checkChargeLevelLastfull () {
return false;
}
- if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.last_full", &charge_level_lastfull)) {
- if (charge_level_lastfull < charge_level_current ) {
- //possible overflow?
- charge_level_lastfull = charge_level_current;
- }
- kdDebugFuncOut(trace);
- return true;
- } else {
- //query was not successfull (is mandatory)
- kdError() << "couldn't query last_full of udi: " << udi << endl;
- charge_level_lastfull = 0; // set back to 0
- kdDebugFuncOut(trace);
- return false;
+ // FIXME VERIFY CORRECTNESS
+ // what does kpowersave expect to see in charge_level_lastfull (battery.charge_level.last_full)?
+ charge_level_lastfull = bdevice->maximumEnergy();
+ if (charge_level_lastfull < charge_level_current ) {
+ //possible overflow?
+ charge_level_lastfull = charge_level_current;
}
+ kdDebugFuncOut(trace);
+ return true;
}
//! to check battery.charge_level.rate
@@ -456,9 +473,12 @@ bool Battery::checkChargeLevelLastfull () {
*/
bool Battery::checkChargeLevelRate () {
kdDebugFuncIn(trace);
-
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkChargeLevelRate couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -471,22 +491,17 @@ bool Battery::checkChargeLevelRate () {
int _rate = present_rate;
- if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.rate", &present_rate)) {
- if (present_rate < 0 )
- present_rate = 0;
+ // FIXME VERIFY CORRECTNESS
+ // what does kpowersave expect to see in present_rate (battery.charge_level.rate)?
+ present_rate = bdevice->dischargeRate();
+ if (present_rate < 0 )
+ present_rate = 0;
- if (present_rate != _rate)
- emit changedBattery();
+ if (present_rate != _rate)
+ emit changedBattery();
- kdDebugFuncOut(trace);
- return true;
- } else {
- //query was not successfull but this is optional
- kdError() << "Couldn't request charge_level.rate for udi: " << udi << endl;
- present_rate = 0;
- kdDebugFuncOut(trace);
- return false;
- }
+ kdDebugFuncOut(trace);
+ return true;
}
@@ -500,8 +515,11 @@ bool Battery::checkChargeLevelRate () {
bool Battery::checkChargeLevelUnit () {
kdDebugFuncOut(trace);
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkChargeLevelRate couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -512,15 +530,13 @@ bool Battery::checkChargeLevelUnit () {
return false;
}
- if (!dbus_HAL->halGetPropertyString(udi, "battery.charge_level.unit", &charge_level_unit)) {
- //query was not successfull but this is optional
- kdWarning() << "Couldn't request charge_level.unit for udi: " << udi << endl;
- kdDebugFuncOut(trace);
- return false;
- } else {
- kdDebugFuncOut(trace);
- return true;
- }
+ // FIXME VERIFY CORRECTNESS
+ // what does kpowersave expect to see in charge_level_unit (battery.charge_level.unit)?
+ charge_level_unit = "wH";
+ //query was not successfull but this is optional
+ kdWarning() << "Couldn't request charge_level.unit for udi: " << udi << endl;
+ kdDebugFuncOut(trace);
+ return false;
}
//! to check battery.charge_level.design
@@ -533,8 +549,11 @@ bool Battery::checkChargeLevelUnit () {
bool Battery::checkChargeLevelDesign () {
kdDebugFuncIn(trace);
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkChargeLevelDesign couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -545,18 +564,15 @@ bool Battery::checkChargeLevelDesign () {
return false;
}
- if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.design", &design_capacity)) {
- if (design_capacity < 0)
- design_capacity = 0;
-
- kdDebugFuncOut(trace);
- return true;
- } else {
- //query was not successfull (is mandatory but not critical)
- kdWarning() << "Couldn't request charge_level.design for udi: " << udi << endl;
- kdDebugFuncOut(trace);
- return false;
+ // FIXME VERIFY CORRECTNESS
+ // what does kpowersave expect to see in design_capacity (battery.charge_level.last_full)?
+ design_capacity = bdevice->maximumDesignEnergy();
+ if (design_capacity < 0) {
+ design_capacity = 0;
}
+
+ kdDebugFuncOut(trace);
+ return true;
}
@@ -574,8 +590,11 @@ bool Battery::checkRemainingPercentage () {
int _val = 0;
int _state = -1;
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkRemainingPercentage couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -586,24 +605,13 @@ bool Battery::checkRemainingPercentage () {
return false;
}
- if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.percentage", &_val)) {
- if (_val > 100) {
- _val = 100;
- } else if (_val < 0) {
- _val = 0;
- }
- ret = true;
- } else {
- //query was not successfull, but this property is optional
- //so we calculate it from charge_level
- if (charge_level_current > 0) {
- _val = (int)((float)(charge_level_current * 100) / (float)charge_level_lastfull);
- ret = true;
- } else {
- kdError() << "Couldn't query percentage of udi: " << udi
- << ". and charge_level_current >= 0" << endl;
- }
+ _val = bdevice->chargePercent();
+ if (_val > 100) {
+ _val = 100;
+ } else if (_val < 0) {
+ _val = 0;
}
+ ret = true;
if (charge_level_percentage != _val) {
if (initialized) {
@@ -660,8 +668,11 @@ bool Battery::checkRemainingTime () {
int _min = 0;
bool _ret = false;
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkRemainingTime couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@@ -672,23 +683,9 @@ bool Battery::checkRemainingTime () {
return false;
}
- if (dbus_HAL->halGetPropertyInt(udi, "battery.remaining_time", &_min)) {
- _min /= 60;
- _ret = true;
- } else {
- //query was not successfull, but this is optional
- //and even very unlikely to be present
-
- //try to get it via charge_level_current and present_rate
- if (charge_level_current > 0 && present_rate > 0) {
- _min = ((charge_level_current * 60 )/ present_rate) ;
- _ret = true;
- } else {
- //we don't know it better
- _min = 0;
- _ret = false;
- }
- }
+ _min = bdevice->timeRemaining();
+ _min /= 60;
+ _ret = true;
if (remaining_minutes != _min) {
if (initialized) {
@@ -718,34 +715,32 @@ bool Battery::checkChargingState () {
bool _ret = false;
int _c_state = -1;
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- kdError() << "Couldn't connect to HAL" << endl;
+ // First make sure the battery object is still available
+ TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
+ if (!bdevice) {
+ //grr... no luck
+ kdError() << "Battery::checkChargingState couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
-
if (!present) {
kdWarning() << "No need to update property, battery not present." << endl;
kdDebugFuncOut(trace);
return false;
}
- if (dbus_HAL->halGetPropertyBool(udi, "battery.rechargeable.is_charging", &tmp_bool) &&
- dbus_HAL->halGetPropertyBool(udi, "battery.rechargeable.is_discharging", &tmp_bool2)) {
- if (tmp_bool && !tmp_bool2) {
- _c_state = CHARGING;
- } else if (tmp_bool2 && !tmp_bool) {
- _c_state = DISCHARGING;
- } else {
- _c_state = UNKNOWN_STATE;
- }
-
- _ret = true;
+ tmp_bool = (bdevice->status() == TDEBatteryStatus::Charging);
+ tmp_bool2 = (bdevice->status() == TDEBatteryStatus::Discharging);
+
+ if (tmp_bool && !tmp_bool2) {
+ _c_state = CHARGING;
+ } else if (tmp_bool2 && !tmp_bool) {
+ _c_state = DISCHARGING;
} else {
- kdError() << "Couldn't get current charging state for udi: " << udi << endl;
_c_state = UNKNOWN_STATE;
- _ret = false;
}
+
+ _ret = true;
if (charging_state != _c_state) {
if (initialized) {
@@ -766,64 +761,16 @@ bool Battery::checkChargingState () {
/*!
* Check for the given property new values from HAL and set them to
* the battery variables.
- * \param _udi TQString with the UDI of the device to recheck
- * \param _property TQString with the property which was changed
- * \return boolean with the result of the operation
- * \retval true if the update was successfull
- * \retval false if the update couldn't be applied
+ * \param device TDEGenericDevice
*/
-bool Battery::updateProperty(TQString _udi, TQString _property) {
+void Battery::updateProperty(TDEGenericDevice* device) {
kdDebugFuncIn(trace);
- //first check whether HAL is available
- if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
- //grr... no luck
- kdError() << "Battery::updateProperty couldn't connect to HAL" << endl;
- kdDebugFuncOut(trace);
- return false;
- }
-
- bool ret = true;
-
- if (udi.startsWith(_udi)) {
- // handle different keys and update only the needed
- if (_property.startsWith("battery.present")) {
- if (!checkBatteryPresent()) ret = false;
- } else if (_property.startsWith("battery.type")) {
- if (!checkBatteryType()) ret = false;
- } else if (_property.startsWith("battery.charge_level.capacity_state")) {
- if (!checkCapacityState()) ret= false;
- } else if (_property.startsWith("battery.charge_level.current")) {
- if (!checkChargeLevelCurrent()) ret = false;
- } else if (_property.startsWith("battery.charge_level.rate")) {
- if (!checkChargeLevelRate()) ret = false;
- } else if (_property.startsWith("battery.charge_level.percentage")) {
- if (!checkRemainingPercentage()) ret = false;
- } else if (_property.startsWith("battery.remaining_time")) {
- if (!checkRemainingTime()) ret = false;
- } else if (_property.startsWith("battery.rechargeable.is_")) {
- if (!checkChargingState()) ret = false;
- } else if (_property.startsWith("battery.charge_level.last_full")) {
- if (!checkChargeLevelLastfull()) ret = false;
- // --> changes on this keys should normally not happen except if battery was added /removed
- } else if (_property.startsWith("battery.technology")) {
- if (!checkBatteryTechnology()) ret = false;
- } else if (_property.startsWith("battery.charge_level.unit")) {
- if (!checkChargeLevelUnit()) ret = false;
- } else if (_property.startsWith("battery.charge_level.design")) {
- if (!checkChargeLevelDesign()) ret = false;
- } else {
- kdDebug() << "Unknown or unhandled device property: " << _property
- << " for device with udi: " << _udi << endl;
- ret = false;
- }
- } else {
- kdError() << "Given UDI doesn't match the UDI of this battery object." << endl;
- ret = false;
+ if (device->uniqueID() == udi) {
+ recheck();
}
kdDebugFuncOut(trace);
- return ret;
}
//! Resets the current HAL udi used by the one given
@@ -838,23 +785,9 @@ bool Battery::updateProperty(TQString _udi, TQString _property) {
bool Battery::resetUdi(TQString _udi) {
kdDebugFuncIn(trace);
- bool tmp_result=false;
-
- //trivial pre-check to eliminate totally dumb _udi strings
- if (!_udi.isNull() && !_udi.isEmpty() && _udi.startsWith("/org/freedesktop/Hal/devices/")) {
-
- //ok, now lets ask HAL if its really a battery
- if (dbus_HAL->isConnectedToHAL() || dbus_HAL->reconnect()) {
-
- dbus_HAL->halQueryCapability(_udi,"battery",&tmp_result);
-
- } else {
- kdError() << "Battery::resetUdi couldn't connect to HAL" << endl;
- }
-
- } else {
- kdError() << "Battery::resetUdi received empty or invalid udi" << endl;
- }
+ // FIXME
+ // What does this function do outside of HAL!?!? Should it even exist any more?
+ bool tmp_result=true;
kdDebugFuncOut(trace);
return tmp_result;