HARDT - The Ham Radio DSP Toolkit
hdemux.h
1 #ifndef __HDEMUX_H
2 #define __HDEMUX_H
3 
19 template <class T>
20 class HDeMux : public HWriter<T>, public HWriterConsumer<T>, public HReader<T>
21 {
22  private:
23 
24  std::vector< HWriter<T>* > _writers;
25  HReader<T>* _reader;
26  T** _buffers;
27  size_t _blocksize;
28 
29  int _readers;
30  T* _readBuffer;
31  int _nextReader;
32 
33  public:
34 
36  HDeMux( std::vector< HWriter<T>* > writers, size_t blocksize);
37 
39  HDeMux( HWriterConsumer<T>* consumer, size_t blocksize);
40 
42  HDeMux( HReader<T>* reader, int readers, size_t blocksize);
43 
45  ~HDeMux();
46 
48  int Write(T* src, size_t blocksize);
49 
51  int Read(T* dest, size_t blocksize);
52 
54  void SetWriter(HWriter<T>* writer)
55  {
56  if( _buffers != NULL )
57  {
58  for( int i = 0; i < _writers.size(); i++ )
59  {
60  delete _buffers[i];
61  }
62  delete _buffers;
63  }
64 
65  _writers.push_back(writer);
66 
67  _buffers = new T*[_writers.size()];
68  for( int i = 0; i < _writers.size(); i++ )
69  {
70  _buffers[i] = new T[_blocksize / _writers.size()];
71  }
72  }
73 
75  bool Command(HCommand* command) {
76  typename std::vector< HWriter<T>* >::iterator it;
77 
78  for( it = _writers.begin(); it != _writers.end(); it++ ) {
79  if( !(*it)->Command(command) ) {
80  return false;
81  }
82  }
83  return true;
84  }
85 
87  bool Start() {
88  typename std::vector< HWriter<T>* >::iterator it;
89 
90  for( it = _writers.begin(); it != _writers.end(); it++ ) {
91  if( !(*it)->Start() ) {
92  return false;
93  }
94  }
95  return true;
96  }
97 
99  bool Stop() {
100  typename std::vector< HWriter<T>* >::iterator it;
101 
102  for( it = _writers.begin(); it != _writers.end(); it++ ) {
103  if( !(*it)->Stop() ) {
104  return false;
105  }
106  }
107  return true;
108  }
109 };
110 
111 #endif
HDeMux::Write
int Write(T *src, size_t blocksize)
Definition: hdemux.cpp:72
HDeMux::~HDeMux
~HDeMux()
Definition: hdemux.cpp:58
HDeMux::SetWriter
void SetWriter(HWriter< T > *writer)
Definition: hdemux.h:54
HWriter
Definition: hwriter.h:10
HDeMux::Command
bool Command(HCommand *command)
Definition: hdemux.h:75
HDeMux
Definition: hdemux.h:20
HDeMux::Start
bool Start()
Definition: hdemux.h:87
HReader
Definition: hreader.h:24
HDeMux::Stop
bool Stop()
Definition: hdemux.h:99
HDeMux::HDeMux
HDeMux(std::vector< HWriter< T > * > writers, size_t blocksize)
Definition: hdemux.cpp:14
HCommand
Definition: hcommand.h:81
HWriterConsumer
Definition: hwriterconsumer.h:8
HDeMux::Read
int Read(T *dest, size_t blocksize)
Definition: hdemux.cpp:100