|
|
|
@ -19,38 +19,52 @@
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \file dbusInterface.cpp
|
|
|
|
|
* \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
|
|
|
|
|
* provide wrapper to HAL lib and functions
|
|
|
|
|
* \brief In this file can be found the functionality to connect to
|
|
|
|
|
* the D-Bus, to handle D-Bus session management
|
|
|
|
|
* \author Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
|
|
|
|
|
* \date 2006-2007
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// KDE Header
|
|
|
|
|
// QT - Header
|
|
|
|
|
#include <tqtimer.h>
|
|
|
|
|
|
|
|
|
|
// KDE Header
|
|
|
|
|
#include <tdelocale.h>
|
|
|
|
|
|
|
|
|
|
// DBUS - Header
|
|
|
|
|
#include "dbus/dbus-shared.h"
|
|
|
|
|
#include "dbusInterface.h"
|
|
|
|
|
#include <tqdbusdatalist.h>
|
|
|
|
|
#include <tqdbusdatamap.h>
|
|
|
|
|
#include <tqdbuserror.h>
|
|
|
|
|
#include <tqdbusmessage.h>
|
|
|
|
|
#include <tqdbusvariant.h>
|
|
|
|
|
|
|
|
|
|
// system headers
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#define DBUS_CONN_NAME "TDEPowersave"
|
|
|
|
|
|
|
|
|
|
static void* myInstance = 0;
|
|
|
|
|
|
|
|
|
|
/*! 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);
|
|
|
|
|
|
|
|
|
|
dbus_is_connected = false;
|
|
|
|
|
acquiredPolicyPower = false;
|
|
|
|
|
|
|
|
|
|
// add pointer to this for filter_function()
|
|
|
|
|
myInstance=this;
|
|
|
|
|
|
|
|
|
|
// init connection to dbus
|
|
|
|
|
if(!initDBUS()) {
|
|
|
|
|
kdError() << "Can't connect to D-Bus" << endl;
|
|
|
|
|
m_dBusQtConnection = NULL;
|
|
|
|
|
}
|
|
|
|
|
initDBUS();
|
|
|
|
|
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
}
|
|
|
|
@ -72,30 +86,19 @@ dbusInterface::~dbusInterface(){
|
|
|
|
|
* \retval false if disconnected
|
|
|
|
|
*/
|
|
|
|
|
bool dbusInterface::isConnectedToDBUS() {
|
|
|
|
|
return dbus_is_connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* 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;
|
|
|
|
|
return dBusConn.isConnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* 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
|
|
|
|
|
* \retval true if successful reconnected to D-Bus and HAL
|
|
|
|
|
* \retval true if successful reconnected to D-Bus
|
|
|
|
|
* \retval false if unsuccessful
|
|
|
|
|
*/
|
|
|
|
|
bool dbusInterface::reconnect() {
|
|
|
|
|
// close D-Bus connection
|
|
|
|
|
close();
|
|
|
|
|
// init D-Bus conntection and HAL context
|
|
|
|
|
// init D-Bus conntection
|
|
|
|
|
return (initDBUS());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -106,18 +109,24 @@ bool dbusInterface::reconnect() {
|
|
|
|
|
* \retval false if any problems
|
|
|
|
|
*/
|
|
|
|
|
bool dbusInterface::close() {
|
|
|
|
|
if ( m_dBusQtConnection != NULL ) {
|
|
|
|
|
releasePolicyPowerIface();
|
|
|
|
|
m_dBusQtConnection->close();
|
|
|
|
|
m_dBusQtConnection = NULL;
|
|
|
|
|
if( dBusConn.isConnected() ) {
|
|
|
|
|
if( dBusWatch ) {
|
|
|
|
|
delete dBusWatch;
|
|
|
|
|
}
|
|
|
|
|
if( dBusLocal ) {
|
|
|
|
|
delete dBusLocal;
|
|
|
|
|
}
|
|
|
|
|
if( systemdSeat ) {
|
|
|
|
|
delete systemdSeat;
|
|
|
|
|
}
|
|
|
|
|
if( consolekitSeat ) {
|
|
|
|
|
delete consolekitSeat;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dbus_is_connected = false;
|
|
|
|
|
|
|
|
|
|
dBusConn.closeConnection(DBUS_CONN_NAME);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----> D-Bus section :: START <---- */
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function initialise the connection to the D-Bus daemon.
|
|
|
|
|
* \return boolean with the result of the operation
|
|
|
|
@ -127,528 +136,260 @@ bool dbusInterface::close() {
|
|
|
|
|
bool dbusInterface::initDBUS(){
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
dbus_is_connected = false;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
dbus_connection = dbus_bus_get( DBUS_BUS_SYSTEM, &error );
|
|
|
|
|
dBusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus, DBUS_CONN_NAME);
|
|
|
|
|
|
|
|
|
|
if (dbus_connection == NULL){
|
|
|
|
|
kdError() << "Failed to open connection to system message bus: " << error.message << endl;
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
if( !dBusConn.isConnected() ) {
|
|
|
|
|
kdError() << "Failed to open connection to system message bus: " << dBusConn.lastError().message() << endl;
|
|
|
|
|
TQTimer::singleShot(4000, this, TQT_SLOT(reconnect()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( dbus_error_is_set( &error ) ) {
|
|
|
|
|
kdError() << "Failed to register connection with system message bus: " << error.message << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
acquirePolicyPowerIface();
|
|
|
|
|
|
|
|
|
|
dbus_connection_set_exit_on_disconnect( dbus_connection, false );
|
|
|
|
|
|
|
|
|
|
/* add the filter function which should be executed on events on the bus */
|
|
|
|
|
if ( ! dbus_connection_add_filter( dbus_connection, filterFunction, this, NULL) ) {
|
|
|
|
|
kdFatal() << "Error: Not enough memory to add filter to dbus connection" << endl;
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add a match rule to catch all signals going through the bus with D-Bus interface */
|
|
|
|
|
dbus_bus_add_match( dbus_connection, "type='signal',"
|
|
|
|
|
"interface='org.freedesktop.DBus',"
|
|
|
|
|
"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;
|
|
|
|
|
// watcher for NameOwnerChanged signals
|
|
|
|
|
dBusWatch = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
|
|
|
|
|
TQObject::connect(dBusWatch, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
|
|
|
|
|
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
|
|
|
|
|
|
|
|
|
|
// watcher for Disconnect signal
|
|
|
|
|
dBusLocal = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_LOCAL, DBUS_INTERFACE_LOCAL, dBusConn);
|
|
|
|
|
TQObject::connect(dBusLocal, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
|
|
|
|
|
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
|
|
|
|
|
|
|
|
|
|
// find already running SystemD
|
|
|
|
|
TQT_DBusProxy checkSystemD(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
|
|
|
|
|
if( checkSystemD.canSend() ) {
|
|
|
|
|
TQValueList<TQT_DBusData> params;
|
|
|
|
|
params << TQT_DBusData::fromString(SYSTEMD_LOGIN1_SERVICE);
|
|
|
|
|
TQT_DBusMessage reply = checkSystemD.sendWithReply("NameHasOwner", params);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
|
|
|
|
|
onServiceRegistered(SYSTEMD_LOGIN1_SERVICE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DBusError err;
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
int ret = dbus_bus_request_name(dbus_connection, "org.freedesktop.Policy.Power",
|
|
|
|
|
DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
|
|
|
|
|
if (dbus_error_is_set(&err)) {
|
|
|
|
|
kdWarning() << "Acquire org.freedesktop.Policy.Power interface failed with error: " << err.message << endl;
|
|
|
|
|
dbus_error_free(&err);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
// find already running ConsoleKit
|
|
|
|
|
TQT_DBusProxy checkConsoleKit(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
|
|
|
|
|
if( checkConsoleKit.canSend() ) {
|
|
|
|
|
TQValueList<TQT_DBusData> params;
|
|
|
|
|
params << TQT_DBusData::fromString(CK_SERVICE);
|
|
|
|
|
TQT_DBusMessage reply = checkConsoleKit.sendWithReply("NameHasOwner", params);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
|
|
|
|
|
onServiceRegistered(CK_SERVICE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return acquiredPolicyPower;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function release 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
|
|
|
|
|
* This function handles signals from the D-Bus daemon.
|
|
|
|
|
*/
|
|
|
|
|
bool dbusInterface::releasePolicyPowerIface(){
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
int result;
|
|
|
|
|
bool retval = false;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
if (dbus_connection == NULL) {
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return false;
|
|
|
|
|
void dbusInterface::handleDBusSignal(const TQT_DBusMessage& msg) {
|
|
|
|
|
// dbus terminated
|
|
|
|
|
if( msg.path() == DBUS_PATH_LOCAL
|
|
|
|
|
&& msg.interface() == DBUS_INTERFACE_LOCAL
|
|
|
|
|
&& msg.member() == "Disconnected" ) {
|
|
|
|
|
close();
|
|
|
|
|
TQTimer::singleShot(1000, this, TQT_SLOT(reconnect()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
result = dbus_bus_release_name(dbus_connection, "org.freedesktop.Policy.Power", &error);
|
|
|
|
|
|
|
|
|
|
if ( dbus_error_is_set( &error ) ) {
|
|
|
|
|
kdError() << "Failed to release org.freedesktop.Policy.Power: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
} 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;
|
|
|
|
|
// service registered / unregistered
|
|
|
|
|
if( msg.path() == DBUS_PATH_DBUS
|
|
|
|
|
&& msg.interface() == DBUS_INTERFACE_DBUS
|
|
|
|
|
&& msg.member() == "NameOwnerChanged" ) {
|
|
|
|
|
if( msg[1].toString().isEmpty() ) {
|
|
|
|
|
// old-owner is empty
|
|
|
|
|
onServiceRegistered(msg[0].toString());
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
if (dbus_connection == NULL) {
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return false;
|
|
|
|
|
// systemd session changed
|
|
|
|
|
if( systemdSeat && systemdSeat->canSend()
|
|
|
|
|
&& msg.path() == systemdSeat->path()
|
|
|
|
|
&& msg.interface() == DBUS_INTERFACE_PROPERTIES
|
|
|
|
|
&& msg.member() == "PropertiesChanged"
|
|
|
|
|
&& 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);
|
|
|
|
|
|
|
|
|
|
retval = dbus_bus_name_has_owner(dbus_connection, "org.freedesktop.Policy.Power", &error);
|
|
|
|
|
|
|
|
|
|
if ( dbus_error_is_set( &error ) ) {
|
|
|
|
|
kdError() << "Failed to check if org.freedesktop.Policy.Power has an owner: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
// consolekit session changed
|
|
|
|
|
if( consolekitSeat && consolekitSeat->canSend()
|
|
|
|
|
&& msg.path() == consolekitSeat->path()
|
|
|
|
|
&& msg.interface() == CK_SEAT_IFACE
|
|
|
|
|
&& msg.member() == "ActiveSessionChanged") {
|
|
|
|
|
emit activeSessionChanged(msg[0].toString() == TQString(consolekitSession));
|
|
|
|
|
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 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
|
|
|
|
|
/*!
|
|
|
|
|
* This function handles dBus service registering
|
|
|
|
|
*/
|
|
|
|
|
bool dbusInterface::dbusMethodCall( TQString interface, TQString path, TQString object, TQString method,
|
|
|
|
|
DBusBusType dbus_type, void *retvalue, int retval_type, int first_arg_type,
|
|
|
|
|
va_list var_args ) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusError error;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
dbus_connection = dbus_bus_get(dbus_type, &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( interface.ascii(), path.ascii(), object.ascii(), method.ascii() );
|
|
|
|
|
dbus_message_append_args_valist(message, first_arg_type, var_args);
|
|
|
|
|
void dbusInterface::onServiceRegistered(const TQString& service) {
|
|
|
|
|
if( service == SYSTEMD_LOGIN1_SERVICE ) {
|
|
|
|
|
// get current session
|
|
|
|
|
TQT_DBusProxy managerIface(SYSTEMD_LOGIN1_SERVICE, SYSTEMD_LOGIN1_PATH, SYSTEMD_LOGIN1_MANAGER_IFACE, dBusConn);
|
|
|
|
|
systemdSession = TQT_DBusObjectPath();
|
|
|
|
|
if( managerIface.canSend() ) {
|
|
|
|
|
TQValueList<TQT_DBusData> params;
|
|
|
|
|
params << TQT_DBusData::fromUInt32( getpid() );
|
|
|
|
|
TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionByPID", params);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
|
|
|
|
|
systemdSession = reply[0].toObjectPath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( !systemdSession.isValid() ) {
|
|
|
|
|
kdWarning() << "The session is not registered with systemd" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (retvalue == NULL) {
|
|
|
|
|
if (!dbus_connection_send(dbus_connection, message, NULL)) {
|
|
|
|
|
kdError() << "Could not send method call." << endl;
|
|
|
|
|
dbus_message_unref( message );
|
|
|
|
|
goto out;
|
|
|
|
|
// get session seat
|
|
|
|
|
TQT_DBusProxy sessionProperties(SYSTEMD_LOGIN1_SERVICE, systemdSession, DBUS_INTERFACE_PROPERTIES, dBusConn);
|
|
|
|
|
TQT_DBusObjectPath seat;
|
|
|
|
|
if( sessionProperties.canSend() ) {
|
|
|
|
|
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 {
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block(dbus_connection, message, -1, &error);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
if( !seat.isValid() ) {
|
|
|
|
|
kdWarning() << "Unable to associate systemd session with a seat" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int type = dbus_message_get_type(reply);
|
|
|
|
|
if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
|
|
|
|
|
if (!dbus_message_get_args(reply, &error, retval_type, retvalue, DBUS_TYPE_INVALID)){
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Could not get argument from reply: "
|
|
|
|
|
<< error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
}
|
|
|
|
|
dbus_message_unref(reply);
|
|
|
|
|
dbus_message_unref(message);
|
|
|
|
|
goto out;
|
|
|
|
|
// watch session changes
|
|
|
|
|
systemdSeat = new TQT_DBusProxy(SYSTEMD_LOGIN1_SERVICE, seat, DBUS_INTERFACE_PROPERTIES, dBusConn);
|
|
|
|
|
TQObject::connect(systemdSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
|
|
|
|
|
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
|
|
|
|
|
|
|
|
|
|
// inhibit systemd handling of power/sleep/hibernate/lid buttons
|
|
|
|
|
// http://www.freedesktop.org/wiki/Software/systemd/inhibit
|
|
|
|
|
if( !systemdInhibit.isValid() && managerIface.canSend() ) {
|
|
|
|
|
TQValueList<TQT_DBusData> params;
|
|
|
|
|
params
|
|
|
|
|
<< 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
|
|
|
|
|
dbus_message_unref(message);
|
|
|
|
|
dbus_connection_flush(dbus_connection);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----> D-Bus methode calls functions :: END <---- */
|
|
|
|
|
/* ---> PolicyKit method call section :: START <--- */
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* 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);
|
|
|
|
|
// get session seat
|
|
|
|
|
TQT_DBusObjectPath seat;
|
|
|
|
|
if( dBusConn.isConnected() ) {
|
|
|
|
|
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(CK_SERVICE, consolekitSession, CK_SESSION_IFACE, "GetSeatId");
|
|
|
|
|
TQT_DBusMessage reply = dBusConn.sendWithReply(msg);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
|
|
|
|
|
seat = reply[0].toObjectPath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( !seat.isValid() ) {
|
|
|
|
|
kdWarning() << "Unable to associate consolekit session with a seat" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *_unique_name;
|
|
|
|
|
const char *_user;
|
|
|
|
|
const char *_privilege;
|
|
|
|
|
|
|
|
|
|
int retval = -1;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
// watch session changes
|
|
|
|
|
consolekitSeat = new TQT_DBusProxy(CK_SERVICE, seat, CK_SEAT_IFACE, dBusConn);
|
|
|
|
|
TQObject::connect(consolekitSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
|
|
|
|
|
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
/* ---> PolicyKit method call section :: END <--- */
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Use this TQT_SLOT to emit a reviced messages to the tdepowersave.
|
|
|
|
|
* 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
|
|
|
|
|
* This function handles dBus service unregistering
|
|
|
|
|
*/
|
|
|
|
|
void dbusInterface::emitMsgReceived( msg_type type, TQString message, TQString string ) {
|
|
|
|
|
|
|
|
|
|
if (message.startsWith("dbus.terminate"))
|
|
|
|
|
dbus_is_connected = false;
|
|
|
|
|
|
|
|
|
|
if (type == POLICY_POWER_OWNER_CHANGED) {
|
|
|
|
|
if (message.startsWith("NOW_OWNER"))
|
|
|
|
|
acquiredPolicyPower = true;
|
|
|
|
|
else
|
|
|
|
|
acquiredPolicyPower = false;
|
|
|
|
|
void dbusInterface::onServiceUnregistered(const TQString& service) {
|
|
|
|
|
if( service == SYSTEMD_LOGIN1_SERVICE ) {
|
|
|
|
|
systemdSession = TQT_DBusObjectPath();
|
|
|
|
|
if( systemdSeat ) {
|
|
|
|
|
delete systemdSeat;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if( service == CK_SERVICE ) {
|
|
|
|
|
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 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
|
|
|
|
|
/*!
|
|
|
|
|
* This functions is used to check if session is active
|
|
|
|
|
*/
|
|
|
|
|
DBusHandlerResult
|
|
|
|
|
filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
bool reply_wanted;
|
|
|
|
|
char *value;
|
|
|
|
|
TQString ifaceType;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init( &error );
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
bool dbusInterface::checkActiveSession() {
|
|
|
|
|
if( systemdSeat && systemdSeat->canSend() ) {
|
|
|
|
|
TQT_DBusObjectPath activeSession;
|
|
|
|
|
TQValueList<TQT_DBusData> params;
|
|
|
|
|
params
|
|
|
|
|
<< TQT_DBusData::fromString( SYSTEMD_LOGIN1_SEAT_IFACE )
|
|
|
|
|
<< TQT_DBusData::fromString( "ActiveSession" );
|
|
|
|
|
TQT_DBusMessage reply = systemdSeat->sendWithReply("Get", params);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
|
|
|
|
|
activeSession = reply[0].toVariant().value.toStruct()[1].toObjectPath();
|
|
|
|
|
return (activeSession == systemdSession);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trace) kdDebug() << "filter_function::SIGNAL=" << signal << " VALUE=" << value << endl;
|
|
|
|
|
|
|
|
|
|
/* our name is... */
|
|
|
|
|
if ( ! strcmp( signal, "NameAcquired" ) ) {
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if( consolekitSeat && consolekitSeat->canSend() ) {
|
|
|
|
|
TQT_DBusObjectPath activeSession;
|
|
|
|
|
TQValueList<TQT_DBusData> params;
|
|
|
|
|
TQT_DBusMessage reply = consolekitSeat->sendWithReply("GetActiveSession", params);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
|
|
|
|
|
activeSession = reply[0].toObjectPath();
|
|
|
|
|
return (activeSession == consolekitSession);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
//! to get the current connection to D-Bus
|
|
|
|
|
DBusConnection * dbusInterface::get_DBUS_connection() {
|
|
|
|
|
return dbus_connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "dbusInterface.moc"
|
|
|
|
|