mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Address clang and lgtm findings
This commit is contained in:
parent
384c861f13
commit
ed31f4d750
@ -4,12 +4,14 @@
|
|||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
namespace {
|
namespace {
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
|
||||||
// Configuration settings
|
// Configuration settings
|
||||||
const char CONFIG_ADDRESS[] = "host";
|
|
||||||
const char RAZOR_DEVICE_TYPE[] = "razorDevice";
|
const char RAZOR_DEVICE_TYPE[] = "razorDevice";
|
||||||
|
|
||||||
// WLED JSON-API elements
|
// WLED JSON-API elements
|
||||||
@ -17,26 +19,17 @@ const char API_DEFAULT_HOST[] = "localhost";
|
|||||||
const int API_DEFAULT_PORT = 54235;
|
const int API_DEFAULT_PORT = 54235;
|
||||||
|
|
||||||
const char API_BASE_PATH[] = "/razer/chromasdk";
|
const char API_BASE_PATH[] = "/razer/chromasdk";
|
||||||
const char API_PATH_INFO[] = "info";
|
|
||||||
const char API_PATH_STATE[] = "state";
|
|
||||||
|
|
||||||
const char API_RESULT[] = "result";
|
const char API_RESULT[] = "result";
|
||||||
|
|
||||||
// List of State Information
|
constexpr std::chrono::milliseconds HEARTBEAT_INTERVALL{1000};
|
||||||
const char STATE_ON[] = "on";
|
|
||||||
const char STATE_VALUE_TRUE[] = "true";
|
|
||||||
const char STATE_VALUE_FALSE[] = "false";
|
|
||||||
} //End of constants
|
} //End of constants
|
||||||
|
|
||||||
LedDeviceRazer::LedDeviceRazer(const QJsonObject& deviceConfig)
|
LedDeviceRazer::LedDeviceRazer(const QJsonObject& /*deviceConfig*/)
|
||||||
: LedDevice()
|
:
|
||||||
, _restApi(nullptr)
|
_restApi(nullptr)
|
||||||
, _apiPort(API_DEFAULT_PORT)
|
, _apiPort(API_DEFAULT_PORT)
|
||||||
{
|
{
|
||||||
_devConfig = deviceConfig;
|
|
||||||
_isDeviceReady = false;
|
|
||||||
|
|
||||||
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LedDevice* LedDeviceRazer::construct(const QJsonObject& deviceConfig)
|
LedDevice* LedDeviceRazer::construct(const QJsonObject& deviceConfig)
|
||||||
@ -44,10 +37,16 @@ LedDevice* LedDeviceRazer::construct(const QJsonObject& deviceConfig)
|
|||||||
return new LedDeviceRazer(deviceConfig);
|
return new LedDeviceRazer(deviceConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LedDeviceRazer::~LedDeviceRazer()
|
||||||
|
{
|
||||||
|
delete _restApi;
|
||||||
|
_restApi = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool LedDeviceRazer::init(const QJsonObject& deviceConfig)
|
bool LedDeviceRazer::init(const QJsonObject& deviceConfig)
|
||||||
{
|
{
|
||||||
bool isInitOK = false;
|
bool isInitOK = false;
|
||||||
setRewriteTime(1000);
|
setRewriteTime(HEARTBEAT_INTERVALL.count());
|
||||||
connect(_refreshTimer, &QTimer::timeout, this, &LedDeviceRazer::rewriteLEDs);
|
connect(_refreshTimer, &QTimer::timeout, this, &LedDeviceRazer::rewriteLEDs);
|
||||||
|
|
||||||
// Initialise sub-class
|
// Initialise sub-class
|
||||||
@ -132,7 +131,6 @@ bool LedDeviceRazer::checkApiError(const httpResponse& response)
|
|||||||
int LedDeviceRazer::open()
|
int LedDeviceRazer::open()
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
QString errortext;
|
|
||||||
_isDeviceReady = false;
|
_isDeviceReady = false;
|
||||||
|
|
||||||
// Try to open the LedDevice
|
// Try to open the LedDevice
|
||||||
|
@ -28,6 +28,11 @@ public:
|
|||||||
///
|
///
|
||||||
static LedDevice* construct(const QJsonObject& deviceConfig);
|
static LedDevice* construct(const QJsonObject& deviceConfig);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Destructor of the LED-device
|
||||||
|
///
|
||||||
|
~LedDeviceRazer() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -130,7 +130,7 @@ httpResponse ProviderRestApi::get(const QUrl& url)
|
|||||||
QNetworkReply* reply = _networkManager->get(request);
|
QNetworkReply* reply = _networkManager->get(request);
|
||||||
// Connect requestFinished signal to quit slot of the loop.
|
// Connect requestFinished signal to quit slot of the loop.
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
loop.connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
// Go into the loop until the request is finished.
|
// Go into the loop until the request is finished.
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ httpResponse ProviderRestApi::put(const QUrl& url, const QString& body)
|
|||||||
QNetworkReply* reply = _networkManager->put(request, body.toUtf8());
|
QNetworkReply* reply = _networkManager->put(request, body.toUtf8());
|
||||||
// Connect requestFinished signal to quit slot of the loop.
|
// Connect requestFinished signal to quit slot of the loop.
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
loop.connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
// Go into the loop until the request is finished.
|
// Go into the loop until the request is finished.
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ httpResponse ProviderRestApi::post(const QUrl& url, const QString& body)
|
|||||||
QNetworkReply* reply = _networkManager->post(request, body.toUtf8());
|
QNetworkReply* reply = _networkManager->post(request, body.toUtf8());
|
||||||
// Connect requestFinished signal to quit slot of the loop.
|
// Connect requestFinished signal to quit slot of the loop.
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
loop.connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
QEventLoop::connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
|
||||||
// Go into the loop until the request is finished.
|
// Go into the loop until the request is finished.
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ httpResponse ProviderRestApi::deleteResource(const QUrl& url)
|
|||||||
QNetworkReply* reply = _networkManager->deleteResource(request);
|
QNetworkReply* reply = _networkManager->deleteResource(request);
|
||||||
// Connect requestFinished signal to quit slot of the loop.
|
// Connect requestFinished signal to quit slot of the loop.
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
loop.connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
// Go into the loop until the request is finished.
|
// Go into the loop until the request is finished.
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
@ -98,14 +98,14 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param[in] host
|
/// @param[in] host
|
||||||
///
|
///
|
||||||
void setHost(const QString& host) { _apiUrl.setHost(host); };
|
void setHost(const QString& host) { _apiUrl.setHost(host); }
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Set an API's port
|
/// @brief Set an API's port
|
||||||
///
|
///
|
||||||
/// @param[in] port
|
/// @param[in] port
|
||||||
///
|
///
|
||||||
void setPort(const int port) { _apiUrl.setPort(port); };
|
void setPort(const int port) { _apiUrl.setPort(port); }
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Set an API's url
|
/// @brief Set an API's url
|
||||||
@ -233,7 +233,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Remove all header fields.
|
/// Remove all header fields.
|
||||||
///
|
///
|
||||||
void removeAllHeaders() { _networkRequestHeaders = QNetworkRequest(); };
|
void removeAllHeaders() { _networkRequestHeaders = QNetworkRequest(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user