diff --git a/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.cpp b/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.cpp index 24c98b79b..27e629dfb 100644 --- a/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.cpp +++ b/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.cpp @@ -29,27 +29,21 @@ #define DBUS_CONNECTION_TIMEOUT 4000 #define DBUS_CONNECTION_RETRY 3 -HardwareControl::HardwareControl(int &argc, char **argv, bool GUIenabled, bool SMenabled) : -TQApplication(argc, argv, GUIenabled, SMenabled) +HardwareControl::HardwareControl(int &argc, char **argv, bool GUIenabled, bool SMenabled) + : TQApplication(argc, argv, GUIenabled, SMenabled), + retryCount(0) { - retryCount=0; // init session connection to dbus if (!initDBUS()) { tqDebug("Failed to initialize the connection to DBus"); TQTimer::singleShot(DBUS_CONNECTION_TIMEOUT, this, TQ_SLOT(slotReconnect())); - retryCount++; } } HardwareControl::~HardwareControl() { // close D-Bus connection - close(); - - delete hardwarecontrolService; - delete trinitydesktopService; - delete orgService; - delete rootService; + dbusConnectionClose(); } bool HardwareControl::initDBUS(){ @@ -60,59 +54,77 @@ bool HardwareControl::initDBUS(){ + m_connection.lastError().message()); return false; } + m_connection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); // try to get a specific service name if (!m_connection.requestName(DBUS_HWCTRL_SERVICE_NAME, TQT_DBusConnection::NoReplace)) return false; + // make sure we get a reply m_connection.scheduleDispatch(); - m_connection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); - - TQTimer::singleShot(10, this, TQ_SLOT(slotConnectionCheck())); return true; } -void HardwareControl::close() { +void HardwareControl::slotDbusSignal(const TQT_DBusMessage& message) { + TQString serviceName = message[0].toString(); + if ( message.interface() == TQString("org.freedesktop.DBus") && + message.member() == TQString("NameAcquired") && + serviceName == DBUS_HWCTRL_SERVICE_NAME ) + { + tqDebug("Name acquired: " + serviceName); + rootService = new RootNodeService(m_connection); + orgService = new OrgNodeService(m_connection); + trinitydesktopService = new TrinityDesktopNodeService(m_connection); + hardwarecontrolService = new HardwareControlNodeService(m_connection); + tqDebug("TDEHW service setup done."); + } else { + tqDebug("TDEHW service ignored: " + serviceName); + } + +} + +void HardwareControl::dbusConnectionClose() { + + if(rootService) + { + delete rootService; + rootService=0; + } + if(orgService) + { + delete orgService; + orgService=0; + } + if(trinitydesktopService) + { + delete trinitydesktopService; + trinitydesktopService=0; + } + if(hardwarecontrolService) + { + delete hardwarecontrolService; + hardwarecontrolService=0; + } + if(m_connection.isConnected()) { m_connection.disconnect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); m_connection.closeConnection(DBUS_HWCTRL_SERVICE_NAME); } + retryCount=0; } void HardwareControl::slotReconnect() { - close(); + dbusConnectionClose(); if (!initDBUS()) { if (DBUS_CONNECTION_RETRY > retryCount) { - tqFatal("Failed to initialize the connection to DBus"); + tqDebug("Failed to initialize the connection to DBus"); } TQTimer::singleShot(DBUS_CONNECTION_TIMEOUT, this, TQ_SLOT(slotReconnect())); retryCount++; } } -void HardwareControl::slotDbusSignal(const TQT_DBusMessage& message) { - if (message.interface() != TQString("org.freedesktop.DBus")) - return; - if (message.member() != TQString("NameAcquired")) - return; - tqDebug("Name acquired: " + message[0].toString()); - serviceName = message[0].toString(); -} - -void HardwareControl::slotConnectionCheck() { - - if (serviceName != DBUS_HWCTRL_SERVICE_NAME) { - tqFatal("TDEHW service already running or no unique name possible."); - } - - rootService = new RootNodeService(m_connection); - orgService = new OrgNodeService(m_connection); - trinitydesktopService = new TrinityDesktopNodeService(m_connection); - hardwarecontrolService = new HardwareControlNodeService(m_connection); - tqDebug("TDEHW service setup done."); -} - #include "HardwareControl.moc" diff --git a/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.h b/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.h index c7e692b90..0ac42b9c6 100644 --- a/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.h +++ b/tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.h @@ -43,14 +43,13 @@ private: */ bool initDBUS(); //! to close the connection to D-Bus - void close(); + void dbusConnectionClose(); RootNodeService *rootService; OrgNodeService *orgService; TrinityDesktopNodeService *trinitydesktopService; HardwareControlNodeService *hardwarecontrolService; int retryCount; - TQString serviceName; TQT_DBusConnection m_connection; private slots: @@ -64,16 +63,6 @@ private slots: * \return void */ void slotDbusSignal(const TQT_DBusMessage&); - /*! - * This function is to check D-Bus connection. - * and if the name is the unique name prepare the receivers - * If the name is not the unique name it mans the service - * is already running or unique name can not be obtained from - * DBus. In this latter case the application will terminate. - * - * \return void - */ - void slotConnectionCheck(); };