Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions

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_nodesol_flow_single_get_child (const struct sol_flow_node *node)
 Return the reference to the inner node. More...
 
struct sol_flow_nodesol_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_typesol_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_typesol_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...
 

Detailed Description

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().

Macro Definition Documentation

#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.

Examples:
/src/samples/flow/c-api/single-node.c.

Referenced by create_minutes(), and create_seconds().

#define SOL_FLOW_SINGLE_OPTIONS_DEFAULTS (   ...)
Value:
{ \
.base = { \
}, \
__VA_ARGS__ \
}
#define SOL_FLOW_SINGLE_OPTIONS_API_VERSION
This versions the rest of the structure and should be used in base.sub_api.
Definition: sol-flow-single.h:96
#define SOL_SET_API_VERSION(expression)
This macro will cope with SOL_NO_API_VERSION and allows easy declaration of api_version fields...
Definition: sol-mainloop.h:660
#define SOL_FLOW_NODE_OPTIONS_API_VERSION
Compile time API version to be checked during runtime.
Definition: sol-flow.h:554

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 Documentation

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.

Function Documentation

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.

Parameters
nodea valid node created from sol_flow_single_new() or sol_flow_single_new_type().
port_idxthe port index to connect.
Returns
number of connections (>1) on success, -errno on error. 0 is never returned.
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.

Note
prefer a static list of connections specified at node creation time. Some inner nodes will deliver packets when they are opened/created, then you will miss the initial packets since they will be dropped due lack of connections.
Parameters
nodea valid node created from sol_flow_single_new() or sol_flow_single_new_type().
port_idxthe port index to connect.
Returns
number of connections (>1) on success, -errno on error. 0 is never returned.
Examples:
/src/samples/flow/c-api/single-node.c.

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.

Parameters
nodea valid node created from sol_flow_single_new() or sol_flow_single_new_type().
port_idxthe port index to disconnect.
Returns
number of connections (>1) on success, -errno on error. 0 if the last connection is gone.
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.

Parameters
nodea valid node created from sol_flow_single_new() or sol_flow_single_new_type().
port_idxthe port index to disconnect.
Returns
number of connections (>1) on success, -errno on error. 0 if the last connection is gone.
Examples:
/src/samples/flow/c-api/single-node.c.

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.

Parameters
nodea valid node created from sol_flow_single_new() or sol_flow_single_new_type().
Returns
the inner node wrapped by the given node.
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.

Parameters
idA string to identify the node, may be NULL.
base_typeThe type of the node to be wrapped, it must be valid and a reference is stored during the returned node lifetime.
optionsthe options to be forwarded to the wrapped node of type base_type.
connected_ports_inif non-NULL, an array of input port indexes to connect. The array must be UINT16_MAX terminated. See SOL_FLOW_SINGLE_CONNECTIONS().
connected_ports_outif non-NULL, an array of output port indexes to connect. The array must be UINT16_MAX terminated. See SOL_FLOW_SINGLE_CONNECTIONS().
processif 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_datathe context to provide to process when it is called.
Returns
NULL on error or the newly created node. It should be deleted with sol_flow_node_del(). One can feed the node with packets by calling sol_flow_send_packet().
See Also
sol_flow_single_new_type()
Examples:
/src/samples/flow/c-api/single-node.c.

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.

Parameters
base_typethe type to be wrapped. It must be a valid type and a reference is stored while the returned type is alive.
Returns
NULL on error or newly allocated node type wrapping base_type, this should be deleted with sol_flow_node_type_del().
See Also
sol_flow_single_new()
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.

Parameters
single_typea type previously created with sol_flow_single_new_type().
Returns
the internal (child or base_type) used with sol_flow_single_new_type(), or NULL on failures.