Roomba App  1.0
frameBuffer.cpp
Go to the documentation of this file.
1 
17 #include "frameBuffer.hh"
18 
19 void FrameBuffer::addFrame(const std::string& frame)
20 {
21  std::lock_guard<std::mutex> guard(_access);
22 
23  _frameList.push_back(frame);
24  while(_frameList.size() > _MAX_LIST_SIZE)
25  {
26  _frameList.pop_front();
27  }
28 }
29 
30 bool FrameBuffer::getFrame(std::string& frame)
31 {
32  std::lock_guard<std::mutex> guard(_access);
33 
34  if(_frameList.empty()) return false;
35 
36  frame = _frameList.front();
37  _frameList.pop_front();
38 
39  return true;
40 }
41 
43 {
44  std::lock_guard<std::mutex> guard(_access);
45  return !_frameList.empty();
46 }
static constexpr int _MAX_LIST_SIZE
Max circular buffer size.
Definition: frameBuffer.hh:32
bool isFrame() const
Check if there is any frame in a circular buffer.
Definition: frameBuffer.cpp:42
std::list< std::string > _frameList
List containing individual frames.
Definition: frameBuffer.hh:30
std::mutex _access
Mutex that provides single access to the list.
Definition: frameBuffer.hh:31
void addFrame(const std::string &frame)
Add one frame at the end of list.
Definition: frameBuffer.cpp:19
bool getFrame(std::string &frame)
Get one frame from the top of the list.
Definition: frameBuffer.cpp:30
FrameBuffer class declaration.