Additional fixups to provide methods needed by kpowersave

pull/16/head
Timothy Pearson 13 years ago
parent 76eb139db2
commit fde8fcb186

@ -930,6 +930,33 @@ void TDECPUDevice::setGovernor(TQString gv) {
stream << gv.lower(); stream << gv.lower();
file.close(); file.close();
} }
// Force update of the device information object
KGlobal::hardwareDevices()->processModifiedCPUs();
}
bool TDECPUDevice::canSetMaximumScalingFrequency() {
TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
int rval = access (freqnode.ascii(), W_OK);
if (rval == 0) {
return TRUE;
}
else {
return FALSE;
}
}
void TDECPUDevice::setMaximumScalingFrequency(double fr) {
TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
TQFile file( freqnode );
if ( file.open( IO_WriteOnly ) ) {
TQTextStream stream( &file );
stream << TQString("%1").arg(fr*1000000.0, 0, 'f', 0);
file.close();
}
// Force update of the device information object
KGlobal::hardwareDevices()->processModifiedCPUs();
} }
TDESensorDevice::TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { TDESensorDevice::TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
@ -1213,6 +1240,14 @@ void TDEBatteryDevice::internalSetDischargeRate(double vt) {
m_dischargeRate = vt; m_dischargeRate = vt;
} }
double TDEBatteryDevice::timeRemaining() {
return m_timeRemaining;
}
void TDEBatteryDevice::internalSetTimeRemaining(double tr) {
m_timeRemaining = tr;
}
TQString TDEBatteryDevice::technology() { TQString TDEBatteryDevice::technology() {
return m_technology; return m_technology;
} }
@ -1221,12 +1256,25 @@ void TDEBatteryDevice::internalSetTechnology(TQString tc) {
m_technology = tc; m_technology = tc;
} }
TQString TDEBatteryDevice::status() { TDEBatteryStatus::TDEBatteryStatus TDEBatteryDevice::status() {
return m_status; return m_status;
} }
void TDEBatteryDevice::internalSetStatus(TQString tc) { void TDEBatteryDevice::internalSetStatus(TQString tc) {
m_status = tc; tc = tc.lower();
if (tc == "charging") {
m_status = TDEBatteryStatus::Charging;
}
else if (tc == "discharging") {
m_status = TDEBatteryStatus::Discharging;
}
else if (tc == "full") {
m_status = TDEBatteryStatus::Full;
}
else {
m_status = TDEBatteryStatus::Unknown;
}
} }
bool TDEBatteryDevice::installed() { bool TDEBatteryDevice::installed() {
@ -1788,7 +1836,7 @@ void TDEHardwareDevices::processHotPluggedHardware() {
TQString actionevent(udev_device_get_action(dev)); TQString actionevent(udev_device_get_action(dev));
if (actionevent == "add") { if (actionevent == "add") {
TDEGenericDevice* device = classifyUnknownDevice(dev); TDEGenericDevice* device = classifyUnknownDevice(dev);
// Make sure this device is not a duplicate // Make sure this device is not a duplicate
TDEGenericDevice *hwdevice; TDEGenericDevice *hwdevice;
for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) { for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
@ -1808,6 +1856,7 @@ void TDEHardwareDevices::processHotPluggedHardware() {
else if (actionevent == "remove") { else if (actionevent == "remove") {
// Delete device from hardware listing // Delete device from hardware listing
TQString systempath(udev_device_get_syspath(dev)); TQString systempath(udev_device_get_syspath(dev));
systempath += "/";
TDEGenericDevice *hwdevice; TDEGenericDevice *hwdevice;
for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) { for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
if (hwdevice->systemPath() == systempath) { if (hwdevice->systemPath() == systempath) {
@ -1837,6 +1886,7 @@ void TDEHardwareDevices::processHotPluggedHardware() {
else if (actionevent == "change") { else if (actionevent == "change") {
// Update device and emit change event // Update device and emit change event
TQString systempath(udev_device_get_syspath(dev)); TQString systempath(udev_device_get_syspath(dev));
systempath += "/";
TDEGenericDevice *hwdevice; TDEGenericDevice *hwdevice;
for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) { for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
if (hwdevice->systemPath() == systempath) { if (hwdevice->systemPath() == systempath) {
@ -1938,7 +1988,7 @@ void TDEHardwareDevices::processModifiedCPUs() {
scalingdriverfile.close(); scalingdriverfile.close();
} }
nodename = cpufreq_dir.path(); nodename = cpufreq_dir.path();
nodename.append("/scaling_min_freq"); nodename.append("/cpuinfo_min_freq");
TQFile minfrequencyfile(nodename); TQFile minfrequencyfile(nodename);
if (minfrequencyfile.open(IO_ReadOnly)) { if (minfrequencyfile.open(IO_ReadOnly)) {
TQTextStream stream( &minfrequencyfile ); TQTextStream stream( &minfrequencyfile );
@ -1946,7 +1996,7 @@ void TDEHardwareDevices::processModifiedCPUs() {
minfrequencyfile.close(); minfrequencyfile.close();
} }
nodename = cpufreq_dir.path(); nodename = cpufreq_dir.path();
nodename.append("/scaling_max_freq"); nodename.append("/cpuinfo_max_freq");
TQFile maxfrequencyfile(nodename); TQFile maxfrequencyfile(nodename);
if (maxfrequencyfile.open(IO_ReadOnly)) { if (maxfrequencyfile.open(IO_ReadOnly)) {
TQTextStream stream( &maxfrequencyfile ); TQTextStream stream( &maxfrequencyfile );
@ -2680,6 +2730,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
devicesubsystem = (udev_device_get_subsystem(dev)); devicesubsystem = (udev_device_get_subsystem(dev));
devicenode = (udev_device_get_devnode(dev)); devicenode = (udev_device_get_devnode(dev));
systempath = (udev_device_get_syspath(dev)); systempath = (udev_device_get_syspath(dev));
systempath += "/";
devicevendorid = (udev_device_get_property_value(dev, "ID_VENDOR_ID")); devicevendorid = (udev_device_get_property_value(dev, "ID_VENDOR_ID"));
devicemodelid = (udev_device_get_property_value(dev, "ID_MODEL_ID")); devicemodelid = (udev_device_get_property_value(dev, "ID_MODEL_ID"));
devicevendoridenc = (udev_device_get_property_value(dev, "ID_VENDOR_ENC")); devicevendoridenc = (udev_device_get_property_value(dev, "ID_VENDOR_ENC"));
@ -3660,6 +3711,9 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
++valuesdirit; ++valuesdirit;
} }
} }
// Calculate time remaining
bdevice->internalSetTimeRemaining(bdevice->energy()*bdevice->dischargeRate()*60);
} }
if (device->type() == TDEGenericDeviceType::PowerSupply) { if (device->type() == TDEGenericDeviceType::PowerSupply) {

@ -773,6 +773,16 @@ class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice
*/ */
void setGovernor(TQString gv); void setGovernor(TQString gv);
/**
* @return TRUE if permissions allow the CPU maximum frequency to be set, FALSE if not
*/
bool canSetMaximumScalingFrequency();
/**
* @param gv a double with the new CPU maximum frequency in MHz
*/
void setMaximumScalingFrequency(double fr);
protected: protected:
/** /**
* @param fr a double with the current CPU frequency in MHz, if available * @param fr a double with the current CPU frequency in MHz, if available
@ -842,6 +852,15 @@ class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice
friend class TDEHardwareDevices; friend class TDEHardwareDevices;
}; };
namespace TDEBatteryStatus {
enum TDEBatteryStatus {
Charging,
Discharging,
Full,
Unknown = 0x80000000
};
};
class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice
{ {
public: public:
@ -901,15 +920,20 @@ class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice
*/ */
double dischargeRate(); double dischargeRate();
/**
* @return a double with the current battery discharge time remaining in seconds, if available
*/
double timeRemaining();
/** /**
* @return a TQString with the battery technology, if available * @return a TQString with the battery technology, if available
*/ */
TQString technology(); TQString technology();
/** /**
* @return a TQString with the battery status, if available * @return a TDEBatteryStatus::TDEBatteryStatus with the current battery status
*/ */
TQString status(); TDEBatteryStatus::TDEBatteryStatus status();
/** /**
* @return TRUE if the battery is installed * @return TRUE if the battery is installed
@ -976,6 +1000,12 @@ class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice
*/ */
void internalSetDischargeRate(double vt); void internalSetDischargeRate(double vt);
/**
* @param a double with the current battery discharge time remaining in seconds, if available
* @internal
*/
void internalSetTimeRemaining(double tr);
/** /**
* @param a TQString with the battery technology, if available * @param a TQString with the battery technology, if available
* @internal * @internal
@ -1004,8 +1034,9 @@ class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice
double m_maximumEnergy; double m_maximumEnergy;
double m_maximumDesignEnergy; double m_maximumDesignEnergy;
double m_dischargeRate; double m_dischargeRate;
double m_timeRemaining;
TQString m_technology; TQString m_technology;
TQString m_status; TDEBatteryStatus::TDEBatteryStatus m_status;
bool m_installed; bool m_installed;
friend class TDEHardwareDevices; friend class TDEHardwareDevices;
@ -1569,7 +1600,7 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
void setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm); void setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm);
/** /**
* @param ps a TDESystemPowerState::TDESystemPowerState with the desired hibernation method * @param ps a TDESystemPowerState::TDESystemPowerState with the desired power state
* @return TRUE if power state was set * @return TRUE if power state was set
*/ */
bool setPowerState(TDESystemPowerState::TDESystemPowerState ps); bool setPowerState(TDESystemPowerState::TDESystemPowerState ps);
@ -1893,6 +1924,13 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject
*/ */
TDERootSystemDevice* rootSystemDevice(); TDERootSystemDevice* rootSystemDevice();
/**
* Rescan a hardware device to look for changes
* WARNING: This method can be very expensive. Use with caution!
* @param hwdevice TDEGenericDevice* with the device to rescan
*/
void rescanDeviceInformation(TDEGenericDevice* hwdevice);
/** /**
* Convert a byte count to human readable form * Convert a byte count to human readable form
* @param bytes a double containing the number of bytes * @param bytes a double containing the number of bytes
@ -1913,7 +1951,6 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject
void processStatelessDevices(); void processStatelessDevices();
private: private:
void rescanDeviceInformation(TDEGenericDevice* hwdevice);
void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev); void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev);
private: private:
@ -1958,6 +1995,7 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject
friend class TDEGenericDevice; friend class TDEGenericDevice;
friend class TDEStorageDevice; friend class TDEStorageDevice;
friend class TDECPUDevice;
}; };
#endif #endif
Loading…
Cancel
Save