From 351651c3e5f68e4ee3f11e016ea3bb6e19c7c867 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 24 Dec 2017 11:04:30 +0100 Subject: [PATCH] FileSource: make Settings an independant struct --- .../samplesource/filesource/CMakeLists.txt | 2 + .../samplesource/filesource/filesource.pro | 6 +- .../samplesource/filesource/filesourcegui.h | 3 +- .../filesource/filesourceinput.cpp | 35 ----------- .../samplesource/filesource/filesourceinput.h | 21 +++---- .../filesource/filesourcesettings.cpp | 58 +++++++++++++++++++ .../filesource/filesourcesettings.h | 34 +++++++++++ 7 files changed, 107 insertions(+), 52 deletions(-) create mode 100644 plugins/samplesource/filesource/filesourcesettings.cpp create mode 100644 plugins/samplesource/filesource/filesourcesettings.h diff --git a/plugins/samplesource/filesource/CMakeLists.txt b/plugins/samplesource/filesource/CMakeLists.txt index f50b39413..6984dd483 100644 --- a/plugins/samplesource/filesource/CMakeLists.txt +++ b/plugins/samplesource/filesource/CMakeLists.txt @@ -7,6 +7,7 @@ set(filesource_SOURCES filesourceinput.cpp filesourceplugin.cpp filesourcethread.cpp + filesourcesettings.cpp ) set(filesource_HEADERS @@ -14,6 +15,7 @@ set(filesource_HEADERS filesourceinput.h filesourceplugin.h filesourcethread.h + filesourcesettings.h ) set(filesource_FORMS diff --git a/plugins/samplesource/filesource/filesource.pro b/plugins/samplesource/filesource/filesource.pro index 66fd4efc6..a22dc7d9d 100644 --- a/plugins/samplesource/filesource/filesource.pro +++ b/plugins/samplesource/filesource/filesource.pro @@ -28,12 +28,14 @@ CONFIG(Debug):build_subdir = debug SOURCES += filesourcegui.cpp\ filesourceinput.cpp\ filesourceplugin.cpp\ - filesourcethread.cpp + filesourcethread.cpp\ + filesourcesettings.cpp HEADERS += filesourcegui.h\ filesourceinput.h\ filesourceplugin.h\ - filesourcethread.h + filesourcethread.h\ + filesourcesettings.h FORMS += filesourcegui.ui diff --git a/plugins/samplesource/filesource/filesourcegui.h b/plugins/samplesource/filesource/filesourcegui.h index ea03c168a..e5a040346 100644 --- a/plugins/samplesource/filesource/filesourcegui.h +++ b/plugins/samplesource/filesource/filesourcegui.h @@ -23,6 +23,7 @@ #include "util/messagequeue.h" +#include "filesourcesettings.h" #include "filesourceinput.h" class DeviceUISet; @@ -54,7 +55,7 @@ private: Ui::FileSourceGui* ui; DeviceUISet* m_deviceUISet; - FileSourceInput::Settings m_settings; + FileSourceSettings m_settings; bool m_doApplySettings; QTimer m_statusTimer; std::vector m_gains; diff --git a/plugins/samplesource/filesource/filesourceinput.cpp b/plugins/samplesource/filesource/filesourceinput.cpp index 23f0643d4..9a9090a01 100644 --- a/plugins/samplesource/filesource/filesourceinput.cpp +++ b/plugins/samplesource/filesource/filesourceinput.cpp @@ -42,41 +42,6 @@ MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceAcquisition, Messag MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamData, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamTiming, Message) -FileSourceInput::Settings::Settings() : - m_fileName("./test.sdriq") -{ -} - -void FileSourceInput::Settings::resetToDefaults() -{ - m_fileName = "./test.sdriq"; -} - -QByteArray FileSourceInput::Settings::serialize() const -{ - SimpleSerializer s(1); - s.writeString(1, m_fileName); - return s.final(); -} - -bool FileSourceInput::Settings::deserialize(const QByteArray& data) -{ - SimpleDeserializer d(data); - - if(!d.isValid()) { - resetToDefaults(); - return false; - } - - if(d.getVersion() == 1) { - d.readString(1, &m_fileName, "./test.sdriq"); - return true; - } else { - resetToDefaults(); - return false; - } -} - FileSourceInput::FileSourceInput(DeviceSourceAPI *deviceAPI) : m_deviceAPI(deviceAPI), m_settings(), diff --git a/plugins/samplesource/filesource/filesourceinput.h b/plugins/samplesource/filesource/filesourceinput.h index b905446a6..cad728555 100644 --- a/plugins/samplesource/filesource/filesourceinput.h +++ b/plugins/samplesource/filesource/filesourceinput.h @@ -24,35 +24,28 @@ #include #include +#include "filesourcesettings.h" + class FileSourceThread; class DeviceSourceAPI; class FileSourceInput : public DeviceSampleSource { public: - struct Settings { - QString m_fileName; - - Settings(); - void resetToDefaults(); - QByteArray serialize() const; - bool deserialize(const QByteArray& data); - }; - class MsgConfigureFileSource : public Message { MESSAGE_CLASS_DECLARATION public: - const Settings& getSettings() const { return m_settings; } + const FileSourceSettings& getSettings() const { return m_settings; } - static MsgConfigureFileSource* create(const Settings& settings) + static MsgConfigureFileSource* create(const FileSourceSettings& settings) { return new MsgConfigureFileSource(settings); } private: - Settings m_settings; + FileSourceSettings m_settings; - MsgConfigureFileSource(const Settings& settings) : + MsgConfigureFileSource(const FileSourceSettings& settings) : Message(), m_settings(settings) { } @@ -259,7 +252,7 @@ public: private: DeviceSourceAPI *m_deviceAPI; QMutex m_mutex; - Settings m_settings; + FileSourceSettings m_settings; std::ifstream m_ifstream; FileSourceThread* m_fileSourceThread; QString m_deviceDescription; diff --git a/plugins/samplesource/filesource/filesourcesettings.cpp b/plugins/samplesource/filesource/filesourcesettings.cpp new file mode 100644 index 000000000..327d84e3c --- /dev/null +++ b/plugins/samplesource/filesource/filesourcesettings.cpp @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "util/simpleserializer.h" + +#include "filesourcesettings.h" + +FileSourceSettings::FileSourceSettings() +{ + resetToDefaults(); +} + +void FileSourceSettings::resetToDefaults() +{ + m_fileName = "./test.sdriq"; +} + +QByteArray FileSourceSettings::serialize() const +{ + SimpleSerializer s(1); + s.writeString(1, m_fileName); + return s.final(); +} + +bool FileSourceSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if(!d.isValid()) { + resetToDefaults(); + return false; + } + + if(d.getVersion() == 1) { + d.readString(1, &m_fileName, "./test.sdriq"); + return true; + } else { + resetToDefaults(); + return false; + } +} + + + + diff --git a/plugins/samplesource/filesource/filesourcesettings.h b/plugins/samplesource/filesource/filesourcesettings.h new file mode 100644 index 000000000..2e151a6cb --- /dev/null +++ b/plugins/samplesource/filesource/filesourcesettings.h @@ -0,0 +1,34 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_ +#define PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_ + +#include +#include + +struct FileSourceSettings { + QString m_fileName; + + FileSourceSettings(); + ~FileSourceSettings() {} + + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); +}; + +#endif /* PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_ */