Switch from dbus-tqt do dbus-1-tqt

Add systemd session and inhibit support
Cleanup unused methods
This partially resolves Bug 1597
pull/1/head
Slávek Banko 11 years ago
parent 5c45c1a222
commit c68a1bac04

@ -51,10 +51,10 @@ if( NOT DBUS_FOUND )
endif( ) endif( )
# check for dbus-tqt # check for dbus-1-tqt
pkg_search_module( DBUS_TQT dbus-tqt ) pkg_search_module( DBUS_TQT dbus-1-tqt )
if( NOT DBUS_TQT_FOUND ) if( NOT DBUS_TQT_FOUND )
tde_message_fatal( "dbus-tqt is required, but was not found on your system" ) tde_message_fatal( "dbus-1-tqt is required, but was not found on your system" )
endif( ) endif( )
# check for msgfmt # check for msgfmt

@ -16,8 +16,8 @@ include_directories(
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${TDE_INCLUDE_DIR} ${TDE_INCLUDE_DIR}
${TQT_INCLUDE_DIRS} ${TQT_INCLUDE_DIRS}
${DBUS_INCLUDE_DIRS}
${DBUS_TQT_INCLUDE_DIRS} ${DBUS_TQT_INCLUDE_DIRS}
${HAL_INCLUDE_DIRS}
) )
link_directories( link_directories(
@ -48,6 +48,6 @@ tde_add_tdeinit_executable( tdepowersave AUTOMOC
tdepowersave.skel log_viewer.ui logviewer.cpp main.cpp tdepowersave.skel log_viewer.ui logviewer.cpp main.cpp
screen.cpp settings.cpp suspenddialog.cpp suspend_Dialog.ui screen.cpp settings.cpp suspenddialog.cpp suspend_Dialog.ui
LINK LINK
${DBUS_TQT_LIBRARIES} tdeio-shared ${HAL_LIBRARIES} ${DBUS_TQT_LIBRARIES} tdeio-shared
${XEXT_LIBRARIES} ${XTST_LIBRARIES} ${XSCRNSAVER_LIBRARIES} ${XEXT_LIBRARIES} ${XTST_LIBRARIES} ${XSCRNSAVER_LIBRARIES}
) )

@ -21,7 +21,6 @@ noinst_HEADERS = \
infodialog.h \ infodialog.h \
tdepowersave.h \ tdepowersave.h \
logviewer.h \ logviewer.h \
privileges.h \
screen.h \ screen.h \
settings.h \ settings.h \
suspenddialog.h suspenddialog.h

@ -19,38 +19,52 @@
/*! /*!
* \file dbusInterface.cpp * \file dbusInterface.cpp
* \brief In this file can be found the functionality to connect to * \brief In this file can be found the functionality to connect to
* the HAL daemon via D-Bus, to handle D-Bus calls/events and to * the D-Bus, to handle D-Bus session management
* provide wrapper to HAL lib and functions
* \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de> * \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
* \date 2006-2007 * \date 2006-2007
*/ */
// KDE Header // QT - Header
#include <tqtimer.h>
// KDE Header
#include <tdelocale.h> #include <tdelocale.h>
// DBUS - Header // DBUS - Header
#include "dbus/dbus-shared.h"
#include "dbusInterface.h" #include "dbusInterface.h"
#include <tqdbusdatalist.h>
#include <tqdbusdatamap.h>
#include <tqdbuserror.h>
#include <tqdbusmessage.h>
#include <tqdbusvariant.h>
// system headers // system headers
#include <iostream> #include <unistd.h>
#define DBUS_CONN_NAME "TDEPowersave"
static void* myInstance = 0; static void* myInstance = 0;
/*! The default constructor of the class dbusInterface. */ /*! The default constructor of the class dbusInterface. */
dbusInterface::dbusInterface(){ dbusInterface::dbusInterface():
dBusConn(),
dBusWatch(0),
dBusLocal(0),
systemdSession(),
systemdSeat(0),
systemdInhibit(-1),
consolekitSession(),
consolekitSeat(0)
{
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
dbus_is_connected = false;
acquiredPolicyPower = false;
// add pointer to this for filter_function() // add pointer to this for filter_function()
myInstance=this; myInstance=this;
// init connection to dbus // init connection to dbus
if(!initDBUS()) { initDBUS();
kdError() << "Can't connect to D-Bus" << endl;
m_dBusQtConnection = NULL;
}
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
} }
@ -72,30 +86,19 @@ dbusInterface::~dbusInterface(){
* \retval false if disconnected * \retval false if disconnected
*/ */
bool dbusInterface::isConnectedToDBUS() { bool dbusInterface::isConnectedToDBUS() {
return dbus_is_connected; return dBusConn.isConnected();
}
/*!
* This function return information if the org.freedesktop.Policy.Power
* interface was claimed.
* \return boolean with the status of claim the interface
* \retval true if acquired
* \retval false if not
*/
bool dbusInterface::acquiredPolicyPowerInterface() {
return acquiredPolicyPower;
} }
/*! /*!
* This function try a reconnect to D-Bus and HAL daemon. * This function try a reconnect to D-Bus.
* \return boolean with the result of the operation * \return boolean with the result of the operation
* \retval true if successful reconnected to D-Bus and HAL * \retval true if successful reconnected to D-Bus
* \retval false if unsuccessful * \retval false if unsuccessful
*/ */
bool dbusInterface::reconnect() { bool dbusInterface::reconnect() {
// close D-Bus connection // close D-Bus connection
close(); close();
// init D-Bus conntection and HAL context // init D-Bus conntection
return (initDBUS()); return (initDBUS());
} }
@ -106,18 +109,24 @@ bool dbusInterface::reconnect() {
* \retval false if any problems * \retval false if any problems
*/ */
bool dbusInterface::close() { bool dbusInterface::close() {
if ( m_dBusQtConnection != NULL ) { if( dBusConn.isConnected() ) {
releasePolicyPowerIface(); if( dBusWatch ) {
m_dBusQtConnection->close(); delete dBusWatch;
m_dBusQtConnection = NULL; }
if( dBusLocal ) {
delete dBusLocal;
}
if( systemdSeat ) {
delete systemdSeat;
}
if( consolekitSeat ) {
delete consolekitSeat;
}
} }
dbus_is_connected = false; dBusConn.closeConnection(DBUS_CONN_NAME);
return true; return true;
} }
/* ----> D-Bus section :: START <---- */
/*! /*!
* This function initialise the connection to the D-Bus daemon. * This function initialise the connection to the D-Bus daemon.
* \return boolean with the result of the operation * \return boolean with the result of the operation
@ -127,528 +136,260 @@ bool dbusInterface::close() {
bool dbusInterface::initDBUS(){ bool dbusInterface::initDBUS(){
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
dbus_is_connected = false; dBusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus, DBUS_CONN_NAME);
DBusError error;
dbus_error_init(&error);
dbus_connection = dbus_bus_get( DBUS_BUS_SYSTEM, &error );
if (dbus_connection == NULL){ if( !dBusConn.isConnected() ) {
kdError() << "Failed to open connection to system message bus: " << error.message << endl; kdError() << "Failed to open connection to system message bus: " << dBusConn.lastError().message() << endl;
dbus_error_free (&error); TQTimer::singleShot(4000, this, TQT_SLOT(reconnect()));
return false; return false;
} }
if ( dbus_error_is_set( &error ) ) { // watcher for NameOwnerChanged signals
kdError() << "Failed to register connection with system message bus: " << error.message << endl; dBusWatch = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
return false; TQObject::connect(dBusWatch, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
} this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
acquirePolicyPowerIface(); // watcher for Disconnect signal
dBusLocal = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_LOCAL, DBUS_INTERFACE_LOCAL, dBusConn);
dbus_connection_set_exit_on_disconnect( dbus_connection, false ); TQObject::connect(dBusLocal, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
/* add the filter function which should be executed on events on the bus */
if ( ! dbus_connection_add_filter( dbus_connection, filterFunction, this, NULL) ) { // find already running SystemD
kdFatal() << "Error: Not enough memory to add filter to dbus connection" << endl; TQT_DBusProxy checkSystemD(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
exit(EXIT_FAILURE); if( checkSystemD.canSend() ) {
} TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromString(SYSTEMD_LOGIN1_SERVICE);
/* add a match rule to catch all signals going through the bus with D-Bus interface */ TQT_DBusMessage reply = checkSystemD.sendWithReply("NameHasOwner", params);
dbus_bus_add_match( dbus_connection, "type='signal'," if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
"interface='org.freedesktop.DBus'," onServiceRegistered(SYSTEMD_LOGIN1_SERVICE);
"member='NameOwnerChanged'", 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',"
"member='ActiveChanged'", NULL);
m_dBusQtConnection = new DBusQt::Connection(this);
m_dBusQtConnection->dbus_connection_setup_with_qt_main(dbus_connection);
dbus_is_connected = true;
kdDebugFuncOut(trace);
return true;
}
/*!
* This function acquire the org.freedesktop.Policy.Power interface
* \return boolean with the result of the operation
* \retval true if successful acquired the interface
* \retval false if unsuccessful
*/
bool dbusInterface::acquirePolicyPowerIface(){
kdDebugFuncIn(trace);
if (dbus_connection == NULL) {
kdDebugFuncOut(trace);
return false;
} }
DBusError err; // find already running ConsoleKit
dbus_error_init(&err); TQT_DBusProxy checkConsoleKit(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
int ret = dbus_bus_request_name(dbus_connection, "org.freedesktop.Policy.Power", if( checkConsoleKit.canSend() ) {
DBUS_NAME_FLAG_REPLACE_EXISTING, &err); TQValueList<TQT_DBusData> params;
if (dbus_error_is_set(&err)) { params << TQT_DBusData::fromString(CK_SERVICE);
kdWarning() << "Acquire org.freedesktop.Policy.Power interface failed with error: " << err.message << endl; TQT_DBusMessage reply = checkConsoleKit.sendWithReply("NameHasOwner", params);
dbus_error_free(&err); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
} onServiceRegistered(CK_SERVICE);
switch (ret) { }
case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
kdDebug() << "Acquired org.freedesktop.Policy.Power interface" << endl;
acquiredPolicyPower = true;
break;
case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
kdWarning() << "Queued to acquire org.freedesktop.Policy.Power interface" << endl;
acquiredPolicyPower = false;
break;
default:
acquiredPolicyPower = false;
break;
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
return acquiredPolicyPower; return true;
} }
/*! /*!
* This function release the org.freedesktop.Policy.Power interface * This function handles signals from the D-Bus daemon.
* \return boolean with the result of the operation
* \retval true if successful acquired the interface
* \retval false if unsuccessful
*/ */
bool dbusInterface::releasePolicyPowerIface(){ void dbusInterface::handleDBusSignal(const TQT_DBusMessage& msg) {
kdDebugFuncIn(trace); // dbus terminated
if( msg.path() == DBUS_PATH_LOCAL
int result; && msg.interface() == DBUS_INTERFACE_LOCAL
bool retval = false; && msg.member() == "Disconnected" ) {
DBusError error; close();
TQTimer::singleShot(1000, this, TQT_SLOT(reconnect()));
if (dbus_connection == NULL) { return;
kdDebugFuncOut(trace);
return false;
} }
dbus_error_init(&error); // service registered / unregistered
if( msg.path() == DBUS_PATH_DBUS
result = dbus_bus_release_name(dbus_connection, "org.freedesktop.Policy.Power", &error); && msg.interface() == DBUS_INTERFACE_DBUS
&& msg.member() == "NameOwnerChanged" ) {
if ( dbus_error_is_set( &error ) ) { if( msg[1].toString().isEmpty() ) {
kdError() << "Failed to release org.freedesktop.Policy.Power: " << error.message << endl; // old-owner is empty
dbus_error_free(&error); onServiceRegistered(msg[0].toString());
} else {
switch (result) {
case DBUS_RELEASE_NAME_REPLY_RELEASED:
kdDebug() << "Released org.freedesktop.Policy.Power interface" << endl;
retval = true;
acquiredPolicyPower = false;
break;
case DBUS_RELEASE_NAME_REPLY_NOT_OWNER:
kdWarning() << "Couldn't release org.freedesktop.Policy.Power, not the owner" << endl;
break;
case DBUS_RELEASE_NAME_REPLY_NON_EXISTENT:
kdWarning() << "Couldn't release org.freedesktop.Policy.Power, Iface not existing" << endl;
break;
default:
kdWarning() << "Couldn't release org.freedesktop.Policy.Power, unknown error" << endl;
break;
} }
if( msg[2].toString().isEmpty() ) {
// new-owner is empty
onServiceUnregistered(msg[0].toString());
}
return;
} }
return retval;
kdDebugFuncOut(trace);
}
/*!
* This function check if the org.freedesktop.Policy.Power
* interface is owned by someone
* \return boolean with the result of the operation
* \retval true if the interface is owned by someone
* \retval false if else
*/
bool dbusInterface::isPolicyPowerIfaceOwned(){
kdDebugFuncIn(trace);
bool retval = false; // systemd session changed
DBusError error; if( systemdSeat && systemdSeat->canSend()
&& msg.path() == systemdSeat->path()
if (dbus_connection == NULL) { && msg.interface() == DBUS_INTERFACE_PROPERTIES
kdDebugFuncOut(trace); && msg.member() == "PropertiesChanged"
return false; && msg[0].toString() == SYSTEMD_LOGIN1_SEAT_IFACE) {
bool activeSessionProperty = false;
TQT_DBusDataMap<TQString> map = msg[1].toStringKeyMap();
TQT_DBusDataMap<TQString>::const_iterator it = map.begin();
for (; !activeSessionProperty && it != map.end(); ++it) {
if( it.key() != "ActiveSession" ) {
activeSessionProperty = true;
}
}
TQValueList<TQString> list = msg[2].toList().toStringList();
TQValueList<TQString>::const_iterator it1 = list.begin();
for (; !activeSessionProperty && it1 != list.end(); ++it1) {
if( (*it1) == "ActiveSession" ) {
activeSessionProperty = true;
}
}
if( activeSessionProperty ) {
emit activeSessionChanged(checkActiveSession());
}
return;
} }
dbus_error_init(&error); // consolekit session changed
if( consolekitSeat && consolekitSeat->canSend()
retval = dbus_bus_name_has_owner(dbus_connection, "org.freedesktop.Policy.Power", &error); && msg.path() == consolekitSeat->path()
&& msg.interface() == CK_SEAT_IFACE
if ( dbus_error_is_set( &error ) ) { && msg.member() == "ActiveSessionChanged") {
kdError() << "Failed to check if org.freedesktop.Policy.Power has an owner: " << error.message << endl; emit activeSessionChanged(msg[0].toString() == TQString(consolekitSession));
dbus_error_free(&error); return;
} }
kdDebugFuncOut(trace);
return retval;
}
/* ----> DBUS section :: END <---- */
/* ----> D-Bus methode calls functions :: START <---- */
/*!
* This function call a D-Bus method
* \param interface TQString with te dbus interface
* \param path TQString with the object path
* \param object TQString with the object name
* \param method TQString with the name of the methode
* \param first_arg_type integer with the dbus type of the first argument
* \param ... more arguments
* \return If the query was successful or not
*/
bool dbusInterface::dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
int first_arg_type, ... ) {
kdDebugFuncIn(trace);
bool _ret = false;
va_list var_args;
va_start(var_args, first_arg_type);
_ret = dbusMethodCall( interface, path, object, method, DBUS_BUS_SYSTEM,
NULL, -1, first_arg_type, var_args);
va_end(var_args);
kdDebugFuncOut(trace);
return _ret;
}
/*!
* This overloaded function call a D-Bus method on the D-Bus system bus with a return value
* \param interface TQString with the dbus interface
* \param path TQString with the object path
* \param object TQString with the object name
* \param method TQString with the name of the method
* \param retvalue void pointer to arguments, if NULL we make a simple call
* \param retval_type Integer with the dbus type of the return value, set to -1 if retvalue is NULL
* \param first_arg_type Integer with the dbus type of the first argument followed by the value
* \return If the query was successful or not
*/
bool dbusInterface::dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
void *retvalue, int retval_type, int first_arg_type, ... ) {
kdDebugFuncIn(trace);
bool _ret = false;
va_list var_args;
va_start(var_args, first_arg_type);
_ret = dbusMethodCall( interface, path, object, method, DBUS_BUS_SYSTEM,
retvalue, retval_type, first_arg_type, var_args);
va_end(var_args);
kdDebugFuncOut(trace);
return _ret;
} }
/*!
/*! * This function handles dBus service registering
* This function call a D-Bus method with a return value
* \param interface TQString with the dbus interface
* \param path TQString with the object path
* \param object TQString with the object name
* \param method TQString with the name of the method
* \param dbus_type DBusBusType with the D-Bus BUS Type
* \param retvalue void pointer to arguments, if NULL we make a simple call
* \param retval_type Integer with the dbus type of the return value, set to -1 if retvalue is NULL
* \param first_arg_type Integer with the dbus type of the first argument followed by the value
* \param var_args va_list with more arguments
* \return If the query was successful or not
*/ */
bool dbusInterface::dbusMethodCall( TQString interface, TQString path, TQString object, TQString method, void dbusInterface::onServiceRegistered(const TQString& service) {
DBusBusType dbus_type, void *retvalue, int retval_type, int first_arg_type, if( service == SYSTEMD_LOGIN1_SERVICE ) {
va_list var_args ) { // get current session
kdDebugFuncIn(trace); TQT_DBusProxy managerIface(SYSTEMD_LOGIN1_SERVICE, SYSTEMD_LOGIN1_PATH, SYSTEMD_LOGIN1_MANAGER_IFACE, dBusConn);
systemdSession = TQT_DBusObjectPath();
DBusMessage *message; if( managerIface.canSend() ) {
DBusMessage *reply; TQValueList<TQT_DBusData> params;
DBusError error; params << TQT_DBusData::fromUInt32( getpid() );
bool ret = false; TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionByPID", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
dbus_error_init(&error); systemdSession = reply[0].toObjectPath();
}
dbus_connection = dbus_bus_get(dbus_type, &error); }
if( !systemdSession.isValid() ) {
if (dbus_error_is_set(&error)) { kdWarning() << "The session is not registered with systemd" << endl;
kdError() << "Could not get dbus connection: " << error.message << endl; return;
dbus_error_free(&error); }
goto out;
}
message = dbus_message_new_method_call( interface.ascii(), path.ascii(), object.ascii(), method.ascii() );
dbus_message_append_args_valist(message, first_arg_type, var_args);
if (retvalue == NULL) { // get session seat
if (!dbus_connection_send(dbus_connection, message, NULL)) { TQT_DBusProxy sessionProperties(SYSTEMD_LOGIN1_SERVICE, systemdSession, DBUS_INTERFACE_PROPERTIES, dBusConn);
kdError() << "Could not send method call." << endl; TQT_DBusObjectPath seat;
dbus_message_unref( message ); if( sessionProperties.canSend() ) {
goto out; TQValueList<TQT_DBusData> params;
params
<< TQT_DBusData::fromString( SYSTEMD_LOGIN1_SESSION_IFACE )
<< TQT_DBusData::fromString( "Seat" );
TQT_DBusMessage reply = sessionProperties.sendWithReply("Get", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
seat = reply[0].toVariant().value.toStruct()[1].toObjectPath();
}
} }
} else { if( !seat.isValid() ) {
reply = dbus_connection_send_with_reply_and_block(dbus_connection, message, -1, &error); kdWarning() << "Unable to associate systemd session with a seat" << endl;
return;
if (dbus_error_is_set(&error)) {
kdError() << "Could not send dbus message: " << error.message << endl;
dbus_message_unref(message);
dbus_error_free(&error);
goto out;
} }
int type = dbus_message_get_type(reply); // watch session changes
if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN) { systemdSeat = new TQT_DBusProxy(SYSTEMD_LOGIN1_SERVICE, seat, DBUS_INTERFACE_PROPERTIES, dBusConn);
if (!dbus_message_get_args(reply, &error, retval_type, retvalue, DBUS_TYPE_INVALID)){ TQObject::connect(systemdSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
if (dbus_error_is_set(&error)) { this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
kdError() << "Could not get argument from reply: "
<< error.message << endl; // inhibit systemd handling of power/sleep/hibernate/lid buttons
dbus_error_free(&error); // http://www.freedesktop.org/wiki/Software/systemd/inhibit
} if( !systemdInhibit.isValid() && managerIface.canSend() ) {
dbus_message_unref(reply); TQValueList<TQT_DBusData> params;
dbus_message_unref(message); params
goto out; << TQT_DBusData::fromString("handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch") // what
<< TQT_DBusData::fromString("TDEPowersave") // who
<< TQT_DBusData::fromString("TDE handles power events") // why
<< TQT_DBusData::fromString("block"); // mode
TQT_DBusMessage reply = managerIface.sendWithReply("Inhibit", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
systemdInhibit = reply[0].toUnixFd();
} }
} else {
kdError() << "Revieved invalid DBUS_MESSAGE_TYPE: " << type
<< "expected: " << DBUS_MESSAGE_TYPE_METHOD_RETURN << endl;
dbus_message_unref(reply);
dbus_message_unref(message);
goto out;
} }
return;
} }
if( service == CK_SERVICE ) {
// get current session
TQT_DBusProxy managerIface(CK_SERVICE, CK_MANAGER_OBJECT, CK_MANAGER_IFACE, dBusConn);
consolekitSession = TQT_DBusObjectPath();
if( managerIface.canSend() ) {
TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromUInt32( getpid() );
TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionForUnixProcess", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
consolekitSession = reply[0].toObjectPath();
}
}
if( !consolekitSession.isValid() ) {
kdWarning() << "The session is not registered with consolekit" << endl;
return;
}
ret = true; // if we are here, everything should be okay // get session seat
dbus_message_unref(message); TQT_DBusObjectPath seat;
dbus_connection_flush(dbus_connection); if( dBusConn.isConnected() ) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(CK_SERVICE, consolekitSession, CK_SESSION_IFACE, "GetSeatId");
out: TQT_DBusMessage reply = dBusConn.sendWithReply(msg);
kdDebugFuncOut(trace); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
return ret; seat = reply[0].toObjectPath();
} }
}
/* ----> D-Bus methode calls functions :: END <---- */ if( !seat.isValid() ) {
/* ---> PolicyKit method call section :: START <--- */ kdWarning() << "Unable to associate consolekit session with a seat" << endl;
return;
/*! }
* Check if the user is privileged to a special privilege
* \param privilege TQString with the name of the requested privilege
* \param udi TQString with the UDI.
* \param ressource TQString with the name of the ressource
* \param user TQString with the name of the user. If empty the current user is used.
* \return int with info if the user is allowed or not.
* \retval 0 if not allowed
* \retval 1 if allowed
* \retval -1 if a error occurs or we could not query the interface
*/
int dbusInterface::isUserPrivileged(TQString privilege, TQString udi, TQString ressource, TQString user) {
kdDebugFuncIn(trace);
const char *_unique_name; // watch session changes
const char *_user; consolekitSeat = new TQT_DBusProxy(CK_SERVICE, seat, CK_SEAT_IFACE, dBusConn);
const char *_privilege; TQObject::connect(consolekitSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
int retval = -1; return;
if (user.isEmpty() || user.isNull())
_user = getenv("USER");
else
_user = user.latin1();
if (_user == NULL || privilege.isEmpty())
goto out;
_unique_name = dbus_bus_get_unique_name(dbus_connection);
_privilege = privilege.latin1();
// not sure if we need this, but to avoid problems
dbus_bool_t _retval;
const char *_ressource;
_ressource = ressource.latin1();
if (!dbusSystemMethodCall( "org.freedesktop.PolicyKit",
"/org/freedesktop/PolicyKit/Manager",
"org.freedesktop.PolicyKit.Manager",
"IsUserPrivileged",
&_retval, DBUS_TYPE_BOOLEAN,
DBUS_TYPE_STRING, &_unique_name,
DBUS_TYPE_STRING, &_user,
DBUS_TYPE_STRING, &_privilege,
DBUS_TYPE_STRING, &_ressource,
DBUS_TYPE_INVALID)) {
retval = -1; // only to be sure we have no changes trough the call
} else {
retval = (int) _retval;
} }
out:
kdDebugFuncOut(trace);
return retval;
} }
/* ---> PolicyKit method call section :: END <--- */
/*! /*!
* Use this TQT_SLOT to emit a reviced messages to the tdepowersave. * This function handles dBus service unregistering
* NOTE: Because of the filter function this need to be a public function.
* Don't use this function in any other place than this class.
* \param type enum with the type of the message
* \param message String with the message
* \param string String with additional info
*/ */
void dbusInterface::emitMsgReceived( msg_type type, TQString message, TQString string ) { void dbusInterface::onServiceUnregistered(const TQString& service) {
if( service == SYSTEMD_LOGIN1_SERVICE ) {
if (message.startsWith("dbus.terminate")) systemdSession = TQT_DBusObjectPath();
dbus_is_connected = false; if( systemdSeat ) {
delete systemdSeat;
if (type == POLICY_POWER_OWNER_CHANGED) { }
if (message.startsWith("NOW_OWNER")) return;
acquiredPolicyPower = true; }
else if( service == CK_SERVICE ) {
acquiredPolicyPower = false; consolekitSession = TQT_DBusObjectPath();
if( consolekitSeat ) {
delete consolekitSeat;
}
return;
} }
emit msgReceived_withStringString( type, message, string );
} }
#include "dbusInterface.moc" /*!
// --> functions which are not member of the class ... * This functions is used to check if session is active
/*!
* This function is needed filter function for the D-Bus connection to filter
* all needed messages from the bus which are needful for TDEPowersave.
* \param connection existing connection to the D-Bus daemon
* \param message the recieved message from the D-Bus daemon
* \param data void pointer (see dbus bindings for more information)
* \return DBusHandlerResult
*/ */
DBusHandlerResult bool dbusInterface::checkActiveSession() {
filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/) { if( systemdSeat && systemdSeat->canSend() ) {
kdDebugFuncIn(trace); TQT_DBusObjectPath activeSession;
TQValueList<TQT_DBusData> params;
bool reply_wanted; params
char *value; << TQT_DBusData::fromString( SYSTEMD_LOGIN1_SEAT_IFACE )
TQString ifaceType; << TQT_DBusData::fromString( "ActiveSession" );
TQT_DBusMessage reply = systemdSeat->sendWithReply("Get", params);
DBusError error; if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
dbus_error_init( &error ); activeSession = reply[0].toVariant().value.toStruct()[1].toObjectPath();
return (activeSession == systemdSession);
if (dbus_message_is_signal (message,
DBUS_INTERFACE_LOCAL,
"Disconnected")){
((dbusInterface*) myInstance)->emitMsgReceived( DBUS_EVENT, "dbus.terminate", 0 );
dbus_connection_unref(connection);
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
if ( dbus_message_get_type( message ) != DBUS_MESSAGE_TYPE_SIGNAL ) {
if (trace) kdDebug() << "recieved message, but wasn't from type DBUS_MESSAGE_TYPE_SIGNAL" << endl;
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
ifaceType = dbus_message_get_interface( message );
if (ifaceType == NULL) {
kdDebug() << "Received message from invalid interface" << endl;
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
reply_wanted = !dbus_message_get_no_reply( message );
if (ifaceType.startsWith(DBUS_INTERFACE_DBUS)) {
if(trace) kdDebug() << "Received from DBUS_INTERFACE_DBUS" << endl;
/* get the name of the signal */
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 " << error.message << " but no string argument" << endl;
dbus_error_free( &error );
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_HANDLED;
} }
}
if (trace) kdDebug() << "filter_function::SIGNAL=" << signal << " VALUE=" << value << endl; if( consolekitSeat && consolekitSeat->canSend() ) {
TQT_DBusObjectPath activeSession;
/* our name is... */ TQValueList<TQT_DBusData> params;
if ( ! strcmp( signal, "NameAcquired" ) ) { TQT_DBusMessage reply = consolekitSeat->sendWithReply("GetActiveSession", params);
kdDebugFuncOut(trace); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
return DBUS_HANDLER_RESULT_HANDLED; activeSession = reply[0].toObjectPath();
} return (activeSession == consolekitSession);
else if ( ! strcmp( signal, "NameOwnerChanged" )) {
char *service;
char *old_owner;
char *new_owner;
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.Policy.Power")) {
const char *own_name;
own_name = dbus_bus_get_unique_name(((dbusInterface*) myInstance)->get_DBUS_connection());
if (!strcmp(new_owner, own_name)) {
kdDebug() << "=== now owner of org.freedesktop.Policy.Power ===" << endl;
// we have now again the ower of the name!
((dbusInterface*) myInstance)->emitMsgReceived( POLICY_POWER_OWNER_CHANGED,
"NOW_OWNER",
NULL );
} else {
// some other has now the interface
kdDebug() << "=== someone owner of org.freedesktop.Policy.Power ===" << endl;
((dbusInterface*) myInstance)->emitMsgReceived( POLICY_POWER_OWNER_CHANGED,
"OTHER_OWNER",
NULL );
}
}
}
}
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_HANDLED;
} else if (ifaceType.startsWith("org.freedesktop.ConsoleKit.Session")) {
kdDebug() << "Received from org.freedesktop.ConsoleKit.Session" << endl;
const char *session = dbus_message_get_path (message);
const char *signal = dbus_message_get_member( message );
if (! strcmp(signal, "ActiveChanged")) {
dbus_bool_t active;
if (dbus_message_get_args( message, &error, DBUS_TYPE_BOOLEAN, &active, DBUS_TYPE_INVALID )) {
((dbusInterface*) myInstance)->emitMsgReceived( CONSOLEKIT_SESSION_ACTIVE,
session, TQString("%1").arg((int)active));
} else {
if (dbus_error_is_set( &error )) dbus_error_free( &error );
}
} else {
kdDebug() << "Received unknown signal from org.freedesktop.ConsoleKit.Session: "
<< signal << endl;
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} }
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_HANDLED;
} else {
kdDebugFuncOut(trace);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} }
return false;
} }
// --> some functions to get private members #include "dbusInterface.moc"
//! to get the current connection to D-Bus
DBusConnection * dbusInterface::get_DBUS_connection() {
return dbus_connection;
}

@ -23,13 +23,13 @@
*/ */
/*! /*!
* \class dbusInterface * \class dbusInterface
* \brief class for connection to HAL via D-Bus * \brief class for connection to D-Bus
* \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de> * \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
* \date 2006-2007 * \date 2006-2007
*/ */
#ifndef _DBUSHAL_H_ #ifndef _DBUS_INTERFACE_H_
#define _DBUSHAL_H_ #define _DBUS_INTERFACE_H_
#ifndef DBUS_API_SUBJECT_TO_CHANGE #ifndef DBUS_API_SUBJECT_TO_CHANGE
#define DBUS_API_SUBJECT_TO_CHANGE #define DBUS_API_SUBJECT_TO_CHANGE
@ -41,12 +41,14 @@
#endif #endif
// QT - Header // QT - Header
#include <tqobject.h>
#include <tqstring.h> #include <tqstring.h>
// D-Bus Header // D-Bus Header
#include <dbus/dbus.h> // needed for dbus_bool_t #include <tqdbusconnection.h>
#include <dbus/message.h> #include <tqdbusobjectpath.h>
#include <dbus/connection.h> #include <tqdbusproxy.h>
#include <tqdbusunixfd.h>
// tdepowersave - Header // tdepowersave - Header
#include "tdepowersave_debug.h" #include "tdepowersave_debug.h"
@ -55,16 +57,13 @@
#define CK_MANAGER_IFACE "org.freedesktop.ConsoleKit.Manager" #define CK_MANAGER_IFACE "org.freedesktop.ConsoleKit.Manager"
#define CK_MANAGER_OBJECT "/org/freedesktop/ConsoleKit/Manager" #define CK_MANAGER_OBJECT "/org/freedesktop/ConsoleKit/Manager"
#define CK_SESSION_IFACE "org.freedesktop.ConsoleKit.Session" #define CK_SESSION_IFACE "org.freedesktop.ConsoleKit.Session"
#define CK_SEAT_IFACE "org.freedesktop.ConsoleKit.Seat"
enum msg_type { #define SYSTEMD_LOGIN1_SERVICE "org.freedesktop.login1"
ACPI_EVENT, #define SYSTEMD_LOGIN1_PATH "/org/freedesktop/login1"
DBUS_EVENT, #define SYSTEMD_LOGIN1_MANAGER_IFACE "org.freedesktop.login1.Manager"
HAL_DEVICE, #define SYSTEMD_LOGIN1_SESSION_IFACE "org.freedesktop.login1.Session"
HAL_PROPERTY_CHANGED, #define SYSTEMD_LOGIN1_SEAT_IFACE "org.freedesktop.login1.Seat"
HAL_CONDITION,
CONSOLEKIT_SESSION_ACTIVE,
POLICY_POWER_OWNER_CHANGED
};
class dbusInterface : public TQObject{ class dbusInterface : public TQObject{
Q_OBJECT Q_OBJECT
@ -72,35 +71,32 @@ class dbusInterface : public TQObject{
private: private:
//! QT connection to D-Bus //! TQt connection to D-Bus
DBusQt::Connection* m_dBusQtConnection; TQT_DBusConnection dBusConn;
//! real connection to D-Bus
DBusConnection *dbus_connection; //! TQt D-Bus proxy for watching signals
TQT_DBusProxy* dBusWatch;
//! to store information if TDEPowersave is connected to D-Bus TQT_DBusProxy* dBusLocal;
/*!
* This boolean represent information about the state of the connection to D-Bus TQT_DBusObjectPath systemdSession;
* \li true: if connected TQT_DBusProxy* systemdSeat;
* \li false: if disconnected TQT_DBusUnixFd systemdInhibit;
*/
bool dbus_is_connected; TQT_DBusObjectPath consolekitSession;
TQT_DBusProxy* consolekitSeat;
//! if we could claim the org.freedesktop.Policy.Power interface
/*!
* This boolean represent information if TDEPowersave could claim the
* org.freedesktop.Policy.Power interface from the D-Bus
* \li true: if acquired
* \li false: if not
*/
bool acquiredPolicyPower;
/* D-Bus helper functions */ /* D-Bus helper functions */
//! to initialise the connection to D-Bus //! to initialise the connection to D-Bus
bool initDBUS(); bool initDBUS();
//! to call a methode on a dbus interface with reply
bool dbusMethodCall( TQString interface, TQString path, TQString object, TQString method, //! handles signal service registred/unregistered
DBusBusType dbus_type, void *retvalue, int retval_type, void onServiceRegistered(const TQString&);
int first_arg_type, va_list var_args); void onServiceUnregistered(const TQString&);
private slots:
//! to reconnect to D-Bus
bool reconnect();
public: public:
@ -109,52 +105,24 @@ public:
//! default destructor //! default destructor
~dbusInterface(); ~dbusInterface();
//! to reconnect to D-Bus and HAL //! to close the connection to D-Bus
bool reconnect();
//! to close the connection to D-Bus and HAL
bool close(); bool close();
//! to acquire the org.freedesktop.Policy.Power interface
bool acquirePolicyPowerIface();
//! to release the org.freedesktop.Policy.Power interface
bool releasePolicyPowerIface();
//! to check if the org.freedesktop.Policy.Power interface has an owner
bool isPolicyPowerIfaceOwned();
// --- helper to get private members of the class --- // // --- helper to get private members of the class --- //
//! to get information if TDEPowersave is connected to D-Bus //! to get information if TDEPowersave is connected to D-Bus
bool isConnectedToDBUS(); bool isConnectedToDBUS();
//! to get info about claim org.freedesktop.Policy.Power interface
bool acquiredPolicyPowerInterface();
//! return the current DBus connection //! to check active session state
DBusConnection *get_DBUS_connection(); bool checkActiveSession();
/* D-Bus helper functions */ public slots:
/* functions to call methodes */ void handleDBusSignal(const TQT_DBusMessage&);
//! to call a methode on a dbus system bus method without reply
bool dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
int first_arg_type, ... );
//! to call a methode on a dbus system bus method with reply
bool dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
void *retvalue, int retval_type, int first_arg_type, ... );
/* PolicyKit call helper */ signals:
//! check if the user has a requested privilege
int isUserPrivileged( TQString privilege, TQString udi, TQString ressource = "", TQString user = TQString());
//! wrapper to emit a signal with a event from HAL void activeSessionChanged(bool);
void emitMsgReceived( msg_type type, TQString message, TQString string );
signals:
//! signal with message to forward from D-Bus to HAL
void msgReceived_withStringString( msg_type, TQString, TQString );
//! signal if we resumed!
void backFromSuspend( int result );
}; };
//! filter function to filter out needed information from D-Bus messages
DBusHandlerResult filterFunction (DBusConnection *connection, DBusMessage *message, void *data);
#endif #endif

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

@ -76,12 +76,6 @@ enum device_type {
UNKNOWN_DEVICE UNKNOWN_DEVICE
}; };
enum ERROR_MSG {
DBUS_NO_RIGHTS,
DBUS_NOT_RUNNING,
DBUS_RUNNING
};
//! hold information if suspend/standby/pm actions are supported and allowed //! hold information if suspend/standby/pm actions are supported and allowed
/*! /*!
* This dictionary contains information about the available pm capabilities and * This dictionary contains information about the available pm capabilities and
@ -138,7 +132,7 @@ private:
TDEHardwareDevices *m_hwdevices; TDEHardwareDevices *m_hwdevices;
//! pointer to the dbusInterface connection class //! pointer to the dbusInterface connection class
dbusInterface *dbus_HAL; dbusInterface *dbus_iface;
//! hold udis of special hardware execpt batteries represented by a TQString pairs (name,udi) //! hold udis of special hardware execpt batteries represented by a TQString pairs (name,udi)
/*! /*!
@ -225,14 +219,6 @@ private:
* \li false: else * \li false: else
*/ */
bool cpuFreq; bool cpuFreq;
//! if the machine support change *SchedPowerSavings methodes via TDE hardware library
/*!
* This boolean represent information if the machine support change the
* SchedPowerSavings methodes via TDE hardware library.
* \li true: if supported
* \li false: else
*/
bool schedPowerSavings;
//! if the machine support change brightness //! if the machine support change brightness
/*! /*!
* This boolean represent information if the machine support brightness changes. * This boolean represent information if the machine support brightness changes.
@ -315,24 +301,18 @@ private:
bool intialiseHWInfo(); bool intialiseHWInfo();
//! reinit all hardware information //! reinit all hardware information
bool reinitHardwareInfos(); bool reinitHardwareInfos();
//! to check the current ConsoleKit session
bool checkConsoleKitSession();
//! to check if we should handle a device //! to check if we should handle a device
bool checkIfHandleDevice ( TQString _udi, int *type ); bool checkIfHandleDevice ( TQString _udi, int *type );
//! to set the CPUFreq governor //! to set the CPUFreq governor
bool setCPUFreqGovernor( const char *governor ); bool setCPUFreqGovernor( const char *governor );
//! to get the state of SchedPowerSave setting of kernel/TDE hardware library
bool getSchedPowerSavings();
//! to set the state of SchedPowerSave setting of kernel/TDE hardware library
bool setSchedPowerSavings( bool enable );
//! find and update a battery information //! find and update a battery information
void updateBatteryValues (TDEGenericDevice* device); void updateBatteryValues (TDEGenericDevice* device);
private slots: private slots:
//! to fetch events from D-Bus and handle them //! handle changes of the session state
void processMessage (msg_type type, TQString message, TQString value); void handleSessionState (bool state);
//! to fetch events from the TDE hardware library and handle them //! to fetch events from the TDE hardware library and handle them
void processHardwareChangedEvent (TDEGenericDevice*); void processHardwareChangedEvent (TDEGenericDevice*);
//! to fetch keypresses from the TDE hardware library and handle them //! to fetch keypresses from the TDE hardware library and handle them
@ -392,10 +372,6 @@ signals:
void batteryWARNState(int type, int state); void batteryWARNState(int type, int state);
// Error signals // Error signals
//! signal if the HAL daemon terminate and restart
void halRunning( bool );
//! signal if the D-Bus daemon terminate and restart
void dbusRunning( int );
//! signal if the IsActive state of //! signal if the IsActive state of
void desktopSessionIsActive (bool); void desktopSessionIsActive (bool);
@ -428,15 +404,6 @@ public:
*/ */
bool update_info_primBattery_changed; bool update_info_primBattery_changed;
//! boolean which tell us if the D-Bus daemon was terminated
/*!
* This boolean contains information if the D-Bus daemon terminated and
* we recieved "dbus.terminate"
* \li true: If D-Bus terminated
* \li false: If D-Bus not terminated
*/
bool dbus_terminated;
// --> functions // --> functions
//! default constructor //! default constructor
HardwareInfo(); HardwareInfo();
@ -463,9 +430,6 @@ public:
//! if the user is allowed to change CPU Freq PolicyKit //! if the user is allowed to change CPU Freq PolicyKit
int isCpuFreqAllowed (); int isCpuFreqAllowed ();
//! if org.freedesktop.Policy.Power has a owner
bool isPolicyPowerIfaceOwned();
//! get state of the AC adapter //! get state of the AC adapter
bool getAcAdapter() const; bool getAcAdapter() const;
//! get the state of the lid button //! get the state of the lid button
@ -498,8 +462,6 @@ public:
bool setBrightnessUp(int percentageStep = -1); bool setBrightnessUp(int percentageStep = -1);
//! set the CPU frequency policy/speed //! set the CPU frequency policy/speed
bool setCPUFreq ( cpufreq_type cpufreq, int limit = 51 ); bool setCPUFreq ( cpufreq_type cpufreq, int limit = 51 );
//! call SetPowerSave method on TDE hardware library.
bool setPowerSave( bool on );
//! function to set warning states for the primary battery collection //! function to set warning states for the primary battery collection
void setPrimaryBatteriesWarningLevel (int _warn = -1, int _low = -1, int _crit = -1 ); void setPrimaryBatteriesWarningLevel (int _warn = -1, int _low = -1, int _crit = -1 );

@ -279,35 +279,6 @@ bool Battery::checkBatteryType () {
// For now just report any batteries as primary... // For now just report any batteries as primary...
type = BAT_PRIMARY; type = BAT_PRIMARY;
return true; return true;
#if 0
if (dbus_HAL->halGetPropertyString(udi,"battery.type", &tmp_qstring)) {
if (tmp_qstring.compare("primary") == 0) {
type = BAT_PRIMARY;
} else if (tmp_qstring.compare("mouse") == 0) {
type = BAT_MOUSE;
} else if (tmp_qstring.compare("keyboard") == 0) {
type = BAT_KEYBOARD;
} else if (tmp_qstring.compare("keyboard_mouse") == 0) {
type = BAT_KEY_MOUSE;
} else if (tmp_qstring.compare("camera") == 0) {
type = BAT_CAMERA;
} else if (tmp_qstring.compare("ups") == 0) {
type = BAT_UPS;
} else {
//anything else will currently be "UNKNOWN"
type = BAT_UNKNOWN;
}
kdDebugFuncOut(trace);
return true;
} else {
//query was not successfull
kdWarning() << "Query of battery.type of " << udi << " was not successfull." << endl;
type = BAT_UNKNOWN;
kdDebugFuncOut(trace);
return false;
}
#endif
} }
//! to check battery.technology //! to check battery.technology

@ -45,7 +45,7 @@
// TDE hardware library // TDE hardware library
#include <tdehardwaredevices.h> #include <tdehardwaredevices.h>
#include "dbusInterface.h" #include "tdepowersave_debug.h"
class Battery : public TQObject { class Battery : public TQObject {

@ -1,46 +0,0 @@
/***************************************************************************
* Copyright (C) 2007 by Danny Kukawka *
* <dkukawka@suse.de, danny.kukawka@web.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License *
* as published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
/*!
* \file privileges.h
* \brief Headerfile containing defines for privileges
* \author Danny Kukawka, <dkukawka@suse.de, danny.kukawka@web.de>
* \date 2007
*/
#ifndef _PRIVILEGES_H_
#define _PRIVILEGES_H_
#ifdef HAVE_HAL_0_5_10
#define PRIV_SUSPEND "org.freedesktop.hal.power-management.suspend"
#define PRIV_HIBERNATE "org.freedesktop.hal.power-management.hibernate"
#define PRIV_STANDBY "org.freedesktop.hal.power-management.standby"
#define PRIV_CPUFREQ "org.freedesktop.hal.power-management.cpufreq"
#define PRIV_LAPTOP_PANEL "org.freedesktop.hal.power-management.lcd-panel"
#define PRIV_SETPOWERSAVE "org.freedesktop.hal.power-management.set-powersave"
#else
#define PRIV_SUSPEND "hal-power-suspend"
#define PRIV_HIBERNATE "hal-power-hibernate"
#define PRIV_STANDBY "hal-power-standby"
#define PRIV_CPUFREQ "hal-power-cpufreq"
#define PRIV_LAPTOP_PANEL "hal-power-lcd-panel"
#define PRIV_SETPOWERSAVE "hal-power-set-powersave"
#endif
#endif

@ -61,7 +61,6 @@ Settings::~Settings()
bool Settings::load_scheme_settings(TQString schemeName){ bool Settings::load_scheme_settings(TQString schemeName){
tdeconfig->reparseConfiguration(); tdeconfig->reparseConfiguration();
bool setToDefault = false;
if( schemeName == "Performance" || schemeName == i18n("Performance")) if( schemeName == "Performance" || schemeName == i18n("Performance"))
schemeName = "Performance"; schemeName = "Performance";
@ -78,7 +77,6 @@ bool Settings::load_scheme_settings(TQString schemeName){
// fallback to 'default-scheme' // fallback to 'default-scheme'
tdeconfig->setGroup("default-scheme"); tdeconfig->setGroup("default-scheme");
schemeName = "default-scheme"; schemeName = "default-scheme";
setToDefault = true;
} }
currentScheme = schemeName; currentScheme = schemeName;
@ -250,7 +248,6 @@ bool Settings::load_general_settings(){
psMsgAsPassivePopup = tdeconfig->readBoolEntry("psMsgAsPassivePopup",false); psMsgAsPassivePopup = tdeconfig->readBoolEntry("psMsgAsPassivePopup",false);
forceDpmsOffOnLidClose = tdeconfig->readBoolEntry("forceDpmsOffOnLidClose",false); forceDpmsOffOnLidClose = tdeconfig->readBoolEntry("forceDpmsOffOnLidClose",false);
unmountExternalOnSuspend = tdeconfig->readBoolEntry("unmountExternalOnSuspend",true); unmountExternalOnSuspend = tdeconfig->readBoolEntry("unmountExternalOnSuspend",true);
callSetPowerSaveOnAC = tdeconfig->readBoolEntry("callSetPowerSaveOnAC",true);
lockmethod = tdeconfig->readEntry("lockMethod", "NULL"); lockmethod = tdeconfig->readEntry("lockMethod", "NULL");
if(lockmethod == "NULL") lockmethod = "automatic"; if(lockmethod == "NULL") lockmethod = "automatic";

@ -200,14 +200,6 @@ public:
* \li false: if not * \li false: if not
*/ */
bool forceDpmsOffOnLidClose; bool forceDpmsOffOnLidClose;
//! if tdepowersave should call SetPowerSave() on HAL
/*!
* This boolean tells if tdepowersave should call SetPowerSave on HAL depending
* on the AC state.
* \li true: if should call
* \li false: if not
*/
bool callSetPowerSaveOnAC;
//! time after resume to fake keyevent //! time after resume to fake keyevent
/*! /*!

@ -1790,14 +1790,6 @@ void tdepowersave::setSchemeSettings(){
} }
} }
// call setPowerSave() depending on AC state
if (settings->callSetPowerSaveOnAC) {
if (hwinfo->getAcAdapter())
hwinfo->setPowerSave(false);
else
hwinfo->setPowerSave(true);
}
// --> set autosuspend settings // --> set autosuspend settings
if(settings->autoSuspend) { if(settings->autoSuspend) {
setAutoSuspend(false); setAutoSuspend(false);
@ -2176,10 +2168,12 @@ void tdepowersave::handleActionCall ( action action, int value , bool checkAC, b
break; break;
} }
} else if (batWarnCall) { } else if (batWarnCall) {
if (!hwinfo->isPolicyPowerIfaceOwned()) { // FIXME
// Is there a way to check if is active power manager on currently active session?
if (true) {
switch (action) { switch (action) {
case GO_SHUTDOWN: case GO_SHUTDOWN:
// to be shure if we really need the shutdown // to be sure if we really need the shutdown
if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) { if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) {
DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" ); DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" );
shutdown.send("logout", 0, 2, 2); shutdown.send("logout", 0, 2, 2);
@ -2509,7 +2503,7 @@ TQString tdepowersave::currentScheme (){
if(hwinfo->isOnline()) { if(hwinfo->isOnline()) {
return settings->currentScheme; return settings->currentScheme;
} else { } else {
return "ERROR: D-Bus and/or HAL not running"; return "ERROR: D-Bus not running";
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
@ -2540,7 +2534,7 @@ TQString tdepowersave::currentCPUFreqPolicy() {
} }
return _cpuFreq; return _cpuFreq;
} else { } else {
return "ERROR: HAL or/and DBus not running"; return "ERROR: DBus not running";
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
@ -2630,7 +2624,7 @@ TQStringList tdepowersave::allowed_sleepingStates(){
} }
} }
else { else {
sleepList.append("ERROR: D-Bus and/or HAL not running"); sleepList.append("ERROR: D-Bus not running");
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
@ -2651,7 +2645,7 @@ TQStringList tdepowersave::listSchemes(){
} }
} }
else { else {
_schemeList.append("ERROR: D-Bus and/or HAL not running"); _schemeList.append("ERROR: D-Bus not running");
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);

Loading…
Cancel
Save