/** * DbWriter for RecordingManagement * $Id$ * $HeadURL$ * $Author$ */ #pragma once #include #include #include #include #include #include "logger.h" class NSqlQuery; namespace NGL { class Settings; } namespace RecordReplay { class RecordReplayPlugin; } namespace RecordingManagement { class DatabaseInterface; class DbWriterSnapshot : public QObject { Q_OBJECT public: explicit DbWriterSnapshot(const QVector &plugins, int exerciseId, NGL::Settings *settings); ~DbWriterSnapshot(); /** * Set the minimum sample time per topic which was found during the last record calls * to ensure, that all telegrams are considered during snapshot creation * because some telegrams can come in very later (tetra buffering / player unit out of tetra coverage) */ void setMinRecordedSampleTimes(const QHash &minRecordedSampleTimes); void init(); void cleanup(); private: static QString dbConnectionName() { return QStringLiteral("DbWriterSnapshotThread"); } void initSnapshot(); QHash getMinRecordedSampleTimes(qint64 getUntil); void writeSnapshotData(); void writeSnapshotDataPlugin(qint64 endInterval, NSqlQuery &recSnapshotQuery, RecordReplay::RecordReplayPlugin *recPlugin, const QHash &minRecordedSampleTimes); private: QVector m_plugins; int m_snapshotInterval; QHash m_minRecordedSampleTimes; // do not access directly, only through minRecordedSampleTime() QMutex m_minRecordedSampleTimesMutex; std::shared_ptr m_dbInterface; int m_exerciseId; NGL::Settings *m_settings; LOGGER_T m_logger; }; class DbWriterSnapshotThread : public QThread { Q_OBJECT public: DbWriterSnapshotThread(DbWriterSnapshot *dbWriterSnapshot, QObject *parent = nullptr) : QThread(parent) , m_dbWriterSnapshot(dbWriterSnapshot) {} protected: void run() override final; private: DbWriterSnapshot *m_dbWriterSnapshot; }; } // namespace RecordingManagement