From 76d39c08dad733bec53f00b9a6e2a23f198169ec Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 26 Jun 2018 23:39:28 -0700 Subject: [PATCH] Implement app list parsing --- app/http/computermanager.h | 36 ++++++++++++++++++++++-------------- app/http/nvhttp.cpp | 38 ++++++++++++++++++++++++++++++++++++++ app/http/nvhttp.h | 21 +++++++++++++++++++++ 3 files changed, 81 insertions(+), 14 deletions(-) diff --git a/app/http/computermanager.h b/app/http/computermanager.h index fde36d89..ad2d90a4 100644 --- a/app/http/computermanager.h +++ b/app/http/computermanager.h @@ -4,19 +4,6 @@ #include #include -class NvApp -{ -public: - bool operator==(const NvApp& other) const - { - return id == other.id; - } - - int id; - QString name; - bool hdrSupported; -}; - class NvComputer { public: @@ -101,7 +88,28 @@ private: bool updateAppList(bool& changed) { - return false; + Q_ASSERT(m_Computer->activeAddress != nullptr); + + NvHTTP http(m_Computer->activeAddress); + + QVector appList; + + try { + appList = http.getAppList(); + if (appList.isEmpty()) { + return false; + } + } catch (...) { + return false; + } + + QWriteLocker lock(&m_Computer->lock); + if (m_Computer->appList != appList) { + m_Computer->appList = appList; + changed = true; + } + + return true; } void run() override diff --git a/app/http/nvhttp.cpp b/app/http/nvhttp.cpp index c581c180..2085d91d 100644 --- a/app/http/nvhttp.cpp +++ b/app/http/nvhttp.cpp @@ -181,6 +181,44 @@ NvHTTP::quitApp() } } +QVector +NvHTTP::getAppList() +{ + QString appxml = openConnectionToString(m_BaseUrlHttps, + "applist", + nullptr, + true); + verifyResponseStatus(appxml); + + QXmlStreamReader xmlReader(appxml); + QVector apps; + while (!xmlReader.atEnd()) { + while (xmlReader.readNextStartElement()) { + QStringRef name = xmlReader.name(); + if (xmlReader.name() == "App") { + // We must have a valid app before advancing to the next one + if (!apps.isEmpty() && !apps.last().isInitialized()) { + qWarning() << "Invalid applist XML"; + Q_ASSERT(false); + return QVector(); + } + apps.append(NvApp()); + } + else if (xmlReader.name() == "AppTitle") { + apps.last().name = xmlReader.readElementText(); + } + else if (xmlReader.name() == "ID") { + apps.last().id = xmlReader.readElementText().toInt(); + } + else if (xmlReader.name() == "IsHdrSupported") { + apps.last().hdrSupported = xmlReader.readElementText() == "1"; + } + } + } + + return apps; +} + void NvHTTP::verifyResponseStatus(QString xml) { diff --git a/app/http/nvhttp.h b/app/http/nvhttp.h index aab30557..4d0ac790 100644 --- a/app/http/nvhttp.h +++ b/app/http/nvhttp.h @@ -7,6 +7,24 @@ #include #include +class NvApp +{ +public: + bool operator==(const NvApp& other) const + { + return id == other.id; + } + + bool isInitialized() + { + return id != 0 && !name.isNull(); + } + + int id; + QString name; + bool hdrSupported; +}; + class GfeHttpResponseException : public std::exception { public: @@ -86,6 +104,9 @@ public: bool localAudio, int gamepadMask); + QVector + getAppList(); + QUrl m_BaseUrlHttp; QUrl m_BaseUrlHttps; private: