Cleanup HardwareControl

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
feat/new_hwcontrol
Emanoil Kotsev 6 months ago
parent 571215e14d
commit 802ffbda85
No known key found for this signature in database
GPG Key ID: F1EEB8CD9FB16A50

@ -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"

@ -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();
};

Loading…
Cancel
Save