1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -05:00

FileSource: make Settings an independant struct

This commit is contained in:
f4exb 2017-12-24 11:04:30 +01:00
parent 996f964435
commit 351651c3e5
7 changed files with 107 additions and 52 deletions

View File

@ -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

View File

@ -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

View File

@ -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<int> m_gains;

View File

@ -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(),

View File

@ -24,35 +24,28 @@
#include <iostream>
#include <fstream>
#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;

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_
#define PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_
#include <QString>
#include <QByteArray>
struct FileSourceSettings {
QString m_fileName;
FileSourceSettings();
~FileSourceSettings() {}
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_ */