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
Typedefs | Functions

Flow-builder is a helper component that creates nodes and connections specs with a friendly API. More...

Typedefs

typedef struct sol_flow_builder sol_flow_builder
 Builder's handle. More...
 

Functions

int sol_flow_builder_add_node (struct sol_flow_builder *builder, const char *name, const struct sol_flow_node_type *type, const struct sol_flow_node_options *option)
 Add a node to the nodes spec of the resulting flow. More...
 
int sol_flow_builder_add_node_by_type (struct sol_flow_builder *builder, const char *name, const char *type_name, const char *const *options_strv)
 Add a node (via its type's name) to the nodes spec of the resulting flow. More...
 
int sol_flow_builder_connect (struct sol_flow_builder *builder, const char *src_name, const char *src_port_name, int src_port_idx, const char *dst_name, const char *dst_port_name, int dst_port_idx)
 Add a connection (via port names) to the conn spec of the resulting flow. More...
 
int sol_flow_builder_connect_by_index (struct sol_flow_builder *builder, const char *src_name, uint16_t src_port_index, const char *dst_name, uint16_t dst_port_index)
 Add a connection to the conn spec of the resulting flow. More...
 
int sol_flow_builder_del (struct sol_flow_builder *builder)
 Destroy a sol_flow_builder instance. More...
 
int sol_flow_builder_export_option (struct sol_flow_builder *builder, const char *node_name, const char *option_name, const char *exported_name)
 Exports an given option of a node using exported_name as identifier. More...
 
int sol_flow_builder_export_port_in (struct sol_flow_builder *builder, const char *node_name, const char *port_name, int port_idx, const char *exported_name)
 Exports an input port of a node using exported_name as identifier. More...
 
int sol_flow_builder_export_port_out (struct sol_flow_builder *builder, const char *node_name, const char *port_name, int port_idx, const char *exported_name)
 Exports an output port of a node using exported_name as identifier. More...
 
struct sol_flow_node_typesol_flow_builder_get_node_type (struct sol_flow_builder *builder)
 Returns the node type generated by the builder. More...
 
struct sol_flow_buildersol_flow_builder_new (void)
 Creates a new instance of a sol_flow_builder. More...
 
void sol_flow_builder_set_resolver (struct sol_flow_builder *builder, const struct sol_flow_resolver *resolver)
 Set the Resolver to be used by the builder's resulting flow. More...
 
int sol_flow_builder_set_type_description (struct sol_flow_builder *builder, const char *name, const char *category, const char *description, const char *author, const char *url, const char *license, const char *version)
 Set the type description to be used by the builder. More...
 

Detailed Description

Flow-builder is a helper component that creates nodes and connections specs with a friendly API.

Instead of declaring a node spec structure and an ordered connection spec structure directly, using node and port indexes, builder can be used to add nodes and connections in a programmatic way, using nodes and ports names.

This approach should led to a code easier to read and maintain, but it would consume a bit more memory and processing when compared with the static version.

Typedef Documentation

Builder's handle.

Function Documentation

int sol_flow_builder_add_node ( struct sol_flow_builder builder,
const char *  name,
const struct sol_flow_node_type type,
const struct sol_flow_node_options option 
)

Add a node to the nodes spec of the resulting flow.

Warning
Node names can't be NULL and must be unique within a flow.
Parameters
builderThe Builder
nameNode name
typeNode type
optionNode options
Returns
0 on success, error code (always negative) otherwise
See Also
sol_flow_builder_add_node_by_type
Examples:
/src/samples/flow/c-api/highlevel.c, and /src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

int sol_flow_builder_add_node_by_type ( struct sol_flow_builder builder,
const char *  name,
const char *  type_name,
const char *const *  options_strv 
)

Add a node (via its type's name) to the nodes spec of the resulting flow.

Resolver will be used to get the node type and options base on the type's name provided.

Warning
Node names can't be NULL and must be unique within a flow.
Parameters
builderThe Builder
nameNode name
type_nameName of the node type
options_strvNode options in a string "list" format
Returns
0 on success, error code (always negative) otherwise
See Also
sol_flow_builder_add_node
Examples:
/src/samples/flow/c-api/highlevel.c, and /src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

int sol_flow_builder_connect ( struct sol_flow_builder builder,
const char *  src_name,
const char *  src_port_name,
int  src_port_idx,
const char *  dst_name,
const char *  dst_port_name,
int  dst_port_idx 
)

Add a connection (via port names) to the conn spec of the resulting flow.

Warning
The nodes used in the connection must have been previously added by sol_flow_builder_add_node. So the names can be found by this function.

Port names must be as declared in the description structure of the node types. If no description was declared, sol_flow_builder_connect_by_index() should be used instead of this function.

Parameters
builderThe Builder
src_nameName of the source node
src_port_namePort's name in the source node
src_port_idxPort's index in the source node
dst_nameName of the destination node
dst_port_namePort's name in the destination node
dst_port_idxPort's index in the destination node
Returns
0 on success, error code (always negative) otherwise
See Also
sol_flow_builder_connect_by_index
Examples:
/src/samples/flow/c-api/highlevel.c, and /src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

int sol_flow_builder_connect_by_index ( struct sol_flow_builder builder,
const char *  src_name,
uint16_t  src_port_index,
const char *  dst_name,
uint16_t  dst_port_index 
)

Add a connection to the conn spec of the resulting flow.

Warning
The nodes used in the connection must have been previously added by sol_flow_builder_add_node. So the names can be found by this function.
Parameters
builderThe Builder
src_nameName of the source node
src_port_indexPort's index in the source node
dst_nameName of the destination node
dst_port_indexPort's index in the destination node
Returns
0 on success, error code (always negative) otherwise
See Also
sol_flow_builder_add_node_by_type
int sol_flow_builder_del ( struct sol_flow_builder builder)

Destroy a sol_flow_builder instance.

Parameters
builderBuilder to be destroyed
Returns
0 on success, error code (always negative) otherwise
Examples:
/src/samples/flow/c-api/highlevel.c, and /src/samples/flow/c-api/simple-c-type.c.

Referenced by shutdown(), and startup().

int sol_flow_builder_export_option ( struct sol_flow_builder builder,
const char *  node_name,
const char *  option_name,
const char *  exported_name 
)

Exports an given option of a node using exported_name as identifier.

Warning
The node must have been previously added by sol_flow_builder_add_node before this function is used.
Parameters
builderThe Builder
node_nameNode's name
option_nameOption's name
exported_nameName used to identify the exported option
Returns
0 on success, error code (always negative) otherwise
int sol_flow_builder_export_port_in ( struct sol_flow_builder builder,
const char *  node_name,
const char *  port_name,
int  port_idx,
const char *  exported_name 
)

Exports an input port of a node using exported_name as identifier.

Warning
The node must have been previously added by sol_flow_builder_add_node before this function is used.
Parameters
builderThe Builder
node_nameNode's name
port_namePort's name
port_idxPort's index
exported_nameName used to identify the exported port
Returns
0 on success, error code (always negative) otherwise
See Also
sol_flow_builder_export_port_out
int sol_flow_builder_export_port_out ( struct sol_flow_builder builder,
const char *  node_name,
const char *  port_name,
int  port_idx,
const char *  exported_name 
)

Exports an output port of a node using exported_name as identifier.

Warning
The node must have been previously added by sol_flow_builder_add_node before this function is used.
Parameters
builderThe Builder
node_nameNode's name
port_namePort's name
port_idxPort's index
exported_nameName used to identify the exported port
Returns
0 on success, error code (always negative) otherwise
See Also
sol_flow_builder_export_port_in
struct sol_flow_node_type* sol_flow_builder_get_node_type ( struct sol_flow_builder builder)

Returns the node type generated by the builder.

It should be used to create nodes with sol_flow_node_new(). After the type is created, no more nodes or connections can be added.

This node type must be deleted using sol_flow_node_type_del().

Parameters
builderThe Builder
Returns
The generated node type on success, NULL otherwise
Examples:
/src/samples/flow/c-api/highlevel.c, and /src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

struct sol_flow_builder* sol_flow_builder_new ( void  )

Creates a new instance of a sol_flow_builder.

It should be deleted with sol_flow_builder_del() only after the flow stops running.

Returns
A new Builder's instance, NULL on error.
Examples:
/src/samples/flow/c-api/highlevel.c, and /src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

void sol_flow_builder_set_resolver ( struct sol_flow_builder builder,
const struct sol_flow_resolver resolver 
)

Set the Resolver to be used by the builder's resulting flow.

Parameters
builderThe Builder
resolverResolver to be used
Note
Passing NULL to resolver will set the default resolver.
int sol_flow_builder_set_type_description ( struct sol_flow_builder builder,
const char *  name,
const char *  category,
const char *  description,
const char *  author,
const char *  url,
const char *  license,
const char *  version 
)

Set the type description to be used by the builder.

Input/output ports and options descriptions are automatically set. The strings passed as arguments will be copied.

Parameters
builderThe Builder
nameNode type name
categoryNode type category
descriptionNode type description
authorAuthor's name
urlNode type url
licenseLicense text
versionNode type version
Returns
0 on success, error code (always negative) otherwise