Address clang and lgtm findings

This commit is contained in:
LordGrey 2020-10-28 14:17:15 +01:00
parent 384c861f13
commit ed31f4d750
4 changed files with 27 additions and 24 deletions

View File

@ -4,12 +4,14 @@
#if _WIN32
#include <windows.h>
#endif
#include <chrono>
// Constants
namespace {
bool verbose = false;
// Configuration settings
const char CONFIG_ADDRESS[] = "host";
const char RAZOR_DEVICE_TYPE[] = "razorDevice";
// WLED JSON-API elements
@ -17,26 +19,17 @@ const char API_DEFAULT_HOST[] = "localhost";
const int API_DEFAULT_PORT = 54235;
const char API_BASE_PATH[] = "/razer/chromasdk";
const char API_PATH_INFO[] = "info";
const char API_PATH_STATE[] = "state";
const char API_RESULT[] = "result";
// List of State Information
const char STATE_ON[] = "on";
const char STATE_VALUE_TRUE[] = "true";
const char STATE_VALUE_FALSE[] = "false";
constexpr std::chrono::milliseconds HEARTBEAT_INTERVALL{1000};
} //End of constants
LedDeviceRazer::LedDeviceRazer(const QJsonObject& deviceConfig)
: LedDevice()
, _restApi(nullptr)
LedDeviceRazer::LedDeviceRazer(const QJsonObject& /*deviceConfig*/)
:
_restApi(nullptr)
, _apiPort(API_DEFAULT_PORT)
{
_devConfig = deviceConfig;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceRazer::construct(const QJsonObject& deviceConfig)
@ -44,10 +37,16 @@ LedDevice* LedDeviceRazer::construct(const QJsonObject& deviceConfig)
return new LedDeviceRazer(deviceConfig);
}
LedDeviceRazer::~LedDeviceRazer()
{
delete _restApi;
_restApi = nullptr;
}
bool LedDeviceRazer::init(const QJsonObject& deviceConfig)
{
bool isInitOK = false;
setRewriteTime(1000);
setRewriteTime(HEARTBEAT_INTERVALL.count());
connect(_refreshTimer, &QTimer::timeout, this, &LedDeviceRazer::rewriteLEDs);
// Initialise sub-class
@ -132,7 +131,6 @@ bool LedDeviceRazer::checkApiError(const httpResponse& response)
int LedDeviceRazer::open()
{
int retval = -1;
QString errortext;
_isDeviceReady = false;
// Try to open the LedDevice

View File

@ -28,6 +28,11 @@ public:
///
static LedDevice* construct(const QJsonObject& deviceConfig);
///
/// @brief Destructor of the LED-device
///
~LedDeviceRazer() override;
protected:
///

View File

@ -130,7 +130,7 @@ httpResponse ProviderRestApi::get(const QUrl& url)
QNetworkReply* reply = _networkManager->get(request);
// Connect requestFinished signal to quit slot of the 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.
loop.exec();
@ -160,7 +160,7 @@ httpResponse ProviderRestApi::put(const QUrl& url, const QString& body)
QNetworkReply* reply = _networkManager->put(request, body.toUtf8());
// Connect requestFinished signal to quit slot of the 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.
loop.exec();
@ -191,7 +191,7 @@ httpResponse ProviderRestApi::post(const QUrl& url, const QString& body)
QNetworkReply* reply = _networkManager->post(request, body.toUtf8());
// Connect requestFinished signal to quit slot of the 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.
loop.exec();
@ -217,7 +217,7 @@ httpResponse ProviderRestApi::deleteResource(const QUrl& url)
QNetworkReply* reply = _networkManager->deleteResource(request);
// Connect requestFinished signal to quit slot of the 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.
loop.exec();

View File

@ -98,14 +98,14 @@ public:
///
/// @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
///
/// @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
@ -233,7 +233,7 @@ public:
///
/// Remove all header fields.
///
void removeAllHeaders() { _networkRequestHeaders = QNetworkRequest(); };
void removeAllHeaders() { _networkRequestHeaders = QNetworkRequest(); }
private: