Initial migration off of HAL

pull/1/head
Timothy Pearson 13 years ago
parent 82806a03ea
commit 3ec8230e9f

@ -131,7 +131,7 @@ else
echo "enabled faked sysfs - proc environment: no"
fi
pkg_modules="dbus-1 >= 0.6, hal >= 0.5.6"
pkg_modules="dbus-1 >= 0.6"
PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
# get dbus system bus socket
@ -145,18 +145,6 @@ AC_DEFINE_UNQUOTED(DBUS_SYSTEM_BUS_SOCKET, ["$DBUS_SYSTEM_BUS_SOCKET"],
[dbus system bus socket path])
#check for PolicyKit version
LIBHAL_POLICYCHECK=no
AC_CHECK_LIB([hal], [libhal_device_is_caller_privileged], [LIBHAL_POLICYCHECK=yes], [LIBHAL_POLICYCHECK=no])
if test "x$LIBHAL_POLICYCHECK" = "xyes"; then
AC_DEFINE([USE_LIBHAL_POLICYCHECK],1,[Set if should use libhal to check policy.])
fi
#check for HAL version >= 0.5.10
if $PKG_CONFIG --atleast-version 0.5.10 hal; then
AC_DEFINE([HAVE_HAL_0_5_10],1,[Set if we use HAL >= 0.5.10])
fi
# check for dbus qt bindings --> copied from KNetworkmanager
safe_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $PACKAGE_CFLAGS $all_includes"

@ -2163,7 +2163,7 @@
</connection>
<connection>
<sender>listBox_schemes</sender>
<signal>currentChanged(QListBoxItem*)</signal>
<signal>currentChanged(TQListBoxItem*)</signal>
<receiver>configure_Dialog</receiver>
<slot>listBox_schemes_currentChanged()</slot>
</connection>

@ -42,9 +42,7 @@ dbusHAL::dbusHAL(){
kdDebugFuncIn(trace);
dbus_is_connected = false;
hal_is_connected = false;
aquiredPolicyPower = false;
hal_ctx = NULL;
// add pointer to this for filter_function()
myInstance=this;
@ -53,8 +51,6 @@ dbusHAL::dbusHAL(){
kdError() << "Can't connect to D-Bus" << endl;
m_dBusQtConnection = NULL;
}
if(!initHAL())
kdError() << "Can't connect to HAL" << endl;
kdDebugFuncOut(trace);
}
@ -79,16 +75,6 @@ bool dbusHAL::isConnectedToDBUS() {
return dbus_is_connected;
}
/*!
* This function return information about connection status to the HAL daemon.
* \return boolean with the state of the connection to HAL
* \retval true if connected
* \retval false if disconnected
*/
bool dbusHAL::isConnectedToHAL() {
return hal_is_connected;
}
/*!
* This function return information if the org.freedesktop.Policy.Power
* interface was claimed.
@ -107,12 +93,10 @@ bool dbusHAL::aquiredPolicyPowerInterface() {
* \retval false if unsuccessful
*/
bool dbusHAL::reconnect() {
// free HAL context
freeHAL();
// close D-Bus connection
close();
// init D-Bus conntection and HAL context
return (initDBUS() && initHAL());
return (initDBUS());
}
/*!
@ -176,20 +160,6 @@ bool dbusHAL::initDBUS(){
"interface='org.freedesktop.DBus',"
"member='NameOwnerChanged'", NULL);
/* add a match rule to catch all signals going through the bus with HAL interface */
dbus_bus_add_match( dbus_connection, "type='signal',"
"interface='org.freedesktop.Hal.Manager',"
"member='DeviceAdded'", NULL);
dbus_bus_add_match( dbus_connection, "type='signal',"
"interface='org.freedesktop.Hal.Manager',"
"member='DeviceRemoved'", NULL);
dbus_bus_add_match( dbus_connection, "type='signal',"
"interface='org.freedesktop.Hal.Device',"
"member='PropertyModified'", NULL);
dbus_bus_add_match( dbus_connection, "type='signal',"
"interface='org.freedesktop.Hal.Device',"
"member='Condition'", NULL);
/* add a match rule to catch all signals going through the bus with ConsoleKit Interface */
dbus_bus_add_match( dbus_connection, "type='signal',"
"interface='org.freedesktop.ConsoleKit.Session',"
@ -318,418 +288,7 @@ bool dbusHAL::isPolicyPowerIfaceOwned(){
}
/* ----> DBUS section :: END <---- */
/* ----> HAL section :: START <---- */
/*!
* This function initialise the connection to HAL over the D-Bus daemon.
* \return boolean with the result of the operation
* \retval true if successful initialised HAL connection and context
* \retval false if unsuccessful
*/
bool dbusHAL::initHAL(){
kdDebugFuncIn(trace);
if ( !dbus_is_connected ) {
freeHAL();
return false;
} else if ( hal_is_connected && (hal_ctx != NULL)) {
return true;
}
// could not connect to HAL, reset all and try again
freeHAL();
DBusError error;
dbus_error_init(&error);
dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if (dbus_connection == NULL || dbus_error_is_set(&error)) {
kdError() << "could not open connection to system bus: " << error.message << endl;
dbus_error_free(&error);
return false;
}
bool hal_is_ready = dbus_bus_name_has_owner(dbus_connection, "org.freedesktop.Hal", &error);
if (!hal_is_ready) {
kdWarning() << "HAL is not ready. We will try later... " << endl;
if ( dbus_error_is_set( &error ) ) {
kdError() << "Error checking if hal service exists: " << error.message << endl;
dbus_error_free( &error );
}
freeHAL();
return false;
}
if((hal_ctx = libhal_ctx_new()) == NULL) {
kdError() << "Could not init HAL context" << endl;
return false;
}
/* setup dbus connection for hal */
if (!libhal_ctx_set_dbus_connection(hal_ctx, dbus_connection)) {
kdError() << "Could not set up connection to dbus for hal" << endl;
freeHAL();
return false;
}
/* init the hal library */
if (!libhal_ctx_init(hal_ctx, &error)) {
kdError() << "Could not init hal library: " << error.message << endl;
freeHAL();
return false;
}
hal_is_connected = true;
kdDebugFuncOut(trace);
return hal_is_connected;
}
/*!
* This function free the hal connection/context.
*/
void dbusHAL::freeHAL(){
if ( hal_ctx != NULL ) {
libhal_ctx_free( hal_ctx );
hal_ctx = NULL;
}
hal_is_connected = false;
}
/*!
* This function try a reconnect to the HAL daemon only.
* \return boolean with the result of the operation
* \retval true if successful reconnected to HAL
* \retval false if unsuccessful
*/
bool dbusHAL::reconnectHAL() {
// free HAL context
freeHAL();
// init HAL context
return (initHAL());
}
/*!
* This function query a integer property from HAL for a given device
* \param udi TQString with the UDI of the device
* \param property TQString with the property
* \param returnval pointer to the return value
* \return If the query was successful or not
*/
bool dbusHAL::halGetPropertyInt(TQString udi, TQString property, int *returnval){
kdDebugFuncIn(trace);
bool ret = false;
if (!initHAL() || udi.isEmpty() || property.isEmpty())
goto out;
DBusError error;
dbus_error_init(&error);
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
goto out;
}
*returnval = libhal_device_get_property_int(hal_ctx, udi.ascii(), property.ascii(), &error);
if (dbus_error_is_set(&error)) {
kdError() << "Fetching property: " << property << " for: " << udi
<< " failed with: " << error.message << endl;
dbus_error_free(&error);
goto out;
} else {
ret = true;
}
out:
kdDebugFuncOut(trace);
return true;
}
/*!
* This function query a boolean property from HAL for a given device
* \param udi TQString with the UDI of the device
* \param property TQString with the property
* \param returnval pointer to the return value
* \return If the query was successful or not
*/
bool dbusHAL::halGetPropertyBool(TQString udi, TQString property, bool *returnval){
kdDebugFuncIn(trace);
bool ret = false;
if (!initHAL() || udi.isEmpty() || property.isEmpty())
goto out;
DBusError error;
dbus_error_init(&error);
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
goto out;
}
*returnval = libhal_device_get_property_bool(hal_ctx, udi.ascii(), property.ascii(), &error);
if (dbus_error_is_set(&error)) {
kdError() << "Fetching property: " << property << " for: " << udi
<< " failed with: " << error.message << endl;
dbus_error_free(&error);
goto out;
} else {
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/*!
* This function query a Sting property from HAL for a given device
* \param udi TQString with the UDI of the device
* \param property TQString with the property
* \param returnval pointer to the return value
* \return If the query was successful or not
*/
bool dbusHAL::halGetPropertyString(TQString udi, TQString property, TQString *returnval){
kdDebugFuncIn(trace);
bool ret = false;
if (!initHAL() || udi.isEmpty() || property.isEmpty())
goto out;
DBusError error;
dbus_error_init(&error);
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
goto out;
}
*returnval = libhal_device_get_property_string(hal_ctx, udi.ascii(), property.ascii(), &error);
if (dbus_error_is_set(&error)) {
kdError() << "Fetching property: " << property << " for: " << udi
<< " failed with: " << error.message << endl;
dbus_error_free(&error);
goto out;
} else {
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/*!
* This function query a String List property from HAL for a given device
* \param udi TQString with the udi of the device
* \param property TQString with the property to query
* \param devices TQStringList to return the values
* \return If the query was successful or not
*/
bool dbusHAL::halGetPropertyStringList (TQString udi, TQString property, TQStringList *devices) {
kdDebugFuncIn(trace);
bool ret = false;
if (!initHAL() || udi.isEmpty() || property.isEmpty())
goto out;
DBusError error;
char ** found;
dbus_error_init(&error);
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
goto out;
}
found = libhal_device_get_property_strlist (hal_ctx, udi.ascii(), property.ascii(), &error);
if (dbus_error_is_set(&error)) {
kdWarning() << "Error while query existing strlist Property: " << property
<< " for: " << udi << " error: " << error.message << endl;
dbus_error_free(&error);
libhal_free_string_array(found);
goto out;
} else {
for (int i = 0; found[i] != NULL ; ++i) {
TQString _to_add = found[i];
if (!_to_add.isEmpty()) *devices += _to_add;
}
libhal_free_string_array(found);
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/*!
* This function query a capability from HAL for a given device
* \param udi TQString with the UDI of the device
* \param capability TQString with the capability to query
* \param returnval pointer to the return value as boolean
* \return If the query was successful or not
*/
bool dbusHAL::halQueryCapability(TQString udi, TQString capability, bool *returnval) {
kdDebugFuncIn(trace);
bool ret = false;
if (!initHAL() || udi.isEmpty() || capability.isEmpty())
goto out;
DBusError error;
dbus_error_init(&error);
*returnval = libhal_device_query_capability(hal_ctx, udi.ascii(), capability.ascii(), &error);
if (dbus_error_is_set(&error)) {
kdError() << "Fetching capability: " << capability << " for: " << udi
<< " failed with: " << error.message << endl;
dbus_error_free(&error);
goto out;
} else {
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/*!
* Use this function to check if a device has a specia property/key.
* \param udi TQString with the UDI of the device
* \param property TQString with the property
* \return If the query was successful or not
*/
bool dbusHAL::halDevicePropertyExist(TQString udi, TQString property ) {
kdDebugFuncIn(trace);
bool ret = false;
if (!initHAL() || udi.isEmpty() || property.isEmpty())
goto out;
DBusError error;
dbus_error_init(&error);
if (! libhal_device_property_exists (hal_ctx, udi.ascii(), property.ascii(), &error)) {
if (dbus_error_is_set(&error)) {
kdError() << "Fetching existing property: " << property << " for: " << udi
<< " failed with: " << error.message << endl;
dbus_error_free(&error);
}
goto out;
} else {
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/*!
* Use this function to search find devices with a give capability
* \param capability TQString with the capability to query
* \param devices TQStringList to return the found devices
* \return If the query was successful or not
*/
bool dbusHAL::halFindDeviceByCapability (TQString capability, TQStringList *devices) {
kdDebugFuncIn(trace);
DBusError error;
char ** found;
int num = 0;
bool ret = false;
if (!initHAL() || capability.isEmpty())
goto out;
dbus_error_init(&error);
found = libhal_find_device_by_capability (hal_ctx, capability.ascii(), &num, &error);
if (dbus_error_is_set(&error)) {
kdError() << "Could not get list of devices with capability: " << capability
<< " error: " << error.message << endl;
dbus_error_free(&error);
libhal_free_string_array(found);
goto out;
} else {
for (int i = 0; i < num; ++i) {
TQString _to_add = found[i];
if (!_to_add.isEmpty()) *devices += _to_add;
}
libhal_free_string_array(found);
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/*!
* Use this function to search find devices with a special string property
* \param property TQString with the name of the property
* \param keyval TQString with value of the string property
* \param devices TQStringList to return the found devices
* \return If the query was successful or not
*/
bool dbusHAL::halFindDeviceByString (TQString property, TQString keyval, TQStringList *devices) {
kdDebugFuncIn(trace);
DBusError error;
char ** found;
int num = 0;
bool ret = false;
if (!initHAL() || property.isEmpty() || keyval.isEmpty())
goto out;
dbus_error_init(&error);
found = libhal_manager_find_device_string_match (hal_ctx, property.ascii(), keyval.ascii(), &num, &error);
if (dbus_error_is_set(&error)) {
kdError() << "Could not get list of devices with key: " << property
<< "and string value: " << keyval << " error: " << error.message << endl;
dbus_error_free(&error);
libhal_free_string_array(found);
goto out;
} else {
for (int i = 0; i < num; ++i) {
TQString _to_add = found[i];
if (!_to_add.isEmpty()) *devices += _to_add;
}
libhal_free_string_array(found);
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/* ----> HAL section :: END <---- */
/* ----> D-Bus methode calls functions :: START <---- */
/*!
* This function call a D-Bus method
@ -868,102 +427,6 @@ out:
return ret;
}
/*!
* Function to call a suspend and call if resumed \ref callBackSuspend()
* to emit a resume signal.
* \param suspend a char pointer with the name of the suspend interface
* \return If the query was successful or not
*/
bool dbusHAL::dbusMethodCallSuspend ( const char *suspend ) {
kdDebugFuncIn(trace);
DBusMessage *message;
DBusError error;
DBusPendingCall* pcall = NULL;
bool ret = false;
dbus_error_init(&error);
dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if (dbus_error_is_set(&error)) {
kdError() << "Could not get dbus connection: " << error.message << endl;
dbus_error_free(&error);
goto out;
}
message = dbus_message_new_method_call( HAL_SERVICE, HAL_COMPUTER_UDI, HAL_PM_IFACE, suspend);
if (strcmp( suspend, "Suspend") == 0) {
int wake_up = 0;
dbus_message_append_args (message, DBUS_TYPE_INT32, &wake_up, DBUS_TYPE_INVALID);
}
if (message) {
// need to set INT_MAX as default and not -1
dbus_connection_send_with_reply (dbus_connection, message, &pcall, INT_MAX);
if (pcall) {
dbus_pending_call_ref (pcall); // really needed?
dbus_pending_call_set_notify (pcall, dbusHAL::callBackSuspend, NULL, NULL);
}
dbus_message_unref (message);
ret = true;
}
out:
kdDebugFuncOut(trace);
return ret;
}
/*!
* Slot called by D-Bus as set in \ref dbusMethodCallSuspend()
* Here we emit the resume signal.
*/
void dbusHAL::callBackSuspend (DBusPendingCall* pcall, void* /*data*/) {
kdDebugFuncIn(trace);
DBusMessage* reply = NULL;
DBusError error;
int result;
bool failed = false;
if (!pcall) {
kdError() << "dbusHAL::callBackSuspend - DBusPendingCall not set, return" << endl;
kdDebugFuncOut(trace);
return;
}
reply = dbus_pending_call_steal_reply (pcall);
if (reply == NULL) {
kdError() << "dbusHAL::callBackSuspend - Got no reply, return" << endl;
goto out;
}
dbus_error_init(&error);
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID)) {
if (dbus_error_is_set(&error)) {
kdError() << "Could not get argument from reply: " << error.message << endl;
dbus_error_free(&error);
}
kdWarning() << "dbusHAL::callBackSuspend dbus_message_get_args failed, maybe timouted" << endl;
failed = true;
}
dbus_message_unref (reply);
out:
dbus_pending_call_unref (pcall);
if (failed)
emit ((dbusHAL*) myInstance)->backFromSuspend( -1 );
else
emit ((dbusHAL*) myInstance)->backFromSuspend( result );
kdDebugFuncOut(trace);
return;
}
/* ----> D-Bus methode calls functions :: END <---- */
/* ---> PolicyKit method call section :: START <--- */
@ -998,38 +461,6 @@ int dbusHAL::isUserPrivileged(TQString privilege, TQString udi, TQString ressour
_unique_name = dbus_bus_get_unique_name(dbus_connection);
_privilege = privilege.latin1();
#ifdef USE_LIBHAL_POLICYCHECK
DBusError error;
char *result;
if (udi.isEmpty()) {
kdError() << "No UDI given ... could not lookup privileges" << endl;
goto out;
}
if (!hal_is_connected) {
kdError() << "HAL not running, could not call libhal for lookup privileges" << endl;
goto out;
}
dbus_error_init(&error);
result = libhal_device_is_caller_privileged ( hal_ctx, udi.latin1(), _privilege, _unique_name, &error);
if ( dbus_error_is_set( &error ) ) {
kdWarning() << "Error while lookup privileges: " << error.message << endl;
dbus_error_free( &error );
retval = -1;
} else {
if (!strcmp(result, "yes")) {
retval = 1;
} else if (!strcmp(result, "no")) {
retval = 0;
} else {
retval = -1;
}
}
libhal_free_string(result);
#else
// not sure if we need this, but to avoid problems
dbus_bool_t _retval;
const char *_ressource;
@ -1049,7 +480,6 @@ int dbusHAL::isUserPrivileged(TQString privilege, TQString udi, TQString ressour
} else {
retval = (int) _retval;
}
#endif
out:
kdDebugFuncOut(trace);
@ -1157,22 +587,7 @@ filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/
if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &service,
DBUS_TYPE_STRING, &old_owner,
DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID)) {
if (!strcmp(service, "org.freedesktop.Hal")) {
if (!strcmp(new_owner, "") && strcmp(old_owner, "")) {
// Hal service stopped.
kdDebug() << "=== org.freedesktop.Hal terminated ===" << endl;
((dbusHAL*) myInstance)->emitMsgReceived( DBUS_EVENT,
"hal.terminate",
NULL );
}
else if (!strcmp(old_owner, "") && strcmp(new_owner, "")) {
// Hal service started.
kdDebug() << "=== org.freedesktop.Hal started ===" << endl;
((dbusHAL*) myInstance)->emitMsgReceived( DBUS_EVENT,
"hal.started",
NULL );
}
} else if (!strcmp(service, "org.freedesktop.Policy.Power")) {
if (!strcmp(service, "org.freedesktop.Policy.Power")) {
const char *own_name;
own_name = dbus_bus_get_unique_name(((dbusHAL*) myInstance)->get_DBUS_connection());
@ -1195,88 +610,6 @@ filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/
}
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_HANDLED;
} else if (ifaceType.startsWith("org.freedesktop.Hal.Manager")) {
kdDebug() << "Received from org.freedesktop.Hal.Manager" << endl;
char *udi;
const char *signal = dbus_message_get_member( message );
/* get the first argument. This must be a string at the moment */
dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID );
if ( dbus_error_is_set( &error ) ) {
kdWarning() << "Received signal, but no string argument: " << error.message << endl;
dbus_error_free( &error );
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_HANDLED;
}
if (dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID )) {
if (! strcmp(signal, "DeviceRemoved") || ! strcmp(signal, "DeviceAdded")) {
((dbusHAL*) myInstance)->emitMsgReceived( HAL_DEVICE, signal, udi );
kdDebug() << "org.freedesktop.Hal.Manager: uid: " << udi
<< " signal: " << signal << endl;
} else {
kdWarning() << "Received unknown signal from org.freedesktop.Hal.Manager: "
<< signal << endl;
}
}
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_HANDLED;
} else if (ifaceType.startsWith("org.freedesktop.Hal.Device")) {
const char *udi = dbus_message_get_path (message);
const char *signal = dbus_message_get_member( message );
/* Code taken from libhal */
if (! strcmp(signal, "PropertyModified")) {
if (trace) kdDebug() << "-------- PropertyModified ------" << endl;
int i, num_modifications;
DBusMessageIter iter;
DBusMessageIter iter_array;
dbus_message_iter_init (message, &iter);
dbus_message_iter_get_basic (&iter, &num_modifications);
dbus_message_iter_next (&iter);
dbus_message_iter_recurse (&iter, &iter_array);
for (i = 0; i < num_modifications; i++) {
dbus_bool_t removed, added;
char *key;
DBusMessageIter iter_struct;
dbus_message_iter_recurse (&iter_array, &iter_struct);
dbus_message_iter_get_basic (&iter_struct, &key);
dbus_message_iter_next (&iter_struct);
dbus_message_iter_get_basic (&iter_struct, &removed);
dbus_message_iter_next (&iter_struct);
dbus_message_iter_get_basic (&iter_struct, &added);
/* don't check if we really need this device, check this in an other class */
((dbusHAL*) myInstance)->emitMsgReceived( HAL_PROPERTY_CHANGED, udi, key);
kdDebug() << "PropertyModified: uid: " << udi << " key: " << key << endl;
dbus_message_iter_next (&iter_array);
}
} else if (! strcmp(signal, "Condition")) {
if (trace) kdDebug() << "-------- Condition ------" << endl;
char *name, *detail;
dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID );
if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &detail, DBUS_TYPE_INVALID)) {
((dbusHAL*) myInstance)->emitMsgReceived( HAL_CONDITION, name, detail );
} else {
if (dbus_error_is_set( &error )) dbus_error_free( &error );
}
} else {
kdDebug() << "Received unknown signal from org.freedesktop.Hal.Device: "
<< signal << endl;
}
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_HANDLED;
} else if (ifaceType.startsWith("org.freedesktop.ConsoleKit.Session")) {
kdDebug() << "Received from org.freedesktop.ConsoleKit.Session" << endl;

@ -48,17 +48,9 @@
#include <dbus/message.h>
#include <dbus/connection.h>
// HAL Library
#include <hal/libhal.h>
// kpowersave - Header
#include "kpowersave_debug.h"
#define HAL_SERVICE "org.freedesktop.Hal"
#define HAL_PM_IFACE "org.freedesktop.Hal.Device.SystemPowerManagement"
#define HAL_LPANEL_IFACE "org.freedesktop.Hal.Device.LaptopPanel"
#define HAL_CPUFREQ_IFACE "org.freedesktop.Hal.Device.CPUFreq"
#define HAL_COMPUTER_UDI "/org/freedesktop/Hal/devices/computer"
#define CK_SERVICE "org.freedesktop.ConsoleKit"
#define CK_MANAGER_IFACE "org.freedesktop.ConsoleKit.Manager"
#define CK_MANAGER_OBJECT "/org/freedesktop/ConsoleKit/Manager"
@ -84,8 +76,6 @@ private:
DBusQt::Connection* m_dBusQtConnection;
//! real connection to D-Bus
DBusConnection *dbus_connection;
//! HAL context
LibHalContext *hal_ctx;
//! to store information if KPowersave is connected to D-Bus
/*!
@ -94,13 +84,6 @@ private:
* \li false: if disconnected
*/
bool dbus_is_connected;
//! to store information if KPowersave is connected to HAL
/*!
* This boolean represent information about the state of the connection to HAL
* \li true: if connected
* \li false: if disconnected
*/
bool hal_is_connected;
//! if we could claim the org.freedesktop.Policy.Power interface
/*!
@ -119,15 +102,6 @@ private:
DBusBusType dbus_type, void *retvalue, int retval_type,
int first_arg_type, va_list var_args);
//! function to be called back by DBusPendingCall::dbus_pending_call_set_notify()
static void callBackSuspend (DBusPendingCall* pcall, void* /*data*/);
/* HAL helper functions */
//! to initialise the connection to HAL
bool initHAL();
//! to free the HAL context
void freeHAL();
public:
//! default constructor
@ -137,8 +111,6 @@ public:
//! to reconnect to D-Bus and HAL
bool reconnect();
//! to reconnect only HAL
bool reconnectHAL();
//! to close the connection to D-Bus and HAL
bool close();
@ -152,36 +124,12 @@ public:
// --- helper to get private members of the class --- //
//! to get information if KPowersave is connected to D-Bus
bool isConnectedToDBUS();
//! to get information if KPowersave is connected to HAL
bool isConnectedToHAL();
//! to get info about claim org.freedesktop.Policy.Power interface
bool aquiredPolicyPowerInterface();
//! return the current HAL context
LibHalContext *get_HAL_context();
//! return the current DBus connection
DBusConnection *get_DBUS_connection();
/* HAL device information stuff */
//! Query a integer device property from HAL
bool halGetPropertyInt(TQString udi, TQString property, int *returnval);
//! Query a bolean device property from HAL
bool halGetPropertyBool(TQString udi, TQString property, bool *returnval);
//! Query a string device property from HAL
bool halGetPropertyString(TQString udi, TQString property, TQString *returnval);
//! Query a string list device property from HAL
bool halGetPropertyStringList (TQString udi, TQString property, TQStringList *devices);
//! Query a capability for a HAL device
bool halQueryCapability(TQString udi, TQString capability, bool *returnval);
/* functions to find devices and check stuff */
//! check if a property exist on a device
bool halDevicePropertyExist(TQString udi, TQString property);
//! to find a device by capability
bool halFindDeviceByCapability (TQString capability, TQStringList *devices);
//! to find a device by a string property
bool halFindDeviceByString (TQString property, TQString keyval, TQStringList *devices);
/* D-Bus helper functions */
/* functions to call methodes */
@ -192,9 +140,6 @@ public:
bool dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
void *retvalue, int retval_type, int first_arg_type, ... );
//! to call a suspend method on HAL
bool dbusMethodCallSuspend ( const char *suspend );
/* PolicyKit call helper */
//! check if the user has a requested privilege
int isUserPrivileged( TQString privilege, TQString udi, TQString ressource = "", TQString user = TQString());

@ -341,7 +341,7 @@
<cstring>tl_powerConsDesc</cstring>
</property>
<property name="text">
<string>Power Consumtion: </string>
<string>Power Consumption: </string>
</property>
</widget>
<widget class="TQLabel">

@ -479,12 +479,12 @@ void detaileddialog::setInfos() {
displayValue += i18n("no") + "\n";
}
display += i18n("HAL Daemon:");
displayValue += i18n("running");
display += i18n("TDE hardware subsystem:");
displayValue += i18n("active");
}
else {
display += i18n("HAL Daemon:");
displayValue += i18n("not running");
display += i18n("TDE hardware subsystem:");
displayValue += i18n("not available");
}
if(!display.isEmpty())

File diff suppressed because it is too large Load Diff

@ -45,6 +45,9 @@
#include <tqptrlist.h>
#include <tqdict.h>
// TDE hardware library
#include <tdehardwaredevices.h>
// HAL Library
#include <hal/libhal.h>
@ -125,6 +128,8 @@ class HardwareInfo : public TQObject{
private:
TDEHardwareDevices *m_hwdevices;
//! pointer to the dbusHAL connection class
dbusHAL *dbus_HAL;
@ -315,12 +320,16 @@ private:
bool setSchedPowerSavings( bool enable );
//! find and update a battery information
void updateBatteryValues (TQString udi, TQString property);
void updateBatteryValues (TDEGenericDevice* device);
private slots:
//! to fetch events from D-Bus and handle them
void processMessage (msg_type type, TQString message, TQString value);
//! to fetch events from the TDE hardware library and handle them
void processHardwareChangedEvent (TDEGenericDevice*);
//! to fetch keypresses from the TDE hardware library and handle them
void processKeyPressEvent (unsigned int, TDEEventDevice*);
//! to update \ref primaryBatteries
void updatePrimaryBatteries ();
//! to set \ref update_info_primBattery_changed
@ -331,9 +340,6 @@ private slots:
void checkACAdapterState();
//! check if brightness change is possible
void checkBrightness();
//! TQT_SLOT to handle the reconnect to D-Bus
void reconnectDBUS();
//! TQT_SLOT to forward signal about changed battery warning state
void emitBatteryWARNState (int type, int state);
@ -423,14 +429,6 @@ public:
* \li false: If D-Bus not terminated
*/
bool dbus_terminated;
//! boolean which tell us if the HAL daemon was terminated
/*!
* This boolean contains information if the HAL daemon terminated and
* we recieved "hal.terminate"
* \li true: If HAL terminated
* \li false: If HAL not terminated
*/
bool hal_terminated;
// --> functions
//! default constructor

@ -26,38 +26,54 @@
#include "hardware_battery.h"
/*! The default constructor of the class Battery. */
Battery::Battery(dbusHAL* _dbus_HAL) : dbus_HAL(_dbus_HAL) {
kdDebugFuncIn(trace);
udi = TQString();
initialized = false;
initDefault();
init(NULL);
kdDebugFuncOut(trace);
}
// FOR REFERENCE
// udi = '/org/freedesktop/Hal/devices/bme'
// info.addons = { 'hald-addon-bme' } (string list)
// maemo.charger.type = 'host 500 mA' (string)
// maemo.charger.connection_status = 'connected' (string)
// maemo.rechargeable.charging_status = 'on' (string)
// maemo.rechargeable.positive_rate = true (bool)
// battery.present = true (bool)
// info.product = 'Battery (BME-HAL)' (string)
// info.subsystem = 'unknown' (string)
// battery.is_rechargeable = true (bool)
// info.udi = '/org/freedesktop/Hal/devices/bme' (string)
// battery.charge_level.unit = 'bars' (string)
// battery.remaining_time = 7200 (0x1c20) (int)
// battery.type = 'pda' (string)
// battery.charge_level.percentage = 71 (0x47) (int)
// battery.charge_level.design = 8 (0x8) (int)
// battery.charge_level.capacity_state = 'ok' (string)
// battery.rechargeable.is_discharging = false (bool)
// battery.charge_level.last_full = 7 (0x7) (int)
// battery.reporting.design = 1258 (0x4ea) (int)
// battery.reporting.last_full = 867 (0x363) (int)
// battery.reporting.current = 903 (0x387) (int)
// battery.voltage.unit = 'mV' (string)
// battery.voltage.design = 4200 (0x1068) (int)
// info.category = 'battery' (string)
// battery.voltage.current = 3947 (0xf6b) (int)
// battery.remaining_time.calculate_per_time = false (bool)
// info.parent = '/org/freedesktop/Hal/devices/computer' (string)
// battery.charge_level.current = 7 (0x7) (int)
// battery.rechargeable.is_charging = true (bool)
// info.capabilities = { 'battery' } (string list)
// battery.reporting.unit = 'mAh' (string)
/*! The default constructor of the class Battery. */
Battery::Battery( dbusHAL* _dbus_HAL, TQString _udi ) : dbus_HAL(_dbus_HAL), udi(_udi) {
Battery::Battery( TQString _udi ) {
if (trace) kdDebug() << funcinfo << "IN , udi: " << udi << endl;
initialized = false;
initDefault();
init(NULL);
m_hwdevices = KGlobal::hardwareDevices();
kdDebugFuncOut(trace);
}
udi = _udi;
/*! The default constructor of the class Battery. */
Battery::Battery() {
kdDebugFuncIn(trace);
connect(m_hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(updateProperty(TDEGenericDevice*)));
initialized = false;
initDefault();
udi = TQString();
init();
kdDebugFuncOut(trace);
}
@ -94,26 +110,18 @@ void Battery::initDefault() {
}
//! initialize this battery object with values from HAL
void Battery::init(dbusHAL* _dbus_HAL) {
void Battery::init() {
kdDebugFuncIn(trace);
if (_dbus_HAL != NULL)
dbus_HAL = _dbus_HAL;
// read battery information from HAL
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
//couldnt connect to HAL
state=BAT_HAL_ERROR;
if (resetUdi(udi)) {
//udi is valid
recheck(); //fills all values
//ready here for now
} else {
if (resetUdi(udi)) {
//udi is valid
recheck(); //fills all values
//ready here for now
} else {
//udi is invalid or is no battery
state=BAT_HAL_ERROR;
kdWarning() << "Warning: Battery::init cannot make use of udi " << udi << endl;
}
//udi is invalid or is no battery
state=BAT_HAL_ERROR;
kdWarning() << "Warning: Battery::init cannot make use of udi " << udi << endl;
}
initialized = true;
@ -127,10 +135,11 @@ void Battery::init(dbusHAL* _dbus_HAL) {
void Battery::minRecheck() {
kdDebugFuncIn(trace);
//first check whether HAL is available
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::recheck couldn't connect to HAL" << endl;
kdError() << "Battery::recheck couldn't find battery" << endl;
kdDebugFuncOut(trace);
return;
}
@ -160,10 +169,11 @@ void Battery::minRecheck() {
void Battery::recheck() {
kdDebugFuncIn(trace);
//first check whether HAL is available
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::recheck couldn't connect to HAL" << endl;
kdError() << "Battery::recheck couldn't find battery" << endl;
kdDebugFuncOut(trace);
return;
}
@ -203,44 +213,40 @@ bool Battery::checkBatteryPresent () {
kdDebugFuncIn(trace);
bool _present = false;
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkBatteryPresent couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
if (dbus_HAL->halGetPropertyBool(udi,"battery.present", &_present)) {
if (_present != present) {
present = _present;
// force depending changes
if (_present) {
// should be now present
recheck();
}
if (!_present) {
//Uhhh, battery is not present, so we need to reset battery to default.
initDefault();
checkBatteryType();
state = BAT_NONE;
}
if (initialized) {
emit changedBatteryPresent();
emit changedBattery();
}
_present = bdevice->installed();
if (_present != present) {
present = _present;
// force depending changes
if (_present) {
// should be now present
recheck();
}
if (!_present) {
//Uhhh, battery is not present, so we need to reset battery to default.
initDefault();
checkBatteryType();
state = BAT_NONE;
}
// also query the serial ... no need to do this in a extra place
dbus_HAL->halGetPropertyString(udi, "battery.serial", &serial);
} else {
//query was not successfull
kdDebug() << "Query of battery.present of " << udi << " wasn't successfull." << endl;
//..but we assume its there try on
present = true;
if (initialized) {
emit changedBatteryPresent();
emit changedBattery();
}
}
// also query the serial ... no need to do this in a extra place
serial = bdevice->serialNumber();
kdDebugFuncOut(trace);
return true;
@ -258,12 +264,22 @@ bool Battery::checkBatteryType () {
TQString tmp_qstring;
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkBatteryType couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
// FIXME
// How can we get battery type from TDE HW library (i.e. how to get type from sysfs)?
// For now just report any batteries as primary...
type = BAT_PRIMARY;
return true;
#if 0
if (dbus_HAL->halGetPropertyString(udi,"battery.type", &tmp_qstring)) {
if (tmp_qstring.compare("primary") == 0) {
type = BAT_PRIMARY;
@ -290,6 +306,7 @@ bool Battery::checkBatteryType () {
kdDebugFuncOut(trace);
return false;
}
#endif
}
//! to check battery.technology
@ -303,9 +320,12 @@ bool Battery::checkBatteryTechnology () {
kdDebugFuncIn(trace);
TQString tmp_qstring;
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkBatteryTechnology couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -316,20 +336,14 @@ bool Battery::checkBatteryTechnology () {
return false;
}
if (dbus_HAL->halGetPropertyString(udi,"battery.technology", &tmp_qstring)) {
if (!tmp_qstring.isEmpty()) {
technology = TQString(tmp_qstring);
} else {
technology = TQString("UNKNOWN");
}
kdDebugFuncOut(trace);
return true;
tmp_qstring = bdevice->technology();
if (!tmp_qstring.isEmpty()) {
technology = TQString(tmp_qstring);
} else {
//query was not successfull, but this property is optional
technology = TQString("UNKNOWN");
kdDebugFuncOut(trace);
return false;
}
kdDebugFuncOut(trace);
return true;
}
@ -344,9 +358,12 @@ bool Battery::checkCapacityState () {
kdDebugFuncIn(trace);
TQString tmp_qstring;
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkCapacityState couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -357,16 +374,20 @@ bool Battery::checkCapacityState () {
return false;
}
if (dbus_HAL->halGetPropertyString(udi, "battery.charge_level.capacity_state", &tmp_qstring)) {
capacity_state = TQString(tmp_qstring);
kdDebugFuncOut(trace);
return true;
} else {
//query was not successfull, but this property is optional
capacity_state = TQString();
kdDebugFuncOut(trace);
return false;
capacity_state = "unknown";
TDEBatteryStatus::TDEBatteryStatus batteryStatus = bdevice->status();
if (batteryStatus == TDEBatteryStatus::Charging) {
capacity_state = "charging";
}
if (batteryStatus == TDEBatteryStatus::Discharging) {
capacity_state = "discharging";
}
if (batteryStatus == TDEBatteryStatus::Full) {
capacity_state = "full";
}
kdDebugFuncOut(trace);
return true;
}
@ -379,9 +400,12 @@ bool Battery::checkCapacityState () {
*/
bool Battery::checkChargeLevelCurrent () {
kdDebugFuncIn(trace);
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkChargeLevelCurrent couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -392,20 +416,15 @@ bool Battery::checkChargeLevelCurrent () {
return false;
}
if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.current", &charge_level_current)) {
if (charge_level_current < 0) {
//overflow?
charge_level_current = 0;
}
kdDebugFuncOut(trace);
return true;
} else {
//query was not successfull (is mandatory)
kdError() << "Couldn't request charge_level.current for udi: " << udi << endl;
state = BAT_NONE;
kdDebugFuncOut(trace);
return false;
// FIXME VERIFY CORRECTNESS
// what does kpowersave expect to see in charge_level_current (battery.charge_level.current)?
charge_level_current = bdevice->energy();
if (charge_level_current < 0) {
//overflow?
charge_level_current = 0;
}
kdDebugFuncOut(trace);
return true;
}
@ -419,8 +438,11 @@ bool Battery::checkChargeLevelCurrent () {
bool Battery::checkChargeLevelLastfull () {
kdDebugFuncIn(trace);
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkChargeLevelLastfull couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -431,20 +453,15 @@ bool Battery::checkChargeLevelLastfull () {
return false;
}
if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.last_full", &charge_level_lastfull)) {
if (charge_level_lastfull < charge_level_current ) {
//possible overflow?
charge_level_lastfull = charge_level_current;
}
kdDebugFuncOut(trace);
return true;
} else {
//query was not successfull (is mandatory)
kdError() << "couldn't query last_full of udi: " << udi << endl;
charge_level_lastfull = 0; // set back to 0
kdDebugFuncOut(trace);
return false;
// FIXME VERIFY CORRECTNESS
// what does kpowersave expect to see in charge_level_lastfull (battery.charge_level.last_full)?
charge_level_lastfull = bdevice->maximumEnergy();
if (charge_level_lastfull < charge_level_current ) {
//possible overflow?
charge_level_lastfull = charge_level_current;
}
kdDebugFuncOut(trace);
return true;
}
//! to check battery.charge_level.rate
@ -456,9 +473,12 @@ bool Battery::checkChargeLevelLastfull () {
*/
bool Battery::checkChargeLevelRate () {
kdDebugFuncIn(trace);
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkChargeLevelRate couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -471,22 +491,17 @@ bool Battery::checkChargeLevelRate () {
int _rate = present_rate;
if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.rate", &present_rate)) {
if (present_rate < 0 )
present_rate = 0;
// FIXME VERIFY CORRECTNESS
// what does kpowersave expect to see in present_rate (battery.charge_level.rate)?
present_rate = bdevice->dischargeRate();
if (present_rate < 0 )
present_rate = 0;
if (present_rate != _rate)
emit changedBattery();
if (present_rate != _rate)
emit changedBattery();
kdDebugFuncOut(trace);
return true;
} else {
//query was not successfull but this is optional
kdError() << "Couldn't request charge_level.rate for udi: " << udi << endl;
present_rate = 0;
kdDebugFuncOut(trace);
return false;
}
kdDebugFuncOut(trace);
return true;
}
@ -500,8 +515,11 @@ bool Battery::checkChargeLevelRate () {
bool Battery::checkChargeLevelUnit () {
kdDebugFuncOut(trace);
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkChargeLevelRate couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -512,15 +530,13 @@ bool Battery::checkChargeLevelUnit () {
return false;
}
if (!dbus_HAL->halGetPropertyString(udi, "battery.charge_level.unit", &charge_level_unit)) {
//query was not successfull but this is optional
kdWarning() << "Couldn't request charge_level.unit for udi: " << udi << endl;
kdDebugFuncOut(trace);
return false;
} else {
kdDebugFuncOut(trace);
return true;
}
// FIXME VERIFY CORRECTNESS
// what does kpowersave expect to see in charge_level_unit (battery.charge_level.unit)?
charge_level_unit = "wH";
//query was not successfull but this is optional
kdWarning() << "Couldn't request charge_level.unit for udi: " << udi << endl;
kdDebugFuncOut(trace);
return false;
}
//! to check battery.charge_level.design
@ -533,8 +549,11 @@ bool Battery::checkChargeLevelUnit () {
bool Battery::checkChargeLevelDesign () {
kdDebugFuncIn(trace);
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkChargeLevelDesign couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -545,18 +564,15 @@ bool Battery::checkChargeLevelDesign () {
return false;
}
if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.design", &design_capacity)) {
if (design_capacity < 0)
design_capacity = 0;
kdDebugFuncOut(trace);
return true;
} else {
//query was not successfull (is mandatory but not critical)
kdWarning() << "Couldn't request charge_level.design for udi: " << udi << endl;
kdDebugFuncOut(trace);
return false;
// FIXME VERIFY CORRECTNESS
// what does kpowersave expect to see in design_capacity (battery.charge_level.last_full)?
design_capacity = bdevice->maximumDesignEnergy();
if (design_capacity < 0) {
design_capacity = 0;
}
kdDebugFuncOut(trace);
return true;
}
@ -574,8 +590,11 @@ bool Battery::checkRemainingPercentage () {
int _val = 0;
int _state = -1;
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkRemainingPercentage couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -586,24 +605,13 @@ bool Battery::checkRemainingPercentage () {
return false;
}
if (dbus_HAL->halGetPropertyInt(udi, "battery.charge_level.percentage", &_val)) {
if (_val > 100) {
_val = 100;
} else if (_val < 0) {
_val = 0;
}
ret = true;
} else {
//query was not successfull, but this property is optional
//so we calculate it from charge_level
if (charge_level_current > 0) {
_val = (int)((float)(charge_level_current * 100) / (float)charge_level_lastfull);
ret = true;
} else {
kdError() << "Couldn't query percentage of udi: " << udi
<< ". and charge_level_current >= 0" << endl;
}
_val = bdevice->chargePercent();
if (_val > 100) {
_val = 100;
} else if (_val < 0) {
_val = 0;
}
ret = true;
if (charge_level_percentage != _val) {
if (initialized) {
@ -660,8 +668,11 @@ bool Battery::checkRemainingTime () {
int _min = 0;
bool _ret = false;
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkRemainingTime couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
@ -672,23 +683,9 @@ bool Battery::checkRemainingTime () {
return false;
}
if (dbus_HAL->halGetPropertyInt(udi, "battery.remaining_time", &_min)) {
_min /= 60;
_ret = true;
} else {
//query was not successfull, but this is optional
//and even very unlikely to be present
//try to get it via charge_level_current and present_rate
if (charge_level_current > 0 && present_rate > 0) {
_min = ((charge_level_current * 60 )/ present_rate) ;
_ret = true;
} else {
//we don't know it better
_min = 0;
_ret = false;
}
}
_min = bdevice->timeRemaining();
_min /= 60;
_ret = true;
if (remaining_minutes != _min) {
if (initialized) {
@ -718,34 +715,32 @@ bool Battery::checkChargingState () {
bool _ret = false;
int _c_state = -1;
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
kdError() << "Couldn't connect to HAL" << endl;
// First make sure the battery object is still available
TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(m_hwdevices->findByUniqueID(udi));
if (!bdevice) {
//grr... no luck
kdError() << "Battery::checkChargingState couldn't find battery" << endl;
kdDebugFuncOut(trace);
return false;
}
if (!present) {
kdWarning() << "No need to update property, battery not present." << endl;
kdDebugFuncOut(trace);
return false;
}
if (dbus_HAL->halGetPropertyBool(udi, "battery.rechargeable.is_charging", &tmp_bool) &&
dbus_HAL->halGetPropertyBool(udi, "battery.rechargeable.is_discharging", &tmp_bool2)) {
if (tmp_bool && !tmp_bool2) {
_c_state = CHARGING;
} else if (tmp_bool2 && !tmp_bool) {
_c_state = DISCHARGING;
} else {
_c_state = UNKNOWN_STATE;
}
_ret = true;
tmp_bool = (bdevice->status() == TDEBatteryStatus::Charging);
tmp_bool2 = (bdevice->status() == TDEBatteryStatus::Discharging);
if (tmp_bool && !tmp_bool2) {
_c_state = CHARGING;
} else if (tmp_bool2 && !tmp_bool) {
_c_state = DISCHARGING;
} else {
kdError() << "Couldn't get current charging state for udi: " << udi << endl;
_c_state = UNKNOWN_STATE;
_ret = false;
}
_ret = true;
if (charging_state != _c_state) {
if (initialized) {
@ -766,64 +761,16 @@ bool Battery::checkChargingState () {
/*!
* Check for the given property new values from HAL and set them to
* the battery variables.
* \param _udi TQString with the UDI of the device to recheck
* \param _property TQString with the property which was changed
* \return boolean with the result of the operation
* \retval true if the update was successfull
* \retval false if the update couldn't be applied
* \param device TDEGenericDevice
*/
bool Battery::updateProperty(TQString _udi, TQString _property) {
void Battery::updateProperty(TDEGenericDevice* device) {
kdDebugFuncIn(trace);
//first check whether HAL is available
if (!dbus_HAL->isConnectedToHAL() && !dbus_HAL->reconnect()) {
//grr... no luck
kdError() << "Battery::updateProperty couldn't connect to HAL" << endl;
kdDebugFuncOut(trace);
return false;
}
bool ret = true;
if (udi.startsWith(_udi)) {
// handle different keys and update only the needed
if (_property.startsWith("battery.present")) {
if (!checkBatteryPresent()) ret = false;
} else if (_property.startsWith("battery.type")) {
if (!checkBatteryType()) ret = false;
} else if (_property.startsWith("battery.charge_level.capacity_state")) {
if (!checkCapacityState()) ret= false;
} else if (_property.startsWith("battery.charge_level.current")) {
if (!checkChargeLevelCurrent()) ret = false;
} else if (_property.startsWith("battery.charge_level.rate")) {
if (!checkChargeLevelRate()) ret = false;
} else if (_property.startsWith("battery.charge_level.percentage")) {
if (!checkRemainingPercentage()) ret = false;
} else if (_property.startsWith("battery.remaining_time")) {
if (!checkRemainingTime()) ret = false;
} else if (_property.startsWith("battery.rechargeable.is_")) {
if (!checkChargingState()) ret = false;
} else if (_property.startsWith("battery.charge_level.last_full")) {
if (!checkChargeLevelLastfull()) ret = false;
// --> changes on this keys should normally not happen except if battery was added /removed
} else if (_property.startsWith("battery.technology")) {
if (!checkBatteryTechnology()) ret = false;
} else if (_property.startsWith("battery.charge_level.unit")) {
if (!checkChargeLevelUnit()) ret = false;
} else if (_property.startsWith("battery.charge_level.design")) {
if (!checkChargeLevelDesign()) ret = false;
} else {
kdDebug() << "Unknown or unhandled device property: " << _property
<< " for device with udi: " << _udi << endl;
ret = false;
}
} else {
kdError() << "Given UDI doesn't match the UDI of this battery object." << endl;
ret = false;
if (device->uniqueID() == udi) {
recheck();
}
kdDebugFuncOut(trace);
return ret;
}
//! Resets the current HAL udi used by the one given
@ -838,23 +785,9 @@ bool Battery::updateProperty(TQString _udi, TQString _property) {
bool Battery::resetUdi(TQString _udi) {
kdDebugFuncIn(trace);
bool tmp_result=false;
//trivial pre-check to eliminate totally dumb _udi strings
if (!_udi.isNull() && !_udi.isEmpty() && _udi.startsWith("/org/freedesktop/Hal/devices/")) {
//ok, now lets ask HAL if its really a battery
if (dbus_HAL->isConnectedToHAL() || dbus_HAL->reconnect()) {
dbus_HAL->halQueryCapability(_udi,"battery",&tmp_result);
} else {
kdError() << "Battery::resetUdi couldn't connect to HAL" << endl;
}
} else {
kdError() << "Battery::resetUdi received empty or invalid udi" << endl;
}
// FIXME
// What does this function do outside of HAL!?!? Should it even exist any more?
bool tmp_result=true;
kdDebugFuncOut(trace);
return tmp_result;

@ -42,6 +42,9 @@
#include <tqstringlist.h>
#include <tqobject.h>
// TDE hardware library
#include <tdehardwaredevices.h>
#include "dbusHAL.h"
class Battery : public TQObject {
@ -50,12 +53,11 @@ class Battery : public TQObject {
private:
//! Internal reference to dbusHAL for communication with HAL daemon
dbusHAL* dbus_HAL;
TDEHardwareDevices *m_hwdevices;
//! HAL udi of the battery to represent
//! TDE hardware library udi of the battery to represent
/*!
* This TQString holds the HAL udi adress of the battery.
* This TQString holds the TDE hardware library udi adress of the battery.
* \li empty: all primary batteries are represented
* \li e.g. "/org/freedesktop/Hal/devices/acpi_BAT0": first acpi battery
*/
@ -67,10 +69,10 @@ private:
* \li e.g. "LION"
*/
TQString technology;
//! Current charging state of this battery as reported by HAL
//! Current charging state of this battery as reported by TDE hardware library
/*!
* This TQString tells the current capacity_state HAL is reporting.
* \li as of current HAL spec: "ok", "critical"
* This TQString tells the current capacity_state TDE hardware library is reporting.
* \li as of current TDE hardware library spec: "ok", "critical"
*/
TQString capacity_state;
//! Unit of charge_level_unit and charge_level_lastfull.
@ -116,7 +118,7 @@ private:
* \li BAT_LOW: batterylevel is already low
* \li BAT_CRIT: batterylevel has become really critical
* \li BAT_NONE: battery state not available
* \li BAT_HAL_ERROR: battery state couldn't be retrieved because of a HAL error
* \li BAT_TDE hardware library_ERROR: battery state couldn't be retrieved because of a TDE hardware library error
*/
int state;
//! Current charging state of this battery
@ -221,31 +223,30 @@ signals:
void changedBatteryWarnState (int state);
//! emitted if any Battery state changed
void changedBattery();
public slots:
//! update a property on device event
void updateProperty(TDEGenericDevice*);
public:
//! default constructor
Battery( dbusHAL* _dbus_HAL, TQString _udi );
//! default constructor
Battery( dbusHAL* _dbus_HAL );
//! this constructor forces the use of init with dbuHAL pointer set!
Battery();
Battery( TQString _udi );
//! default destructor
~Battery();
//! initialize this battery object with values from HAL
void init( dbusHAL* _dbus_HAL = NULL );
//! initialize this battery object with values from TDE hardware library
void init();
//! recheck all properties of the battery
void recheck();
//! rechecks only minimalistic set properties
void minRecheck();
//! update a property on HAL event
bool updateProperty(TQString _udi, TQString _property);
//ro-Interface to internal data
//! reports the HAL udi of this battery
//! reports the TDE hardware library udi of this battery
TQString getUdi() const;
//! reports HAL capacity_state value
//! reports TDE hardware library capacity_state value
TQString getCapacityState() const;
//! reports the physical unit of values like DesignCapacity, PresentRate and Lastfull
TQString getChargelevelUnit() const;
@ -282,9 +283,9 @@ public:
int getCritLevel() const;
//writeable access to internals
//! Resets the current HAL udi used by the one given
//! Resets the current TDE hardware library udi used by the one given
/*!
* The given TQString will be (checked and) used as new HAL udi for the battery.
* The given TQString will be (checked and) used as new TDE hardware library udi for the battery.
* But don't forget to do a recheck of the battery afterwards.
* \li returns TRUE: if reset was successfull
* \li returns FALSE: if reset couldn't be applied

@ -46,6 +46,8 @@ CPUInfo::CPUInfo() {
update_info_cpufreq_speed_changed = true;
numOfCPUs = -1;
m_hwdevices = KGlobal::hardwareDevices();
kdDebugFuncOut(trace);
}
@ -60,35 +62,8 @@ CPUInfo::~CPUInfo() {
* Returns the total count of CPUs - _not_ the last CPU ID!
*/
int CPUInfo::getCPUNum() {
kdDebugFuncIn(trace);
int cpu_id=0;
TQDir tmp_dir;
TQString cpu_path = "/sys/devices/system/cpu/cpu0/";
#ifdef FAKE_CPU
cpu_path.prepend("/tmp/foo");
#endif
// let check if we support cpufreq in general
if (tmp_dir.exists(tmp_dir.absFilePath(cpu_path + "cpufreq/scaling_cur_freq", true))) {
cpuFreqHW = true;
} else {
cpuFreqHW = false;
}
TQString tmp_path = tmp_dir.absFilePath(cpu_path, true);
while (tmp_dir.exists(tmp_path)) {
int tmp = cpu_id;
cpu_id++;
cpu_path.replace(TQString::number(tmp), TQString::number(cpu_id));
tmp_path = tmp_dir.absFilePath(cpu_path, true);
}
kdDebug() << "getCPUNum() return: '" << cpu_id << "'" << endl;
kdDebugFuncOut(trace);
return cpu_id;
TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
return hwlist.count();
}
/*!

@ -43,6 +43,9 @@
#include <tqobject.h>
#include <tqvaluelist.h>
// TDE hardware library
#include <tdehardwaredevices.h>
// own headers
#include "kpowersave_debug.h"
@ -57,6 +60,8 @@ private:
/*! This contains the number of CPUs in the current system */
int numOfCPUs;
TDEHardwareDevices *m_hwdevices;
public:
//! represent the current Throttling of the CPU

@ -102,8 +102,6 @@ kpowersave::kpowersave( bool force_acpi_check, bool trace_func ) : KSystemTray(0
// connect to error mesages
connect(autoSuspend, TQT_SIGNAL(displayErrorMsg(TQString)), this, TQT_SLOT(showErrorMessage(TQString)));
connect(hwinfo, TQT_SIGNAL(halRunning(bool)), this, TQT_SLOT(showHalErrorMsg()));
connect(hwinfo, TQT_SIGNAL(dbusRunning(int)), this, TQT_SLOT(showDBusErrorMsg(int)));
// connect to events
connect(hwinfo, TQT_SIGNAL(lidclosetStatus(bool)), this, TQT_SLOT(handleLidEvent(bool)));
@ -121,7 +119,6 @@ kpowersave::kpowersave( bool force_acpi_check, bool trace_func ) : KSystemTray(0
config_dialog_shown = false;
suspend_dialog_shown = false;
detailedIsShown = false;
hal_error_shown = false;
icon_set_colored = false;
icon_BG_is_colored = false;
@ -134,9 +131,6 @@ kpowersave::kpowersave( bool force_acpi_check, bool trace_func ) : KSystemTray(0
BAT_WARN_ICON_Timer = new TQTimer(this);
connect(BAT_WARN_ICON_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_setIconBG()));
DISPLAY_HAL_ERROR_Timer = new TQTimer(this);
connect(DISPLAY_HAL_ERROR_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(showHalErrorMsg()));
AUTODIMM_Timer = new TQTimer(this);
initMenu();
@ -287,7 +281,7 @@ void kpowersave::showConfigureDialog() {
i18n("Warning").ascii(), 15000);
}
} else {
configDlg->setWindowState(configDlg->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
configDlg->setWindowState((configDlg->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
configDlg->setActiveWindow();
}
@ -317,7 +311,7 @@ void kpowersave::loadIcon(){
BatteryCollection *primary = hwinfo->getPrimaryBatteries();
if (hwinfo->hal_terminated || !hwinfo->isOnline() ) {
if ( !hwinfo->isOnline() ) {
pixmap_name_tmp = TQString("ERROR");
}
else if (hwinfo->getAcAdapter() || primary->getBatteryState() == BAT_NONE) {
@ -461,7 +455,7 @@ void kpowersave::updateTooltip(){
num3.setNum(minutes % 60);
num3 = num3.rightJustify(2, '0');
if (hwinfo->hal_terminated){
if ( !hwinfo->isOnline() ){
tmp = i18n("No information about battery and AC status available");
}
else if (hwinfo->getAcAdapter()) {
@ -1647,85 +1641,6 @@ void kpowersave::closedetaileddialog() {
detailedIsShown = false;
}
/*!
* \b TQT_SLOT used to display error messages related to D-Bus in kpowersave. This function
* block all messeges which we have in kpowersave!
* TODO: do something usefull
*/
void kpowersave::showDBusErrorMsg( int type ){
kdDebugFuncIn(trace);
static bool displayed = false;
TQString msg;
TQString dlg_name;
switch (type) {
case DBUS_RUNNING:
update();
return;
case DBUS_NOT_RUNNING:
msg = i18n("The D-Bus daemon is not running.\nStarting it will "
"provide full functionality: /etc/init.d/dbus start");
dlg_name = "dbusNotRunning";
break;
default:
kdDebugFuncOut(trace);
return;
}
if (!displayed && !dlg_name.isEmpty()) {
infoDialog *dlg = new infoDialog( config, i18n("Warning"), msg,
i18n("Don't show this message again."), dlg_name);
if (!dlg->dialogIsDisabled()) {
dlg->show();
}
// set this always to true ... this should reduce the calls
displayed = true;
}
kdDebugFuncOut(trace);
}
/*!
* \b TQT_SLOT to display the HAL error message. We use this
* function to delay the message, and prevent display them is HAL or
* powersaved restarted.
*/
void kpowersave::showHalErrorMsg() {
kdDebugFuncIn(trace);
if (hwinfo->isOnline()) {
// HAL is back!
update();
}
if (!hwinfo->dbus_terminated) {
if(hal_error_shown && !DISPLAY_HAL_ERROR_Timer->isActive() && hwinfo->hal_terminated){
KPassivePopup::message( i18n("ERROR"),
i18n("Could not get information from HAL. The haldaemon is "
"maybe not running."),
SmallIcon("messagebox_warning", 20), this,
i18n("Error").ascii(), 5000);
}
else if (hwinfo->hal_terminated && !hal_error_shown && !DISPLAY_HAL_ERROR_Timer->isActive()) {
hal_error_shown = true;
DISPLAY_HAL_ERROR_Timer->start(HAL_ERROR_MSG_intervall, true);
}
else if (!hwinfo->hal_terminated) {
hal_error_shown = false;
DISPLAY_HAL_ERROR_Timer->stop();
}
} else {
// only for the case that HAL is also down with dbus and not back after restart
if (hwinfo->hal_terminated && !hal_error_shown && !DISPLAY_HAL_ERROR_Timer->isActive())
DISPLAY_HAL_ERROR_Timer->start(HAL_ERROR_MSG_intervall, true);
}
kdDebugFuncOut(trace);
return;
}
/*!
* \b TQT_SLOT used to display messeges in kpowersave. This function
* block all messeges which we have in kpowersave!

@ -156,14 +156,6 @@ private:
* \li false: if not
*/
bool suspend_dialog_shown;
//! represent display state of HAL error message
/*!
* This boolean represent information about the current state of
* the HAL error message
* \li true: if the errormessage was already displayed in this context
* \li false: if not
*/
bool hal_error_shown;
//! tell if the display should get dimmed down
/*!
@ -238,13 +230,6 @@ private:
*/
static const int BAT_icon_BG_intervall = 1000;
//! TQTimer-interval for display HAL error message
/*!
* Time intervall to delay display the HAL error message to prevent displayed
* the message if only HAL or powersave is restarted. The value is 15000 msec/ 15 sec.
*/
static const int HAL_ERROR_MSG_intervall = 15000;
//! type of current running suspend
/*! TQString store the name of the current running suspend*/
TQString suspendType;
@ -288,12 +273,6 @@ private:
* The timerinterval is defined in \ref BAT_icon_BG_intervall .
*/
TQTimer *BAT_WARN_ICON_Timer;
//! Timer to delay the HAL error message
/*!
* This timer is used to add a delay befor display the HAL error message
* The timerinterval is defined in \ref HAL_ERROR_MSG_intervall .
*/
TQTimer *DISPLAY_HAL_ERROR_Timer;
//! Timer to dimm down/up the brightness
/*!
* This timer is used dimm the display up and down. The timerinterval
@ -329,11 +308,11 @@ private:
private slots:
//! send command for stand-by to the HAL daemon
//! send command for stand-by to the TDE hardware library
bool do_standby();
//! send command for suspend_to_disk to the HAL daemon
//! send command for suspend_to_disk to the TDE hardware library
bool do_suspend2disk();
//! send command for suspend_to_RAM to the HAL daemon
//! send command for suspend_to_RAM to the TDE hardware library
bool do_suspend2ram();
//! show warning dialog or call autosuspend if signal \ref inactivity::inactivityTimeExpired() recieved
@ -348,7 +327,7 @@ private slots:
void do_setIconBG();
//! to set the autosuspend on/off over the menu
void do_setAutosuspend();
//! sets the CPU Freq policy via the HAL daemon
//! sets the CPU Freq policy via the TDE hardware library
void do_setSpeedPolicy( int );
//! called if there are problems with starting yast module
void slotConfigProcessExited( KProcess * );
@ -423,10 +402,6 @@ private slots:
//! this emit the KNotify events if the machine resumed
void handleResumeSignal();
//! to display HAL error msg
void showHalErrorMsg( );
//! this is invoked to display powersave error message
void showDBusErrorMsg( int );
//! this show a blocking dialog from kpowersave with the given message
void showErrorMessage( TQString msg );

Loading…
Cancel
Save