• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

tdecpudevice.cpp

00001 /* This file is part of the TDE libraries
00002    Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
00003              (C) 2013 Golubev Alexander <fatzer2@gmail.com>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "tdecpudevice.h"
00021 
00022 #include <unistd.h>
00023 
00024 #include <tqfile.h>
00025 
00026 #include "tdeglobal.h"
00027 
00028 #include "tdehardwaredevices.h"
00029 
00030 #include "config.h"
00031 
00032 // uPower
00033 #if defined(WITH_TDEHWLIB_DAEMONS) || defined(WITH_HAL)
00034     #include <tqdbusdata.h>
00035     #include <tqdbusmessage.h>
00036     #include <tqdbusproxy.h>
00037     #include <tqdbusvariant.h>
00038     #include <tqdbusconnection.h>
00039 #endif // defined(WITH_TDEHWLIB_DAEMONS) || defined(WITH_HAL)
00040 
00041 
00042 TDECPUDevice::TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
00043     m_frequency = -1;
00044     m_minfrequency = -1;
00045     m_maxfrequency = -1;
00046     m_corenumber = -1;
00047     m_transitionlatency = -1;
00048 }
00049 
00050 TDECPUDevice::~TDECPUDevice() {
00051 }
00052 
00053 double TDECPUDevice::frequency() {
00054     return m_frequency;
00055 }
00056 
00057 void TDECPUDevice::internalSetFrequency(double fr) {
00058     m_frequency = fr;
00059 }
00060 
00061 double TDECPUDevice::minFrequency() {
00062     return m_minfrequency;
00063 }
00064 
00065 void TDECPUDevice::internalSetMinFrequency(double fr) {
00066     m_minfrequency = fr;
00067 }
00068 
00069 double TDECPUDevice::maxFrequency() {
00070     return m_maxfrequency;
00071 }
00072 
00073 void TDECPUDevice::internalSetMaxFrequency(double fr) {
00074     m_maxfrequency = fr;
00075 }
00076 
00077 double TDECPUDevice::transitionLatency() {
00078     return m_transitionlatency;
00079 }
00080 
00081 void TDECPUDevice::internalSetTransitionLatency(double tl) {
00082     m_transitionlatency = tl;
00083 }
00084 
00085 TQString TDECPUDevice::governor() {
00086     return m_governor;
00087 }
00088 
00089 void TDECPUDevice::internalSetGovernor(TQString gr) {
00090     m_governor = gr;
00091 }
00092 
00093 TQString TDECPUDevice::scalingDriver() {
00094     return m_scalingdriver;
00095 }
00096 
00097 void TDECPUDevice::internalSetScalingDriver(TQString dr) {
00098     m_scalingdriver = dr;
00099 }
00100 
00101 TQStringList TDECPUDevice::dependentProcessors() {
00102     return m_tiedprocs;
00103 }
00104 
00105 void TDECPUDevice::internalSetDependentProcessors(TQStringList dp) {
00106     m_tiedprocs = dp;
00107 }
00108 
00109 TQStringList TDECPUDevice::availableFrequencies() {
00110     return m_frequencies;
00111 }
00112 
00113 void TDECPUDevice::internalSetAvailableFrequencies(TQStringList af) {
00114     m_frequencies = af;
00115 }
00116 
00117 TQStringList TDECPUDevice::availableGovernors() {
00118     return m_governers;
00119 }
00120 
00121 void TDECPUDevice::internalSetAvailableGovernors(TQStringList gp) {
00122     m_governers = gp;
00123 }
00124 
00125 void TDECPUDevice::internalSetCoreNumber(int cn) {
00126     m_corenumber = cn;
00127 }
00128 
00129 bool TDECPUDevice::canSetGovernor() {
00130     TQString governornode = systemPath() + "/cpufreq/scaling_governor";
00131     int rval = access (governornode.ascii(), W_OK);
00132     if (rval == 0) {
00133         return TRUE;
00134     }
00135 
00136 #ifdef WITH_TDEHWLIB_DAEMONS
00137     {
00138         TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
00139         if (dbusConn.isConnected()) {
00140             TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
00141             if (hardwareControl.canSend()) {
00142                 // can set CPU governor?
00143                 TQValueList<TQT_DBusData> params;
00144                 params << TQT_DBusData::fromInt32(coreNumber());
00145                 TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", params);
00146                 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
00147                     return reply[0].toBool();
00148                 }
00149             }
00150         }
00151     }
00152 #endif // WITH_TDEHWLIB_DAEMONS
00153 
00154 #ifdef WITH_HAL
00155     {
00156         TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
00157         if (dbusConn.isConnected()) {
00158             TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
00159                         "org.freedesktop.Hal",
00160                         "/org/freedesktop/Hal/devices/computer",
00161                         "org.freedesktop.Hal.Device.CPUFreq",
00162                         "GetCPUFreqGovernor");
00163             TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
00164             if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
00165                 return true;
00166             }
00167         }
00168     }
00169 #endif // WITH_HAL
00170 
00171     return FALSE;
00172 }
00173 
00174 void TDECPUDevice::setGovernor(TQString gv) {
00175     bool setGovernorDone = FALSE;
00176 
00177     TQString governornode = systemPath() + "/cpufreq/scaling_governor";
00178     TQFile file( governornode );
00179     if ( file.open( IO_WriteOnly ) ) {
00180         TQTextStream stream( &file );
00181         stream << gv.lower();
00182         file.close();
00183         setGovernorDone = TRUE;
00184     }
00185 
00186 #ifdef WITH_TDEHWLIB_DAEMONS
00187     if ( !setGovernorDone ) {
00188         TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
00189         if (dbusConn.isConnected()) {
00190             TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
00191             if (hardwareControl.canSend()) {
00192                 // set CPU governor
00193                 TQValueList<TQT_DBusData> params;
00194                 params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower());
00195                 TQT_DBusMessage reply = hardwareControl.sendWithReply("SetCPUGovernor", params);
00196                 if (reply.type() == TQT_DBusMessage::ReplyMessage) {
00197                     setGovernorDone = TRUE;
00198                 }
00199             }
00200         }
00201     }
00202 #endif // WITH_TDEHWLIB_DAEMONS
00203 
00204 #ifdef WITH_HAL
00205     if ( !setGovernorDone ) {
00206         TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
00207         if (dbusConn.isConnected()) {
00208             TQT_DBusProxy cpuFreqControl("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.CPUFreq", dbusConn);
00209             if (cpuFreqControl.canSend()) {
00210                 // set CPU governor
00211                 TQValueList<TQT_DBusData> params;
00212                 params << TQT_DBusData::fromString(gv.lower());
00213                 TQT_DBusMessage reply = cpuFreqControl.sendWithReply("SetCPUFreqGovernor", params);
00214                 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
00215                     setGovernorDone = TRUE;
00216                 }
00217             }
00218         }
00219     }
00220 #endif // WITH_HAL
00221 
00222     // Force update of the device information object
00223     if ( setGovernorDone ) {
00224         TDEGlobal::hardwareDevices()->processModifiedCPUs();
00225     }
00226 }
00227 
00228 bool TDECPUDevice::canSetMaximumScalingFrequency() {
00229     TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
00230     int rval = access (freqnode.ascii(), W_OK);
00231     if (rval == 0) {
00232         return TRUE;
00233     }
00234     else {
00235         return FALSE;
00236     }
00237 }
00238 
00239 void TDECPUDevice::setMaximumScalingFrequency(double fr) {
00240     TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
00241     TQFile file( freqnode );
00242     if ( file.open( IO_WriteOnly ) ) {
00243         TQTextStream stream( &file );
00244         stream << TQString("%1").arg(fr*1000000.0, 0, 'f', 0);
00245         file.close();
00246     }
00247 
00248     // Force update of the device information object
00249     TDEGlobal::hardwareDevices()->processModifiedCPUs();
00250 }
00251 
00252 int TDECPUDevice::coreNumber() {
00253     return m_corenumber;
00254 }
00255 
00256 #include "tdecpudevice.moc"

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.6.3
This website is maintained by Timothy Pearson.