diff options
author | Golubev Alexander <fatzer2@gmail.com> | 2013-07-27 03:05:37 +0400 |
---|---|---|
committer | Golubev Alexander <fatzer2@gmail.com> | 2013-07-27 11:20:30 +0400 |
commit | 4b775b444d1558705c4aa9a0b5f1d18e2a81f092 (patch) | |
tree | 7c9cd3a3e0f4000670ae76c944dd02a5ed8a0765 /tdecore | |
parent | 8bc5f3a2940f27486ae31b83a9b7cd74076b4885 (diff) | |
download | tdelibs-4b775b444d1558705c4aa9a0b5f1d18e2a81f092.tar.gz tdelibs-4b775b444d1558705c4aa9a0b5f1d18e2a81f092.zip |
tdehw: three more classes splited
Diffstat (limited to 'tdecore')
-rw-r--r-- | tdecore/tdehw/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tdecore/tdehw/tdebatterydevice.cpp | 149 | ||||
-rw-r--r-- | tdecore/tdehw/tdebatterydevice.h | 215 | ||||
-rw-r--r-- | tdecore/tdehw/tdecpudevice.cpp | 223 | ||||
-rw-r--r-- | tdecore/tdehw/tdecpudevice.h | 186 | ||||
-rw-r--r-- | tdecore/tdehw/tdehardwaredevices.cpp | 325 | ||||
-rw-r--r-- | tdecore/tdehw/tdehardwaredevices.h | 385 | ||||
-rw-r--r-- | tdecore/tdehw/tdemainspowerdevice.cpp | 36 | ||||
-rw-r--r-- | tdecore/tdehw/tdemainspowerdevice.h | 57 |
9 files changed, 872 insertions, 709 deletions
diff --git a/tdecore/tdehw/CMakeLists.txt b/tdecore/tdehw/CMakeLists.txt index af050ed0e..4496d3f2d 100644 --- a/tdecore/tdehw/CMakeLists.txt +++ b/tdecore/tdehw/CMakeLists.txt @@ -64,7 +64,7 @@ link_directories( ##### headers ################################### install( FILES tdehardwaredevices.h tdenetworkconnections.h tdegenericdevice.h - tdestoragedevice.h + tdestoragedevice.h tdecpudevice.h tdebatterydevice.h tdemainspowerdevice.h DESTINATION ${INCLUDE_INSTALL_DIR} ) @@ -74,7 +74,8 @@ set( target tdehw ) set( ${target}_SRCS tdehardwaredevices.cpp tdenetworkconnections.cpp tdegenericdevice.cpp - tdestoragedevice.cpp + tdestoragedevice.cpp tdecpudevice.cpp tdebatterydevice.cpp + tdemainspowerdevice.cpp ) tde_add_library( ${target} STATIC_PIC AUTOMOC diff --git a/tdecore/tdehw/tdebatterydevice.cpp b/tdecore/tdehw/tdebatterydevice.cpp new file mode 100644 index 000000000..0245d2c67 --- /dev/null +++ b/tdecore/tdehw/tdebatterydevice.cpp @@ -0,0 +1,149 @@ +/* This file is part of the TDE libraries + Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net> + (C) 2013 Golubev Alexander <fatzer2@gmail.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdebatterydevice.h" + +TDEBatteryDevice::TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { +} + +TDEBatteryDevice::~TDEBatteryDevice() { +} + +double TDEBatteryDevice::voltage() { + return m_currentVoltage; +} + +void TDEBatteryDevice::internalSetVoltage(double vt) { + m_currentVoltage = vt; +} + +double TDEBatteryDevice::maximumVoltage() { + return m_maximumVoltage; +} + +void TDEBatteryDevice::internalSetMaximumVoltage(double vt) { + m_maximumVoltage = vt; +} + +double TDEBatteryDevice::minimumVoltage() { + return m_minimumVoltage; +} + +void TDEBatteryDevice::internalSetMinimumVoltage(double vt) { + m_minimumVoltage = vt; +} + +double TDEBatteryDevice::maximumDesignVoltage() { + return m_maximumDesignVoltage; +} + +void TDEBatteryDevice::internalSetMaximumDesignVoltage(double vt) { + m_maximumDesignVoltage = vt; +} + +double TDEBatteryDevice::energy() { + return m_currentEnergy; +} + +void TDEBatteryDevice::internalSetEnergy(double vt) { + m_currentEnergy = vt; +} + +double TDEBatteryDevice::alarmEnergy() { + return m_alarmEnergy; +} + +void TDEBatteryDevice::internalSetAlarmEnergy(double vt) { + m_alarmEnergy = vt; +} + +double TDEBatteryDevice::maximumEnergy() { + return m_maximumEnergy; +} + +void TDEBatteryDevice::internalSetMaximumEnergy(double vt) { + m_maximumEnergy = vt; +} + +double TDEBatteryDevice::maximumDesignEnergy() { + return m_maximumDesignEnergy; +} + +void TDEBatteryDevice::internalSetMaximumDesignEnergy(double vt) { + m_maximumDesignEnergy = vt; +} + +double TDEBatteryDevice::dischargeRate() { + return m_dischargeRate; +} + +void TDEBatteryDevice::internalSetDischargeRate(double vt) { + m_dischargeRate = vt; +} + +double TDEBatteryDevice::timeRemaining() { + return m_timeRemaining; +} + +void TDEBatteryDevice::internalSetTimeRemaining(double tr) { + m_timeRemaining = tr; +} + +TQString TDEBatteryDevice::technology() { + return m_technology; +} + +void TDEBatteryDevice::internalSetTechnology(TQString tc) { + m_technology = tc; +} + +TDEBatteryStatus::TDEBatteryStatus TDEBatteryDevice::status() { + return m_status; +} + +void TDEBatteryDevice::internalSetStatus(TQString 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() { + return m_installed; +} + +void TDEBatteryDevice::internalSetInstalled(bool tc) { + m_installed = tc; +} + +double TDEBatteryDevice::chargePercent() { + return (m_currentEnergy/m_maximumEnergy)*100.0; +} + +#include "tdebatterydevice.moc" diff --git a/tdecore/tdehw/tdebatterydevice.h b/tdecore/tdehw/tdebatterydevice.h new file mode 100644 index 000000000..6556b5268 --- /dev/null +++ b/tdecore/tdehw/tdebatterydevice.h @@ -0,0 +1,215 @@ +/* This file is part of the TDE libraries + Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net> + (C) 2013 Golubev Alexander <fatzer2@gmail.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _TDEBATTERYDEVICE_H +#define _TDEBATTERYDEVICE_H + +#include "tdegenericdevice.h" + +namespace TDEBatteryStatus { +enum TDEBatteryStatus { + Charging, + Discharging, + Full, + Unknown = 0x80000000 +}; +}; + +class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice +{ + public: + /** + * Constructor. + * @param Device type + */ + TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); + + /** + * Destructor. + */ + ~TDEBatteryDevice(); + + /** + * @return a double with the current battery voltage, if available + */ + double voltage(); + + /** + * @return a double with the minimum battery voltage, if available + */ + double minimumVoltage(); + + /** + * @return a double with the maximum battery voltage, if available + */ + double maximumVoltage(); + + /** + * @return a double with the designed maximum battery voltage, if available + */ + double maximumDesignVoltage(); + + /** + * @return a double with the current battery energy in watt-hours, if available + */ + double energy(); + + /** + * @return a double with the current battery alarm energy in watt-hours, if available + */ + double alarmEnergy(); + + /** + * @return a double with the maximum battery energy in watt-hours, if available + */ + double maximumEnergy(); + + /** + * @return a double with the designed maximum battery energy in watt-hours, if available + */ + double maximumDesignEnergy(); + + /** + * @return a double with the current battery discharge rate in watt-hours, if available + */ + 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 + */ + TQString technology(); + + /** + * @return a TDEBatteryStatus::TDEBatteryStatus with the current battery status + */ + TDEBatteryStatus::TDEBatteryStatus status(); + + /** + * @return TRUE if the battery is installed + */ + bool installed(); + + /** + * @return a double with the current battery charge in percent, if available + */ + double chargePercent(); + + protected: + /** + * @param a double with the current battery voltage, if available + * @internal + */ + void internalSetVoltage(double vt); + + /** + * @param a double with the minimum battery voltage, if available + * @internal + */ + void internalSetMinimumVoltage(double vt); + + /** + * @param a double with the maximum battery voltage, if available + * @internal + */ + void internalSetMaximumVoltage(double vt); + + /** + * @param a double with the designed maximum battery voltage, if available + * @internal + */ + void internalSetMaximumDesignVoltage(double vt); + + /** + * @param a double with the current battery energy in watt-hours, if available + * @internal + */ + void internalSetEnergy(double vt); + + /** + * @param a double with the current battery alarm energy in watt-hours, if available + * @internal + */ + void internalSetAlarmEnergy(double vt); + + /** + * @param a double with the maximum battery energy in watt-hours, if available + * @internal + */ + void internalSetMaximumEnergy(double vt); + + /** + * @param a double with the designed maximum battery energy in watt-hours, if available + * @internal + */ + void internalSetMaximumDesignEnergy(double vt); + + /** + * @param a double with the current battery discharge rate in volt-hours, if available + * @internal + */ + 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 + * @internal + */ + void internalSetTechnology(TQString tc); + + /** + * @param a TQString with the battery status, if available + * @internal + */ + void internalSetStatus(TQString tc); + + /** + * @param TRUE if the battery is installed + * @internal + */ + void internalSetInstalled(bool tc); + + private: + double m_currentVoltage; + double m_minimumVoltage; + double m_maximumVoltage; + double m_maximumDesignVoltage; + double m_alarmEnergy; + double m_currentEnergy; + double m_maximumEnergy; + double m_maximumDesignEnergy; + double m_dischargeRate; + double m_timeRemaining; + TQString m_technology; + TDEBatteryStatus::TDEBatteryStatus m_status; + bool m_installed; + + friend class TDEHardwareDevices; +}; + +#endif // _TDEBATTERYDEVICE_H diff --git a/tdecore/tdehw/tdecpudevice.cpp b/tdecore/tdehw/tdecpudevice.cpp new file mode 100644 index 000000000..268682727 --- /dev/null +++ b/tdecore/tdehw/tdecpudevice.cpp @@ -0,0 +1,223 @@ +/* This file is part of the TDE libraries + Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net> + (C) 2013 Golubev Alexander <fatzer2@gmail.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdecpudevice.h" + +#include <unistd.h> + +#include <tqfile.h> + +// uPower +#if defined(WITH_UPOWER) + #include <tqdbusdata.h> + #include <tqdbusmessage.h> + #include <tqdbusproxy.h> + #include <tqdbusvariant.h> + #include <tqdbusconnection.h> +#endif // defined(WITH_UPOWER) + +#include <tdeglobal.h> + +#include "tdehardwaredevices.h" + +TDECPUDevice::TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { + m_frequency = -1; + m_minfrequency = -1; + m_maxfrequency = -1; + m_corenumber = -1; + m_transitionlatency = -1; +} + +TDECPUDevice::~TDECPUDevice() { +} + +double TDECPUDevice::frequency() { + return m_frequency; +} + +void TDECPUDevice::internalSetFrequency(double fr) { + m_frequency = fr; +} + +double TDECPUDevice::minFrequency() { + return m_minfrequency; +} + +void TDECPUDevice::internalSetMinFrequency(double fr) { + m_minfrequency = fr; +} + +double TDECPUDevice::maxFrequency() { + return m_maxfrequency; +} + +void TDECPUDevice::internalSetMaxFrequency(double fr) { + m_maxfrequency = fr; +} + +double TDECPUDevice::transitionLatency() { + return m_transitionlatency; +} + +void TDECPUDevice::internalSetTransitionLatency(double tl) { + m_transitionlatency = tl; +} + +TQString TDECPUDevice::governor() { + return m_governor; +} + +void TDECPUDevice::internalSetGovernor(TQString gr) { + m_governor = gr; +} + +TQString TDECPUDevice::scalingDriver() { + return m_scalingdriver; +} + +void TDECPUDevice::internalSetScalingDriver(TQString dr) { + m_scalingdriver = dr; +} + +TQStringList TDECPUDevice::dependentProcessors() { + return m_tiedprocs; +} + +void TDECPUDevice::internalSetDependentProcessors(TQStringList dp) { + m_tiedprocs = dp; +} + +TQStringList TDECPUDevice::availableFrequencies() { + return m_frequencies; +} + +void TDECPUDevice::internalSetAvailableFrequencies(TQStringList af) { + m_frequencies = af; +} + +TQStringList TDECPUDevice::availableGovernors() { + return m_governers; +} + +void TDECPUDevice::internalSetAvailableGovernors(TQStringList gp) { + m_governers = gp; +} + +void TDECPUDevice::internalSetCoreNumber(int cn) { + m_corenumber = cn; +} + +bool TDECPUDevice::canSetGovernor() { + TQString governornode = systemPath() + "/cpufreq/scaling_governor"; + int rval = access (governornode.ascii(), W_OK); + if (rval == 0) { + return TRUE; + } + else { +#ifdef WITH_UPOWER + TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); + if (dbusConn.isConnected()) { + TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn); + if (hardwareControl.canSend()) { + // can set CPU governor? + TQValueList<TQT_DBusData> params; + params << TQT_DBusData::fromInt32(coreNumber()); + TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", params); + if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { + return reply[0].toVariant().value.toBool(); + } + else { + return FALSE; + } + } + else { + return FALSE; + } + } + else { + return FALSE; + } +#else // WITH_UPOWER + return FALSE; +#endif// WITH_UPOWER + } +} + +void TDECPUDevice::setGovernor(TQString gv) { + TQString governornode = systemPath() + "/cpufreq/scaling_governor"; + TQFile file( governornode ); + if ( file.open( IO_WriteOnly ) ) { + TQTextStream stream( &file ); + stream << gv.lower(); + file.close(); + } +#ifdef WITH_UPOWER + else { + TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); + if (dbusConn.isConnected()) { + TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn); + if (hardwareControl.canSend()) { + // set CPU governor + TQValueList<TQT_DBusData> params; + params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower()); + hardwareControl.sendWithReply("SetCPUGovernor", params); + } + else { + return; + } + } + else { + return; + } + } +#endif // WITH_UPOWER + + // Force update of the device information object + TDEGlobal::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 + TDEGlobal::hardwareDevices()->processModifiedCPUs(); +} + +int TDECPUDevice::coreNumber() { + return m_corenumber; +} + +#include "tdecpudevice.moc" diff --git a/tdecore/tdehw/tdecpudevice.h b/tdecore/tdehw/tdecpudevice.h new file mode 100644 index 000000000..6037fcb69 --- /dev/null +++ b/tdecore/tdehw/tdecpudevice.h @@ -0,0 +1,186 @@ +/* This file is part of the TDE libraries + Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net> + (C) 2013 Golubev Alexander <fatzer2@gmail.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _TDECPUDEVICE_H +#define _TDECPUDEVICE_H + +#include "tdegenericdevice.h" + +class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice +{ + public: + /** + * Constructor. + * @param Device type + */ + TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); + + /** + * Destructor. + */ + ~TDECPUDevice(); + + /** + * @return a double with the current CPU frequency in MHz, if available + */ + double frequency(); + + /** + * @return a double with the minimum CPU frequency in MHz, if available + */ + double minFrequency(); + + /** + * @return a double with the maximum CPU frequency in MHz, if available + */ + double maxFrequency(); + + /** + * @return a double with the transition latency in ns, if available + */ + double transitionLatency(); + + /** + * @return a TQString with the current CPU governor policy, if available + */ + TQString governor(); + + /** + * @return a TQString with the current CPU scaling driver, if available + */ + TQString scalingDriver(); + + /** + * @return a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available + */ + TQStringList dependentProcessors(); + + /** + * @return a TQStringList with all valid scaling frequencies in Hz, if available + */ + TQStringList availableFrequencies(); + + /** + * @return a TQStringList with all available governor policies, if available + */ + TQStringList availableGovernors(); + + /** + * @return TRUE if permissions allow the CPU governor to be set, FALSE if not + */ + bool canSetGovernor(); + + /** + * @param gv a TQString with the new CPU governor policy name + */ + 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); + + /** + * @return an integer with the core number, starting at 0 + */ + int coreNumber(); + + protected: + /** + * @param fr a double with the current CPU frequency in MHz, if available + * @internal + */ + void internalSetFrequency(double fr); + + /** + * @param fr a double with the minimum CPU frequency in MHz, if available + * @internal + */ + void internalSetMinFrequency(double fr); + + /** + * @param fr a double with the maximum CPU frequency in MHz, if available + * @internal + */ + void internalSetMaxFrequency(double fr); + + /** + * @param tl a double with the transition latency in ns, if available + * @internal + */ + void internalSetTransitionLatency(double tl); + + /** + * @param gr a TQString with the current CPU governor policy, if available + * @internal + */ + void internalSetGovernor(TQString gr); + + /** + * @param dr a TQString with the current CPU scaling driver, if available + * @internal + */ + void internalSetScalingDriver(TQString dr); + + /** + * @param dp a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available + * @internal + */ + void internalSetDependentProcessors(TQStringList dp); + + /** + * @param af a TQStringList with all valid scaling frequencies in Hz, if available + * @internal + */ + void internalSetAvailableFrequencies(TQStringList af); + + /** + * @param gp a TQStringList with all available governor policies, if available + * @internal + */ + void internalSetAvailableGovernors(TQStringList gp); + + /** + * @param cn an integer with the core number, starting at 0 + * @internal + */ + void internalSetCoreNumber(int cn); + + private: + double m_frequency; + double m_minfrequency; + double m_maxfrequency; + double m_transitionlatency; + TQString m_governor; + TQString m_scalingdriver; + TQStringList m_tiedprocs; + TQStringList m_frequencies; + TQStringList m_governers; + int m_corenumber; + + friend class TDEHardwareDevices; +}; + + +#endif // _TDECPUDEVICE_H diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp index aaba9e4ed..3cf62e8af 100644 --- a/tdecore/tdehw/tdehardwaredevices.cpp +++ b/tdecore/tdehw/tdehardwaredevices.cpp @@ -109,190 +109,6 @@ TDESensorCluster::TDESensorCluster() { critical = -1; } -TDECPUDevice::TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { - m_frequency = -1; - m_minfrequency = -1; - m_maxfrequency = -1; - m_corenumber = -1; - m_transitionlatency = -1; -} - -TDECPUDevice::~TDECPUDevice() { -} - -double TDECPUDevice::frequency() { - return m_frequency; -} - -void TDECPUDevice::internalSetFrequency(double fr) { - m_frequency = fr; -} - -double TDECPUDevice::minFrequency() { - return m_minfrequency; -} - -void TDECPUDevice::internalSetMinFrequency(double fr) { - m_minfrequency = fr; -} - -double TDECPUDevice::maxFrequency() { - return m_maxfrequency; -} - -void TDECPUDevice::internalSetMaxFrequency(double fr) { - m_maxfrequency = fr; -} - -double TDECPUDevice::transitionLatency() { - return m_transitionlatency; -} - -void TDECPUDevice::internalSetTransitionLatency(double tl) { - m_transitionlatency = tl; -} - -TQString TDECPUDevice::governor() { - return m_governor; -} - -void TDECPUDevice::internalSetGovernor(TQString gr) { - m_governor = gr; -} - -TQString TDECPUDevice::scalingDriver() { - return m_scalingdriver; -} - -void TDECPUDevice::internalSetScalingDriver(TQString dr) { - m_scalingdriver = dr; -} - -TQStringList TDECPUDevice::dependentProcessors() { - return m_tiedprocs; -} - -void TDECPUDevice::internalSetDependentProcessors(TQStringList dp) { - m_tiedprocs = dp; -} - -TQStringList TDECPUDevice::availableFrequencies() { - return m_frequencies; -} - -void TDECPUDevice::internalSetAvailableFrequencies(TQStringList af) { - m_frequencies = af; -} - -TQStringList TDECPUDevice::availableGovernors() { - return m_governers; -} - -void TDECPUDevice::internalSetAvailableGovernors(TQStringList gp) { - m_governers = gp; -} - -void TDECPUDevice::internalSetCoreNumber(int cn) { - m_corenumber = cn; -} - -bool TDECPUDevice::canSetGovernor() { - TQString governornode = systemPath() + "/cpufreq/scaling_governor"; - int rval = access (governornode.ascii(), W_OK); - if (rval == 0) { - return TRUE; - } - else { -#ifdef WITH_UPOWER - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn); - if (hardwareControl.canSend()) { - // can set CPU governor? - TQValueList<TQT_DBusData> params; - params << TQT_DBusData::fromInt32(coreNumber()); - TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", params); - if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { - return reply[0].toVariant().value.toBool(); - } - else { - return FALSE; - } - } - else { - return FALSE; - } - } - else { - return FALSE; - } -#else // WITH_UPOWER - return FALSE; -#endif// WITH_UPOWER - } -} - -void TDECPUDevice::setGovernor(TQString gv) { - TQString governornode = systemPath() + "/cpufreq/scaling_governor"; - TQFile file( governornode ); - if ( file.open( IO_WriteOnly ) ) { - TQTextStream stream( &file ); - stream << gv.lower(); - file.close(); - } -#ifdef WITH_UPOWER - else { - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn); - if (hardwareControl.canSend()) { - // set CPU governor - TQValueList<TQT_DBusData> params; - params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower()); - hardwareControl.sendWithReply("SetCPUGovernor", params); - } - else { - return; - } - } - else { - return; - } - } -#endif // WITH_UPOWER - - // Force update of the device information object - TDEGlobal::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 - TDEGlobal::hardwareDevices()->processModifiedCPUs(); -} - -int TDECPUDevice::coreNumber() { - return m_corenumber; -} - TDESensorDevice::TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { } @@ -708,147 +524,6 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState return false; } -TDEBatteryDevice::TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { -} - -TDEBatteryDevice::~TDEBatteryDevice() { -} - -double TDEBatteryDevice::voltage() { - return m_currentVoltage; -} - -void TDEBatteryDevice::internalSetVoltage(double vt) { - m_currentVoltage = vt; -} - -double TDEBatteryDevice::maximumVoltage() { - return m_maximumVoltage; -} - -void TDEBatteryDevice::internalSetMaximumVoltage(double vt) { - m_maximumVoltage = vt; -} - -double TDEBatteryDevice::minimumVoltage() { - return m_minimumVoltage; -} - -void TDEBatteryDevice::internalSetMinimumVoltage(double vt) { - m_minimumVoltage = vt; -} - -double TDEBatteryDevice::maximumDesignVoltage() { - return m_maximumDesignVoltage; -} - -void TDEBatteryDevice::internalSetMaximumDesignVoltage(double vt) { - m_maximumDesignVoltage = vt; -} - -double TDEBatteryDevice::energy() { - return m_currentEnergy; -} - -void TDEBatteryDevice::internalSetEnergy(double vt) { - m_currentEnergy = vt; -} - -double TDEBatteryDevice::alarmEnergy() { - return m_alarmEnergy; -} - -void TDEBatteryDevice::internalSetAlarmEnergy(double vt) { - m_alarmEnergy = vt; -} - -double TDEBatteryDevice::maximumEnergy() { - return m_maximumEnergy; -} - -void TDEBatteryDevice::internalSetMaximumEnergy(double vt) { - m_maximumEnergy = vt; -} - -double TDEBatteryDevice::maximumDesignEnergy() { - return m_maximumDesignEnergy; -} - -void TDEBatteryDevice::internalSetMaximumDesignEnergy(double vt) { - m_maximumDesignEnergy = vt; -} - -double TDEBatteryDevice::dischargeRate() { - return m_dischargeRate; -} - -void TDEBatteryDevice::internalSetDischargeRate(double vt) { - m_dischargeRate = vt; -} - -double TDEBatteryDevice::timeRemaining() { - return m_timeRemaining; -} - -void TDEBatteryDevice::internalSetTimeRemaining(double tr) { - m_timeRemaining = tr; -} - -TQString TDEBatteryDevice::technology() { - return m_technology; -} - -void TDEBatteryDevice::internalSetTechnology(TQString tc) { - m_technology = tc; -} - -TDEBatteryStatus::TDEBatteryStatus TDEBatteryDevice::status() { - return m_status; -} - -void TDEBatteryDevice::internalSetStatus(TQString 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() { - return m_installed; -} - -void TDEBatteryDevice::internalSetInstalled(bool tc) { - m_installed = tc; -} - -double TDEBatteryDevice::chargePercent() { - return (m_currentEnergy/m_maximumEnergy)*100.0; -} - -TDEMainsPowerDevice::TDEMainsPowerDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { -} - -TDEMainsPowerDevice::~TDEMainsPowerDevice() { -} - -bool TDEMainsPowerDevice::online() { - return m_online; -} - -void TDEMainsPowerDevice::internalSetOnline(bool tc) { - m_online = tc; -} - TDENetworkDevice::TDENetworkDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { m_rxbytes = -1; m_txbytes = -1; diff --git a/tdecore/tdehw/tdehardwaredevices.h b/tdecore/tdehw/tdehardwaredevices.h index 710d7bd8e..200999bf1 100644 --- a/tdecore/tdehw/tdehardwaredevices.h +++ b/tdecore/tdehw/tdehardwaredevices.h @@ -36,6 +36,9 @@ // FIXME delete those headers after complete porting #include "tdegenericdevice.h" #include "tdestoragedevice.h" +#include "tdecpudevice.h" +#include "tdemainspowerdevice.h" +#include "tdebatterydevice.h" /** * Hardware Device Access and Monitoring Library @@ -73,388 +76,6 @@ class TDECORE_EXPORT TDESensorCluster double critical; }; -class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice -{ - public: - /** - * Constructor. - * @param Device type - */ - TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); - - /** - * Destructor. - */ - ~TDECPUDevice(); - - /** - * @return a double with the current CPU frequency in MHz, if available - */ - double frequency(); - - /** - * @return a double with the minimum CPU frequency in MHz, if available - */ - double minFrequency(); - - /** - * @return a double with the maximum CPU frequency in MHz, if available - */ - double maxFrequency(); - - /** - * @return a double with the transition latency in ns, if available - */ - double transitionLatency(); - - /** - * @return a TQString with the current CPU governor policy, if available - */ - TQString governor(); - - /** - * @return a TQString with the current CPU scaling driver, if available - */ - TQString scalingDriver(); - - /** - * @return a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available - */ - TQStringList dependentProcessors(); - - /** - * @return a TQStringList with all valid scaling frequencies in Hz, if available - */ - TQStringList availableFrequencies(); - - /** - * @return a TQStringList with all available governor policies, if available - */ - TQStringList availableGovernors(); - - /** - * @return TRUE if permissions allow the CPU governor to be set, FALSE if not - */ - bool canSetGovernor(); - - /** - * @param gv a TQString with the new CPU governor policy name - */ - 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); - - /** - * @return an integer with the core number, starting at 0 - */ - int coreNumber(); - - protected: - /** - * @param fr a double with the current CPU frequency in MHz, if available - * @internal - */ - void internalSetFrequency(double fr); - - /** - * @param fr a double with the minimum CPU frequency in MHz, if available - * @internal - */ - void internalSetMinFrequency(double fr); - - /** - * @param fr a double with the maximum CPU frequency in MHz, if available - * @internal - */ - void internalSetMaxFrequency(double fr); - - /** - * @param tl a double with the transition latency in ns, if available - * @internal - */ - void internalSetTransitionLatency(double tl); - - /** - * @param gr a TQString with the current CPU governor policy, if available - * @internal - */ - void internalSetGovernor(TQString gr); - - /** - * @param dr a TQString with the current CPU scaling driver, if available - * @internal - */ - void internalSetScalingDriver(TQString dr); - - /** - * @param dp a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available - * @internal - */ - void internalSetDependentProcessors(TQStringList dp); - - /** - * @param af a TQStringList with all valid scaling frequencies in Hz, if available - * @internal - */ - void internalSetAvailableFrequencies(TQStringList af); - - /** - * @param gp a TQStringList with all available governor policies, if available - * @internal - */ - void internalSetAvailableGovernors(TQStringList gp); - - /** - * @param cn an integer with the core number, starting at 0 - * @internal - */ - void internalSetCoreNumber(int cn); - - private: - double m_frequency; - double m_minfrequency; - double m_maxfrequency; - double m_transitionlatency; - TQString m_governor; - TQString m_scalingdriver; - TQStringList m_tiedprocs; - TQStringList m_frequencies; - TQStringList m_governers; - int m_corenumber; - - friend class TDEHardwareDevices; -}; - -namespace TDEBatteryStatus { -enum TDEBatteryStatus { - Charging, - Discharging, - Full, - Unknown = 0x80000000 -}; -}; - -class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice -{ - public: - /** - * Constructor. - * @param Device type - */ - TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); - - /** - * Destructor. - */ - ~TDEBatteryDevice(); - - /** - * @return a double with the current battery voltage, if available - */ - double voltage(); - - /** - * @return a double with the minimum battery voltage, if available - */ - double minimumVoltage(); - - /** - * @return a double with the maximum battery voltage, if available - */ - double maximumVoltage(); - - /** - * @return a double with the designed maximum battery voltage, if available - */ - double maximumDesignVoltage(); - - /** - * @return a double with the current battery energy in watt-hours, if available - */ - double energy(); - - /** - * @return a double with the current battery alarm energy in watt-hours, if available - */ - double alarmEnergy(); - - /** - * @return a double with the maximum battery energy in watt-hours, if available - */ - double maximumEnergy(); - - /** - * @return a double with the designed maximum battery energy in watt-hours, if available - */ - double maximumDesignEnergy(); - - /** - * @return a double with the current battery discharge rate in watt-hours, if available - */ - 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 - */ - TQString technology(); - - /** - * @return a TDEBatteryStatus::TDEBatteryStatus with the current battery status - */ - TDEBatteryStatus::TDEBatteryStatus status(); - - /** - * @return TRUE if the battery is installed - */ - bool installed(); - - /** - * @return a double with the current battery charge in percent, if available - */ - double chargePercent(); - - protected: - /** - * @param a double with the current battery voltage, if available - * @internal - */ - void internalSetVoltage(double vt); - - /** - * @param a double with the minimum battery voltage, if available - * @internal - */ - void internalSetMinimumVoltage(double vt); - - /** - * @param a double with the maximum battery voltage, if available - * @internal - */ - void internalSetMaximumVoltage(double vt); - - /** - * @param a double with the designed maximum battery voltage, if available - * @internal - */ - void internalSetMaximumDesignVoltage(double vt); - - /** - * @param a double with the current battery energy in watt-hours, if available - * @internal - */ - void internalSetEnergy(double vt); - - /** - * @param a double with the current battery alarm energy in watt-hours, if available - * @internal - */ - void internalSetAlarmEnergy(double vt); - - /** - * @param a double with the maximum battery energy in watt-hours, if available - * @internal - */ - void internalSetMaximumEnergy(double vt); - - /** - * @param a double with the designed maximum battery energy in watt-hours, if available - * @internal - */ - void internalSetMaximumDesignEnergy(double vt); - - /** - * @param a double with the current battery discharge rate in volt-hours, if available - * @internal - */ - 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 - * @internal - */ - void internalSetTechnology(TQString tc); - - /** - * @param a TQString with the battery status, if available - * @internal - */ - void internalSetStatus(TQString tc); - - /** - * @param TRUE if the battery is installed - * @internal - */ - void internalSetInstalled(bool tc); - - private: - double m_currentVoltage; - double m_minimumVoltage; - double m_maximumVoltage; - double m_maximumDesignVoltage; - double m_alarmEnergy; - double m_currentEnergy; - double m_maximumEnergy; - double m_maximumDesignEnergy; - double m_dischargeRate; - double m_timeRemaining; - TQString m_technology; - TDEBatteryStatus::TDEBatteryStatus m_status; - bool m_installed; - - friend class TDEHardwareDevices; -}; - -class TDECORE_EXPORT TDEMainsPowerDevice : public TDEGenericDevice -{ - public: - /** - * Constructor. - * @param Device type - */ - TDEMainsPowerDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); - - /** - * Destructor. - */ - ~TDEMainsPowerDevice(); - - /** - * @return TRUE if power supply is online via mains power, FALSE if not - */ - bool online(); - - protected: - /** - * @param TRUE if power supply is online via mains power, FALSE if not - * @internal - */ - void internalSetOnline(bool vt); - - private: - bool m_online; - - friend class TDEHardwareDevices; -}; - class TDECORE_EXPORT TDENetworkDevice : public TDEGenericDevice { public: diff --git a/tdecore/tdehw/tdemainspowerdevice.cpp b/tdecore/tdehw/tdemainspowerdevice.cpp new file mode 100644 index 000000000..60eb4f169 --- /dev/null +++ b/tdecore/tdehw/tdemainspowerdevice.cpp @@ -0,0 +1,36 @@ +/* This file is part of the TDE libraries + Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net> + (C) 2013 Golubev Alexander <fatzer2@gmail.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdemainspowerdevice.h" + +TDEMainsPowerDevice::TDEMainsPowerDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { +} + +TDEMainsPowerDevice::~TDEMainsPowerDevice() { +} + +bool TDEMainsPowerDevice::online() { + return m_online; +} + +void TDEMainsPowerDevice::internalSetOnline(bool tc) { + m_online = tc; +} + +#include "tdemainspowerdevice.moc" diff --git a/tdecore/tdehw/tdemainspowerdevice.h b/tdecore/tdehw/tdemainspowerdevice.h new file mode 100644 index 000000000..8dcaeeea4 --- /dev/null +++ b/tdecore/tdehw/tdemainspowerdevice.h @@ -0,0 +1,57 @@ +/* This file is part of the TDE libraries + Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net> + (C) 2013 Golubev Alexander <fatzer2@gmail.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _TDEMAINSPOWERDEVICE_H +#define _TDEMAINSPOWERDEVICE_H + +#include "tdegenericdevice.h" + +class TDECORE_EXPORT TDEMainsPowerDevice : public TDEGenericDevice +{ + public: + /** + * Constructor. + * @param Device type + */ + TDEMainsPowerDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); + + /** + * Destructor. + */ + ~TDEMainsPowerDevice(); + + /** + * @return TRUE if power supply is online via mains power, FALSE if not + */ + bool online(); + + protected: + /** + * @param TRUE if power supply is online via mains power, FALSE if not + * @internal + */ + void internalSetOnline(bool vt); + + private: + bool m_online; + + friend class TDEHardwareDevices; +}; + +#endif // _TDEMAINSPOWERDEVICE_H |