Pothos  0.4.0-gd11861cd
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
BufferManager.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <Pothos/Config.hpp>
15 #include <memory> //shared_ptr
16 #include <string>
17 #include <functional>
18 
19 namespace Pothos {
20 
25 {
26  BufferManagerArgs(void);
27 
35  size_t numBuffers;
36 
41  size_t bufferSize;
42 
49 };
50 
57 {
58 public:
59 
60  typedef std::shared_ptr<BufferManager> Sptr;
61 
71  static Sptr make(const std::string &name);
72 
82  static Sptr make(const std::string &name, const BufferManagerArgs &args);
83 
87  virtual void init(const BufferManagerArgs &args);
88 
93  virtual bool empty(void) const = 0;
94 
102  const BufferChunk &front(void) const;
103 
117  virtual void pop(const size_t numBytes) = 0;
118 
126  virtual void push(const ManagedBuffer &buff) = 0;
127 
133  void pushExternal(const ManagedBuffer &buff);
134 
138  void setCallback(const std::function<void(const ManagedBuffer &)> &callback);
139 
141  bool isInitialized(void) const;
142 
143 protected:
145  BufferManager(void);
146 
148  void setFrontBuffer(const BufferChunk &buff);
149 
150 private:
151  bool _initialized;
152  BufferChunk _frontBuffer;
153  std::function<void(const ManagedBuffer &)> _callback;
154 };
155 
156 } //namespace Pothos
157 
159 {
160  return _frontBuffer;
161 }
162 
164 {
165  _frontBuffer = buff;
166 }
167 
169 {
170  if (_callback) _callback(buff);
171  else this->push(buff);
172 }
173 
175 {
176  return _initialized;
177 }
size_t numBuffers
Definition: BufferManager.hpp:35
const BufferChunk & front(void) const
Definition: BufferManager.hpp:158
#define POTHOS_API
Definition: Config.hpp:41
void pushExternal(const ManagedBuffer &buff)
Definition: BufferManager.hpp:168
long nodeAffinity
Definition: BufferManager.hpp:48
Definition: BufferManager.hpp:56
Definition: ManagedBuffer.hpp:31
void setFrontBuffer(const BufferChunk &buff)
Called by derived classes to set the buffer for front()
Definition: BufferManager.hpp:163
bool isInitialized(void) const
Has this buffer manager been initialized?
Definition: BufferManager.hpp:174
Definition: BufferManager.hpp:24
std::shared_ptr< BufferManager > Sptr
Definition: BufferManager.hpp:60
POTHOS_API void init(void)
size_t bufferSize
Definition: BufferManager.hpp:41
Definition: BufferChunk.hpp:30