Soletta™ Framework
|
Single flow is a parent node that creates a single children that works stand alone. More...
Data Structures | |
struct | sol_flow_single_options |
Structure for the specification of a single node. More... | |
Macros | |
#define | SOL_FLOW_SINGLE_CONNECTIONS(...) (const uint16_t[]){ __VA_ARGS__, UINT16_MAX } |
Convenience macro to declare an array of uint16_t terminated by UINT16_MAX . More... | |
#define | SOL_FLOW_SINGLE_OPTIONS_DEFAULTS(...) |
This macro sets struct sol_flow_single_options base member to contain the proper api_version (SOL_FLOW_NODE_OPTIONS_API_VERSION) and sub_api (SOL_FLOW_SINGLE_OPTIONS_API_VERSION). More... | |
Typedefs | |
typedef struct sol_flow_single_options | sol_flow_single_options |
Structure for the specification of a single node. More... | |
Functions | |
int32_t | sol_flow_single_connect_port_in (struct sol_flow_node *node, uint16_t port_idx) |
Connect the input port port_idx of the inner node. More... | |
int32_t | sol_flow_single_connect_port_out (struct sol_flow_node *node, uint16_t port_idx) |
Connect the output port port_idx of the inner node. More... | |
int32_t | sol_flow_single_disconnect_port_in (struct sol_flow_node *node, uint16_t port_idx) |
Disconnect the input port port_idx of the inner node. More... | |
int32_t | sol_flow_single_disconnect_port_out (struct sol_flow_node *node, uint16_t port_idx) |
Disconnect the output port port_idx of the inner node. More... | |
struct sol_flow_node * | sol_flow_single_get_child (const struct sol_flow_node *node) |
Return the reference to the inner node. More... | |
struct sol_flow_node * | sol_flow_single_new (const char *id, const struct sol_flow_node_type *base_type, const struct sol_flow_node_options *options, const uint16_t *connected_ports_in, const uint16_t *connected_ports_out, void(*process)(void *user_data, struct sol_flow_node *node, uint16_t port, const struct sol_flow_packet *packet), const void *user_data) |
create a single-node instance for the given base_type. More... | |
struct sol_flow_node_type * | sol_flow_single_new_type (const struct sol_flow_node_type *base_type) |
create a wrapper type to use base_type nodes without a flow. More... | |
const struct sol_flow_node_type * | sol_flow_single_type_get_child_type (const struct sol_flow_node_type *single_type) |
Given a single-node type wrapper, return the internal (child) type. More... | |
Single flow is a parent node that creates a single children that works stand alone.
Sometimes it is desired to use a single node, manually feeding packets and processing those being sent on the node's output port.
The single node type does exactly that by wrapping a base type (also called "child type"), it will create an internal node and take care to deliver incoming packets to that and also take its outgoing packets and calling the provided process()
method, if any.
It also forwards connections and disconnections requests, as some nodes will only work if there is a connection established for a given port.
See sol_flow_single_new() and sol_flow_single_new_type().
#define SOL_FLOW_SINGLE_CONNECTIONS | ( | ... | ) | (const uint16_t[]){ __VA_ARGS__, UINT16_MAX } |
Convenience macro to declare an array of uint16_t
terminated by UINT16_MAX
.
This can be used in sol_flow_single_new() or struct sol_flow_single_options.
Referenced by create_minutes(), and create_seconds().
#define SOL_FLOW_SINGLE_OPTIONS_DEFAULTS | ( | ... | ) |
This macro sets struct sol_flow_single_options base member to contain the proper api_version
(SOL_FLOW_NODE_OPTIONS_API_VERSION) and sub_api
(SOL_FLOW_SINGLE_OPTIONS_API_VERSION).
The remaining variable arguments are passed as member initializers, please use ".name = value" to avoid problems and make code easy to read.
typedef struct sol_flow_single_options sol_flow_single_options |
Structure for the specification of a single node.
This option is used to instatiate a single-node that wrappes an inner node of a given type specified at sol_flow_single_new_type().
It is used internally by sol_flow_single_new() or explicitly by those calling sol_flow_new() manually.
It contains a struct sol_flow_node_options header (base
) so it conforms to the options protocol. Be sure to fill its api_version
with SOL_FLOW_NODE_OPTIONS_API_VERSION and sub_api
with SOL_FLOW_SINGLE_OPTIONS_API_VERSION, or use SOL_FLOW_SINGLE_OPTIONS_DEFAULTS() to help you.
int32_t sol_flow_single_connect_port_in | ( | struct sol_flow_node * | node, |
uint16_t | port_idx | ||
) |
Connect the input port port_idx of the inner node.
Ports connections are counted, so a matching number of disconnects must happen to actually disconnect.
node | a valid node created from sol_flow_single_new() or sol_flow_single_new_type(). |
port_idx | the port index to connect. |
int32_t sol_flow_single_connect_port_out | ( | struct sol_flow_node * | node, |
uint16_t | port_idx | ||
) |
Connect the output port port_idx of the inner node.
Ports connections are counted, so a matching number of disconnects must happen to actually disconnect.
node | a valid node created from sol_flow_single_new() or sol_flow_single_new_type(). |
port_idx | the port index to connect. |
Referenced by on_minutes_packet().
int32_t sol_flow_single_disconnect_port_in | ( | struct sol_flow_node * | node, |
uint16_t | port_idx | ||
) |
Disconnect the input port port_idx of the inner node.
Ports connections are counted, so a matching number of disconnects must happen to actually disconnect.
node | a valid node created from sol_flow_single_new() or sol_flow_single_new_type(). |
port_idx | the port index to disconnect. |
int32_t sol_flow_single_disconnect_port_out | ( | struct sol_flow_node * | node, |
uint16_t | port_idx | ||
) |
Disconnect the output port port_idx of the inner node.
Ports connections are counted, so a matching number of disconnects must happen to actually disconnect.
node | a valid node created from sol_flow_single_new() or sol_flow_single_new_type(). |
port_idx | the port index to disconnect. |
Referenced by on_minutes_packet().
struct sol_flow_node* sol_flow_single_get_child | ( | const struct sol_flow_node * | node | ) |
Return the reference to the inner node.
node | a valid node created from sol_flow_single_new() or sol_flow_single_new_type(). |
struct sol_flow_node* sol_flow_single_new | ( | const char * | id, |
const struct sol_flow_node_type * | base_type, | ||
const struct sol_flow_node_options * | options, | ||
const uint16_t * | connected_ports_in, | ||
const uint16_t * | connected_ports_out, | ||
void(*)(void *user_data, struct sol_flow_node *node, uint16_t port, const struct sol_flow_packet *packet) | process, | ||
const void * | user_data | ||
) |
create a single-node instance for the given base_type.
Sometimes it is desired to use a single node, manually feeding packets and processing those being sent on the node's output port.
This function is a helper around sol_flow_single_new_type() that creates the type and instance using the provided parameters.
If many instances of the same type are desired, it is recommended to create a single type with sol_flow_single_new_type() and then call sol_flow_node_new() on it, using struct sol_flow_single_options to inform options of the inner node, connected ports and process callback.
It is worth to mention that node must be informed of the ports they will receive packets and those that they should send by specifying the connected_ports_in
and connected_ports_out
arrays.
id | A string to identify the node, may be NULL . |
base_type | The type of the node to be wrapped, it must be valid and a reference is stored during the returned node lifetime. |
options | the options to be forwarded to the wrapped node of type base_type. |
connected_ports_in | if non-NULL, an array of input port indexes to connect. The array must be UINT16_MAX terminated. See SOL_FLOW_SINGLE_CONNECTIONS(). |
connected_ports_out | if non-NULL, an array of output port indexes to connect. The array must be UINT16_MAX terminated. See SOL_FLOW_SINGLE_CONNECTIONS(). |
process | if non-NULL, the callback to process outgoing packets produced by node. The first argument, user_data will be the value of the same-name sibling parameter. |
user_data | the context to provide to process when it is called. |
Referenced by create_minutes(), and create_seconds().
struct sol_flow_node_type* sol_flow_single_new_type | ( | const struct sol_flow_node_type * | base_type | ) |
create a wrapper type to use base_type nodes without a flow.
Sometimes it is desired to use a single node, manually feeding packets and processing those being sent on the node's output port.
To make it easy this function returns a wrapper node type that can be instantiated with sol_flow_node_new() and when sol_flow_send_packet() (or variants such as sol_flow_send_bool_packet()) will feed the base type's instance with such packets, as well as outgoing packets produced by that instance can be processed by the external user.
To process the outgoing packets provide the process
member of the struct sol_flow_single_options or the same-name parameter for the sol_flow_single_new() helper. They will receive the context data provided in user_data
.
It is worth to mention that node must be informed of the ports they will receive packets and those that they should send by specifying the connected_ports_in
and connected_ports_out
arrays. Sending packets to disconnected ports is not verified may result in malfunction.
However, some nodes may produce packets even in disconnected ports and these are not filtered-out automatically. If you do not want to receive packets in disconnected ports, filter them by checking the port
parameter.
base_type | the type to be wrapped. It must be a valid type and a reference is stored while the returned type is alive. |
NULL
on error or newly allocated node type wrapping base_type, this should be deleted with sol_flow_node_type_del().const struct sol_flow_node_type* sol_flow_single_type_get_child_type | ( | const struct sol_flow_node_type * | single_type | ) |
Given a single-node type wrapper, return the internal (child) type.
This is useful to create options since the wrapper type options differ from the internal.
single_type | a type previously created with sol_flow_single_new_type(). |