Public Types | Public Member Functions | Private Attributes | List of all members
dai::DataOutputQueue Class Reference

#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< ADatatypefront ()
 
template<class T >
std::shared_ptr< T > get ()
 
std::shared_ptr< ADatatypeget ()
 
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< ADatatypeget (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< ADatatypetryGet ()
 
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}
 

Detailed Description

Access to receive messages coming from XLink stream

Definition at line 22 of file DataQueue.hpp.

Member Typedef Documentation

◆ CallbackId

Alias for callback id.

Definition at line 25 of file DataQueue.hpp.

Constructor & Destructor Documentation

◆ DataOutputQueue()

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.

◆ ~DataOutputQueue()

dai::DataOutputQueue::~DataOutputQueue ( )

Definition at line 128 of file DataQueue.cpp.

Member Function Documentation

◆ addCallback() [1/3]

int dai::DataOutputQueue::addCallback ( std::function< void()>  callback)

Adds a callback on message received

Parameters
callbackCallback function without any parameters
Returns
Callback id

Definition at line 179 of file DataQueue.cpp.

◆ addCallback() [2/3]

int dai::DataOutputQueue::addCallback ( std::function< void(std::shared_ptr< ADatatype >)>  callback)

Adds a callback on message received

Parameters
callbackCallback function with message pointer
Returns
Callback id

Definition at line 174 of file DataQueue.cpp.

◆ addCallback() [3/3]

int dai::DataOutputQueue::addCallback ( std::function< void(std::string, std::shared_ptr< ADatatype >)>  callback)

Adds a callback on message received

Parameters
callbackCallback function with queue name and message pointer
Returns
Callback id

Definition at line 160 of file DataQueue.cpp.

◆ close()

void dai::DataOutputQueue::close ( )

Closes the queue and the underlying thread

Definition at line 114 of file DataQueue.cpp.

◆ front() [1/2]

template<class T >
std::shared_ptr<T> dai::DataOutputQueue::front ( )
inline

Gets first message in the queue.

Returns
Message of type T or nullptr if no message available

Definition at line 200 of file DataQueue.hpp.

◆ front() [2/2]

std::shared_ptr<ADatatype> dai::DataOutputQueue::front ( )
inline

Gets first message in the queue.

Returns
Message or nullptr if no message available

Definition at line 212 of file DataQueue.hpp.

◆ get() [1/4]

template<class T >
std::shared_ptr<T> dai::DataOutputQueue::get ( )
inline

Block until a message is available.

Returns
Message of type T or nullptr if no message available

Definition at line 176 of file DataQueue.hpp.

◆ get() [2/4]

std::shared_ptr<ADatatype> dai::DataOutputQueue::get ( )
inline

Block until a message is available.

Returns
Message or nullptr if no message available

Definition at line 190 of file DataQueue.hpp.

◆ get() [3/4]

template<class T , typename Rep , typename Period >
std::shared_ptr<T> dai::DataOutputQueue::get ( std::chrono::duration< Rep, Period >  timeout,
bool &  hasTimedout 
)
inline

Block until a message is available with a timeout.

Parameters
timeoutDuration for which the function should block
[out]hasTimedoutOutputs true if timeout occurred, false otherwise
Returns
Message of type T otherwise nullptr if message isn't type T or timeout occurred

Definition at line 224 of file DataQueue.hpp.

◆ get() [4/4]

template<typename Rep , typename Period >
std::shared_ptr<ADatatype> dai::DataOutputQueue::get ( std::chrono::duration< Rep, Period >  timeout,
bool &  hasTimedout 
)
inline

Block until a message is available with a timeout.

Parameters
timeoutDuration for which the function should block
[out]hasTimedoutOutputs true if timeout occurred, false otherwise
Returns
Message of type T otherwise nullptr if message isn't type T or timeout occurred

Definition at line 243 of file DataQueue.hpp.

◆ getAll() [1/4]

template<class T >
std::vector<std::shared_ptr<T> > dai::DataOutputQueue::getAll ( )
inline

Block until at least one message in the queue. Then return all messages from the queue.

Returns
Vector of messages which can either be of type T or nullptr

Definition at line 282 of file DataQueue.hpp.

◆ getAll() [2/4]

std::vector<std::shared_ptr<ADatatype> > dai::DataOutputQueue::getAll ( )
inline

Block until at least one message in the queue. Then return all messages from the queue.

Returns
Vector of messages

Definition at line 301 of file DataQueue.hpp.

◆ getAll() [3/4]

template<class T , typename Rep , typename Period >
std::vector<std::shared_ptr<T> > dai::DataOutputQueue::getAll ( std::chrono::duration< Rep, Period >  timeout,
bool &  hasTimedout 
)
inline

Block for maximum timeout duration. Then return all messages from the queue.

Parameters
timeoutMaximum duration to block
[out]hasTimedoutOutputs true if timeout occurred, false otherwise
Returns
Vector of messages which can either be of type T or nullptr

Definition at line 313 of file DataQueue.hpp.

◆ getAll() [4/4]

template<typename Rep , typename Period >
std::vector<std::shared_ptr<ADatatype> > dai::DataOutputQueue::getAll ( std::chrono::duration< Rep, Period >  timeout,
bool &  hasTimedout 
)
inline

Block for maximum timeout duration. Then return all messages from the queue.

Parameters
timeoutMaximum duration to block
[out]hasTimedoutOutputs true if timeout occurred, false otherwise
Returns
Vector of messages

Definition at line 336 of file DataQueue.hpp.

◆ getBlocking()

bool dai::DataOutputQueue::getBlocking ( ) const

Gets current queue behavior when full (maxSize)

Returns
True if blocking, false otherwise

Definition at line 141 of file DataQueue.cpp.

◆ getMaxSize()

unsigned int dai::DataOutputQueue::getMaxSize ( ) const

Gets queue maximum size

Returns
Maximum queue size

Definition at line 151 of file DataQueue.cpp.

◆ getName()

std::string dai::DataOutputQueue::getName ( ) const

Gets queues name

Returns
Queue name

Definition at line 156 of file DataQueue.cpp.

◆ has() [1/2]

template<class T >
bool dai::DataOutputQueue::has ( )
inline

Check whether front of the queue has message of type T

Returns
True if queue isn't empty and the first element is of type T, false otherwise

Definition at line 130 of file DataQueue.hpp.

◆ has() [2/2]

bool dai::DataOutputQueue::has ( )
inline

Check whether front of the queue has a message (isn't empty)

Returns
True if queue isn't empty, false otherwise

Definition at line 143 of file DataQueue.hpp.

◆ isClosed()

bool dai::DataOutputQueue::isClosed ( ) const

Check whether queue is closed

Warning
This function is thread-unsafe and may return outdated incorrect values. It is only meant for use in simple single-threaded code. Well written code should handle exceptions when calling any DepthAI apis to handle hardware events and multithreaded use.

Definition at line 110 of file DataQueue.cpp.

◆ removeCallback()

bool dai::DataOutputQueue::removeCallback ( CallbackId  callbackId)

Removes a callback

Parameters
callbackIdId of callback to be removed
Returns
True if callback was removed, false otherwise

Definition at line 184 of file DataQueue.cpp.

◆ setBlocking()

void dai::DataOutputQueue::setBlocking ( bool  blocking)

Sets queue behavior when full (maxSize)

Parameters
blockingSpecifies if block or overwrite the oldest message in the queue

Definition at line 136 of file DataQueue.cpp.

◆ setMaxSize()

void dai::DataOutputQueue::setMaxSize ( unsigned int  maxSize)

Sets queue maximum size

Parameters
maxSizeSpecifies maximum number of messages in the queue

Definition at line 146 of file DataQueue.cpp.

◆ tryGet() [1/2]

template<class T >
std::shared_ptr<T> dai::DataOutputQueue::tryGet ( )
inline

Try to retrieve message T from queue. If message isn't of type T it returns nullptr

Returns
Message of type T or nullptr if no message available

Definition at line 154 of file DataQueue.hpp.

◆ tryGet() [2/2]

std::shared_ptr<ADatatype> dai::DataOutputQueue::tryGet ( )
inline

Try to retrieve message from queue. If no message available, return immediately with nullptr

Returns
Message or nullptr if no message available

Definition at line 166 of file DataQueue.hpp.

◆ tryGetAll() [1/2]

template<class T >
std::vector<std::shared_ptr<T> > dai::DataOutputQueue::tryGetAll ( )
inline

Try to retrieve all messages in the queue.

Returns
Vector of messages which can either be of type T or nullptr

Definition at line 253 of file DataQueue.hpp.

◆ tryGetAll() [2/2]

std::vector<std::shared_ptr<ADatatype> > dai::DataOutputQueue::tryGetAll ( )
inline

Try to retrieve all messages in the queue.

Returns
Vector of messages

Definition at line 271 of file DataQueue.hpp.

Member Data Documentation

◆ callbacks

std::unordered_map<CallbackId, std::function<void(std::string, std::shared_ptr<ADatatype>)> > dai::DataOutputQueue::callbacks
private

Definition at line 34 of file DataQueue.hpp.

◆ callbacksMtx

std::mutex dai::DataOutputQueue::callbacksMtx
private

Definition at line 33 of file DataQueue.hpp.

◆ exceptionMessage

std::string dai::DataOutputQueue::exceptionMessage {""}
private

Definition at line 31 of file DataQueue.hpp.

◆ name

const std::string dai::DataOutputQueue::name {""}
private

Definition at line 32 of file DataQueue.hpp.

◆ queue

LockingQueue<std::shared_ptr<ADatatype> > dai::DataOutputQueue::queue
private

Definition at line 28 of file DataQueue.hpp.

◆ readingThread

std::thread dai::DataOutputQueue::readingThread
private

Definition at line 29 of file DataQueue.hpp.

◆ running

std::atomic<bool> dai::DataOutputQueue::running {true}
private

Definition at line 30 of file DataQueue.hpp.

◆ uniqueCallbackId

CallbackId dai::DataOutputQueue::uniqueCallbackId {0}
private

Definition at line 35 of file DataQueue.hpp.


The documentation for this class was generated from the following files:


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:20