This commit is contained in:
brindosch 2017-05-29 21:34:47 +02:00
parent e2ca9bcaa5
commit a7f72a7bf2
3 changed files with 39 additions and 51 deletions

View File

@ -1,11 +1,9 @@
// qt includes
#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QUrlQuery>
#include <QEventLoop>
#include <QTimer>
// 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);
};

View File

@ -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)

View File

@ -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()));
}
}
}