Implement C++ functions for quitting apps and querying running apps

This commit is contained in:
Cameron Gutman
2018-07-31 22:21:39 -07:00
parent 017362a5d1
commit 3ed5f9edf7
4 changed files with 104 additions and 0 deletions
+14
View File
@@ -446,6 +446,15 @@ void ComputerManager::pairHost(NvComputer* computer, QString pin)
QThreadPool::globalInstance()->start(pairing);
}
void ComputerManager::quitRunningApp(NvComputer* computer)
{
QWriteLocker lock(&computer->lock);
computer->pendingQuit = true;
PendingQuitTask* quit = new PendingQuitTask(this, computer);
QThreadPool::globalInstance()->start(quit);
}
void ComputerManager::stopPollingAsync()
{
QWriteLocker lock(&m_Lock);
@@ -497,6 +506,11 @@ ComputerManager::handleComputerStateChanged(NvComputer* computer)
{
emit computerStateChanged(computer);
if (computer->pendingQuit && computer->currentGameId == 0) {
computer->pendingQuit = false;
emit quitAppCompleted(nullptr);
}
// Save updated hosts to QSettings
saveHosts();
}
+53
View File
@@ -16,10 +16,14 @@
class NvComputer
{
friend class PcMonitorThread;
friend class ComputerManager;
friend class PendingQuitTask;
private:
void sortAppList();
bool pendingQuit;
public:
explicit NvComputer(QString address, QString serverInfo);
@@ -254,6 +258,8 @@ public:
void pairHost(NvComputer* computer, QString pin);
void quitRunningApp(NvComputer* computer);
QVector<NvComputer*> getComputers();
// computer is deleted inside this call
@@ -266,6 +272,8 @@ signals:
void computerAddCompleted(QVariant success);
void quitAppCompleted(QString error);
private slots:
void handleComputerStateChanged(NvComputer* computer);
@@ -333,6 +341,51 @@ private:
QString m_Pin;
};
class PendingQuitTask : public QObject, public QRunnable
{
Q_OBJECT
public:
PendingQuitTask(ComputerManager* computerManager, NvComputer* computer)
: m_Computer(computer)
{
connect(this, &PendingQuitTask::quitAppFailed,
computerManager, &ComputerManager::quitAppCompleted);
}
signals:
void quitAppFailed(QString error);
private:
void run()
{
NvHTTP http(m_Computer->activeAddress);
try {
if (m_Computer->currentGameId != 0) {
http.quitApp();
if (http.getCurrentGame(http.getServerInfo()) != 0) {
{
QWriteLocker lock(&m_Computer->lock);
m_Computer->pendingQuit = false;
}
emit quitAppFailed("Unable to quit game that wasn't started by this computer. "
"You must quit the game on the host PC manually or use the device that originally started the game.");
}
}
} catch (const GfeHttpResponseException& e) {
{
QWriteLocker lock(&m_Computer->lock);
m_Computer->pendingQuit = false;
}
emit quitAppFailed(e.toQString());
}
}
NvComputer* m_Computer;
};
class PendingAddTask : public QObject, public QRunnable
{
Q_OBJECT