• 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) || defined(WITH_HAL)
34  #include <tqdbusdata.h>
35  #include <tqdbusmessage.h>
36  #include <tqdbusproxy.h>
37  #include <tqdbusvariant.h>
38  #include <tqdbusconnection.h>
39 #endif // defined(WITH_TDEHWLIB_DAEMONS) || defined(WITH_HAL)
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 #ifdef WITH_HAL
155  {
156  TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
157  if (dbusConn.isConnected()) {
158  TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
159  "org.freedesktop.Hal",
160  "/org/freedesktop/Hal/devices/computer",
161  "org.freedesktop.Hal.Device.CPUFreq",
162  "GetCPUFreqGovernor");
163  TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
164  if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
165  return true;
166  }
167  }
168  }
169 #endif // WITH_HAL
170 
171  return FALSE;
172 }
173 
174 void TDECPUDevice::setGovernor(TQString gv) {
175  bool setGovernorDone = FALSE;
176 
177  TQString governornode = systemPath() + "/cpufreq/scaling_governor";
178  TQFile file( governornode );
179  if ( file.open( IO_WriteOnly ) ) {
180  TQTextStream stream( &file );
181  stream << gv.lower();
182  file.close();
183  setGovernorDone = TRUE;
184  }
185 
186 #ifdef WITH_TDEHWLIB_DAEMONS
187  if ( !setGovernorDone ) {
188  TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
189  if (dbusConn.isConnected()) {
190  TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
191  if (hardwareControl.canSend()) {
192  // set CPU governor
193  TQValueList<TQT_DBusData> params;
194  params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower());
195  TQT_DBusMessage reply = hardwareControl.sendWithReply("SetCPUGovernor", params);
196  if (reply.type() == TQT_DBusMessage::ReplyMessage) {
197  setGovernorDone = TRUE;
198  }
199  }
200  }
201  }
202 #endif // WITH_TDEHWLIB_DAEMONS
203 
204 #ifdef WITH_HAL
205  if ( !setGovernorDone ) {
206  TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
207  if (dbusConn.isConnected()) {
208  TQT_DBusProxy cpuFreqControl("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.CPUFreq", dbusConn);
209  if (cpuFreqControl.canSend()) {
210  // set CPU governor
211  TQValueList<TQT_DBusData> params;
212  params << TQT_DBusData::fromString(gv.lower());
213  TQT_DBusMessage reply = cpuFreqControl.sendWithReply("SetCPUFreqGovernor", params);
214  if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
215  setGovernorDone = TRUE;
216  }
217  }
218  }
219  }
220 #endif // WITH_HAL
221 
222  // Force update of the device information object
223  if ( setGovernorDone ) {
224  TDEGlobal::hardwareDevices()->processModifiedCPUs();
225  }
226 }
227 
228 bool TDECPUDevice::canSetMaximumScalingFrequency() {
229  TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
230  int rval = access (freqnode.ascii(), W_OK);
231  if (rval == 0) {
232  return TRUE;
233  }
234  else {
235  return FALSE;
236  }
237 }
238 
239 void TDECPUDevice::setMaximumScalingFrequency(double fr) {
240  TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
241  TQFile file( freqnode );
242  if ( file.open( IO_WriteOnly ) ) {
243  TQTextStream stream( &file );
244  stream << TQString("%1").arg(fr*1000000.0, 0, 'f', 0);
245  file.close();
246  }
247 
248  // Force update of the device information object
249  TDEGlobal::hardwareDevices()->processModifiedCPUs();
250 }
251 
252 int TDECPUDevice::coreNumber() {
253  return m_corenumber;
254 }
255 
256 #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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.