diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2023-05-31 18:20:42 +0100 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2023-06-01 13:32:13 +0100 |
commit | c1e9b5f8a2d287865db3a4d5d056ecf736e05b24 (patch) | |
tree | b76929fcd3df118aafb006b529e4a46093a48323 /daemon/logger.cpp | |
parent | 7a8565498f9894a6d8fbb8cd4462048a4c603418 (diff) |
Add a check for whether the daemon is starting the first time this boot
Diffstat (limited to 'daemon/logger.cpp')
-rw-r--r-- | daemon/logger.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/daemon/logger.cpp b/daemon/logger.cpp index 65b5c2b..d4b4d14 100644 --- a/daemon/logger.cpp +++ b/daemon/logger.cpp @@ -35,6 +35,7 @@ Logger::Logger(QObject *parent) : void Logger::setup() { m_iface = new QDBusInterface("com.nokia.mce","/com/nokia/mce/signal", "com.nokia.mce.signal", QDBusConnection::systemBus()); settings = new QSettings; + daemonFresh = getDaemonFresh(); heartrateSensorEnabled = this->settings->value("heartrateSensor/enabled",true).toBool(); stepCounterEnabled = this->settings->value("stepCounter/enabled",true).toBool(); @@ -46,7 +47,7 @@ void Logger::setup() { //initialise step counter if (stepCounterEnabled) { - m_stepCounter = new StepCounterPlugin(this,settings->value("stepCounter/interval",600000).toInt()); + m_stepCounter = new StepCounterPlugin(this,settings->value("stepCounter/interval",600000).toInt(),daemonFresh); } if(!m_iface->isValid()) { @@ -89,6 +90,26 @@ void Logger::triggerRecording() { } } +bool Logger::getDaemonFresh() { + QFile file("/proc/sys/kernel/random/boot_id"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "failed to open bootId"; + return 0; + } + QTextStream inStream(&file); + QString currBootId = inStream.readAll().trimmed(); + file.close(); + QSettings settings("asteroid","sensorlogd"); + if(currBootId == settings.value("lastBootId","")) { + qDebug() << "daemon is not starting for first time this boot"; + return false; + } else { + settings.setValue("lastBootId",currBootId); + qDebug() << "daemon is starting for first time this boot"; + return true; + } +} + 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)); @@ -135,3 +156,4 @@ void setupFilePath(QString sensorPrefix) { QDir::root().mkpath(settings.value("loggerRootPath",QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + sensorPrefix); } + |