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

tdecore

  • tdecore
  • tdehw
tdecpudevice.cpp
1 /* This file is part of the TDE libraries
2  Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
3  (C) 2013 Golubev Alexander <fatzer2@gmail.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "tdecpudevice.h"
21 
22 #include <unistd.h>
23 
24 #include <tqfile.h>
25 
26 #include "tdeglobal.h"
27 
28 #include "tdehardwaredevices.h"
29 
30 #include "config.h"
31 
32 // uPower
33 #if defined(WITH_TDEHWLIB_DAEMONS)
34  #include <tqdbusdata.h>
35  #include <tqdbusmessage.h>
36  #include <tqdbusproxy.h>
37  #include <tqdbusvariant.h>
38  #include <tqdbusconnection.h>
39 #endif
40 
41 
42 TDECPUDevice::TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
43  m_frequency = -1;
44  m_minfrequency = -1;
45  m_maxfrequency = -1;
46  m_corenumber = -1;
47  m_transitionlatency = -1;
48 }
49 
50 TDECPUDevice::~TDECPUDevice() {
51 }
52 
53 double TDECPUDevice::frequency() {
54  return m_frequency;
55 }
56 
57 void TDECPUDevice::internalSetFrequency(double fr) {
58  m_frequency = fr;
59 }
60 
61 double TDECPUDevice::minFrequency() {
62  return m_minfrequency;
63 }
64 
65 void TDECPUDevice::internalSetMinFrequency(double fr) {
66  m_minfrequency = fr;
67 }
68 
69 double TDECPUDevice::maxFrequency() {
70  return m_maxfrequency;
71 }
72 
73 void TDECPUDevice::internalSetMaxFrequency(double fr) {
74  m_maxfrequency = fr;
75 }
76 
77 double TDECPUDevice::transitionLatency() {
78  return m_transitionlatency;
79 }
80 
81 void TDECPUDevice::internalSetTransitionLatency(double tl) {
82  m_transitionlatency = tl;
83 }
84 
85 TQString TDECPUDevice::governor() {
86  return m_governor;
87 }
88 
89 void TDECPUDevice::internalSetGovernor(TQString gr) {
90  m_governor = gr;
91 }
92 
93 TQString TDECPUDevice::scalingDriver() {
94  return m_scalingdriver;
95 }
96 
97 void TDECPUDevice::internalSetScalingDriver(TQString dr) {
98  m_scalingdriver = dr;
99 }
100 
101 TQStringList TDECPUDevice::dependentProcessors() {
102  return m_tiedprocs;
103 }
104 
105 void TDECPUDevice::internalSetDependentProcessors(TQStringList dp) {
106  m_tiedprocs = dp;
107 }
108 
109 TQStringList TDECPUDevice::availableFrequencies() {
110  return m_frequencies;
111 }
112 
113 void TDECPUDevice::internalSetAvailableFrequencies(TQStringList af) {
114  m_frequencies = af;
115 }
116 
117 TQStringList TDECPUDevice::availableGovernors() {
118  return m_governers;
119 }
120 
121 void TDECPUDevice::internalSetAvailableGovernors(TQStringList gp) {
122  m_governers = gp;
123 }
124 
125 void TDECPUDevice::internalSetCoreNumber(int cn) {
126  m_corenumber = cn;
127 }
128 
129 bool TDECPUDevice::canSetGovernor() {
130  TQString governornode = systemPath() + "/cpufreq/scaling_governor";
131  int rval = access (governornode.ascii(), W_OK);
132  if (rval == 0) {
133  return true;
134  }
135 
136 #ifdef WITH_TDEHWLIB_DAEMONS
137  {
138  TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
139  if (dbusConn.isConnected()) {
140  TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
141  if (hardwareControl.canSend()) {
142  // can set CPU governor?
143  TQValueList<TQT_DBusData> params;
144  params << TQT_DBusData::fromInt32(coreNumber());
145  TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", params);
146  if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
147  return reply[0].toBool();
148  }
149  }
150  }
151  }
152 #endif // WITH_TDEHWLIB_DAEMONS
153 
154  return false;
155 }
156 
157 void TDECPUDevice::setGovernor(TQString gv) {
158  bool setGovernorDone = false;
159 
160  TQString governornode = systemPath() + "/cpufreq/scaling_governor";
161  TQFile file( governornode );
162  if ( file.open( IO_WriteOnly ) ) {
163  TQTextStream stream( &file );
164  stream << gv.lower();
165  file.close();
166  setGovernorDone = true;
167  }
168 
169 #ifdef WITH_TDEHWLIB_DAEMONS
170  if ( !setGovernorDone ) {
171  TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
172  if (dbusConn.isConnected()) {
173  TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
174  if (hardwareControl.canSend()) {
175  // set CPU governor
176  TQValueList<TQT_DBusData> params;
177  params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower());
178  TQT_DBusMessage reply = hardwareControl.sendWithReply("SetCPUGovernor", params);
179  if (reply.type() == TQT_DBusMessage::ReplyMessage) {
180  setGovernorDone = true;
181  }
182  }
183  }
184  }
185 #endif // WITH_TDEHWLIB_DAEMONS
186 
187  // Force update of the device information object
188  if ( setGovernorDone ) {
189  TDEGlobal::hardwareDevices()->processModifiedCPUs();
190  }
191 }
192 
193 bool TDECPUDevice::canSetMaximumScalingFrequency() {
194  TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
195  int rval = access (freqnode.ascii(), W_OK);
196  if (rval == 0) {
197  return true;
198  }
199  else {
200  return false;
201  }
202 }
203 
204 void TDECPUDevice::setMaximumScalingFrequency(double fr) {
205  TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
206  TQFile file( freqnode );
207  if ( file.open( IO_WriteOnly ) ) {
208  TQTextStream stream( &file );
209  stream << TQString("%1").arg(fr*1000000.0, 0, 'f', 0);
210  file.close();
211  }
212 
213  // Force update of the device information object
214  TDEGlobal::hardwareDevices()->processModifiedCPUs();
215 }
216 
217 int TDECPUDevice::coreNumber() {
218  return m_corenumber;
219 }
220 
221 #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.9.1
This website is maintained by Timothy Pearson.