mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 02:30:44 +00:00
Reduce PRS1Loader dependency on Machine data structure.
This commit is contained in:
parent
4bfe062ae9
commit
18e97bb025
@ -12,6 +12,11 @@
|
||||
#include "SleepLib/importcontext.h"
|
||||
|
||||
|
||||
ImportContext::ImportContext()
|
||||
: m_machine(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ImportContext::~ImportContext()
|
||||
{
|
||||
FlushUnexpectedMessages();
|
||||
@ -38,6 +43,24 @@ void ImportContext::FlushUnexpectedMessages()
|
||||
m_unexpectedMessages.clear();
|
||||
}
|
||||
|
||||
QString ImportContext::GetBackupPath()
|
||||
{
|
||||
Q_ASSERT(m_machine);
|
||||
return m_machine->getBackupPath();
|
||||
}
|
||||
|
||||
bool ImportContext::SessionExists(SessionID sid)
|
||||
{
|
||||
Q_ASSERT(m_machine);
|
||||
return m_machine->SessionExists(sid);
|
||||
}
|
||||
|
||||
Session* ImportContext::CreateSession(SessionID sid)
|
||||
{
|
||||
Q_ASSERT(m_machine);
|
||||
return new Session(m_machine, sid);
|
||||
}
|
||||
|
||||
|
||||
ProfileImportContext::ProfileImportContext(Profile* profile)
|
||||
: m_profile(profile)
|
||||
|
@ -16,7 +16,7 @@ class ImportContext : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImportContext() {}
|
||||
ImportContext();
|
||||
virtual ~ImportContext();
|
||||
|
||||
// Loaders will call this directly. It manages the machine's stored set of previously seen messages
|
||||
@ -32,6 +32,12 @@ public:
|
||||
|
||||
// TODO: Isolate the Machine object from the loader rather than returning it.
|
||||
virtual Machine* CreateMachineFromInfo(const MachineInfo & info) = 0;
|
||||
|
||||
// TODO: Eventually backup (and rebuild) should be handled invisibly to loaders.
|
||||
virtual QString GetBackupPath();
|
||||
|
||||
virtual bool SessionExists(SessionID sid);
|
||||
virtual Session* CreateSession(SessionID sid);
|
||||
|
||||
void FlushUnexpectedMessages();
|
||||
|
||||
|
@ -775,7 +775,7 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
emit updateMessage(QObject::tr("Backing Up Files..."));
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QString backupPath = m->getBackupPath() + path.section("/", -2);
|
||||
QString backupPath = context()->GetBackupPath() + path.section("/", -2);
|
||||
|
||||
if (QDir::cleanPath(path).compare(QDir::cleanPath(backupPath)) != 0) {
|
||||
copyPath(path, backupPath);
|
||||
@ -785,7 +785,7 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// Walk through the files and create an import task for each logical session.
|
||||
ScanFiles(paths, sessionid_base, m);
|
||||
ScanFiles(paths, sessionid_base);
|
||||
|
||||
int tasks = countTasks();
|
||||
|
||||
@ -907,7 +907,7 @@ static QString chunkComparison(const PRS1DataChunk* a, const PRS1DataChunk* b)
|
||||
|
||||
}
|
||||
|
||||
void PRS1Loader::ScanFiles(const QStringList & paths, int sessionid_base, Machine * m)
|
||||
void PRS1Loader::ScanFiles(const QStringList & paths, int sessionid_base)
|
||||
{
|
||||
Q_ASSERT(m_ctx);
|
||||
SessionID sid;
|
||||
@ -980,7 +980,7 @@ void PRS1Loader::ScanFiles(const QStringList & paths, int sessionid_base, Machin
|
||||
// chunks, which might not correspond to the filename. But before we can
|
||||
// fix this we need to come up with a reasonably fast way to filter previously
|
||||
// imported files without re-reading all of them.
|
||||
if (m->SessionExists(sid)) {
|
||||
if (context()->SessionExists(sid)) {
|
||||
// Skip already imported session
|
||||
qDebug() << path << "session already exists, skipping" << sid;
|
||||
continue;
|
||||
@ -1005,7 +1005,7 @@ void PRS1Loader::ScanFiles(const QStringList & paths, int sessionid_base, Machin
|
||||
// Should probably check if session already imported has this data missing..
|
||||
|
||||
// Create the group if we see it first..
|
||||
task = new PRS1Import(this, sid, m, sessionid_base);
|
||||
task = new PRS1Import(this, sid, sessionid_base);
|
||||
sesstasks[sid] = task;
|
||||
queTask(task);
|
||||
}
|
||||
@ -1055,7 +1055,7 @@ void PRS1Loader::ScanFiles(const QStringList & paths, int sessionid_base, Machin
|
||||
// the first available filename isn't the first session contained in the file.
|
||||
//qDebug() << fi.canonicalFilePath() << "first session is" << chunk_sid << "instead of" << sid;
|
||||
}
|
||||
if (m->SessionExists(chunk_sid)) {
|
||||
if (context()->SessionExists(chunk_sid)) {
|
||||
qDebug() << path << "session already imported, skipping" << sid << chunk_sid;
|
||||
delete chunk;
|
||||
continue;
|
||||
@ -1074,7 +1074,7 @@ void PRS1Loader::ScanFiles(const QStringList & paths, int sessionid_base, Machin
|
||||
if (it != sesstasks.end()) {
|
||||
task = it.value();
|
||||
} else {
|
||||
task = new PRS1Import(this, chunk_sid, m, sessionid_base);
|
||||
task = new PRS1Import(this, chunk_sid, sessionid_base);
|
||||
sesstasks[chunk_sid] = task;
|
||||
// save a loop an que this now
|
||||
queTask(task);
|
||||
@ -2505,7 +2505,7 @@ bool PRS1Import::ParseSession(void)
|
||||
{
|
||||
bool ok = false;
|
||||
bool save = false;
|
||||
session = new Session(mach, sessionid);
|
||||
session = loader->context()->CreateSession(sessionid);
|
||||
|
||||
do {
|
||||
if (compliance != nullptr) {
|
||||
@ -2639,7 +2639,7 @@ void PRS1Import::SaveSessionToDatabase(void)
|
||||
|
||||
// Save is not threadsafe
|
||||
loader->saveMutex.lock();
|
||||
session->Store(mach->getDataPath());
|
||||
session->Store(session->machine()->getDataPath());
|
||||
loader->saveMutex.unlock();
|
||||
|
||||
// Unload them from memory
|
||||
|
@ -67,7 +67,7 @@ class PRS1Loader;
|
||||
class PRS1Import:public ImportTask
|
||||
{
|
||||
public:
|
||||
PRS1Import(PRS1Loader * l, SessionID s, Machine * m, int base): loader(l), sessionid(s), mach(m), m_sessionid_base(base) {
|
||||
PRS1Import(PRS1Loader * l, SessionID s, int base): loader(l), sessionid(s), m_sessionid_base(base) {
|
||||
summary = nullptr;
|
||||
compliance = nullptr;
|
||||
session = nullptr;
|
||||
@ -117,7 +117,6 @@ protected:
|
||||
Session * session;
|
||||
PRS1Loader * loader;
|
||||
SessionID sessionid;
|
||||
Machine * mach;
|
||||
QHash<ChannelID,EventList*> m_importChannels; // map channel ID to the session's current EventList*
|
||||
|
||||
int summary_duration;
|
||||
@ -250,7 +249,7 @@ class PRS1Loader : public CPAPLoader
|
||||
Machine* CreateMachineFromProperties(QString propertyfile);
|
||||
|
||||
//! \brief Scans the given directories for session data and create an import task for each logical session.
|
||||
void ScanFiles(const QStringList & paths, int sessionid_base, Machine * m);
|
||||
void ScanFiles(const QStringList & paths, int sessionid_base);
|
||||
|
||||
// //! \brief Parses "properties.txt" file containing machine information
|
||||
// bool ParseProperties(Machine *m, QString filename);
|
||||
|
@ -103,7 +103,7 @@ void parseAndEmitSessionYaml(const QString & path)
|
||||
return;
|
||||
}
|
||||
|
||||
s_loader->ScanFiles(paths, sessionid_base, m);
|
||||
s_loader->ScanFiles(paths, sessionid_base);
|
||||
|
||||
// Each session now has a PRS1Import object in m_MLtasklist
|
||||
QList<ImportTask*>::iterator i;
|
||||
|
Loading…
Reference in New Issue
Block a user