From 162c92bc3b3a7dbe3d1484f7efc812aa36b23bcb Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Sun, 2 Jul 2023 12:11:28 +0100 Subject: Move fileaddrecord to common.h so that it can be used from qml plugin --- common.cpp | 15 +++++++++++++++ common.h | 1 + daemon/logger.cpp | 12 ------------ daemon/logger.h | 1 - daemon/sensorPlugins/heartrateSensor.cpp | 1 + daemon/sensorPlugins/stepCounter.cpp | 1 + 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/common.cpp b/common.cpp index 077bc4d..4c0f252 100644 --- a/common.cpp +++ b/common.cpp @@ -10,9 +10,24 @@ #include #include +#include +#include #include "common.h" QString fileNameForDate(QDate date, QString prefix) { QSettings settings("asteroid", "sensorlogd"); // this should be moved out of here at some point TODO return settings.value("loggerRootPath", QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + prefix + "/" + date.toString("yyyy-MM-dd.log"); } + +void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime) { //adds a record to today's log file for the given sensor + qDebug() << fileNameForDate(recordTime.date(), sensorPrefix); + QFile file(fileNameForDate(recordTime.date(), sensorPrefix)); + if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { + qDebug() << "failed to open file"; + return; + } + file.seek(file.size()); + QTextStream out(&file); + out << QString::number(recordTime.currentSecsSinceEpoch()) + ":" + logdata + "\n"; + file.close(); +} diff --git a/common.h b/common.h index 573b006..a6b3197 100644 --- a/common.h +++ b/common.h @@ -15,5 +15,6 @@ #include QString fileNameForDate(QDate date, QString prefix); +void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime = QDateTime::currentDateTime()); //adds a record to today's log file for the given sensor #endif //SENSORLOGD_COMMON_H diff --git a/daemon/logger.cpp b/daemon/logger.cpp index e8f75ba..7e06c63 100644 --- a/daemon/logger.cpp +++ b/daemon/logger.cpp @@ -111,18 +111,6 @@ bool Logger::getDaemonFresh() { } } -void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime) { //adds a record to today's log file for the given sensor - qDebug() << fileNameForDate(recordTime.date(), sensorPrefix); - QFile file(fileNameForDate(recordTime.date(), sensorPrefix)); - if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { - qDebug() << "failed to open file"; - return; - } - file.seek(file.size()); - QTextStream out(&file); - out << QString::number(recordTime.currentSecsSinceEpoch()) + ":" + logdata + "\n"; - file.close(); -} bool dayFileExists(QString sensorPrefix, QDateTime dateTime) { return QFile::exists(fileNameForDate(dateTime.date(), sensorPrefix)); } diff --git a/daemon/logger.h b/daemon/logger.h index 328c0d7..c16908d 100644 --- a/daemon/logger.h +++ b/daemon/logger.h @@ -47,7 +47,6 @@ private: bool getDaemonFresh(); }; - void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime = QDateTime::currentDateTime()); //adds a record to today's log file for the given sensor bool dayFileExists(QString sensorPrefix, QDateTime date = QDateTime::currentDateTime()); //check if today has a log file for the given sensor QStringList fileGetPrevRecord(QString sensorPrefix, QDateTime recordTime = QDateTime::currentDateTime()); //works backwards to find the last record in today's file before the given time - returns nothing if no file is found. void setupFilePath(QString sensorPrefix); //sets up the paths for sensors to write into diff --git a/daemon/sensorPlugins/heartrateSensor.cpp b/daemon/sensorPlugins/heartrateSensor.cpp index 8b329b9..d03703c 100644 --- a/daemon/sensorPlugins/heartrateSensor.cpp +++ b/daemon/sensorPlugins/heartrateSensor.cpp @@ -16,6 +16,7 @@ #include #include "../logger.h" +#include "../../common.h" #include "heartrateSensor.h" diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp index fd09e81..87c1c3c 100644 --- a/daemon/sensorPlugins/stepCounter.cpp +++ b/daemon/sensorPlugins/stepCounter.cpp @@ -19,6 +19,7 @@ #include #include "../logger.h" +#include "../../common.h" #include "stepCounter.h" -- cgit v1.2.3-54-g00ecf