|
|
@ -38,17 +38,15 @@ |
|
|
|
PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent) |
|
|
|
PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent) |
|
|
|
: QObject(parent) |
|
|
|
: QObject(parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!QDBusConnection::sessionBus().isConnected()) { |
|
|
|
if (!QDBusConnection::sessionBus().isConnected()) |
|
|
|
|
|
|
|
{ |
|
|
|
qDebug("D-Bus: Could not connect to session bus"); |
|
|
|
qDebug("D-Bus: Could not connect to session bus"); |
|
|
|
m_state = Error; |
|
|
|
m_state = Error; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
m_state = Idle; |
|
|
|
m_state = Idle; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_intendedState = Idle; |
|
|
|
|
|
|
|
m_cookie = 0; |
|
|
|
|
|
|
|
m_useGSM = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PowerManagementInhibitor::requestIdle() |
|
|
|
void PowerManagementInhibitor::requestIdle() |
|
|
@ -73,12 +71,11 @@ void PowerManagementInhibitor::requestIdle() |
|
|
|
u"UnInhibit"_s); |
|
|
|
u"UnInhibit"_s); |
|
|
|
call.setArguments({m_cookie}); |
|
|
|
call.setArguments({m_cookie}); |
|
|
|
|
|
|
|
|
|
|
|
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); |
|
|
|
const QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); |
|
|
|
auto *watcher = new QDBusPendingCallWatcher(pcall, this); |
|
|
|
const auto *watcher = new QDBusPendingCallWatcher(pcall, this); |
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); |
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PowerManagementInhibitor::requestBusy() |
|
|
|
void PowerManagementInhibitor::requestBusy() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_intendedState = Busy; |
|
|
|
m_intendedState = Busy; |
|
|
@ -108,45 +105,55 @@ void PowerManagementInhibitor::requestBusy() |
|
|
|
args << 4u; |
|
|
|
args << 4u; |
|
|
|
call.setArguments(args); |
|
|
|
call.setArguments(args); |
|
|
|
|
|
|
|
|
|
|
|
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); |
|
|
|
const QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); |
|
|
|
auto *watcher = new QDBusPendingCallWatcher(pcall, this); |
|
|
|
const auto *watcher = new QDBusPendingCallWatcher(pcall, this); |
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); |
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) |
|
|
|
void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_state == RequestIdle) { |
|
|
|
call->deleteLater(); |
|
|
|
QDBusPendingReply<> reply = *call; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (reply.isError()) { |
|
|
|
if (m_state == RequestIdle) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const QDBusPendingReply reply = *call; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (reply.isError()) |
|
|
|
|
|
|
|
{ |
|
|
|
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); |
|
|
|
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); |
|
|
|
m_state = Error; |
|
|
|
m_state = Error; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
m_state = Idle; |
|
|
|
m_state = Idle; |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Request successful"); |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Request successful"); |
|
|
|
if (m_intendedState == Busy) |
|
|
|
if (m_intendedState == Busy) |
|
|
|
requestBusy(); |
|
|
|
requestBusy(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (m_state == RequestBusy) { |
|
|
|
else if (m_state == RequestBusy) |
|
|
|
QDBusPendingReply<uint> reply = *call; |
|
|
|
{ |
|
|
|
|
|
|
|
const QDBusPendingReply<quint32> reply = *call; |
|
|
|
|
|
|
|
|
|
|
|
if (reply.isError()) { |
|
|
|
if (reply.isError()) |
|
|
|
|
|
|
|
{ |
|
|
|
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); |
|
|
|
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); |
|
|
|
|
|
|
|
|
|
|
|
if (m_useGSM) { |
|
|
|
if (m_useGSM) |
|
|
|
|
|
|
|
{ |
|
|
|
qDebug("D-Bus: Falling back to org.freedesktop.PowerManagement"); |
|
|
|
qDebug("D-Bus: Falling back to org.freedesktop.PowerManagement"); |
|
|
|
m_useGSM = false; |
|
|
|
m_useGSM = false; |
|
|
|
m_state = Idle; |
|
|
|
m_state = Idle; |
|
|
|
if (m_intendedState == Busy) |
|
|
|
if (m_intendedState == Busy) |
|
|
|
requestBusy(); |
|
|
|
requestBusy(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
m_state = Error; |
|
|
|
m_state = Error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
m_state = Busy; |
|
|
|
m_state = Busy; |
|
|
|
m_cookie = reply.value(); |
|
|
|
m_cookie = reply.value(); |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie); |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie); |
|
|
@ -154,10 +161,9 @@ void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) |
|
|
|
requestIdle(); |
|
|
|
requestIdle(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
qDebug("D-Bus: Unexpected reply in state %d", m_state); |
|
|
|
qDebug("D-Bus: Unexpected reply in state %d", m_state); |
|
|
|
m_state = Error; |
|
|
|
m_state = Error; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
call->deleteLater(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|