Pass strings as const references in MachineLoaders

This commit is contained in:
Mark Watkins 2018-04-27 14:29:03 +10:00
parent 2ef5170940
commit 53addb62e7
28 changed files with 144 additions and 409 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@
*.so
*.dll
*.dylib
*.qm
# Qt-es

View File

@ -65,7 +65,7 @@ bool CMS50Loader::Detect(const QString &path)
return false;
}
int CMS50Loader::Open(QString path)
int CMS50Loader::Open(const QString & path)
{
// Only one active Oximeter module at a time, set in preferences

View File

@ -1,4 +1,4 @@
/* SleepLib CMS50X Loader Header
/* SleepLib CMS50X Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -28,7 +28,7 @@ Q_OBJECT
virtual ~CMS50Loader();
virtual bool Detect(const QString &path);
virtual int Open(QString path);
virtual int Open(const QString & path);
static void Register();

View File

@ -115,7 +115,7 @@ bool CMS50F37Loader::Detect(const QString &path)
return false;
}
int CMS50F37Loader::Open(QString path)
int CMS50F37Loader::Open(const QString & path)
{
// Only one active Oximeter module at a time, set in preferences
@ -850,7 +850,7 @@ void CMS50F37Loader::shutdownPorts()
bool CMS50F37Loader::readSpoRFile(QString path)
bool CMS50F37Loader::readSpoRFile(const QString & path)
{
QFile file(path);
if (!file.exists()) {

View File

@ -1,4 +1,4 @@
/* SleepLib CMS50X Loader Header
/* SleepLib CMS50X Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -28,7 +28,7 @@ Q_OBJECT
virtual ~CMS50F37Loader();
virtual bool Detect(const QString &path);
virtual int Open(QString path);
virtual int Open(const QString & path);
virtual bool openDevice();
@ -89,7 +89,7 @@ protected slots:
protected:
bool readSpoRFile(QString path);
bool readSpoRFile(const QString & path);
virtual void processBytes(QByteArray bytes);
// int doLiveMode();

View File

@ -211,7 +211,7 @@ bool EDFParser::Parse()
return true;
}
bool EDFParser::Open(QString name)
bool EDFParser::Open(const QString & name)
{
if (buffer != nullptr) {
qWarning() << "EDFParser::Open() called with buffer already initialized";
@ -282,7 +282,7 @@ badfile:
return false;
}
EDFSignal *EDFParser::lookupLabel(QString name, int index)
EDFSignal *EDFParser::lookupLabel(const QString & name, int index)
{
QHash<QString, QList<EDFSignal *> >::iterator it = signalList.find(name);

View File

@ -105,7 +105,7 @@ class EDFParser
~EDFParser();
//! \brief Open the EDF+ file, and read it's header
bool Open(QString name);
bool Open(const QString & name);
//! \brief Read n bytes of 8 bit data from the EDF+ data stream
QString Read(unsigned n);
@ -124,7 +124,7 @@ class EDFParser
QList<EDFSignal *> signal;
EDFSignal *lookupLabel(QString name, int index=0);
EDFSignal *lookupLabel(const QString & name, int index=0);
//! \brief Returns the number of signals contained in this EDF file
long GetNumSignals() { return num_signals; }

View File

@ -73,20 +73,21 @@ bool FPIconLoader::Detect(const QString & givenpath)
}
int FPIconLoader::Open(QString path)
int FPIconLoader::Open(const QString & path)
{
QString newpath;
QString tmp = path;
path = path.replace("\\", "/");
if (path.endsWith("/")) {
path.chop(1);
tmp = tmp.replace("\\", "/");
if (tmp.endsWith("/")) {
tmp.chop(1);
}
if (path.endsWith("/" + FPHCARE)) {
newpath = path;
QString newpath;
if (tmp.endsWith("/" + FPHCARE)) {
newpath = tmp;
} else {
newpath = path + "/" + FPHCARE;
newpath = tmp + "/" + FPHCARE;
}
newpath += "/ICON/";
@ -179,7 +180,7 @@ bool operator<(const FPWaveChunk &a, const FPWaveChunk &b)
return (a.st < b.st);
}
int FPIconLoader::OpenMachine(Machine *mach, QString &path)
int FPIconLoader::OpenMachine(Machine *mach, const QString & path)
{
qDebug() << "Opening FPIcon " << path;
QDir dir(path);
@ -425,7 +426,7 @@ hour=(ts >> 12) & 0x1f; */
// 0x01ff 8 bit additive sum checksum byte of previous header bytes
// 0x0200-0x0203 32bit timestamp in
bool FPIconLoader::OpenFLW(Machine *mach, QString filename)
bool FPIconLoader::OpenFLW(Machine *mach, const QString & filename)
{
Q_UNUSED(mach);
@ -621,7 +622,7 @@ bool FPIconLoader::OpenFLW(Machine *mach, QString filename)
////////////////////////////////////////////////////////////////////////////////////////////
// Open Summary file
////////////////////////////////////////////////////////////////////////////////////////////
bool FPIconLoader::OpenSummary(Machine *mach, QString filename)
bool FPIconLoader::OpenSummary(Machine *mach, const QString & filename)
{
qDebug() << filename;
QByteArray header;
@ -771,7 +772,7 @@ bool FPIconLoader::OpenSummary(Machine *mach, QString filename)
return true;
}
bool FPIconLoader::OpenDetail(Machine *mach, QString filename)
bool FPIconLoader::OpenDetail(Machine *mach, const QString & filename)
{
Q_UNUSED(mach);

View File

@ -1,4 +1,4 @@
/* SleepLib Fisher & Paykel Icon Loader Implementation
/* SleepLib Fisher & Paykel Icon Loader Implementation
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -55,13 +55,13 @@ class FPIconLoader : public CPAPLoader
virtual bool Detect(const QString & path);
//! \brief Scans path for F&P Icon data signature, and Loads any new data
virtual int Open(QString path);
virtual int Open(const QString & path);
int OpenMachine(Machine *mach, QString &path);
int OpenMachine(Machine *mach, const QString &path);
bool OpenSummary(Machine *mach, QString path);
bool OpenDetail(Machine *mach, QString path);
bool OpenFLW(Machine *mach, QString filename);
bool OpenSummary(Machine *mach, const QString & path);
bool OpenDetail(Machine *mach, const QString & path);
bool OpenFLW(Machine *mach, const QString & filename);
//! \brief Returns SleepLib database version of this F&P Icon loader
virtual int Version() { return fpicon_data_version; }

View File

@ -84,7 +84,7 @@ bool IntellipapLoader::Detect(const QString & givenpath)
enum INTPAP_Type { INTPAP_Unknown, INTPAP_DV5, INTPAP_DV6 };
int IntellipapLoader::OpenDV5(QString path)
int IntellipapLoader::OpenDV5(const QString & path)
{
QString newpath = path + SL_DIR;
QString filename;
@ -642,7 +642,7 @@ struct DV6_S_Record
};
int IntellipapLoader::OpenDV6(QString path)
int IntellipapLoader::OpenDV6(const QString & path)
{
QString newpath = path + DV6_DIR;
@ -1457,10 +1457,11 @@ int IntellipapLoader::OpenDV6(QString path)
return summaryList.size();
}
int IntellipapLoader::Open(QString path)
int IntellipapLoader::Open(const QString & dirpath)
{
// Check for SL directory
// Check for DV5MFirm.bin?
QString path(dirpath);
path = path.replace("\\", "/");
if (path.endsWith(SL_DIR)) {

View File

@ -1,4 +1,4 @@
/* Intellipap Loader Header
/* Intellipap Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -55,11 +55,11 @@ class IntellipapLoader : public CPAPLoader
virtual bool Detect(const QString & path);
//! \brief Scans path for Intellipap data signature, and Loads any new data
virtual int Open(QString path);
virtual int Open(const QString & path);
//! \brief Scans path for Intellipap DV5 data signature, and Loads any new data
virtual int OpenDV5(QString path);
virtual int OpenDV5(const QString & path);
//! \brief Scans path for Intellipap DV6 data signature, and Loads any new data
virtual int OpenDV6(QString path);
virtual int OpenDV6(const QString & path);
//! \brief Returns SleepLib database version of this IntelliPap loader
virtual int Version() { return intellipap_data_version; }

View File

@ -1,4 +1,4 @@
/* SleepLib ChoiceMMed MD300W1 Oximeter Loader Implementation
/* SleepLib ChoiceMMed MD300W1 Oximeter Loader Implementation
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -61,7 +61,7 @@ bool MD300W1Loader::Detect(const QString &path)
return false;
}
int MD300W1Loader::Open(QString path)
int MD300W1Loader::Open(const QString & path)
{
// Only one active Oximeter module at a time, set in preferences
@ -156,7 +156,7 @@ void MD300W1Loader::resetImportTimeout()
// 0 0 id yr mm dd hh mm ss o2 pulse
// report title etc.
bool MD300W1Loader::readDATFile(QString path)
bool MD300W1Loader::readDATFile(const QString & path)
{
QFile file(path);

View File

@ -1,4 +1,4 @@
/* SleepLib ChoiceMMed MD300W1 Oximeter Loader Header
/* SleepLib ChoiceMMed MD300W1 Oximeter Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -26,7 +26,7 @@ Q_OBJECT
virtual ~MD300W1Loader();
virtual bool Detect(const QString &path);
virtual int Open(QString path);
virtual int Open(const QString & path);
static void Register();
@ -50,7 +50,7 @@ protected slots:
protected:
bool readDATFile(QString path);
bool readDATFile(const QString & path);
virtual void processBytes(QByteArray bytes);
int doImportMode();

View File

@ -1,4 +1,4 @@
/* SleepLib RemStar M-Series Loader Implementation
/* SleepLib RemStar M-Series Loader Implementation
*
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -109,7 +109,7 @@ blockLayoutOffsets {
*/
int MSeriesLoader::Open(QString path)
int MSeriesLoader::Open(const QString & path)
{
// Until a smartcard reader is written, this is not an auto-scanner.. it just opens a block file..

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sts=4 et sw=4 tw=99:
*
* SleepLib RemStar M-Series Loader Header
@ -51,7 +51,7 @@ class MSeriesLoader : public MachineLoader
virtual bool Detect(const QString & path) { Q_UNUSED(path); return false; }
//! \brief Opens M-Series block device
virtual int Open(QString file);
virtual int Open(const QString & file);
//! \brief Returns the database version of this loader
virtual int Version() { return mseries_data_version; }

View File

@ -215,7 +215,7 @@ QString PRS1Loader::checkDir(const QString & path)
return machpath;
}
void parseModel(MachineInfo & info, QString modelnum)
void parseModel(MachineInfo & info, const QString & modelnum)
{
info.modelnumber = modelnum;
@ -290,7 +290,7 @@ void parseModel(MachineInfo & info, QString modelnum)
}
}
bool PRS1Loader::PeekProperties(MachineInfo & info, QString filename, Machine * mach)
bool PRS1Loader::PeekProperties(MachineInfo & info, const QString & filename, Machine * mach)
{
QFile f(filename);
if (!f.open(QFile::ReadOnly)) {
@ -364,9 +364,10 @@ MachineInfo PRS1Loader::PeekInfo(const QString & path)
}
int PRS1Loader::Open(QString path)
int PRS1Loader::Open(const QString & dirpath)
{
QString newpath;
QString path(dirpath);
path = path.replace("\\", "/");
if (path.endsWith("/" + PR_STR_PSeries)) {
@ -493,7 +494,7 @@ int PRS1Loader::Open(QString path)
return true;
}*/
int PRS1Loader::OpenMachine(QString path)
int PRS1Loader::OpenMachine(const QString & path)
{
if (p_profile == nullptr) {
qWarning() << "PRS1Loader::OpenMachine() called without a valid p_profile object present";
@ -676,7 +677,7 @@ int PRS1Loader::OpenMachine(QString path)
}
// Parse the data chunks and read the files..
QList<PRS1DataChunk *> Chunks = ParseFile2(fi.canonicalFilePath());
QList<PRS1DataChunk *> Chunks = ParseFile(fi.canonicalFilePath());
for (int i=0; i < Chunks.size(); ++i) {
PRS1DataChunk * chunk = Chunks.at(i);
@ -2848,10 +2849,10 @@ void PRS1Import::run()
if ((compliance && ParseCompliance()) || (summary && ParseSummary())) {
if (event && !ParseEvents()) {
}
waveforms = loader->ParseFile2(wavefile);
waveforms = loader->ParseFile(wavefile);
ParseWaveforms();
oximetery = loader->ParseFile2(oxifile);
oximetery = loader->ParseFile(oxifile);
ParseOximetery();
if (session->first() > 0) {
@ -2884,7 +2885,7 @@ void PRS1Import::run()
}
QList<PRS1DataChunk *> PRS1Loader::ParseFile2(QString path)
QList<PRS1DataChunk *> PRS1Loader::ParseFile(const QString & path)
{
QList<PRS1DataChunk *> CHUNKS;
@ -2980,33 +2981,6 @@ QList<PRS1DataChunk *> PRS1Loader::ParseFile2(QString path)
header_size += hdb_size+1;
} else headerB2 = QByteArray();
/* if (ext == 1) { // Summary Chunk
if ((family == 0) && (familyVersion == 6)) {
header_size = 43;
} else if ((family == 5) && (familyVersion == 3)) {
header_size = 37;
}
} else if (ext == 2) { // Event Chunk
if (familyVersion == 3) {
if (family == 3) {
header_size = 62;
} else if (family == 5) { // ASV
header_size = 49;
}
} else if ((familyVersion==6) && (family==0)) {
header_size=61;
}
}
extra_bytes = header_size - 16; // remainder of the header bytes to read, including the 8bit additive checksum.
// Read the extra header bytes
extra = f.read(extra_bytes);
if (extra.size() != extra_bytes) {
break;
}
headerBA.append(extra); */
} else { // Waveform Chunk
extra = f.read(4);
if (extra.size() != 4) {
@ -3195,265 +3169,6 @@ QList<PRS1DataChunk *> PRS1Loader::ParseFile2(QString path)
return CHUNKS;
}
QList<PRS1DataChunk *> PRS1Loader::ParseFile(QString path)
{
QList<PRS1DataChunk *> CHUNKS;
if (path.isEmpty())
return CHUNKS;
QFile f(path);
if (!f.exists()) {
return CHUNKS;
}
if (!f.open(QIODevice::ReadOnly)) {
return CHUNKS;
}
PRS1DataChunk *chunk = nullptr, *lastchunk = nullptr;
quint16 blocksize;
quint16 wvfm_signals;
unsigned char * header;
int cnt = 0;
//int lastheadersize = 0;
int lastblocksize = 0;
int cruft = 0;
int firstsession = 0;
do {
QByteArray headerBA = f.read(16);
if (headerBA.size() != 16) {
break;
}
header = (unsigned char *)headerBA.data();
blocksize = (header[2] << 8) | header[1];
if (blocksize == 0) break;
chunk = new PRS1DataChunk();
chunk->sessionid = (header[10] << 24) | (header[9] << 16) | (header[8] << 8) | header[7];
if (!firstsession) {
firstsession = chunk->sessionid;
}
chunk->fileVersion = header[0];
chunk->htype = header[3]; // 00 = normal ?? // 01=waveform ?? // could be a bool signifying extra header bytes?
chunk->family = header[4];
chunk->familyVersion = header[5];
chunk->ext = header[6];
chunk->timestamp = (header[14] << 24) | (header[13] << 16) | (header[12] << 8) | header[11];
if (lastchunk != nullptr) {
if ((lastchunk->fileVersion != chunk->fileVersion)
&& (lastchunk->ext != chunk->ext)
&& (lastchunk->family != chunk->family)
&& (lastchunk->familyVersion != chunk->familyVersion)
&& (lastchunk->htype != chunk->htype)) {
QByteArray junk = f.read(lastblocksize - 16);
Q_UNUSED(junk)
if (lastchunk->ext == 5) {
// The data is random crap
// lastchunk->m_data.append(junk.mid(lastheadersize-16));
}
delete chunk;
++cruft;
if (cruft > 3)
break;
continue;
// Corrupt header.. skip it.
}
}
int diff = 0;
//////////////////////////////////////////////////////////
// Family 3 (1060P)
//////////////////////////////////////////////////////////
if ((chunk->family == 3) && (chunk->ext == 2)) {
QByteArray extra = f.read(47);
if (extra.size() != 47) {
delete chunk;
break;
}
headerBA.append(extra);
header = (unsigned char *)headerBA.data();
chunk->m_headerblock = headerBA.right(48);
}
//////////////////////////////////////////////////////////
// Waveform Header
//////////////////////////////////////////////////////////
if ((chunk->ext == 5) || (chunk->ext == 6)) {
// Get extra 8 bytes in waveform header.
QByteArray extra = f.read(4);
if (extra.size() != 4) {
delete chunk;
break;
}
headerBA.append(extra);
// Get the header address again to be safe
header = (unsigned char *)headerBA.data();
chunk->duration = header[0x0f] | header[0x10] << 8;
wvfm_signals = header[0x12] | header[0x13] << 8;
int ws_size = (chunk->fileVersion == 3) ? 4 : 3;
int sbsize = wvfm_signals * ws_size + 1;
QByteArray sbextra = f.read(sbsize);
if (sbextra.size() != sbsize) {
delete chunk;
break;
}
headerBA.append(sbextra);
header = (unsigned char *)headerBA.data();
// Read the waveform information in reverse.
int pos = 0x14 + (wvfm_signals - 1) * ws_size;
for (int i = 0; i < wvfm_signals; ++i) {
quint16 interleave = header[pos] | header[pos + 1] << 8; // samples per block (Usually 05 00)
if (chunk->fileVersion == 2) {
quint8 sample_format = header[pos + 2];
chunk->waveformInfo.push_back(PRS1Waveform(interleave, sample_format));
pos -= 3;
} else if (chunk->fileVersion == 3) {
//quint16 sample_size = header[pos + 2] | header[pos + 3] << 8; // size in bits?? (08 00)
// Possibly this is size in bits, and sign bit for the other byte?
chunk->waveformInfo.push_back(PRS1Waveform(interleave, 0));
pos -= 4;
}
}
if (lastchunk != nullptr) {
diff = (chunk->timestamp - lastchunk->timestamp) - lastchunk->duration;
}
}
int headersize = headerBA.size();
lastblocksize = blocksize;
blocksize -= headersize;
//lastheadersize = headersize;
// Check header checksum
quint8 csum = 0;
for (int i=0; i < headersize-1; ++i) csum += header[i];
if ((chunk->fileVersion==2) || (chunk->ext >= 5)) {
if (csum != header[headersize-1]) {
// header checksum error.
delete chunk;
return CHUNKS;
}
} else if ((chunk->fileVersion==3) && (chunk->ext <= 2)) {
// DreamStation has an additional block of data following the timestamp, preceded by a length count,
// followed by the additive checksum
char len = header[headersize-1];
csum += len;
int h2len = len*2+1;
blocksize -= h2len;
// Read the extra data block
chunk->m_headerblock = f.read(h2len);
if (chunk->m_headerblock.size() < h2len) {
delete chunk;
return CHUNKS;
}
unsigned char * header2 = (unsigned char*) chunk->m_headerblock.data();
// Checksum the whole header
for (int i=0; i < h2len-1; ++i) csum += header2[i];
if (csum != header2[h2len-1]) {
// header checksum error.
delete chunk;
return CHUNKS;
}
} else {
// uhhhh.. should not of got this far. because this is an unknown or corrupt file format.
delete chunk;
return CHUNKS;
}
// Read data block
chunk->m_data = f.read(blocksize);
if (chunk->m_data.size() < blocksize) {
delete chunk;
break;
}
if (chunk->fileVersion==3) {
//int ds = chunk->m_data.size();
//quint32 crc16 = chunk->m_data.at(ds-2) | chunk->m_data.at(ds-1) << 8;
chunk->m_data.chop(4);
} else {
// last two bytes contain crc16 checksum.
int ds = chunk->m_data.size();
quint16 crc16 = chunk->m_data.at(ds-2) | chunk->m_data.at(ds-1) << 8;
chunk->m_data.chop(2);
#ifdef PRS1_CRC_CHECK
// This fails.. it needs to include the header!
quint16 calc16 = CRC16((unsigned char *)chunk->m_data.data(), chunk->m_data.size());
if (calc16 != crc16) {
// corrupt data block.. bleh..
// qDebug() << "CRC16 doesn't match for chunk" << chunk->sessionid << "for" << path;
}
#endif
}
if ((chunk->ext == 5) || (chunk->ext == 6)) { // if Flow/MaskPressure Waveform or OXI Waveform file
if (lastchunk != nullptr) {
if (lastchunk->sessionid != chunk->sessionid) {
qWarning() << "lastchunk->sessionid != chunk->sessionid in PRS1Loader::ParseFile()";
break;
}
if (diff == 0) {
// In sync, so append waveform data to previous chunk
lastchunk->m_data.append(chunk->m_data);
lastchunk->duration += chunk->duration;
delete chunk;
cnt++;
chunk = lastchunk;
continue;
}
// else start a new chunk to resync
}
}
CHUNKS.append(chunk);
lastchunk = chunk;
cnt++;
} while (!f.atEnd());
return CHUNKS;
}
void InitModelMap()
{
ModelMap[0x34] = QObject::tr("RemStar Pro with C-Flex+"); // 450/460P

View File

@ -1,4 +1,4 @@
/* SleepLib PRS1 Loader Header
/* SleepLib PRS1 Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -185,7 +185,7 @@ class PRS1Loader : public CPAPLoader
QString checkDir(const QString & path);
//! \brief Peek into PROP.TXT or properties.txt at given path, and use it to fill MachineInfo structure
bool PeekProperties(MachineInfo & info, QString path, Machine * mach = nullptr);
bool PeekProperties(MachineInfo & info, const QString & path, Machine * mach = nullptr);
//! \brief Detect if the given path contains a valid Folder structure
virtual bool Detect(const QString & path);
@ -194,7 +194,7 @@ class PRS1Loader : public CPAPLoader
virtual MachineInfo PeekInfo(const QString & path);
//! \brief Scans directory path for valid PRS1 signature
virtual int Open(QString path);
virtual int Open(const QString & path);
//! \brief Returns the database version of this loader
virtual int Version() { return prs1_data_version; }
@ -203,8 +203,7 @@ class PRS1Loader : public CPAPLoader
virtual const QString &loaderName() { return prs1_class_name; }
//! \brief Parse a PRS1 summary/event/waveform file and break into invidivual session or waveform chunks
QList<PRS1DataChunk *> ParseFile(QString path);
QList<PRS1DataChunk *> ParseFile2(QString path);
QList<PRS1DataChunk *> ParseFile(const QString & path);
//! \brief Register this Module to the list of Loaders, so it knows to search for PRS1 data.
static void Register();
@ -237,13 +236,13 @@ class PRS1Loader : public CPAPLoader
QHash<QString, Machine *> PRS1List;
//! \brief Opens the SD folder structure for this machine, scans for data files and imports any new sessions
int OpenMachine(QString path);
int OpenMachine(const QString & path);
// //! \brief Parses "properties.txt" file containing machine information
// bool ParseProperties(Machine *m, QString filename);
//! \brief Parse a .005 waveform file, extracting Flow Rate waveform (and Mask Pressure data if available)
bool OpenWaveforms(SessionID sid, QString filename);
bool OpenWaveforms(SessionID sid, const QString & filename);
//! \brief Parse a data chunk from the .000 (brick) and .001 (summary) files.
bool ParseSummary(Machine *mach, qint32 sequence, quint32 timestamp, unsigned char *data,
@ -252,7 +251,7 @@ class PRS1Loader : public CPAPLoader
//! \brief Open a PRS1 data file, and break into data chunks, delivering them to the correct parser.
bool OpenFile(Machine *mach, QString filename);
bool OpenFile(Machine *mach, const QString & filename);
QHash<SessionID, Session *> extra_session;

View File

@ -116,10 +116,10 @@ bool matchSignal(ChannelID ch, const QString & name)
void ResmedLoader::ParseSTR(Machine *mach, QStringList strfiles)
void ResmedLoader::ParseSTR(Machine *mach, const QStringList & strfiles)
{
QStringList::iterator strend = strfiles.end();
for (QStringList::iterator it = strfiles.begin(); it != strend; ++it) {
const QStringList::const_iterator strend = strfiles.cend();
for (QStringList::const_iterator it = strfiles.cbegin(); it != strend; ++it) {
ResMedEDFParser str(*it);
if (!str.Parse()) continue;
if (mach->serial() != str.serialnumber) {
@ -133,6 +133,8 @@ void ResmedLoader::ParseSTR(Machine *mach, QStringList strfiles)
qDebug() << "Parsing" << *it << date << str.GetNumDataRecords() << str.GetNumSignals();
// ResMed and their consistent naming and spacing... :/
EDFSignal *maskon = str.lookupLabel("Mask On");
if (!maskon) {
maskon = str.lookupLabel("MaskOn");
@ -141,6 +143,7 @@ void ResmedLoader::ParseSTR(Machine *mach, QStringList strfiles)
if (!maskoff) {
maskoff = str.lookupLabel("MaskOff");
}
EDFSignal *sig = nullptr;
quint32 laston = 0;
@ -1076,7 +1079,7 @@ struct EDFduration {
EDFType type;
};
EDFType lookupEDFType(QString text)
EDFType lookupEDFType(const QString & text)
{
if (text == "EVE") {
return EDF_EVE;
@ -1214,7 +1217,7 @@ int PeekAnnotations(const QString & path, quint32 &start, quint32 &end)
// Looks inside an EDF or EDF.gz and grabs the start and duration
EDFduration getEDFDuration(QString filename)
EDFduration getEDFDuration(const QString & filename)
{
QString ext = filename.section("_", -1).section(".",0,0).toUpper();
@ -1341,7 +1344,7 @@ EDFduration getEDFDuration(QString filename)
return dur;
}
int ResmedLoader::scanFiles(Machine * mach, QString datalog_path)
int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
{
QHash<QString, SessionID> skipfiles;
@ -1740,7 +1743,7 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path)
return c;
}
int ResmedLoader::Open(QString path)
int ResmedLoader::Open(const QString & dirpath)
{
QString key, value;
@ -1750,6 +1753,7 @@ int ResmedLoader::Open(QString path)
QHash<QString, QString> idmap; // Temporary properties hash
QString path(dirpath);
path = path.replace("\\", "/");
// Strip off end "/" if any
@ -2141,7 +2145,7 @@ int ResmedLoader::Open(QString path)
}
QString ResmedLoader::backup(QString fullname, QString backup_path)
QString ResmedLoader::backup(const QString & fullname, const QString & backup_path)
{
bool compress = p_profile->session->compressBackupData();

View File

@ -26,7 +26,7 @@ const int resmed_data_version = 11;
enum EDFType { EDF_UNKNOWN, EDF_BRP, EDF_PLD, EDF_SAD, EDF_EVE, EDF_CSL };
EDFType lookupEDFType(QString text);
EDFType lookupEDFType(const QString & text);
const QString resmed_class_name = STR_MACH_ResMed;
@ -193,12 +193,11 @@ struct STRRecord
};
class ResmedLoader;
struct EDFGroup {
EDFGroup() { }
EDFGroup(QString brp, QString eve, QString pld, QString sad, QString csl) {
EDFGroup(QString &brp, QString &eve, QString &pld, QString &sad, QString &csl) {
BRP = brp;
EVE = eve;
CSL = csl;
@ -261,13 +260,11 @@ class ResmedLoader : public CPAPLoader
//! \brief Detect if the given path contains a valid Folder structure
virtual bool Detect(const QString & path);
//! \brief Look up machine model information of ResMed file structure stored at path
virtual MachineInfo PeekInfo(const QString & path);
//! \brief Scans for ResMed SD folder structure signature, and loads any new data if found
virtual int Open(QString path);
virtual int Open(const QString &);
//! \brief Returns the version number of this ResMed loader
virtual int Version() { return resmed_data_version; }
@ -322,12 +319,12 @@ class ResmedLoader : public CPAPLoader
protected:
void ParseSTR(Machine *mach, QStringList strfiles);
void ParseSTR(Machine *mach, const QStringList & strfiles);
//! \brief Scan for new files to import, group into sessions and add to task que
int scanFiles(Machine * mach, QString datalog_path);
int scanFiles(Machine * mach, const QString & datalog_path);
QString backup(QString file, QString backup_path);
QString backup(const QString & file, const QString & backup_path);
QMap<SessionID, QStringList> sessfiles;
QMap<quint32, STRRecord> strsess;

View File

@ -1,4 +1,4 @@
/* SleepLib Somnopose Loader Implementation
/* SleepLib Somnopose Loader Implementation
*
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -26,16 +26,15 @@ SomnoposeLoader::SomnoposeLoader()
SomnoposeLoader::~SomnoposeLoader()
{
}
int SomnoposeLoader::Open(QString path)
int SomnoposeLoader::Open(const QString & dirpath)
{
Q_UNUSED(path)
QString newpath;
QString dirtag = "somnopose";
// Could Scan the ZEO folder for a list of CSVs
QString path(dirpath);
path = path.replace("\\", "/");
if (path.toLower().endsWith("/" + dirtag)) {
@ -52,7 +51,7 @@ int SomnoposeLoader::Open(QString path)
return 0; // number of machines affected
}
int SomnoposeLoader::OpenFile(QString filename)
int SomnoposeLoader::OpenFile(const QString & filename)
{
QFile file(filename);

View File

@ -1,4 +1,4 @@
/* SleepLib Somnopose Loader Header
/* SleepLib Somnopose Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -26,8 +26,8 @@ class SomnoposeLoader : public MachineLoader
virtual bool Detect(const QString & path) { Q_UNUSED(path); return false; } // bypass autoscanner
virtual int Open(QString path);
virtual int OpenFile(QString filename);
virtual int Open(const QString & path);
virtual int OpenFile(const QString & filename);
static void Register();
virtual int Version() { return somnopose_data_version; }

View File

@ -1,4 +1,4 @@
/* SleepLib Weinmann SOMNOsoft/Balance Loader Implementation
/* SleepLib Weinmann SOMNOsoft/Balance Loader Implementation
*
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -114,9 +114,9 @@ void HighPass(char * data, int samples, float cutoff, float dt)
delete [] Y;
}
int WeinmannLoader::Open(QString path)
int WeinmannLoader::Open(const QString & dirpath)
{
QString path(dirpath);
path = path.replace("\\", "/");
QFile wmdata(path + "/WM_DATA.TDF");

View File

@ -1,4 +1,4 @@
/* SleepLib Weinmann SOMNOsoft/Balance Loader Header
/* SleepLib Weinmann SOMNOsoft/Balance Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -95,7 +95,7 @@ class WeinmannLoader : public CPAPLoader
virtual bool Detect(const QString & path);
//! \brief Scans path for Weinmann data signature, and Loads any new data
virtual int Open(QString path);
virtual int Open(const QString & path);
//! \brief Returns SleepLib database version of this Weinmann loader
virtual int Version() { return weinmann_data_version; }

View File

@ -1,4 +1,4 @@
/* SleepLib ZEO Loader Implementation
/* SleepLib ZEO Loader Implementation
*
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -27,16 +27,15 @@ ZEOLoader::~ZEOLoader()
{
}
int ZEOLoader::Open(QString path)
int ZEOLoader::Open(const QString & dirpath)
{
Q_UNUSED(path)
QString newpath;
QString dirtag = "zeo";
// Could Scan the ZEO folder for a list of CSVs
QString path(dirpath);
path = path.replace("\\", "/");
if (path.toLower().endsWith("/" + dirtag)) {
@ -80,7 +79,7 @@ int ZEOLoader::Open(QString path)
15267: "Detailed Sleep Graph"
15268: "Firmware Version" */
int ZEOLoader::OpenFile(QString filename)
int ZEOLoader::OpenFile(const QString & filename)
{
QFile file(filename);

View File

@ -1,4 +1,4 @@
/* SleepLib ZEO Loader Header
/* SleepLib ZEO Loader Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -26,8 +26,8 @@ class ZEOLoader : public MachineLoader
virtual bool Detect(const QString &path) { Q_UNUSED(path); return false; } // bypass autoscanner
virtual int Open(QString path);
virtual int OpenFile(QString filename);
virtual int Open(const QString & path);
virtual int OpenFile(const QString & filename);
static void Register();
virtual int Version() { return zeo_data_version; }

View File

@ -171,33 +171,52 @@ void MachineLoader::queTask(ImportTask * task)
void MachineLoader::runTasks(bool threaded)
{
threaded=AppSetting->multithreading();
m_totaltasks=m_tasklist.size();
if (m_totaltasks == 0) return;
m_currenttask=0;
threaded=AppSetting->multithreading();
if (!threaded) {
while (!m_tasklist.isEmpty()) {
ImportTask * task = m_tasklist.takeFirst();
task->run();
float f = float(m_currenttask) / float(m_totaltasks) * 100.0;
qprogress->setValue(f);
m_currenttask++;
if ((m_currenttask % 50)==0) {
qprogress->setValue(f);
QApplication::processEvents();
}
}
} else {
ImportTask * task = m_tasklist[0];
QThreadPool * threadpool = QThreadPool::globalInstance();
qprogress->setMaximum(m_totaltasks);
while (true) {
if (threadpool->tryStart(task)) {
m_tasklist.pop_front();
if (!m_tasklist.isEmpty()) {
// next task to be run
task = m_tasklist[0];
// update progress bar
m_currenttask++;
if ((m_currenttask % 50) == 0) {
qprogress->setValue(m_currenttask);
QApplication::processEvents();
}
} else {
QThreadPool * threadpool = QThreadPool::globalInstance();
qprogress->setMaximum(m_totaltasks);
while (!m_tasklist.isEmpty()) {
if (threadpool->tryStart(m_tasklist.at(0))) {
m_tasklist.pop_front();
//float f = float(m_currenttask) / float(m_totaltasks) * 100.0;
qprogress->setValue(m_currenttask);
m_currenttask++;
// job list finished
break;
}
if ((m_currenttask % 50)==0) {
QApplication::processEvents();
}
//QThread::sleep(100);
}
QThreadPool::globalInstance()->waitForDone(-1);
}

View File

@ -44,7 +44,7 @@ class MachineLoader: public QObject
virtual MachineInfo PeekInfo(const QString & path) { Q_UNUSED(path); return MachineInfo(); }
//! \brief Override this to scan path and detect new machine data
virtual int Open(QString path) = 0;
virtual int Open(const QString & path) = 0;
//! \brief Override to returns the Version number of this MachineLoader
virtual int Version() = 0;

View File

@ -1,4 +1,4 @@
/* SleepLib MachineLoader Base Class Header
/* SleepLib MachineLoader Base Class Header
*
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -41,7 +41,7 @@ public:
virtual ~SerialOximeter() {}
virtual bool Detect(const QString &path)=0;
virtual int Open(QString path)=0;
virtual int Open(const QString & path)=0;
static void Register() {}
@ -60,7 +60,7 @@ public:
virtual void syncClock() {}
virtual QString getDeviceID() { return QString(); }
virtual void setDeviceID(QString) {}
virtual void setDeviceID(const QString &) {}
virtual void eraseSession(int /*user*/, int /*session*/) {}