#include <DataQueue.hpp>
Public Types | |
using | CallbackId = int |
Alias for callback id. More... | |
Public Member Functions | |
CallbackId | addCallback (std::function< void()> callback) |
CallbackId | addCallback (std::function< void(std::shared_ptr< ADatatype >)>) |
CallbackId | addCallback (std::function< void(std::string, std::shared_ptr< ADatatype >)>) |
void | close () |
DataOutputQueue (const std::shared_ptr< XLinkConnection > conn, const std::string &streamName, unsigned int maxSize=16, bool blocking=true) | |
template<class T > | |
std::shared_ptr< T > | front () |
std::shared_ptr< ADatatype > | front () |
template<class T > | |
std::shared_ptr< T > | get () |
std::shared_ptr< ADatatype > | get () |
template<class T , typename Rep , typename Period > | |
std::shared_ptr< T > | get (std::chrono::duration< Rep, Period > timeout, bool &hasTimedout) |
template<typename Rep , typename Period > | |
std::shared_ptr< ADatatype > | get (std::chrono::duration< Rep, Period > timeout, bool &hasTimedout) |
template<class T > | |
std::vector< std::shared_ptr< T > > | getAll () |
std::vector< std::shared_ptr< ADatatype > > | getAll () |
template<class T , typename Rep , typename Period > | |
std::vector< std::shared_ptr< T > > | getAll (std::chrono::duration< Rep, Period > timeout, bool &hasTimedout) |
template<typename Rep , typename Period > | |
std::vector< std::shared_ptr< ADatatype > > | getAll (std::chrono::duration< Rep, Period > timeout, bool &hasTimedout) |
bool | getBlocking () const |
unsigned int | getMaxSize () const |
std::string | getName () const |
template<class T > | |
bool | has () |
bool | has () |
bool | isClosed () const |
bool | removeCallback (CallbackId callbackId) |
void | setBlocking (bool blocking) |
void | setMaxSize (unsigned int maxSize) |
template<class T > | |
std::shared_ptr< T > | tryGet () |
std::shared_ptr< ADatatype > | tryGet () |
template<class T > | |
std::vector< std::shared_ptr< T > > | tryGetAll () |
std::vector< std::shared_ptr< ADatatype > > | tryGetAll () |
~DataOutputQueue () | |
Private Attributes | |
std::unordered_map< CallbackId, std::function< void(std::string, std::shared_ptr< ADatatype >)> > | callbacks |
std::mutex | callbacksMtx |
std::string | exceptionMessage {""} |
const std::string | name {""} |
LockingQueue< std::shared_ptr< ADatatype > > | queue |
std::thread | readingThread |
std::atomic< bool > | running {true} |
CallbackId | uniqueCallbackId {0} |
Access to receive messages coming from XLink stream
Definition at line 22 of file DataQueue.hpp.
using dai::DataOutputQueue::CallbackId = int |
Alias for callback id.
Definition at line 25 of file DataQueue.hpp.
dai::DataOutputQueue::DataOutputQueue | ( | const std::shared_ptr< XLinkConnection > | conn, |
const std::string & | streamName, | ||
unsigned int | maxSize = 16 , |
||
bool | blocking = true |
||
) |
Definition at line 30 of file DataQueue.cpp.
dai::DataOutputQueue::~DataOutputQueue | ( | ) |
Definition at line 128 of file DataQueue.cpp.
int dai::DataOutputQueue::addCallback | ( | std::function< void()> | callback | ) |
Adds a callback on message received
callback | Callback function without any parameters |
Definition at line 179 of file DataQueue.cpp.
int dai::DataOutputQueue::addCallback | ( | std::function< void(std::shared_ptr< ADatatype >)> | callback | ) |
Adds a callback on message received
callback | Callback function with message pointer |
Definition at line 174 of file DataQueue.cpp.
int dai::DataOutputQueue::addCallback | ( | std::function< void(std::string, std::shared_ptr< ADatatype >)> | callback | ) |
Adds a callback on message received
callback | Callback function with queue name and message pointer |
Definition at line 160 of file DataQueue.cpp.
void dai::DataOutputQueue::close | ( | ) |
Closes the queue and the underlying thread
Definition at line 114 of file DataQueue.cpp.
|
inline |
Gets first message in the queue.
Definition at line 200 of file DataQueue.hpp.
|
inline |
Gets first message in the queue.
Definition at line 212 of file DataQueue.hpp.
|
inline |
Block until a message is available.
Definition at line 176 of file DataQueue.hpp.
|
inline |
Block until a message is available.
Definition at line 190 of file DataQueue.hpp.
|
inline |
Block until a message is available with a timeout.
timeout | Duration for which the function should block | |
[out] | hasTimedout | Outputs true if timeout occurred, false otherwise |
Definition at line 224 of file DataQueue.hpp.
|
inline |
Block until a message is available with a timeout.
timeout | Duration for which the function should block | |
[out] | hasTimedout | Outputs true if timeout occurred, false otherwise |
Definition at line 243 of file DataQueue.hpp.
|
inline |
Block until at least one message in the queue. Then return all messages from the queue.
Definition at line 282 of file DataQueue.hpp.
|
inline |
Block until at least one message in the queue. Then return all messages from the queue.
Definition at line 301 of file DataQueue.hpp.
|
inline |
Block for maximum timeout duration. Then return all messages from the queue.
timeout | Maximum duration to block | |
[out] | hasTimedout | Outputs true if timeout occurred, false otherwise |
Definition at line 313 of file DataQueue.hpp.
|
inline |
Block for maximum timeout duration. Then return all messages from the queue.
timeout | Maximum duration to block | |
[out] | hasTimedout | Outputs true if timeout occurred, false otherwise |
Definition at line 336 of file DataQueue.hpp.
bool dai::DataOutputQueue::getBlocking | ( | ) | const |
Gets current queue behavior when full (maxSize)
Definition at line 141 of file DataQueue.cpp.
unsigned int dai::DataOutputQueue::getMaxSize | ( | ) | const |
std::string dai::DataOutputQueue::getName | ( | ) | const |
|
inline |
Check whether front of the queue has message of type T
Definition at line 130 of file DataQueue.hpp.
|
inline |
Check whether front of the queue has a message (isn't empty)
Definition at line 143 of file DataQueue.hpp.
bool dai::DataOutputQueue::isClosed | ( | ) | const |
Check whether queue is closed
Definition at line 110 of file DataQueue.cpp.
bool dai::DataOutputQueue::removeCallback | ( | CallbackId | callbackId | ) |
Removes a callback
callbackId | Id of callback to be removed |
Definition at line 184 of file DataQueue.cpp.
void dai::DataOutputQueue::setBlocking | ( | bool | blocking | ) |
Sets queue behavior when full (maxSize)
blocking | Specifies if block or overwrite the oldest message in the queue |
Definition at line 136 of file DataQueue.cpp.
void dai::DataOutputQueue::setMaxSize | ( | unsigned int | maxSize | ) |
Sets queue maximum size
maxSize | Specifies maximum number of messages in the queue |
Definition at line 146 of file DataQueue.cpp.
|
inline |
Try to retrieve message T from queue. If message isn't of type T it returns nullptr
Definition at line 154 of file DataQueue.hpp.
|
inline |
Try to retrieve message from queue. If no message available, return immediately with nullptr
Definition at line 166 of file DataQueue.hpp.
|
inline |
Try to retrieve all messages in the queue.
Definition at line 253 of file DataQueue.hpp.
|
inline |
Try to retrieve all messages in the queue.
Definition at line 271 of file DataQueue.hpp.
|
private |
Definition at line 34 of file DataQueue.hpp.
|
private |
Definition at line 33 of file DataQueue.hpp.
|
private |
Definition at line 31 of file DataQueue.hpp.
|
private |
Definition at line 32 of file DataQueue.hpp.
|
private |
Definition at line 28 of file DataQueue.hpp.
|
private |
Definition at line 29 of file DataQueue.hpp.
|
private |
Definition at line 30 of file DataQueue.hpp.
|
private |
Definition at line 35 of file DataQueue.hpp.