SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
filesinkoutput.h
Go to the documentation of this file.
1 // Copyright (C) 2016 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef INCLUDE_FILESINKOUTPUT_H
19 #define INCLUDE_FILESINKOUTPUT_H
20 
21 #include <QString>
22 #include <QTimer>
23 #include <ctime>
24 #include <iostream>
25 #include <fstream>
26 
27 #include "dsp/devicesamplesink.h"
28 #include "filesinksettings.h"
29 
30 class FileSinkThread;
31 class DeviceAPI;
32 
34 public:
35  class MsgConfigureFileSink : public Message {
37 
38  public:
39  const FileSinkSettings& getSettings() const { return m_settings; }
40  bool getForce() const { return m_force; }
41 
42  static MsgConfigureFileSink* create(const FileSinkSettings& settings, bool force)
43  {
44  return new MsgConfigureFileSink(settings, force);
45  }
46 
47  private:
49  bool m_force;
50 
51  MsgConfigureFileSink(const FileSinkSettings& settings, bool force) :
52  Message(),
53  m_settings(settings),
54  m_force(force)
55  { }
56  };
57 
58  class MsgStartStop : public Message {
60 
61  public:
62  bool getStartStop() const { return m_startStop; }
63 
64  static MsgStartStop* create(bool startStop) {
65  return new MsgStartStop(startStop);
66  }
67 
68  protected:
70 
71  MsgStartStop(bool startStop) :
72  Message(),
73  m_startStop(startStop)
74  { }
75  };
76 
79 
80  public:
81  const QString& getFileName() const { return m_fileName; }
82 
83  static MsgConfigureFileSinkName* create(const QString& fileName)
84  {
85  return new MsgConfigureFileSinkName(fileName);
86  }
87 
88  private:
89  QString m_fileName;
90 
91  MsgConfigureFileSinkName(const QString& fileName) :
92  Message(),
93  m_fileName(fileName)
94  { }
95  };
96 
99 
100  public:
101  bool isWorking() const { return m_working; }
102 
103  static MsgConfigureFileSinkWork* create(bool working)
104  {
105  return new MsgConfigureFileSinkWork(working);
106  }
107 
108  private:
109  bool m_working;
110 
111  MsgConfigureFileSinkWork(bool working) :
112  Message(),
113  m_working(working)
114  { }
115  };
116 
119 
120  public:
121 
123  {
125  }
126 
127  private:
128 
130  Message()
131  { }
132  };
133 
136 
137  public:
138  bool getAcquisition() const { return m_acquisition; }
139 
140  static MsgReportFileSinkGeneration* create(bool acquisition)
141  {
142  return new MsgReportFileSinkGeneration(acquisition);
143  }
144 
145  protected:
147 
148  MsgReportFileSinkGeneration(bool acquisition) :
149  Message(),
150  m_acquisition(acquisition)
151  { }
152  };
153 
156 
157  public:
158  std::size_t getSamplesCount() const { return m_samplesCount; }
159 
160  static MsgReportFileSinkStreamTiming* create(std::size_t samplesCount)
161  {
162  return new MsgReportFileSinkStreamTiming(samplesCount);
163  }
164 
165  protected:
166  std::size_t m_samplesCount;
167 
168  MsgReportFileSinkStreamTiming(std::size_t samplesCount) :
169  Message(),
170  m_samplesCount(samplesCount)
171  { }
172  };
173 
174  FileSinkOutput(DeviceAPI *deviceAPI);
175  virtual ~FileSinkOutput();
176  virtual void destroy();
177 
178  virtual void init();
179  virtual bool start();
180  virtual void stop();
181 
182  virtual QByteArray serialize() const;
183  virtual bool deserialize(const QByteArray& data);
184 
185  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
186  virtual const QString& getDeviceDescription() const;
187  virtual int getSampleRate() const;
188  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
189  virtual quint64 getCenterFrequency() const;
190  virtual void setCenterFrequency(qint64 centerFrequency);
191  std::time_t getStartingTimeStamp() const;
192 
193  virtual bool handleMessage(const Message& message);
194 
195  virtual int webapiRunGet(
196  SWGSDRangel::SWGDeviceState& response,
197  QString& errorMessage);
198 
199  virtual int webapiRun(
200  bool run,
201  SWGSDRangel::SWGDeviceState& response,
202  QString& errorMessage);
203 
204 private:
206  QMutex m_mutex;
208  std::ofstream m_ofstream;
211  QString m_fileName;
212  std::time_t m_startingTimeStamp;
213  const QTimer& m_masterTimer;
214 
215  void openFileStream();
216  void applySettings(const FileSinkSettings& settings, bool force = false);
217 };
218 
219 #endif // INCLUDE_FILESINKOUTPUT_H
virtual ~FileSinkOutput()
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
static MsgReportFileSinkStreamTiming * create(std::size_t samplesCount)
std::ofstream m_ofstream
virtual void destroy()
MsgReportFileSinkStreamTiming(std::size_t samplesCount)
DeviceAPI * m_deviceAPI
virtual const QString & getDeviceDescription() const
void applySettings(const FileSinkSettings &settings, bool force=false)
virtual int getSampleRate() const
Sample rate exposed by the sink.
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
virtual bool handleMessage(const Message &message)
FileSinkOutput(DeviceAPI *deviceAPI)
static MsgConfigureFileSinkStreamTiming * create()
static MsgStartStop * create(bool startStop)
virtual quint64 getCenterFrequency() const
Center frequency exposed by the sink.
const QTimer & m_masterTimer
static MsgConfigureFileSinkWork * create(bool working)
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
const FileSinkSettings & getSettings() const
virtual QByteArray serialize() const
virtual void setSampleRate(int sampleRate)
For when the sink sample rate is set externally.
virtual void setCenterFrequency(qint64 centerFrequency)
MsgConfigureFileSinkName(const QString &fileName)
FileSinkSettings m_settings
static MsgConfigureFileSinkName * create(const QString &fileName)
static MsgReportFileSinkGeneration * create(bool acquisition)
virtual bool deserialize(const QByteArray &data)
virtual void stop()
MsgConfigureFileSink(const FileSinkSettings &settings, bool force)
std::time_t getStartingTimeStamp() const
QString m_deviceDescription
FileSinkThread * m_fileSinkThread
std::time_t m_startingTimeStamp
virtual void setMessageQueueToGUI(MessageQueue *queue)
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
static MsgConfigureFileSink * create(const FileSinkSettings &settings, bool force)
virtual bool start()