Roomba App  1.0
frameBuffer.cpp
Go to the documentation of this file.
1 
12 #include <QDebug>
13 
14 #include "frameBuffer.hh"
15 
16 constexpr int MAX_LIST_SIZE = 10;
17 
19 
21 
22 void FrameBuffer::addFrame(const std::string& frame)
23 {
24  std::lock_guard<std::mutex> guard(_access);
25 
26  _frameList.push_back(frame);
27  while(_frameList.size() > MAX_LIST_SIZE)
28  {
29  _frameList.pop_front();
30  }
31 }
32 
33 bool FrameBuffer::getFrame(std::string& frame)
34 {
35  std::lock_guard<std::mutex> guard(_access);
36 
37  if(_frameList.empty()) return false;
38 
39  frame = _frameList.front();
40  _frameList.pop_front();
41 
42  return true;
43 }
44 
46 {
47  std::lock_guard<std::mutex> guard(_access);
48 
49  return !_frameList.empty();
50 }
bool isFrame() const
Check if list contain any frame.
Definition: frameBuffer.cpp:45
FrameBuffer()
Construct new FrameBuffer object.
Definition: frameBuffer.cpp:18
std::list< std::string > _frameList
List containing individual frames.
Definition: frameBuffer.hh:28
std::mutex _access
Mutex that provides single access to the list.
Definition: frameBuffer.hh:33
void addFrame(const std::string &frame)
Add one frame to the end of the list.
Definition: frameBuffer.cpp:22
~FrameBuffer()
Desctruct FrameBuffer object.
Definition: frameBuffer.cpp:20
bool getFrame(std::string &frame)
Get one frame from the top of the list.
Definition: frameBuffer.cpp:33
constexpr int MAX_LIST_SIZE
Definition: frameBuffer.cpp:16
Header file for FrameBuffer class.