Add quit cli command and app quit option after stream session. Fixes #92 (#138)

* Add quit cli command and app quit option after stream session. Fixes #92

* Code review fixes.
This commit is contained in:
Janne Hakonen
2018-12-06 04:45:28 +02:00
committed by Cameron Gutman
parent ad47990a87
commit 0ab07303c9
22 changed files with 678 additions and 67 deletions
+6
View File
@@ -1,6 +1,7 @@
#include "computermanager.h"
#include "nvhttp.h"
#include "settings/streamingpreferences.h"
#include "streaming/session.h"
#include <Limelight.h>
#include <QtEndian>
@@ -478,6 +479,11 @@ void ComputerManager::quitRunningApp(NvComputer* computer)
QThreadPool::globalInstance()->start(quit);
}
void ComputerManager::quitRunningApp(Session *session)
{
quitRunningApp(session->getComputer());
}
void ComputerManager::stopPollingAsync()
{
QWriteLocker lock(&m_Lock);
+3
View File
@@ -14,6 +14,8 @@
#include <QSettings>
#include <QRunnable>
class Session;
class MdnsPendingComputer : public QObject
{
Q_OBJECT
@@ -72,6 +74,7 @@ public:
void pairHost(NvComputer* computer, QString pin);
void quitRunningApp(NvComputer* computer);
Q_INVOKABLE void quitRunningApp(Session* session);
QVector<NvComputer*> getComputers();
+59
View File
@@ -0,0 +1,59 @@
#include "computerseeker.h"
#include "computermanager.h"
#include <QTimer>
ComputerSeeker::ComputerSeeker(ComputerManager *manager, QString computerName, QObject *parent)
: QObject(parent), m_ComputerManager(manager), m_ComputerName(computerName),
m_TimeoutTimer(new QTimer(this))
{
m_TimeoutTimer->setSingleShot(true);
connect(m_TimeoutTimer, &QTimer::timeout,
this, &ComputerSeeker::onTimeout);
connect(m_ComputerManager, &ComputerManager::computerStateChanged,
this, &ComputerSeeker::onComputerUpdated);
}
void ComputerSeeker::start(int timeout)
{
m_TimeoutTimer->start(timeout);
// Seek desired computer by both connecting to it directly (this may fail
// if m_ComputerName is UUID, or the name that doesn't resolve to an IP
// address) and by polling it using mDNS, hopefully one of these methods
// would find the host
m_ComputerManager->addNewHost(m_ComputerName, false);
m_ComputerManager->startPolling();
}
void ComputerSeeker::onComputerUpdated(NvComputer *computer)
{
if (!m_TimeoutTimer->isActive()) {
return;
}
if (matchComputer(computer) && isOnline(computer)) {
m_ComputerManager->stopPollingAsync();
m_TimeoutTimer->stop();
emit computerFound(computer);
}
}
bool ComputerSeeker::matchComputer(NvComputer *computer) const
{
QString value = m_ComputerName.toLower();
return computer->name.toLower() == value ||
computer->localAddress.toLower() == value ||
computer->remoteAddress.toLower() == value ||
computer->manualAddress.toLower() == value ||
computer->uuid.toLower() == value;
}
bool ComputerSeeker::isOnline(NvComputer *computer) const
{
return computer->state == NvComputer::CS_ONLINE;
}
void ComputerSeeker::onTimeout()
{
m_TimeoutTimer->stop();
m_ComputerManager->stopPollingAsync();
emit errorTimeout();
}
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <QObject>
class ComputerManager;
class NvComputer;
class QTimer;
class ComputerSeeker : public QObject
{
Q_OBJECT
public:
explicit ComputerSeeker(ComputerManager *manager, QString computerName, QObject *parent = nullptr);
void start(int timeout);
signals:
void computerFound(NvComputer *computer);
void errorTimeout();
private slots:
void onComputerUpdated(NvComputer *computer);
void onTimeout();
private:
bool matchComputer(NvComputer *computer) const;
bool isOnline(NvComputer *computer) const;
private:
ComputerManager *m_ComputerManager;
QString m_ComputerName;
QTimer *m_TimeoutTimer;
};
+6 -1
View File
@@ -57,8 +57,13 @@ NvHTTP::getCurrentGame(QString serverInfo)
// GFE 2.8 started keeping currentgame set to the last game played. As a result, it no longer
// has the semantics that its name would indicate. To contain the effects of this change as much
// as possible, we'll force the current game to zero if the server isn't in a streaming session.
//
// However, current game info must be available also in other states than just _SERVER_BUSY as
// it is required for quitting currently running app. Quitting app occurs at end of stream if
// configured so. At that point the server state may be in some other state than _SERVER_BUSY
// for a short while, but that must not prevent quitting of the app.
QString serverState = getXmlString(serverInfo, "state");
if (serverState != nullptr && serverState.endsWith("_SERVER_BUSY"))
if (serverState != nullptr && !serverState.endsWith("_SERVER_AVAILABLE"))
{
return getXmlString(serverInfo, "currentgame").toInt();
}