summaryrefslogtreecommitdiffstats
path: root/src/hardware.cpp
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2014-02-08 18:21:28 +0100
committerSlávek Banko <slavek.banko@axis.cz>2014-02-08 18:21:28 +0100
commitc68a1bac04c5cfdb0cdcbd91dc54995bfa05e292 (patch)
tree5a6bc1d0a5eba85862a2008df71bc6d273a13397 /src/hardware.cpp
parent5c45c1a222eb91ea429f8c5245e32e43e7505582 (diff)
downloadtdepowersave-c68a1bac04c5cfdb0cdcbd91dc54995bfa05e292.tar.gz
tdepowersave-c68a1bac04c5cfdb0cdcbd91dc54995bfa05e292.zip
Switch from dbus-tqt do dbus-1-tqt
Add systemd session and inhibit support Cleanup unused methods This partially resolves Bug 1597
Diffstat (limited to 'src/hardware.cpp')
-rw-r--r--src/hardware.cpp269
1 files changed, 17 insertions, 252 deletions
diff --git a/src/hardware.cpp b/src/hardware.cpp
index e3b811a..cb4e98c 100644
--- a/src/hardware.cpp
+++ b/src/hardware.cpp
@@ -37,7 +37,6 @@
// include own header
#include "hardware.h"
#include "tdepowersave_debug.h"
-#include "privileges.h"
// #define USE_EVENT_DEVICES_DIRECTLY 1
@@ -51,7 +50,6 @@ HardwareInfo::HardwareInfo() {
laptop = false;
brightness = false;
brightness_in_hardware = false;
- schedPowerSavings = false;
sessionIsActive = true; // assume as first we are active
// initialize connection to the TDE hardware library
@@ -79,20 +77,15 @@ HardwareInfo::HardwareInfo() {
primaryBatteries = new BatteryCollection(BAT_PRIMARY);
setPrimaryBatteriesWarningLevel(); // force default settings
- // connect to D-Bus and HAL
- dbus_HAL = new dbusInterface();
- if (dbus_HAL->isConnectedToDBUS()) {
- dbus_terminated = false;
- } else {
- kdError() << "Could not connect to D-Bus & HAL" << endl;
- }
+ // connect to D-Bus
+ dbus_iface = new dbusInterface();
+ sessionIsActive = dbus_iface->checkActiveSession();
+ connect(dbus_iface, TQT_SIGNAL(activeSessionChanged(bool)), this, TQT_SLOT(handleSessionState(bool)));
- checkConsoleKitSession();
checkPowermanagement();
checkIsLaptop();
checkBrightness();
checkCPUFreq();
- // getSchedPowerSavings();
checkSuspend();
intialiseHWInfo();
@@ -141,15 +134,26 @@ bool HardwareInfo::reinitHardwareInfos () {
checkCPUFreq();
checkSuspend();
intialiseHWInfo();
- // getSchedPowerSavings();
updatePrimaryBatteries();
kdDebugFuncOut(trace);
return true;
}
+
/*!
- * This funtion is used to parse changed hardware nofifications from the TDE hardware library
+ * \b TQT_SLOT called if the state of the current session change
+ * \param state boolean represent the state of the session
+ */
+void HardwareInfo::handleSessionState( bool state ) {
+ if( state != sessionIsActive ) {
+ sessionIsActive = state;
+ TQTimer::singleShot(50, this, TQT_SLOT(emitSessionActiveState()));
+ }
+}
+
+/*!
+ * This function is used to parse changed hardware nofifications from the TDE hardware library
* \param device a \ref TDEGenericDevice* which should be processed
*/
void HardwareInfo::processHardwareChangedEvent (TDEGenericDevice* device) {
@@ -216,99 +220,6 @@ void HardwareInfo::processKeyPressEvent(unsigned int keycode, TDEEventDevice* ed
}
/*!
- * This funtion is used to parse a message from D-Bus for the different
- * messagetypes and events.
- * \param type a \ref msg_type which should be parse/processed
- * \param message the message
- * \param value an optional message value as e.g. message string
- */
-void HardwareInfo::processMessage (msg_type type, TQString message, TQString value) {
- kdDebugFuncIn(trace);
-
- switch(type) {
- case ACPI_EVENT:
- // we don't handle acpi events here atm
- break;
- case HAL_DEVICE:
- // --> we can maybe ignore these events except for batteries, not shure atm
- int _type;
-
- if (message.startsWith("DeviceAdded")) {
- if (checkIfHandleDevice(value, &_type)) {
- switch (_type) {
- case BATTERY:
- case AC_ADAPTER:
- case BUTTON_SLEEP:
- case BUTTON_POWER:
- case LID:
- // TODO: handle code if needed actually not
- break;
- case LAPTOP_PANEL:
- checkBrightness();
- break;
- default:
- kdDebug() << "New device added Device udi: "
- << value << "type: " << _type << endl;
- break;
- }
- }
- } else if (message.startsWith("DeviceRemoved")) {
- if (allUDIs.contains(value)) {
- if (checkIfHandleDevice(value, &_type)) {
- switch (_type) {
- case BATTERY:
- case AC_ADAPTER:
- case BUTTON_SLEEP:
- case BUTTON_POWER:
- case LID:
- // TODO: handle code if needed
- break;
- case LAPTOP_PANEL:
- checkBrightness();
- break;
- default:
- kdDebug() << "Couldn't handle unknown device" << endl;
- break;
- }
- }
- } else {
- kdDebug() << "Not monitored device removed: " << value << endl;
- }
- } else {
- kdDebug() << "Unknown HAL_DEVICE message: " << message << endl;
- }
- break;
- case CONSOLEKIT_SESSION_ACTIVE:
- if (!message.isEmpty() && !value.isEmpty()) {
- if (message == consoleKitSession) {
- if (value == "1") {
- sessionIsActive = true;
- } else {
- sessionIsActive = false;
- }
- TQTimer::singleShot(50, this, TQT_SLOT(emitSessionActiveState()));
- } else {
- if (trace)
- kdDebug() << "CONSOLEKIT_SESSION_ACTIVE: not our session" << endl;
- }
- }
- break;
- case POLICY_POWER_OWNER_CHANGED:
- if (message.startsWith("NOW_OWNER")) {
- // TODO: add code
- } else if (message.startsWith("OTHER_OWNER")){
- // TODO: add code
- }
- break;
- default:
- kdDebug() << "Recieved unknown package type: " << type << endl;
- break;
- }
-
- kdDebugFuncOut(trace);
-}
-
-/*!
* This TQT_SLOT is used to fetch the resume signal and multiplex. If needed some
* actions after resume, do this here.
* \param result integer with the result of the resume/suspend
@@ -331,61 +242,6 @@ void HardwareInfo::handleResumeSignal (int result) {
}
/*!
- * This function checks the session for the running TDEPowersave instance
- * \return Boolean with result of operation
- * \retval true if the query/check could get finished
- * \retval false on every error
- */
-bool HardwareInfo::checkConsoleKitSession () {
- kdDebugFuncIn(trace);
-
- bool retval = false;
-
- if (dbus_HAL->isConnectedToDBUS()) {
- char *reply;
- char *cookie = getenv("XDG_SESSION_COOKIE");
-
- if (cookie == NULL) {
- kdDebug() << "Could not get XDG_SESSION_COOKIE from environment" << endl;
- sessionIsActive = true;
- } else {
- if (dbus_HAL->dbusSystemMethodCall( CK_SERVICE, CK_MANAGER_OBJECT,
- CK_MANAGER_IFACE, "GetSessionForCookie",
- &reply, DBUS_TYPE_OBJECT_PATH,
- DBUS_TYPE_STRING, &cookie,
- DBUS_TYPE_INVALID)) {
- if (trace)
- kdDebug() << "GetSessionForCookie returned: " << reply << endl;
-
- if (reply != NULL) {
- dbus_bool_t i_reply;
- consoleKitSession = reply;
-
- if (dbus_HAL->dbusSystemMethodCall( CK_SERVICE, consoleKitSession,
- CK_SESSION_IFACE, "IsActive",
- &i_reply, DBUS_TYPE_BOOLEAN,
- DBUS_TYPE_INVALID)) {
- sessionIsActive = ((i_reply != 0) ? true: false);
- if (trace)
- kdDebug() << "IsActive returned: " << sessionIsActive << endl;
-
- retval = true;
- } else {
- kdError() << "Could get session cookie and session name, but not "
- << "but not the status of the session. Assume for now "
- << "the Session is inactive!" << endl;
- sessionIsActive = false;
- }
- }
- }
- }
- }
-
- kdDebugFuncOut(trace);
- return retval;
-}
-
-/*!
* This function check for a given UDI, if we should handle a device
* \param _udi TQString with the UDI of the device
* \param *type pointer to a integer to return the type of the device, see \ref device_type
@@ -1090,7 +946,6 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) {
TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
if (hwlist.count() > 0) {
- dbus_bool_t consider = (dbus_bool_t) getAcAdapter();
TQStringList dynamic;
if (checkCurrentCPUFreqPolicy() == cpufreq) {
@@ -1122,20 +977,6 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) {
}
}
-#if 0
- // FIXME
- // What does "SetCPUFreqConsiderNice" actually do??!?!
-
- // correct set ondemand
- if (!dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI,
- HAL_CPUFREQ_IFACE,
- "SetCPUFreqConsiderNice",
- DBUS_TYPE_BOOLEAN, &consider,
- DBUS_TYPE_INVALID)) {
- kdError() << "Couldn't set SetCPUFreqConsiderNice for DYNAMIC" << endl;
- }
-
-#endif
// Set performance limits on all CPUs
TDEGenericDevice *hwdevice;
TDECPUDevice *cpudevice;
@@ -1185,7 +1026,6 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) {
bool HardwareInfo::setCPUFreqGovernor( const char *governor ) {
kdDebugFuncIn(trace);
- int reply;
bool ret = true;
TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
@@ -1205,61 +1045,6 @@ bool HardwareInfo::setCPUFreqGovernor( const char *governor ) {
}
-/*!
- * Function to set the powersave mode (incl. e.g. disk settings) via TDE hardware library.
- * \param on boolean which tell if enable/disable powersave mode
- * \return boolean with result of the operation
- * \retval true if successful
- * \retval false else, if a error occurs
- */
-bool HardwareInfo::setPowerSave( bool on ) {
- kdDebugFuncIn(trace);
-
- bool retval = false;
-
- // FIXME
- // Set up power saving to the best of our ability using "raw" functions
- printf("[FIXME] HardwareInfo::setPowerSave unimplemented!\n"); fflush(stdout);
-
- kdDebugFuncOut(trace);
- return retval;
-}
-
-/*!
- * Function to call GetSchedPowerSavings() via TDE hardware library.
- * \return boolean with result of the operation
- * \retval true if successful
- * \retval false else, if a error occurs
- */
-bool HardwareInfo::getSchedPowerSavings() {
- kdDebugFuncIn(trace);
-
- bool returnval = false;
-
- // What does the HAL method GetSchedPowerSavings actually do?!?!?
-
- kdDebugFuncOut(trace);
- return returnval;
-}
-
-/*!
- * Function to call SetSchedPowerSavings() via TDE hardware library.
- * Note: this would only work on multiprocessor/-core machines.
- * \return boolean with result of the operation
- * \retval true if successful
- * \retval false else, if a error occurs
- */
-bool HardwareInfo::setSchedPowerSavings( bool enable ) {
- kdDebugFuncIn(trace);
-
- bool retval = false;
-
- // What does the HAL method SetCPUFreqPerformance actually do?!?!?
-
- kdDebugFuncOut(trace);
- return retval;
-}
-
// --> TDE hardware library method call (trigger actions) section -- END <---
@@ -1304,16 +1089,6 @@ void HardwareInfo::emitS2diskButtonPressed() {
* Function to emit the signal about changes in the session state
*/
void HardwareInfo::emitSessionActiveState() {
- if (sessionIsActive) {
- if (!dbus_HAL->acquiredPolicyPowerInterface()) {
- dbus_HAL->acquirePolicyPowerIface();
- }
- } else {
- if (dbus_HAL->acquiredPolicyPowerInterface()) {
- dbus_HAL->releasePolicyPowerIface();
- }
- }
-
emit desktopSessionIsActive(sessionIsActive);
}
@@ -1635,16 +1410,6 @@ int HardwareInfo::isCpuFreqAllowed () {
return cpuFreqAllowed;
}
-/*! check if the org.freedesktop.Policy.Power interface has an owner
- * \return boolean with info if org.freedesktop.Policy.Power interface has an owner or not
- * \retval true if there is a owner
- * \retval false else
- */
-bool HardwareInfo::isPolicyPowerIfaceOwned () {
- return dbus_HAL->isPolicyPowerIfaceOwned();
-}
-
-
// --> get private members section -- END <---
#include "hardware.moc"