diff options
Diffstat (limited to 'src/hardware.cpp')
-rw-r--r-- | src/hardware.cpp | 781 |
1 files changed, 335 insertions, 446 deletions
diff --git a/src/hardware.cpp b/src/hardware.cpp index ab65969..227c7a5 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -31,6 +31,9 @@ #include <tqtimer.h> #include <tqdir.h> +// keycode definitions +#include <linux/input.h> + // include own header #include "hardware.h" #include "kpowersave_debug.h" @@ -43,14 +46,17 @@ HardwareInfo::HardwareInfo() { // init members acadapter = true; lidclose = false; - dbus_terminated = true; - hal_terminated = true; 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 + m_hwdevices = KGlobal::hardwareDevices(); + connect(m_hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(processHardwareChangedEvent(TDEGenericDevice*))); + connect(m_hwdevices, TQT_SIGNAL(eventDeviceKeyPressed(unsigned int, TDEEventDevice*)), this, TQT_SLOT(processKeyPressEvent(unsigned int, TDEEventDevice*))); + // update everything the first time update_info_ac_changed = true; update_info_cpufreq_policy_changed = true; @@ -72,11 +78,6 @@ HardwareInfo::HardwareInfo() { dbus_HAL = new dbusHAL(); if (dbus_HAL->isConnectedToDBUS()) { dbus_terminated = false; - if (dbus_HAL->isConnectedToHAL()) { - hal_terminated = false; - } else { - kdError() << "Could not connect to HAL" << endl; - } } else { kdError() << "Could not connect to D-Bus & HAL" << endl; } @@ -92,11 +93,6 @@ HardwareInfo::HardwareInfo() { updatePrimaryBatteries(); - // connect to signals - connect(dbus_HAL, TQT_SIGNAL(msgReceived_withStringString( msg_type, TQString, TQString )), - this, TQT_SLOT(processMessage( msg_type, TQString, TQString ))); - connect(dbus_HAL, TQT_SIGNAL(backFromSuspend(int)), this, TQT_SLOT(handleResumeSignal(int))); - kdDebugFuncOut(trace); } @@ -104,40 +100,6 @@ HardwareInfo::HardwareInfo() { HardwareInfo::~HardwareInfo() { kdDebugFuncIn(trace); - delete dbus_HAL; - dbus_HAL = NULL; - - kdDebugFuncOut(trace); -} - -/*! - * This funtion is used to handle the reconnect to the D-Bus daemon - */ -void HardwareInfo::reconnectDBUS() { - kdDebugFuncIn(trace); - - if (!dbus_HAL->isConnectedToDBUS()) { - bool _reconnect = dbus_HAL->reconnect(); - - if (!_reconnect && !dbus_HAL->isConnectedToDBUS()) { - //reconnect failed - emit dbusRunning(DBUS_NOT_RUNNING); - TQTimer::singleShot(4000, this, TQT_SLOT(reconnectDBUS())); - } else if (!_reconnect && dbus_HAL->isConnectedToDBUS()) { - // reset everything, we are reconnected - dbus_terminated = false; - hal_terminated = true; - emit dbusRunning(DBUS_RUNNING); - } else if (_reconnect) { - // reset everything, we are reconnected - dbus_terminated = false; - hal_terminated = false; - reinitHardwareInfos(); - emit dbusRunning(hal_terminated); - emit halRunning(DBUS_RUNNING); - } - } - kdDebugFuncOut(trace); } @@ -150,43 +112,101 @@ void HardwareInfo::reconnectDBUS() { bool HardwareInfo::reinitHardwareInfos () { kdDebugFuncIn(trace); - if (dbus_HAL->isConnectedToDBUS() && dbus_HAL->isConnectedToHAL()) { - /* first cleanup */ - acadapter = true; - lidclose = false; - laptop = false; - brightness = false; - has_APM = false; - has_ACPI = false; + /* first cleanup */ + acadapter = true; + lidclose = false; + laptop = false; + brightness = false; + has_APM = false; + has_ACPI = false; + + update_info_ac_changed = true; + update_info_cpufreq_policy_changed = true; + update_info_primBattery_changed = true; - update_info_ac_changed = true; - update_info_cpufreq_policy_changed = true; - update_info_primBattery_changed = true; - - allUDIs = TQStringList(); + allUDIs = TQStringList(); - BatteryList.clear(); - primaryBatteries = new BatteryCollection(BAT_PRIMARY); + BatteryList.clear(); + primaryBatteries = new BatteryCollection(BAT_PRIMARY); - // check the current desktop session again - checkConsoleKitSession(); - - /* reinit hardware data */ - checkPowermanagement(); - checkIsLaptop(); - checkBrightness(); - checkCPUFreq(); - checkSuspend(); - intialiseHWInfo(); - // getSchedPowerSavings(); - updatePrimaryBatteries(); - - kdDebugFuncOut(trace); - return true; + /* reinit hardware data */ + checkPowermanagement(); + checkIsLaptop(); + checkBrightness(); + checkCPUFreq(); + checkSuspend(); + intialiseHWInfo(); + // getSchedPowerSavings(); + updatePrimaryBatteries(); + + kdDebugFuncOut(trace); + return true; +} + +/*! + * This funtion 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) { + kdDebugFuncIn(trace); + + if (allUDIs.contains( device->uniqueID() )) { + if (device->type() == TDEGenericDeviceType::PowerSupply) { + TQTimer::singleShot(50, this, TQT_SLOT(checkACAdapterState())); + } else if (device->type() == TDEGenericDeviceType::Battery) { + // this is a battery event + updateBatteryValues(device); + } else if (device->type() == TDEGenericDeviceType::Event) { + TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(device); + if (edevice) { + if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) { + TQTimer::singleShot(50, this, TQT_SLOT(checkLidcloseState())); + } + } + } else if (device->type() == TDEGenericDeviceType::Backlight) { + TQTimer::singleShot(50, this, TQT_SLOT(checkBrightness())); + } + // TODO: add needed code } else { - kdDebugFuncOut(trace); - return false; + kdDebug() << "unmonitored device changed: " << device->uniqueID() << endl; } + + kdDebugFuncOut(trace); +} + +/*! + * This funtion is used to parse changed hardware nofifications from the TDE hardware library + * \param keycode a keycode which should be processed + * \param edevice the \ref TDEEventDevice* from whence the keypress originated + */ +void HardwareInfo::processKeyPressEvent(unsigned int keycode, TDEEventDevice* edevice) { + kdDebugFuncIn(trace); + + // FIXME + // How can I get specific button press/release information (instead of just "something happened to the button") from the TDE hardware library? + // FIXME + // How are sleep buttons normally handled? On my Thinkpad pressing Fn+Sleep doesn't generate an event from the ACPI sleep button event device... + // TODO: Check if we really need to monitor this events. We get maybe also + // HAL_PROPERTY_CHANGED event for the key +// if (message.startsWith("ButtonPressed")) { + kdDebug() << "ButtonPressed event from TDE HW library " << endl; + if ((edevice->eventType() == TDEEventDeviceType::ACPIPowerButton) && (keycode == KEY_POWER)) { + TQTimer::singleShot(50, this, TQT_SLOT(emitPowerButtonPressed())); + } else if ((edevice->eventType() == TDEEventDeviceType::ACPISleepButton) && (keycode == KEY_SLEEP)) { + TQTimer::singleShot(50, this, TQT_SLOT(emitSleepButtonPressed())); +// } else if (value.startsWith("hibernate")) { +// TQTimer::singleShot(50, this, TQT_SLOT(emitS2diskButtonPressed())); +// } else if (value.startsWith("brightness-")) { +// if (!brightness_in_hardware && value.endsWith("-up")) +// TQTimer::singleShot(50, this, TQT_SLOT(brightnessUpPressed())); +// else if (!brightness_in_hardware && value.endsWith("-down")) +// TQTimer::singleShot(50, this, TQT_SLOT(brightnessDownPressed())); + } +// } else { +// kdDebug() << "Unmonitored HAL_CONDITION: " << message << " : " << value << endl; +// } + + kdDebugFuncOut(trace); } /*! @@ -203,29 +223,6 @@ void HardwareInfo::processMessage (msg_type type, TQString message, TQString val case ACPI_EVENT: // we don't handle acpi events here atm break; - case DBUS_EVENT: - kdDebug() << "D-Bus Event: " << value << endl; - if ( message.startsWith("dbus.terminate")){ - // TODO: addapt from pdaemon - dbus_terminated = true; - TQTimer::singleShot(4000, this, TQT_SLOT(reconnectDBUS())); - } - else if ( message.startsWith("hal.")) { - if ( message.startsWith("hal.terminate")) { - hal_terminated = true; - emit halRunning(false); - // TODO: update data - emit generalDataChanged(); - } else if ( message.startsWith("hal.started")) { - hal_terminated = false; - reinitHardwareInfos(); - emit halRunning( true ); - // TODO: update data - emit generalDataChanged(); - } - // TODO: addapt from pdaemon - } - break; case HAL_DEVICE: // --> we can maybe ignore these events except for batteries, not shure atm int _type; @@ -275,50 +272,6 @@ void HardwareInfo::processMessage (msg_type type, TQString message, TQString val kdDebug() << "Unknown HAL_DEVICE message: " << message << endl; } break; - case HAL_PROPERTY_CHANGED: - if (!message.isEmpty() && allUDIs.contains( message )) { - if (value.startsWith( "ac_adapter.present" )) { - TQTimer::singleShot(50, this, TQT_SLOT(checkACAdapterState())); - } else if (value.startsWith( "battery." )) { - // this is a battery event - updateBatteryValues(message, value); - } else if (value.startsWith( "button.state.value" )) { - if (message.startsWith( *udis["lidclose"] )) { - TQTimer::singleShot(50, this, TQT_SLOT(checkLidcloseState())); - } - } else if (value.startsWith( "laptop_panel")) { - if (message.startsWith( *udis["laptop_panel"] )) { - TQTimer::singleShot(50, this, TQT_SLOT(checkBrightness())); - } - } - // TODO: add needed code - } else { - kdDebug() << "HAL_PROPERTY_CHANGED for unmonitored device: " << value << endl; - } - break; - case HAL_CONDITION: - // TODO: Check if we really need to monitor this events. We get maybe also - // HAL_PROPERTY_CHANGED event for the key - if (message.startsWith("ButtonPressed")) { - kdDebug() << "ButtonPressed event from HAL: " << value << endl; - if (value.startsWith("lid")) { - TQTimer::singleShot(50, this, TQT_SLOT(checkLidcloseState())); - } else if (value.startsWith("power")) { - TQTimer::singleShot(50, this, TQT_SLOT(emitPowerButtonPressed())); - } else if (value.startsWith("sleep") || value.startsWith("suspend")) { - TQTimer::singleShot(50, this, TQT_SLOT(emitSleepButtonPressed())); - } else if (value.startsWith("hibernate")) { - TQTimer::singleShot(50, this, TQT_SLOT(emitS2diskButtonPressed())); - } else if (value.startsWith("brightness-")) { - if (!brightness_in_hardware && value.endsWith("-up")) - TQTimer::singleShot(50, this, TQT_SLOT(brightnessUpPressed())); - else if (!brightness_in_hardware && value.endsWith("-down")) - TQTimer::singleShot(50, this, TQT_SLOT(brightnessDownPressed())); - } - } else { - kdDebug() << "Unmonitored HAL_CONDITION: " << message << " : " << value << endl; - } - break; case CONSOLEKIT_SESSION_ACTIVE: if (!message.isEmpty() && !value.isEmpty()) { if (message == consoleKitSession) { @@ -426,7 +379,6 @@ bool HardwareInfo::checkConsoleKitSession () { return retval; } - /*! * This function check for a given UDI, if we should handle a device * \param _udi TQString with the UDI of the device @@ -440,18 +392,21 @@ bool HardwareInfo::checkIfHandleDevice ( TQString _udi, int *type) { TQStringList _cap; bool ret = true; + + TDEGenericDevice* hwdevice = m_hwdevices->findByUniqueID(_udi); - if (dbus_HAL->halGetPropertyStringList( _udi, "info.capabilities", &_cap) && !_cap.isEmpty()) { - if (_cap.contains("ac_adapter")) { + if (hwdevice) { + TDEGenericDeviceType::TDEGenericDeviceType devtype = hwdevice->type(); + if (devtype == TDEGenericDeviceType::PowerSupply) { *type = BATTERY; - } else if (_cap.contains("button")) { - TQString _val; - if (dbus_HAL->halGetPropertyString( _udi, "button.type", &_val)) { - if (_val.startsWith("lid")) { + } else if (devtype == TDEGenericDeviceType::Event) { + TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(hwdevice); + if (edevice) { + if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) { *type = LID; - } else if ( _val.startsWith("power")) { + } else if (edevice->eventType() == TDEEventDeviceType::ACPIPowerButton) { *type = BUTTON_POWER; - } else if ( _val.startsWith("sleep")) { + } else if (edevice->eventType() == TDEEventDeviceType::ACPISleepButton) { *type = BUTTON_SLEEP; } else { ret = false; @@ -459,13 +414,13 @@ bool HardwareInfo::checkIfHandleDevice ( TQString _udi, int *type) { } else { ret = false; } - } else if (_cap.contains("battery")) { + } else if (devtype == TDEGenericDeviceType::Battery) { *type = BATTERY; - } else if (_cap.contains("laptop_panel")) { + } else if (devtype == TDEGenericDeviceType::Backlight) { *type = LAPTOP_PANEL; } else { ret = false; - kdDebug() << "Device with capability " << _cap.join(", ") << " unhandled" << endl; + kdDebug() << "Device with type " << devtype << " unhandled" << endl; } } else { ret = false; @@ -516,15 +471,13 @@ void HardwareInfo::checkIsLaptop () { kdDebugFuncIn(trace); TQString ret; - - if (dbus_HAL->halGetPropertyString(HAL_COMPUTER_UDI, "system.formfactor", &ret)) { - if (!ret.isEmpty() && ret.startsWith("laptop")) - laptop = true; - else - laptop = false; - } else { - // error case + TDERootSystemDevice* rdevice = m_hwdevices->rootSystemDevice(); + + if (rdevice->formFactor() == TDESystemFormFactor::Laptop) { + laptop = true; + } + else { laptop = false; } @@ -532,7 +485,7 @@ void HardwareInfo::checkIsLaptop () { } /*! - * The function checks wether the machine support ACPI/APM/PMU or not. + * The function checks whether the machine support ACPI/APM/PMU or not. */ void HardwareInfo::checkPowermanagement() { kdDebugFuncIn(trace); @@ -542,97 +495,63 @@ void HardwareInfo::checkPowermanagement() { has_APM = false; has_ACPI = false; has_PMU = false; - - if (dbus_HAL->halGetPropertyString( HAL_COMPUTER_UDI, "power_management.type", &ret)) { - - if (ret.isEmpty()) { - return; - } else if (ret.startsWith("acpi")) { - has_ACPI = true; - } else if (ret.startsWith("apm")) { - has_APM = true; - } else if (ret.startsWith("pmu")) { - has_PMU = true; - } + + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::OtherACPI); + if (hwlist.count() > 0) { + has_ACPI = true; } + + // FIXME + // Do we even need to detect APM and PMU devices in the year 2012?!? kdDebugFuncOut(trace); } /*! - * The function checks wether the machine can suspend/standby. + * The function checks whether the machine can suspend/standby. */ void HardwareInfo::checkSuspend() { kdDebugFuncIn(trace); - TQStringList ret; - bool _ret_b = false; - suspend_states = SuspendStates(); - if (dbus_HAL->halGetPropertyStringList( HAL_COMPUTER_UDI, HAL_PM_IFACE ".method_names", - &ret )) { - // check for suspend2ram - if (dbus_HAL->halGetPropertyBool( HAL_COMPUTER_UDI, "power_management.can_suspend", &_ret_b ) || - dbus_HAL->halGetPropertyBool( HAL_COMPUTER_UDI, "power_management.can_suspend_to_ram", - &_ret_b )) { - suspend_states.suspend2ram_can = _ret_b; - if (_ret_b) { - if (ret.contains( "Suspend" )) { - suspend_states.suspend2ram = true; - suspend_states.suspend2ram_allowed = dbus_HAL->isUserPrivileged(PRIV_SUSPEND, - HAL_COMPUTER_UDI); + suspend_states.suspend2ram = false; + suspend_states.suspend2ram_can = false; + suspend_states.suspend2ram_allowed = -1; + suspend_states.suspend2disk = false; + suspend_states.suspend2disk_can = false; + suspend_states.suspend2disk_allowed = -1; + suspend_states.standby = false; + suspend_states.standby_can = false; + suspend_states.standby_allowed = -1; + + TDERootSystemDevice* rdevice = m_hwdevices->rootSystemDevice(); + TDESystemPowerStateList powerStates = rdevice->powerStates(); + if (powerStates.count() > 0) { + TDESystemPowerStateList::iterator it; + for (it = powerStates.begin(); it != powerStates.end(); ++it) { + if ((*it) == TDESystemPowerState::Active) { + // } - } else { - suspend_states.suspend2ram = false; - suspend_states.suspend2ram_allowed = -1; + if ((*it) == TDESystemPowerState::Standby) { + suspend_states.standby = true; + suspend_states.standby_allowed = rdevice->canStandby(); + suspend_states.standby_can = suspend_states.standby_allowed & suspend_states.standby; } - } else { - suspend_states.suspend2ram_can = false; - suspend_states.suspend2ram = false; - suspend_states.suspend2ram_allowed = -1; - } - - // check for suspend2disk - if (dbus_HAL->halGetPropertyBool( HAL_COMPUTER_UDI, "power_management.can_hibernate", &_ret_b ) || - dbus_HAL->halGetPropertyBool( HAL_COMPUTER_UDI, "power_management.can_suspend_to_disk", - &_ret_b )) { - suspend_states.suspend2disk_can = _ret_b; - if (_ret_b) { - if (ret.contains( "Hibernate" )) { - suspend_states.suspend2disk = true; - suspend_states.suspend2disk_allowed = - dbus_HAL->isUserPrivileged(PRIV_HIBERNATE, - HAL_COMPUTER_UDI); + if ((*it) == TDESystemPowerState::Suspend) { + suspend_states.suspend2ram = true; + suspend_states.suspend2ram_allowed = rdevice->canSuspend(); + suspend_states.suspend2ram_can = suspend_states.suspend2ram_allowed & suspend_states.suspend2ram; } - } else { - suspend_states.suspend2disk = false; - suspend_states.suspend2disk_allowed = -1; - } - } else { - suspend_states.suspend2disk_can = false; - suspend_states.suspend2disk = false; - suspend_states.suspend2disk_allowed = -1; - } - - // check for StandBy - if (dbus_HAL->halGetPropertyBool( HAL_COMPUTER_UDI, "power_management.can_standby", &_ret_b )) { - suspend_states.standby_can = _ret_b; - if (_ret_b) { - if (ret.contains( "Standby" )) { - suspend_states.standby = true; - suspend_states.standby_allowed = dbus_HAL->isUserPrivileged(PRIV_STANDBY, - HAL_COMPUTER_UDI); + if ((*it) == TDESystemPowerState::Hibernate) { + suspend_states.suspend2disk = true; + suspend_states.suspend2disk_allowed = rdevice->canSuspend(); + suspend_states.suspend2disk_can = suspend_states.suspend2disk_allowed & suspend_states.suspend2disk; } - } else { - suspend_states.standby = false; - suspend_states.standby_allowed = -1; + if ((*it) == TDESystemPowerState::PowerOff) { + // } - } else { - suspend_states.standby_can = false; - suspend_states.standby = false; - suspend_states.standby_allowed = -1; } } @@ -640,17 +559,20 @@ void HardwareInfo::checkSuspend() { } /*! - * The function checks wether the machine support CPU frequency changes - * via HAL. + * The function checks whether the machine support CPU frequency changes */ void HardwareInfo::checkCPUFreq() { kdDebugFuncIn(trace); - - bool ret = false; - if (dbus_HAL->halQueryCapability( HAL_COMPUTER_UDI, "cpufreq_control", &ret )) { - cpuFreq = ret; - cpuFreqAllowed = dbus_HAL->isUserPrivileged( PRIV_CPUFREQ, HAL_COMPUTER_UDI); + // Use the first CPU in the list; permissions are probably the same across all CPUs + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); + + if (!cpudevice->scalingDriver().isNull()) { + cpuFreq = true; + cpuFreqAllowed = cpudevice->canSetGovernor(); checkCurrentCPUFreqPolicy(); } else { @@ -666,33 +588,30 @@ void HardwareInfo::checkCPUFreq() { */ cpufreq_type HardwareInfo::checkCurrentCPUFreqPolicy() { kdDebugFuncIn(trace); + + // Use the first CPU in the list; permissions are probably the same across all CPUs + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); - char *gov; + TQString gov = cpudevice->governor(); cpufreq_type _current = UNKNOWN_CPUFREQ; if (cpuFreq) { - - if (dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI, - HAL_CPUFREQ_IFACE, "GetCPUFreqGovernor", - &gov, DBUS_TYPE_STRING, DBUS_TYPE_INVALID)) { - if (gov != NULL) { - kdDebug() << "got CPU Freq gov: " << gov << endl; - if (!strcmp(gov, "ondemand") || !strcmp(gov, "userspace") || - !strcmp(gov, "conservative")) { - _current = DYNAMIC; - } else if (!strcmp(gov, "powersave")) { - _current = POWERSAVE; - } else if (!strcmp(gov, "performance")) { - _current = PERFORMANCE; - } else { - kdError() << "Got unknown CPUFreq Policy back: " << gov << endl; - } - cpuFreqGovernor = gov; - } - else { - kdWarning() << "Could not get information about current governor" << endl; + if (!gov.isNull()) { + kdDebug() << "got CPU Freq gov: " << gov << endl; + if ((gov == "ondemand") || (gov == "userspace") || (gov == "conservative")) { + _current = DYNAMIC; + } else if (gov == "powersave") { + _current = POWERSAVE; + } else if (gov =="performance") { + _current = PERFORMANCE; + } else { + kdError() << "Got unknown CPUFreq Policy back: " << gov << endl; } + cpuFreqGovernor = gov; } else { kdWarning() << "Could not get information about current governor" << endl; } @@ -714,7 +633,7 @@ cpufreq_type HardwareInfo::checkCurrentCPUFreqPolicy() { /*! - * The function checks wether the machine provide a brightness interface and init + * The function checks whether the machine provide a brightness interface and init * (if needed) brightness information. */ void HardwareInfo::checkBrightness() { @@ -726,42 +645,36 @@ void HardwareInfo::checkBrightness() { currentBrightnessLevel = -1; availableBrightnessLevels = -1; - if( dbus_HAL->halFindDeviceByCapability("laptop_panel", &devices)) { - if (devices.isEmpty()) { - udis.remove("laptop_panel"); - kdDebug() << "no device with category laptop_panel found" << endl; - kdDebugFuncOut(trace); - return; - } else { - int retval; - - - kdDebug() << "laptop_panel device found: " << devices.first() << endl; - // we should asume there is only one laptop panel device in the system - if (dbus_HAL->halGetPropertyInt(devices.first(), "laptop_panel.num_levels", &retval )) { - udis.insert("laptop_panel", new TQString( devices.first() )); - if (!allUDIs.contains( devices.first() )) - allUDIs.append( devices.first() ); - - if (retval > 1) { - dbus_HAL->halGetPropertyBool(devices.first(), "laptop_panel.brightness_in_hardware", - &brightness_in_hardware); - - availableBrightnessLevels = retval; -#ifdef USE_LIBHAL_POLICYCHECK - brightnessAllowed = dbus_HAL->isUserPrivileged( PRIV_LAPTOP_PANEL, - devices.first()); - // TODO: check brightnessAllowed -#endif - brightness = true; - // get the current level via GetBrightness - checkCurrentBrightness(); - } else { - kdError() << "Found a Panel, but laptop_panel.num_levels < 2, which means " - << "KPowersave can't set usefull values" << endl; - } - } + // Use the first backlight in the list + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); + + if (backlightdevice) { + udis.insert("laptop_panel", new TQString( hwdevice->uniqueID() )); + if (!allUDIs.contains( hwdevice->uniqueID() )) { + allUDIs.append( hwdevice->uniqueID() ); } + + availableBrightnessLevels = backlightdevice->brightnessSteps(); + + if (availableBrightnessLevels > 1) { + brightnessAllowed = backlightdevice->canSetBrightness(); + + brightness = true; + // get the current level via GetBrightness + checkCurrentBrightness(); + } + else { + availableBrightnessLevels = -1; + } + } + else { + udis.remove("laptop_panel"); + kdDebug() << "no device with category laptop_panel found" << endl; + kdDebugFuncOut(trace); + return; } kdDebugFuncOut(trace); @@ -775,12 +688,14 @@ void HardwareInfo::checkCurrentBrightness() { kdDebugFuncIn(trace); if (brightness) { - int retval; - // get the current level via GetBrightness - if (dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, *udis["laptop_panel"], HAL_LPANEL_IFACE, - "GetBrightness", &retval, DBUS_TYPE_INT32, - DBUS_TYPE_INVALID ) ) { - currentBrightnessLevel = (int) retval; + // Use the first backlight in the list + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); + + if (backlightdevice) { + currentBrightnessLevel = backlightdevice->rawBrightness(); } } @@ -798,54 +713,43 @@ void HardwareInfo::checkCurrentBrightness() { bool HardwareInfo::intialiseHWInfo() { kdDebugFuncIn(trace); - TQStringList ret; - - if (!dbus_HAL->isConnectedToDBUS() || !dbus_HAL->isConnectedToHAL()) - return false; + TDEGenericDevice *hwdevice; + TDEGenericHardwareList hwlist; - if( dbus_HAL->halFindDeviceByCapability("ac_adapter", &ret)) { - // there should be normaly only one device, but let be sure - for ( TQStringList::iterator it = ret.begin(); it != ret.end(); ++it ) { - // we need a deep copy - udis.insert("acadapter", new TQString( *it )); - if (!allUDIs.contains( *it )) - allUDIs.append( *it ); - checkACAdapterState(); + hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::PowerSupply); + for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { + udis.insert("acadapter", new TQString( hwdevice->uniqueID() )); + if (!allUDIs.contains( hwdevice->uniqueID() )) { + allUDIs.append( hwdevice->uniqueID() ); } + checkACAdapterState(); } - - ret.clear(); - - if( dbus_HAL->halFindDeviceByString("button.type", "lid", &ret)) { - // there should be normaly only one device, but let be sure - for ( TQStringList::iterator it = ret.begin(); it != ret.end(); ++it ) { - // we need a deep copy - udis.insert("lidclose", new TQString( *it )); - if (!allUDIs.contains( *it )) - allUDIs.append( *it ); + + hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Event); + for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { + TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(hwdevice); + if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) { + udis.insert("lidclose", new TQString( hwdevice->uniqueID() )); + if (!allUDIs.contains( hwdevice->uniqueID() )) { + allUDIs.append( hwdevice->uniqueID() ); + } checkLidcloseState(); } } - ret.clear(); - // find batteries and fill battery information - if( dbus_HAL->halFindDeviceByCapability("battery", &ret)) { - if (!ret.isEmpty()) { - // there should be normaly only one device, but let be sure - for ( TQStringList::iterator it = ret.begin(); it != ret.end(); ++it ) { - if (!allUDIs.contains( *it )) - allUDIs.append( *it ); - BatteryList.append( new Battery(dbus_HAL, *it) ); - } - - // connect to signals for primary batteries: - Battery *bat; - for (bat = BatteryList.first(); bat; bat = BatteryList.next() ) { - if (bat->getType() == BAT_PRIMARY) { - connect(bat, TQT_SIGNAL(changedBattery()),this, TQT_SLOT(updatePrimaryBatteries())); - } - } + hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Battery); + for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { + if (!allUDIs.contains( hwdevice->uniqueID() )) { + allUDIs.append( hwdevice->uniqueID() ); + } + BatteryList.append( new Battery( hwdevice->uniqueID() ) ); + } + // connect to signals for primary batteries: + Battery *bat; + for (bat = BatteryList.first(); bat; bat = BatteryList.next() ) { + if (bat->getType() == BAT_PRIMARY) { + connect(bat, TQT_SIGNAL(changedBattery()),this, TQT_SLOT(updatePrimaryBatteries())); } } @@ -862,7 +766,9 @@ void HardwareInfo::checkACAdapterState() { if ( udis["acadapter"] ) { bool _state; - if (dbus_HAL->halGetPropertyBool(*udis["acadapter"] , "ac_adapter.present", &_state )) { + TDEMainsPowerDevice* mdevice = dynamic_cast<TDEMainsPowerDevice*>(m_hwdevices->findByUniqueID(*udis["acadapter"])); + if (mdevice) { + _state = mdevice->online(); if (_state != acadapter) { acadapter = _state; update_info_ac_changed = true; @@ -870,7 +776,8 @@ void HardwareInfo::checkACAdapterState() { } else { update_info_ac_changed = false; } - } else { + } + else { // we use true as default e.g. for workstations acadapter = true; } @@ -888,7 +795,9 @@ void HardwareInfo::checkLidcloseState() { if ( udis["lidclose"] ) { bool _state; - if (dbus_HAL->halGetPropertyBool(*udis["lidclose"] , "button.state.value", &_state )) { + TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(m_hwdevices->findByUniqueID(*udis["lidclose"])); + if (edevice) { + _state = (edevice->activeSwitches() & TDESwitchType::Lid); if (_state != lidclose) { lidclose = _state; emit lidclosetStatus( lidclose ); @@ -907,20 +816,23 @@ void HardwareInfo::checkLidcloseState() { * \param udi TQString with the UDI of the battery * \param property TQString with the changed property */ -void HardwareInfo::updateBatteryValues (TQString udi, TQString property) { +void HardwareInfo::updateBatteryValues (TDEGenericDevice* device) { kdDebugFuncIn(trace); - if (!udi.isEmpty() && allUDIs.contains( udi )) { + if (device && allUDIs.contains( device->uniqueID() )) { // find effected battery object Battery *bat; for (bat = BatteryList.first(); bat; bat = BatteryList.next() ) { - if (udi.startsWith( bat->getUdi())) { - // found a battery with udi - bat->updateProperty(udi, property); + if (device->uniqueID().startsWith( bat->getUdi())) { + TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(device); + if (bdevice) { + // found a battery with udi + bat->updateProperty(bdevice); + } } } } else { - kdDebug() << "UDI is empty or not in the list of monitored devices: " << udi << endl; + kdDebug() << "UDI is empty or not in the list of monitored devices " << endl; } kdDebugFuncOut(trace); @@ -995,15 +907,15 @@ bool HardwareInfo::suspend( suspend_type suspend ) { calledSuspend = TQTime(); - if (dbus_HAL->isConnectedToDBUS() && dbus_HAL->isConnectedToHAL()) { + TDERootSystemDevice* rdevice = m_hwdevices->rootSystemDevice(); + + if (rdevice) { switch (suspend) { case SUSPEND2DISK: if (suspend_states.suspend2disk && (suspend_states.suspend2disk_allowed != 0)) { - if (dbus_HAL->dbusMethodCallSuspend("Hibernate")) { + if (rdevice->setPowerState(TDESystemPowerState::Hibernate)) { calledSuspend.start(); return true; - } else { - return false; } } else { if ( !suspend_states.suspend2disk ) @@ -1016,7 +928,7 @@ bool HardwareInfo::suspend( suspend_type suspend ) { break; case SUSPEND2RAM: if (suspend_states.suspend2ram && (suspend_states.suspend2ram_allowed != 0)) { - if (dbus_HAL->dbusMethodCallSuspend("Suspend")) { + if (rdevice->setPowerState(TDESystemPowerState::Suspend)) { calledSuspend.start(); return true; } else { @@ -1033,7 +945,7 @@ bool HardwareInfo::suspend( suspend_type suspend ) { break; case STANDBY: if (suspend_states.standby && (suspend_states.standby_allowed != 0)) { - if (dbus_HAL->dbusMethodCallSuspend("Standby")) { + if (rdevice->setPowerState(TDESystemPowerState::Standby)) { calledSuspend.start(); return true; } else { @@ -1083,9 +995,16 @@ bool HardwareInfo::setBrightness ( int level, int percent ){ } } - if (dbus_HAL->isConnectedToDBUS() && dbus_HAL->isConnectedToHAL()) { - if (!brightness) + // Use the first backlight in the list + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); + + if (backlightdevice) { + if (!brightness) { checkBrightness(); + } if (!brightness || (level < 0 ) || (level >= availableBrightnessLevels)) { kdError() << "Change brightness or requested level not supported " << endl; @@ -1094,12 +1013,8 @@ bool HardwareInfo::setBrightness ( int level, int percent ){ kdDebug() << "Brightness level not changed, requested level == current level" << endl; retval = true; } else { - if (dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, *udis["laptop_panel"], - HAL_LPANEL_IFACE, "SetBrightness", - DBUS_TYPE_INT32, &level, - DBUS_TYPE_INVALID )) { - retval = true; - } + backlightdevice->setRawBrightness(level); + retval = true; } } } @@ -1130,8 +1045,10 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { kdError() << "Could not set CPU Freq, this not the needed privileges." << endl; return false; } - - if (dbus_HAL->isConnectedToDBUS() && dbus_HAL->isConnectedToHAL()) { + + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + + if (hwlist.count() > 0) { dbus_bool_t consider = (dbus_bool_t) getAcAdapter(); TQStringList dynamic; @@ -1163,16 +1080,10 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { break; } } - - // set dynamic performance limit - if (!dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI, - HAL_CPUFREQ_IFACE, - "SetCPUFreqPerformance", - DBUS_TYPE_INT32, &limit, - DBUS_TYPE_INVALID)) { - kdError() << "Could not call/set SetCPUFreqPerformance with value: " - << limit << endl; - } + +#if 0 + // FIXME + // What does "SetCPUFreqConsiderNice" actually do??!?! // correct set ondemand if (!dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI, @@ -1183,6 +1094,21 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { kdError() << "Couldn't set SetCPUFreqConsiderNice for DYNAMIC" << endl; } +#endif + // Set performance limits on all CPUs + TDEGenericDevice *hwdevice; + TDECPUDevice *cpudevice; + for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { + cpudevice = static_cast<TDECPUDevice*>(hwdevice); + // set dynamic performance limit + // scale the desired limit so that when limit==0 the minFrequency() is used, and when limit==100 the maxFrequency() is used + double cpuLimit = cpudevice->maxFrequency() - cpudevice->minFrequency(); + cpuLimit = (cpuLimit * limit) / 100.0; + cpuLimit = cpudevice->maxFrequency() + cpuLimit; + cpudevice->setMaximumScalingFrequency(cpuLimit); + + } + break; case POWERSAVE: if (!setCPUFreqGovernor("powersave")) { @@ -1221,14 +1147,16 @@ bool HardwareInfo::setCPUFreqGovernor( const char *governor ) { int reply; bool ret = true; - kdDebug() << "Try to set CPUFreq to governor: " << governor << endl; - if (!dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI, - HAL_CPUFREQ_IFACE, "SetCPUFreqGovernor", - &reply, DBUS_TYPE_INVALID, - DBUS_TYPE_STRING, &governor, - DBUS_TYPE_INVALID)) { - kdError() << "Could not set CPU Freq to governor: " << governor << endl; - ret = false; + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + TDECPUDevice *cpudevice; + // Set governor on all CPUs + for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { + cpudevice = static_cast<TDECPUDevice*>(hwdevice); + cpudevice->setGovernor(governor); + if (cpudevice->governor() != governor) { + ret = false; + } } kdDebugFuncOut(trace); @@ -1248,30 +1176,9 @@ bool HardwareInfo::setPowerSave( bool on ) { bool retval = false; - if (dbus_HAL->isConnectedToDBUS() && dbus_HAL->isConnectedToHAL()) { - dbus_bool_t _tmp = (dbus_bool_t) on; - int reply; - -#ifdef USE_LIBHAL_POLICYCHECK - if (dbus_HAL->isUserPrivileged(PRIV_SETPOWERSAVE, HAL_COMPUTER_UDI) != 0) { -#else - if (true) { -#endif - if (!dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI, - HAL_PM_IFACE, "SetPowerSave", - &reply, DBUS_TYPE_INT32, - DBUS_TYPE_BOOLEAN, &_tmp, - DBUS_TYPE_INVALID)) { - kdError() << "Could not call/set SetPowerSave on HAL, " - << "could be a bug in HAL spec" << endl; - } else { - retval = true; - } - } else { - kdError() << "The user isn't allowed to call SetPowerSave() on HAL. " - << "Maybe KPowersave run not in a active session." << endl; - } - } + // FIXME + // Set up power saving to the best of our ability using "raw" functions + printf("[FIXME] HardwareInfo::setPowerSave unimplemented!\n\r"); fflush(stdout); kdDebugFuncOut(trace); return retval; @@ -1288,20 +1195,7 @@ bool HardwareInfo::getSchedPowerSavings() { bool returnval = false; - if (dbus_HAL->isConnectedToDBUS() && dbus_HAL->isConnectedToHAL()) { - dbus_bool_t ret; - - //NOTE: the kernel only allow 1/0 for the related sysfs entry - if (dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI, - HAL_CPUFREQ_IFACE, "GetSchedPowerSavings", - &ret, DBUS_TYPE_BOOLEAN, DBUS_TYPE_INVALID)) { - schedPowerSavings = ((ret != 0) ? true: false); - returnval = true; - } else { - schedPowerSavings = false; - kdWarning() << "Could not call GetSchedPowerSavings() " << endl; - } - } + // What does the HAL method GetSchedPowerSavings actually do?!?!? kdDebugFuncOut(trace); return returnval; @@ -1319,20 +1213,7 @@ bool HardwareInfo::setSchedPowerSavings( bool enable ) { bool retval = false; - if (dbus_HAL->isConnectedToDBUS() && dbus_HAL->isConnectedToHAL()) { - dbus_bool_t _tmp = (dbus_bool_t) enable; - - //NOTE: the kernel only allow 1/0 for the related sysfs entry - if (dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI, - HAL_CPUFREQ_IFACE, - "SetCPUFreqPerformance", - DBUS_TYPE_BOOLEAN, &_tmp, - DBUS_TYPE_INVALID)) { - retval = true; - } else { - kdWarning() << "Could not call SetSchedPowerSavings() " << endl; - } - } + // What does the HAL method SetCPUFreqPerformance actually do?!?!? kdDebugFuncOut(trace); return retval; @@ -1629,7 +1510,9 @@ bool HardwareInfo::isLaptop() const { * \retval false if not connected */ bool HardwareInfo::isOnline() const { - return (!dbus_terminated && !hal_terminated); + // FIXME + // Is there ANY case where the TDE hardware library would not function? + return true; } /*! @@ -1701,7 +1584,13 @@ bool HardwareInfo::currentSessionIsActive() const { * \retval -1 unknown */ int HardwareInfo::isCpuFreqAllowed () { - cpuFreqAllowed = dbus_HAL->isUserPrivileged( PRIV_CPUFREQ, HAL_COMPUTER_UDI); + // Use the first CPU in the list; permissions are probably the same across all CPUs + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); + + cpuFreqAllowed = cpudevice->canSetGovernor(); return cpuFreqAllowed; } |