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