#include <serial_listener.h>
Public Member Functions | |
BufferedFilter (ComparatorType comparator, size_t buffer_size, SerialListener &listener) | |
void | callback (const std::string &token) |
size_t | capacity () |
void | clear () |
size_t | count () |
std::string | wait (long ms) |
virtual | ~BufferedFilter () |
Public Attributes | |
FilterPtr | filter_ptr |
Private Attributes | |
size_t | buffer_size_ |
SerialListener * | listener_ |
ConcurrentQueue< std::string > | queue |
std::string | result |
This is the a filter that provides a wait function for blocking until a match is found. It will also buffer up to a given buffer size of tokens so that they can be counted or accessed after they are matched by the filter.
This should probably not be created manually, but instead should be constructed using SerialListener::createBufferedFilter(ComparatorType) function which returns a BufferedFilter instance.
The internal buffer is a circular queue buffer, so when the buffer is full, the oldest token is dropped and the new one is added. Additionally, when wait is a called the oldest available token is returned.
Definition at line 798 of file serial_listener.h.
serial::utils::BufferedFilter::BufferedFilter | ( | ComparatorType | comparator, |
size_t | buffer_size, | ||
SerialListener & | listener | ||
) | [inline] |
Definition at line 801 of file serial_listener.h.
virtual serial::utils::BufferedFilter::~BufferedFilter | ( | ) | [inline, virtual] |
Definition at line 810 of file serial_listener.h.
void serial::utils::BufferedFilter::callback | ( | const std::string & | token | ) | [inline] |
Definition at line 863 of file serial_listener.h.
size_t serial::utils::BufferedFilter::capacity | ( | ) | [inline] |
Returns the capacity of the buffer.
Definition at line 857 of file serial_listener.h.
void serial::utils::BufferedFilter::clear | ( | ) | [inline] |
Clears the buffer of any tokens.
Definition at line 843 of file serial_listener.h.
size_t serial::utils::BufferedFilter::count | ( | ) | [inline] |
Returns the number of tokens waiting in the buffer.
Definition at line 850 of file serial_listener.h.
std::string serial::utils::BufferedFilter::wait | ( | long | ms | ) | [inline] |
Waits a given number of milliseconds or until a matched token is available in the buffer. If a token is matched it is returned, otherwise an empty string is returned.
ms | Time in milliseconds to wait on a new token. If ms is set to 0 then it will try to get a new token if one is available but will not block. |
Definition at line 827 of file serial_listener.h.
size_t serial::utils::BufferedFilter::buffer_size_ [private] |
Definition at line 876 of file serial_listener.h.
Definition at line 861 of file serial_listener.h.
Definition at line 877 of file serial_listener.h.
ConcurrentQueue<std::string> serial::utils::BufferedFilter::queue [private] |
Definition at line 878 of file serial_listener.h.
std::string serial::utils::BufferedFilter::result [private] |
Definition at line 879 of file serial_listener.h.