31 m_description(QStringLiteral(
"IOTLogger")),
34 m_apiKey(QStringLiteral(
"")),
37 m_maxUpdateInterval(15),
38 m_lastUpdate(QDateTime::fromMSecsSinceEpoch(0)),
46 for (
int i = 0; i < 32; i++)
52 QMutexLocker locker(&
lock);
66 if (Details.contains(QStringLiteral(
"apikey")))
67 m_apiKey = Details.value(QStringLiteral(
"apikey")).toString().trimmed();
71 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1 logger has no api key - disabling").arg(
m_description));
75 if (Details.contains(QStringLiteral(
"fields")))
77 QVariantMap fields = Details.value(QStringLiteral(
"fields")).toMap();
80 QString field = QStringLiteral(
"field%1").arg(i +1);
81 if (fields.contains(field))
83 QString
value = fields.value(field).toString().trimmed();
95 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1 logger has no valid fields - disabling").arg(
m_description));
112 QMap<QString,int>::const_iterator it =
m_fields.constBegin();
113 for ( ; it !=
m_fields.constEnd(); ++it)
114 result << QStringLiteral(
"field%1: %2").arg(it.value() + 1).arg(it.key());
123 bool updated =
false;
126 QMutexLocker locker(&
lock);
128 QMap<QString,int>::const_iterator it =
m_fields.constBegin();
129 for ( ; it !=
m_fields.constEnd(); ++it)
131 if (Notification.contains(it.key()))
133 m_fieldValues[it.value()] = Notification.value(it.key()).toString();
150 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Not sending %1 update. Network is not available").arg(
m_description));
154 QDateTime now = QDateTime::currentDateTime();
176 QMutexLocker locker(&
lock);
187 QMutexLocker locker(&
lock);
190 LOG(VB_GENERAL, LOG_WARNING, QStringLiteral(
"Response to unknown %1 request").arg(
m_description));
201 if (Request->
GetReplyError() != QNetworkReply::HostNotFoundError)
205 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1 %2 update errors. Disabling logger - Check your config.")
virtual bool Initialise(const QVariantMap &Details)
virtual void SetValid(bool Valid)
void RequestReady(TorcNetworkRequest *Request)
QStringList GetDescription(void) overridefinal
A wrapper around QNetworkRequest.
static bool GetAsynchronous(TorcNetworkRequest *Request, QObject *Parent)
Queue an asynchronous HTTP request.
QMap< QString, int > m_fields
static QString StatusToString(HTTPStatus Status)
QMap< int, QString > m_reverseFields
QNetworkReply::NetworkError GetReplyError(void) const
static bool IsAvailable(void)
virtual bool DownRef(void)
TorcIOTLogger(const QVariantMap &Details)
virtual void ProcessRequest(TorcNetworkRequest *Request)=0
void Notify(const QVariantMap &Notification) override
virtual TorcNetworkRequest * CreateRequest(void)=0
QList< TorcNetworkRequest * > m_requests
QString m_fieldValues[32]
#define LOG(_MASK_, _LEVEL_, _STRING_)
static void Cancel(TorcNetworkRequest *Request)
int GetStatus(void) const
void StartTimer(int Milliseconds)