Implement app list parsing

This commit is contained in:
Cameron Gutman 2018-06-26 23:39:28 -07:00
parent 16d7dca784
commit 76d39c08da
3 changed files with 81 additions and 14 deletions

View File

@ -4,19 +4,6 @@
#include <QThread>
#include <QReadWriteLock>
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<NvApp> 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

View File

@ -181,6 +181,44 @@ NvHTTP::quitApp()
}
}
QVector<NvApp>
NvHTTP::getAppList()
{
QString appxml = openConnectionToString(m_BaseUrlHttps,
"applist",
nullptr,
true);
verifyResponseStatus(appxml);
QXmlStreamReader xmlReader(appxml);
QVector<NvApp> 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<NvApp>();
}
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)
{

View File

@ -7,6 +7,24 @@
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
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<NvApp>
getAppList();
QUrl m_BaseUrlHttp;
QUrl m_BaseUrlHttps;
private: