Class Node

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< Node >

Derived Types

Class Documentation

class Node : public std::enable_shared_from_this<Node>

Abstract Node.

Subclassed by dai::NodeGroup, dai::ThreadedNode

Public Types

using Id = std::int64_t

Node identificator. Unique for every node on a single Pipeline.

Public Functions

Node(const Node&) = delete
Node &operator=(const Node&) = delete
Node(Node&&) = delete
Node &operator=(Node&&) = delete
std::string createUniqueInputName()
std::string createUniqueOutputName()
Pipeline getParentPipeline()
const Pipeline getParentPipeline() const
inline std::string getAlias() const

Get alias.

inline void setAlias(std::string alias)

Set alias.

virtual const char *getName() const = 0

Retrieves nodes name.

inline virtual void start()

Start node execution.

inline virtual void wait()

Wait for node to finish execution.

inline virtual void stop()

Stop node execution.

void stopPipeline()
virtual void buildStage1()

Build stages;.

virtual void buildStage2()
virtual void buildStage3()
std::vector<Output> getOutputs()

Retrieves all nodes outputs.

std::vector<Input> getInputs()

Retrieves all nodes inputs.

std::vector<Output*> getOutputRefs()

Retrieves reference to node outputs.

std::vector<const Output*> getOutputRefs() const

Retrieves reference to node outputs.

std::vector<Input*> getInputRefs()

Retrieves reference to node inputs.

std::vector<const Input*> getInputRefs() const

Retrieves reference to node inputs.

std::vector<OutputMap*> getOutputMapRefs()

Retrieves reference to node outputs.

std::vector<InputMap*> getInputMapRefs()

Retrieves reference to node inputs.

Output *getOutputRef(std::string name)

Retrieves reference to specific output.

Output *getOutputRef(std::string group, std::string name)
Input *getInputRef(std::string name)

Retrieves reference to specific input.

Input *getInputRef(std::string group, std::string name)
OutputMap *getOutputMapRef(std::string group)

Retrieves reference to specific output map.

InputMap *getInputMapRef(std::string group)

Retrieves reference to specific input map.

virtual bool isSourceNode() const
virtual ~Node() = default
const AssetManager &getAssetManager() const

Get node AssetManager as a const reference.

AssetManager &getAssetManager()

Get node AssetManager as a reference.

std::vector<uint8_t> loadResource(std::filesystem::path uri)

Loads resource specified by URI and returns its data.

std::vector<uint8_t> moveResource(std::filesystem::path uri)

Moves the resource out.

template<class N>
inline std::shared_ptr<N> create()

Create and place Node to this Node.

void add(std::shared_ptr<Node> node)

Add existing node to nodeMap.

std::vector<std::shared_ptr<Node>> getAllNodes() const
std::shared_ptr<const Node> getNode(Node::Id id) const
std::shared_ptr<Node> getNode(Node::Id id)
void remove(std::shared_ptr<Node> node)
ConnectionMap getConnectionMap()
void link(const Node::Output &out, const Node::Input &in)
void unlink(const Node::Output &out, const Node::Input &in)
virtual void link(std::shared_ptr<Node> in)

Get a reference to internal node map.

virtual Node::Output *requestOutput(const Capability &capability, bool onHost)
virtual std::vector<std::pair<Input&, std::shared_ptr<Capability>>> getRequiredInputs()
virtual bool runOnHost() const = 0

Returns true or false whether the node should be run on host or not.

inline const NodeMap &getNodeMap() const
inline virtual void buildInternal()

Function called from within the create function to build the node. This function is useful for initialization, setting up inputs and outputs = stuff that cannot be perform in the constuctor.

Public Members

Id id = {-1}

Id of node. Assigned after being placed on the pipeline.

Id inputId = {0}
Id outputId = {0}
std::string alias

alias or name

Public Static Attributes

static constexpr auto DEFAULT_GROUP = ""
static constexpr auto DEFAULT_NAME = ""
static constexpr auto DEFAULT_BLOCKING = true
static constexpr auto DEFAULT_QUEUE_SIZE = 3
static constexpr auto DEFAULT_WAIT_FOR_MESSAGE = false
static constexpr auto BLOCKING_QUEUE = true
static constexpr auto NON_BLOCKING_QUEUE = false

Protected Types

using NodeMap = std::vector<std::shared_ptr<Node>>
using SetConnectionInternal = std::unordered_set<ConnectionInternal, ConnectionInternal::Hash>
using ConnectionMap = std::unordered_map<std::shared_ptr<Node>, SetConnectionInternal>

Protected Functions

void setOutputRefs(std::initializer_list<Output*> l)
void setOutputRefs(Output *outRef)
void setInputRefs(std::initializer_list<Input*> l)
void setInputRefs(Input *inRef)
void setOutputMapRefs(std::initializer_list<OutputMap*> l)
void setOutputMapRefs(OutputMap *outMapRef)
void setInputMapRefs(std::initializer_list<InputMap*> l)
void setInputMapRefs(InputMap *inMapRef)
void setNodeRefs(std::initializer_list<std::pair<std::string, std::shared_ptr<Node>*>> l)
void setNodeRefs(std::pair<std::string, std::shared_ptr<Node>*> nodeRef)
void setNodeRefs(std::string alias, std::shared_ptr<Node> *nodeRef)
inline virtual bool needsBuild()
Node() = default
Node(bool conf)
void removeConnectionToNode(std::shared_ptr<Node> node)

Protected Attributes

std::vector<Output*> outputRefs
std::vector<Input*> inputRefs
std::vector<OutputMap*> outputMapRefs
std::vector<InputMap*> inputMapRefs
std::vector<std::shared_ptr<Node>*> nodeRefs
bool configureMode = {false}
std::weak_ptr<PipelineImpl> parent
int parentId = {-1}
AssetManager assetManager
NodeMap nodeMap
SetConnectionInternal connections

Friends

friend class Subnode
struct Connection

Connection between an Input and Output.

Public Functions

Connection(Output out, Input in)
Connection(ConnectionInternal c)
bool operator==(const Connection &rhs) const

Public Members

Id outputId
std::string outputName
std::string outputGroup
Id inputId
std::string inputName
std::string inputGroup

Friends

friend struct std::hash< Connection >
struct ConnectionInternal

Connection between an Input and Output internal.

Public Functions

ConnectionInternal(Output &out, Input &in)
bool operator==(const ConnectionInternal &rhs) const

Public Members

std::weak_ptr<Node> outputNode
std::string outputName
std::string outputGroup
std::weak_ptr<Node> inputNode
std::string inputName
std::string inputGroup
Output *out
Input *in
struct Hash

Public Functions

size_t operator()(const dai::Node::ConnectionInternal &obj) const
struct DatatypeHierarchy

Public Functions

inline DatatypeHierarchy(DatatypeEnum d, bool c)

Public Members

DatatypeEnum datatype
bool descendants
class Input : public dai::MessageQueue

Public Types

enum class Type

Values:

enumerator SReceiver
enumerator MReceiver

Public Functions

~Input() override
inline explicit Input(Node &par, InputDescription desc, bool ref = true)
inline const Node &getParent() const

Get the parent node

inline Node &getParent()

Get the parent node

inline Type getType() const

Get type

std::string toString() const

Input to string representation

void setWaitForMessage(bool waitForMessage)

Overrides default wait for message behavior. Applicable for nodes with multiple inputs. Specifies behavior whether to wait for this input when a Node processes certain data or not.

Parameters:

waitForMessage – Whether to wait for message to arrive to this input or not

bool getWaitForMessage() const

Get behavior whether to wait for this input when a Node processes certain data or not

Returns:

Whether to wait for message to arrive to this input or not

std::vector<DatatypeHierarchy> getPossibleDatatypes() const

Get possible datatypes that can be received

void setPossibleDatatypes(std::vector<DatatypeHierarchy> types)

Set possible datatypes that can be received

void setReusePreviousMessage(bool reusePreviousMessage)

Equivalent to setWaitForMessage but with inverted logic.

bool getReusePreviousMessage() const

Equivalent to getWaitForMessage but with inverted logic.

void setGroup(std::string group)

Set group name for this input

std::string getGroup() const

Get group name for this input

bool isConnected() const

Check if this input is connected

std::shared_ptr<InputQueue> createInputQueue(unsigned int maxSize = INPUT_QUEUE_DEFAULT_MAX_SIZE, bool blocking = INPUT_QUEUE_DEFAULT_BLOCKING)

Create an shared pointer to an input queue that can be used to send messages to this input from onhost.

Parameters:
  • maxSize – Maximum size of the input queue

  • blocking – Whether the input queue should block when full

Returns:

std::shared_ptr<InputQueue>: shared pointer to an input queue

Public Members

std::vector<DatatypeHierarchy> possibleDatatypes

Public Static Attributes

static constexpr bool INPUT_QUEUE_DEFAULT_BLOCKING = false

Default value for the blocking argument in the createInputQueue method

static constexpr unsigned int INPUT_QUEUE_DEFAULT_MAX_SIZE = 16

Default value for the maxSize argument in the createInputQueue method

Protected Attributes

std::vector<Output*> connectedOutputs
struct InputDescription

Public Members

std::string name = DEFAULT_NAME
std::string group = DEFAULT_GROUP
bool blocking = {DEFAULT_BLOCKING}
int queueSize = {DEFAULT_QUEUE_SIZE}
std::vector< DatatypeHierarchy > types DEFAULT_TYPES
bool waitForMessage = {DEFAULT_WAIT_FOR_MESSAGE}
class InputMap : public std::unordered_map<std::pair<std::string, std::string>, Input, PairHash>

Input map which keeps track of inputs assigned to a node Extends std::unordered_map<std::string, dai::Node::Input>

Public Functions

InputMap(Node &parent, InputDescription defaultInput)
InputMap(Node &parent, std::string name, InputDescription defaultInput)
Input &operator[](const std::string &key)

Create or modify an input.

Input &operator[](std::pair<std::string, std::string> groupKey)

Create or modify an input with specified group.

bool has(const std::string &key) const

Public Members

std::string name
class Output

Public Types

enum class Type

Values:

enumerator MSender
enumerator SSender

Public Functions

virtual ~Output() = default
inline Output(Node &par, OutputDescription desc, bool ref = true)
inline Node &getParent()
inline const Node &getParent() const
std::string toString() const

Output to string representation.

inline std::string getName() const

Get name of the output

inline std::string getGroup() const

Get group of the output

inline void setGroup(std::string group)

Set group name for this output

inline void setName(std::string name)

Set name for this output

inline Type getType() const

Get type of the output

std::vector<DatatypeHierarchy> getPossibleDatatypes() const

Get possible datatypes that can be sent

void setPossibleDatatypes(std::vector<DatatypeHierarchy> types)

Set possible datatypes that can be sent

bool isSamePipeline(const Input &in)

Check if this output and given input are on the same pipeline.

See also

canConnect for checking if connection is possible

Returns:

True if output and input are on the same pipeline

bool canConnect(const Input &in)

Check if connection is possible

Parameters:

inInput to connect to

Returns:

True if connection is possible, false otherwise

std::vector<ConnectionInternal> getConnections()

Retrieve all connections from this output

Returns:

Vector of connections

inline std::vector<QueueConnection> getQueueConnections()

Retrieve all queue connections from this output

Returns:

Vector of queue connections

std::shared_ptr<dai::MessageQueue> createOutputQueue(unsigned int maxSize = OUTPUT_QUEUE_DEFAULT_MAX_SIZE, bool blocking = OUTPUT_QUEUE_DEFAULT_BLOCKING)

Construct and return a shared pointer to an output message queue.

Parameters:
  • maxSize – Maximum size of the output queue

  • blocking – Whether the output queue should block when full

Returns:

std::shared_ptr<dai::MessageQueue>: shared pointer to an output queue

void link(Input &in)

Link current output to input.

Throws an error if this output cannot be linked to given input, or if they are already linked

Parameters:

inInput to link to

virtual void link(std::shared_ptr<Node> in)
void unlink(Input &in)

Unlink a previously linked connection

Throws an error if not linked.

Parameters:

inInput from which to unlink from

void send(const std::shared_ptr<ADatatype> &msg)

Sends a Message to all connected inputs

Parameters:

msg – Message to send to all connected inputs

bool trySend(const std::shared_ptr<ADatatype> &msg)

Try sending a message to all connected inputs

Parameters:

msg – Message to send to all connected inputs

Returns:

True if ALL connected inputs got the message, false otherwise

Public Static Attributes

static constexpr bool OUTPUT_QUEUE_DEFAULT_BLOCKING = false

Default value for the blocking argument in the createOutputQueue method

static constexpr unsigned int OUTPUT_QUEUE_DEFAULT_MAX_SIZE = 16

Default value for the maxSize argument in the createOutputQueue method

struct QueueConnection

Public Functions

inline bool operator==(const QueueConnection &rhs) const

Public Members

Output *output
std::shared_ptr<MessageQueue> queue
struct OutputDescription

Public Members

std::string name = {DEFAULT_NAME}
std::string group = {DEFAULT_GROUP}
std::vector< DatatypeHierarchy > types DEFAULT_TYPES
class OutputMap : public std::unordered_map<std::pair<std::string, std::string>, Output, PairHash>

Output map which keeps track of extra outputs assigned to a node Extends std::unordered_map<std::string, dai::Node::Output>

Public Functions

OutputMap(Node &parent, std::string name, OutputDescription defaultOutput, bool ref = true)
OutputMap(Node &parent, OutputDescription defaultOutput, bool ref = true)
Output &operator[](const std::string &key)

Create or modify an output.

Output &operator[](std::pair<std::string, std::string> groupKey)

Create or modify an output with specified group.

Public Members

std::string name
struct PairHash

Public Functions

template<class T1, class T2>
inline std::size_t operator()(const std::pair<T1, T2> &pair) const