Class DataOutputQueue

Class Documentation

class DataOutputQueue

Access to receive messages coming from XLink stream

Public Types

using CallbackId = int

Alias for callback id.

Public Functions

DataOutputQueue(const std::shared_ptr<XLinkConnection> conn, const std::string &streamName, unsigned int maxSize = 16, bool blocking = true)
~DataOutputQueue()
bool 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.

void close()

Closes the queue and the underlying thread

void setBlocking(bool blocking)

Sets queue behavior when full (maxSize)

Parameters:

blocking – Specifies if block or overwrite the oldest message in the queue

bool getBlocking() const

Gets current queue behavior when full (maxSize)

Returns:

True if blocking, false otherwise

void setMaxSize(unsigned int maxSize)

Sets queue maximum size

Parameters:

maxSize – Specifies maximum number of messages in the queue

unsigned int getMaxSize() const

Gets queue maximum size

Returns:

Maximum queue size

std::string getName() const

Gets queues name

Returns:

Queue name

CallbackId addCallback(std::function<void(std::string, std::shared_ptr<ADatatype>)>)

Adds a callback on message received

Parameters:

callback – Callback function with queue name and message pointer

Returns:

Callback id

CallbackId addCallback(std::function<void(std::shared_ptr<ADatatype>)>)

Adds a callback on message received

Parameters:

callback – Callback function with message pointer

Returns:

Callback id

CallbackId addCallback(std::function<void()> callback)

Adds a callback on message received

Parameters:

callback – Callback function without any parameters

Returns:

Callback id

bool removeCallback(CallbackId callbackId)

Removes a callback

Parameters:

callbackId – Id of callback to be removed

Returns:

True if callback was removed, false otherwise

template<class T>
inline bool has()

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

inline bool has()

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

Returns:

True if queue isn’t empty, false otherwise

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

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

inline std::shared_ptr<ADatatype> tryGet()

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

Returns:

Message or nullptr if no message available

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

Block until a message is available.

Returns:

Message of type T or nullptr if no message available

inline std::shared_ptr<ADatatype> get()

Block until a message is available.

Returns:

Message or nullptr if no message available

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

Gets first message in the queue.

Returns:

Message of type T or nullptr if no message available

inline std::shared_ptr<ADatatype> front()

Gets first message in the queue.

Returns:

Message or nullptr if no message available

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

Block until a message is available with a timeout.

Parameters:
  • timeout – Duration for which the function should block

  • hasTimedout[out] Outputs true if timeout occurred, false otherwise

Returns:

Message of type T otherwise nullptr if message isn’t type T or timeout occurred

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

Block until a message is available with a timeout.

Parameters:
  • timeout – Duration for which the function should block

  • hasTimedout[out] Outputs true if timeout occurred, false otherwise

Returns:

Message of type T otherwise nullptr if message isn’t type T or timeout occurred

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

Try to retrieve all messages in the queue.

Returns:

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

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

Try to retrieve all messages in the queue.

Returns:

Vector of messages

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

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

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

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

Returns:

Vector of messages

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

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

Parameters:
  • timeout – Maximum duration to block

  • hasTimedout[out] Outputs true if timeout occurred, false otherwise

Returns:

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

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

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

Parameters:
  • timeout – Maximum duration to block

  • hasTimedout[out] Outputs true if timeout occurred, false otherwise

Returns:

Vector of messages