HARDT - The Ham Radio DSP Toolkit
hinputwriter.h
1 #ifndef __HINPUTWRITER_H
2 #define __HINPUTWRITER_H
3 
4 #include "hwriter.h"
5 #include "hwriterconsumer.h"
6 
11 template <class T>
12 class HInputWriter : public HWriter<T>, public HWriterConsumer<T>
13 {
14  private:
15 
16  HWriter<T>* _writer;
17  bool _autostart;
18  bool _started;
19 
20  public:
21 
28  HInputWriter(HWriter<T>* writer, bool autostart = true):
29  _writer(writer),
30  _autostart(autostart),
31  _started(false) {}
32 
38  HInputWriter(bool autostart = true):
39  _writer(nullptr),
40  _autostart(autostart),
41  _started(false) {}
42 
44  int Write(T* src, size_t blocksize) {
45  if( _autostart && !_started ) {
46  _started = Start();
47  }
48  return _writer->Write(src, blocksize);
49  }
50 
52  void SetWriter(HWriter<T>* writer) {
53  _writer = writer;
54  }
55 
57  bool Start() {
58  if( _writer != nullptr )
59  {
60  return _writer->Start();
61  }
62  return true;
63  }
64 
66  bool Stop() {
67  if( _writer != nullptr )
68  {
69  return _writer->Stop();
70  }
71  return true;
72  }
73 
75  bool Command(HCommand* command) {
76  return _writer->Command(command);
77  }
78 };
79 
80 #endif
HInputWriter::SetWriter
void SetWriter(HWriter< T > *writer)
Definition: hinputwriter.h:52
HInputWriter::HInputWriter
HInputWriter(bool autostart=true)
Definition: hinputwriter.h:38
HInputWriter::Stop
bool Stop()
Definition: hinputwriter.h:66
HWriter
Definition: hwriter.h:10
HInputWriter
Definition: hinputwriter.h:12
HWriter::Write
virtual int Write(T *src, size_t blocksize)=0
HWriter::Command
virtual bool Command(HCommand *command)=0
HWriter::Start
virtual bool Start()
Definition: hwriter.h:21
HInputWriter::Command
bool Command(HCommand *command)
Definition: hinputwriter.h:75
HCommand
Definition: hcommand.h:81
HWriter::Stop
virtual bool Stop()
Definition: hwriter.h:27
HInputWriter::HInputWriter
HInputWriter(HWriter< T > *writer, bool autostart=true)
Definition: hinputwriter.h:28
HInputWriter::Write
int Write(T *src, size_t blocksize)
Definition: hinputwriter.h:44
HInputWriter::Start
bool Start()
Definition: hinputwriter.h:57
HWriterConsumer
Definition: hwriterconsumer.h:8