moonlight-qt/app/backend/nvhttp.h

203 lines
4 KiB
C
Raw Normal View History

2018-04-28 22:39:50 +00:00
#pragma once
2018-04-29 05:14:27 +00:00
#include "identitymanager.h"
#include "nvapp.h"
#include "nvaddress.h"
2018-04-29 05:14:27 +00:00
2018-06-24 07:14:23 +00:00
#include <Limelight.h>
2018-04-28 22:39:50 +00:00
#include <QUrl>
#include <QNetworkAccessManager>
#include <QNetworkReply>
2018-04-28 22:39:50 +00:00
class NvComputer;
class NvDisplayMode
{
public:
bool operator==(const NvDisplayMode& other) const
{
return width == other.width &&
height == other.height &&
refreshRate == other.refreshRate;
}
int width;
int height;
int refreshRate;
};
2021-03-03 00:14:15 +00:00
Q_DECLARE_TYPEINFO(NvDisplayMode, Q_PRIMITIVE_TYPE);
2018-04-29 00:08:05 +00:00
class GfeHttpResponseException : public std::exception
{
public:
GfeHttpResponseException(int statusCode, QString message) :
m_StatusCode(statusCode),
m_StatusMessage(message)
{
}
2018-09-29 10:11:17 +00:00
const char* what() const throw()
2018-04-29 00:08:05 +00:00
{
2018-04-29 05:14:27 +00:00
return m_StatusMessage.toLatin1();
2018-04-29 00:08:05 +00:00
}
2018-04-29 05:14:27 +00:00
const char* getStatusMessage() const
2018-04-29 00:08:05 +00:00
{
2018-04-29 05:14:27 +00:00
return m_StatusMessage.toLatin1();
2018-04-29 00:08:05 +00:00
}
2018-04-29 05:14:27 +00:00
int getStatusCode() const
2018-04-29 00:08:05 +00:00
{
return m_StatusCode;
}
QString toQString() const
{
return m_StatusMessage + " (Error " + QString::number(m_StatusCode) + ")";
}
2018-04-29 00:08:05 +00:00
private:
int m_StatusCode;
QString m_StatusMessage;
};
class QtNetworkReplyException : public std::exception
{
public:
QtNetworkReplyException(QNetworkReply::NetworkError error, QString errorText) :
m_Error(error),
m_ErrorText(errorText)
{
}
2018-09-29 10:11:17 +00:00
const char* what() const throw()
{
return m_ErrorText.toLatin1();
}
const char* getErrorText() const
{
return m_ErrorText.toLatin1();
}
QNetworkReply::NetworkError getError() const
{
return m_Error;
}
QString toQString() const
{
return m_ErrorText + " (Error " + QString::number(m_Error) + ")";
}
private:
QNetworkReply::NetworkError m_Error;
QString m_ErrorText;
};
class NvHTTP : public QObject
2018-04-28 22:39:50 +00:00
{
Q_OBJECT
2018-04-28 22:39:50 +00:00
public:
enum NvLogLevel {
2019-01-20 05:32:35 +00:00
NVLL_NONE,
NVLL_ERROR,
NVLL_VERBOSE
};
2021-07-03 05:00:27 +00:00
explicit NvHTTP(NvAddress address, uint16_t httpsPort, QSslCertificate serverCert);
2018-04-28 22:39:50 +00:00
explicit NvHTTP(NvComputer* computer);
2018-06-27 04:47:01 +00:00
static
2018-04-29 00:08:05 +00:00
int
getCurrentGame(QString serverInfo);
QString
getServerInfo(NvLogLevel logLevel, bool fastFail = false);
2018-04-29 00:08:05 +00:00
2018-06-27 04:47:01 +00:00
static
2018-04-29 00:08:05 +00:00
void
verifyResponseStatus(QString xml);
2018-06-27 04:47:01 +00:00
static
2018-04-29 00:08:05 +00:00
QString
getXmlString(QString xml,
QString tagName);
2018-06-27 04:47:01 +00:00
static
2018-04-29 08:48:41 +00:00
QByteArray
getXmlStringFromHex(QString xml,
QString tagName);
2018-04-29 00:08:05 +00:00
QString
openConnectionToString(QUrl baseUrl,
QString command,
QString arguments,
2019-01-06 22:35:33 +00:00
int timeoutMs,
2019-01-20 05:32:35 +00:00
NvLogLevel logLevel = NvLogLevel::NVLL_VERBOSE);
2018-04-29 00:08:05 +00:00
2018-12-23 03:55:28 +00:00
void setServerCert(QSslCertificate serverCert);
void setAddress(NvAddress address);
void setHttpsPort(uint16_t port);
2019-08-01 05:07:20 +00:00
NvAddress address();
2019-08-01 05:07:20 +00:00
QSslCertificate serverCert();
uint16_t httpPort();
uint16_t httpsPort();
2018-06-27 04:47:01 +00:00
static
2018-04-29 02:01:00 +00:00
QVector<int>
2018-07-06 06:12:55 +00:00
parseQuad(QString quad);
2018-04-29 02:01:00 +00:00
2018-06-24 07:14:23 +00:00
void
quitApp();
void
resumeApp(PSTREAM_CONFIGURATION streamConfig,
QString& rtspSessionUrl);
2018-06-24 07:14:23 +00:00
void
launchApp(int appId,
PSTREAM_CONFIGURATION streamConfig,
bool sops,
bool localAudio,
int gamepadMask,
QString& rtspSessionUrl);
2018-06-24 07:14:23 +00:00
2018-06-27 06:39:28 +00:00
QVector<NvApp>
getAppList();
2018-06-27 06:49:44 +00:00
QImage
getBoxArt(int appId);
static
QVector<NvDisplayMode>
getDisplayModeList(QString serverInfo);
2018-04-28 22:39:50 +00:00
QUrl m_BaseUrlHttp;
QUrl m_BaseUrlHttps;
2018-04-29 05:14:27 +00:00
private:
void
handleSslErrors(QNetworkReply* reply, const QList<QSslError>& errors);
2018-04-29 05:14:27 +00:00
QNetworkReply*
openConnection(QUrl baseUrl,
QString command,
QString arguments,
2019-01-06 22:35:33 +00:00
int timeoutMs,
NvLogLevel logLevel);
2018-04-29 05:14:27 +00:00
NvAddress m_Address;
2018-04-28 22:39:50 +00:00
QNetworkAccessManager m_Nam;
2018-12-22 02:08:07 +00:00
QSslCertificate m_ServerCert;
2018-04-28 22:39:50 +00:00
};