From a7f72a7bf27be8f9f9f686781a6abcd3264eb047 Mon Sep 17 00:00:00 2001 From: brindosch Date: Mon, 29 May 2017 21:34:47 +0200 Subject: [PATCH] fix mess --- include/utils/Stats.h | 8 +-- libsrc/effectengine/EffectEngine.cpp | 6 +-- libsrc/utils/Stats.cpp | 76 +++++++++++++--------------- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/include/utils/Stats.h b/include/utils/Stats.h index 193c8986..76c68518 100644 --- a/include/utils/Stats.h +++ b/include/utils/Stats.h @@ -1,11 +1,9 @@ // qt includes -#include #include #include #include #include #include -#include #include // hyperion includes @@ -22,13 +20,15 @@ public: private: Logger* _log; QString _hash = ""; + QByteArray _ba; + QNetworkRequest _req; QNetworkAccessManager _mgr; bool trigger(bool set = false); private slots: - void sendHTTP(bool put = false); + void sendHTTP(); + void sendHTTPp(); void resolveReply(QNetworkReply *reply); - }; diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 7f575a7e..327c9d87 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -293,7 +293,7 @@ void EffectEngine::readEffects() Warning(_log, "Failed to create Effect path \"%s\", please check permissions",path.toUtf8().constData() ); } } - if (directory.exists(path)) + else { int efxCount = 0; QStringList filenames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase); @@ -336,10 +336,6 @@ void EffectEngine::readEffects() if (efxCount > 0) Info(_log, "%d effect schemas loaded from directory %s", efxCount, (path + "schema/").toUtf8().constData()); } - else - { - Warning(_log, "Effect path \"%s\" does not exist",path.toUtf8().constData() ); - } } foreach(auto item, availableEffects) diff --git a/libsrc/utils/Stats.cpp b/libsrc/utils/Stats.cpp index 356cd44a..6b701c7f 100644 --- a/libsrc/utils/Stats.cpp +++ b/libsrc/utils/Stats.cpp @@ -19,7 +19,6 @@ Stats::Stats() , _log(Logger::getInstance("STATS")) { // generate hash - QString hash; foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces()) { if (!(interface.flags() & QNetworkInterface::IsLoopBack)) @@ -35,36 +34,13 @@ Stats::Stats() Warning(_log, "No interface found, abort"); return; } - - connect(&_mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(resolveReply(QNetworkReply*))); - // 7 days interval - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(sendHTTP())); - timer->start(604800000); - - // check instant execution required - if(trigger()) - { - QTimer::singleShot(0, this, [=]() { - sendHTTP(); - }); - } -} - -Stats::~Stats() -{ - -} - -void Stats::sendHTTP(bool put) -{ + // prepare content QJsonObject config = Hyperion::getInstance()->getConfig(); SysInfo::HyperionSysInfo data = SysInfo::get(); QJsonObject system; system["kType" ] = data.kernelType; - //system["kernelVersion" ] = data.kernelVersion; system["arch" ] = data.architecture; system["pType" ] = data.productType; system["pVersion" ] = data.productVersion; @@ -82,24 +58,43 @@ void Stats::sendHTTP(bool put) system["comp_uc" ] = config["grabberV4L2"].toArray().at(0).toObject().take("enable"); QJsonDocument doc(system); - QByteArray ba = doc.toJson(); + _ba = doc.toJson(); - QNetworkRequest req; - req.setRawHeader("Content-Type", "application/json"); - req.setRawHeader("Authorization", "Basic SHlwZXJpb25YbDQ5MlZrcXA6ZDQxZDhjZDk4ZjAwYjIw"); - - if(put) + // QNetworkRequest Header + _req.setRawHeader("Content-Type", "application/json"); + _req.setRawHeader("Authorization", "Basic SHlwZXJpb25YbDQ5MlZrcXA6ZDQxZDhjZDk4ZjAwYjIw"); + + connect(&_mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(resolveReply(QNetworkReply*))); + + // 7 days interval + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(sendHTTP())); + timer->start(604800000); + + // check instant execution required + if(trigger()) { - req.setUrl(QUrl("https://api.hyperion-project.org/api/stats/"+_hash)); - _mgr.put(req,ba); - } - else - { - req.setUrl(QUrl("https://api.hyperion-project.org/api/stats")); - _mgr.post(req,ba); + QTimer::singleShot(0,this, SLOT(sendHTTP())); } } +Stats::~Stats() +{ + +} + +void Stats::sendHTTP() +{ + _req.setUrl(QUrl("https://api.hyperion-project.org/api/stats")); + _mgr.post(_req,_ba); +} + +void Stats::sendHTTPp() +{ + _req.setUrl(QUrl("https://api.hyperion-project.org/api/stats/"+_hash)); + _mgr.put(_req,_ba); +} + void Stats::resolveReply(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) @@ -109,10 +104,7 @@ void Stats::resolveReply(QNetworkReply *reply) // already created, update entry if(reply->readAll().startsWith("null")) { - //bool put = true; - QTimer::singleShot(0, this, [=]() { - sendHTTP(true); - }); + QTimer::singleShot(0, this, SLOT(sendHTTPp())); } } }