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
Flow's Simple C Type

Helper to create a flow node type from a simple C function. More...

Data Structures

struct  sol_flow_simple_c_type_event
 Simple C event structure. More...
 

Macros

#define sol_flow_simple_c_type_new(context_data_type, cb,...)   sol_flow_simple_c_type_new_full(#cb, sizeof(context_data_type), sizeof(struct sol_flow_node_type), cb, ## __VA_ARGS__, NULL)
 This macro will simplify usage of sol_flow_simple_c_type_new_full() by taking only a context data type and the callback, as well as the port information. More...
 
#define sol_flow_simple_c_type_new_nocontext(cb,...)   sol_flow_simple_c_type_new_full(#cb, 0, sizeof(struct sol_flow_node_type), cb, ## __VA_ARGS__, NULL)
 This macro will simplify usage of sol_flow_simple_c_type_new_full() by taking only the callback as well as the port information. More...
 
#define SOL_FLOW_SIMPLE_C_TYPE_PORT_IN(name, type)
 Helper macro to declare an input port. More...
 
#define SOL_FLOW_SIMPLE_C_TYPE_PORT_OUT(name, type)
 Helper macro to declare an output port. More...
 
#define SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_IN   1
 Input port identifier. More...
 
#define SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_OUT   2
 Output port identifier. More...
 

Typedefs

typedef struct
sol_flow_simple_c_type_event 
sol_flow_simple_c_type_event
 Simple C event structure. More...
 

Functions

uint16_t sol_flow_simple_c_type_get_port_in_index (const struct sol_flow_node_type *type, const char *port_in_name)
 Helper to retrieve the input port index from its name. More...
 
uint16_t sol_flow_simple_c_type_get_port_out_index (const struct sol_flow_node_type *type, const char *port_out_name)
 Helper to retrieve the output port index from its name. More...
 
struct sol_flow_node_typesol_flow_simple_c_type_new_full (const char *name, size_t context_data_size, uint16_t options_size, int(*func)(struct sol_flow_node *node, const struct sol_flow_simple_c_type_event *ev, void *data),...) SOL_ATTR_SENTINEL
 Creates a flow node type using a simple C function. More...
 

Detailed Description

Helper to create a flow node type from a simple C function.

Simple C Type is a helper to ease development of custom nodes where the full power of a node type is not needed. Instead, a single function is used and given to the node, the node private data and the event.

Each node will have a context (private) data of size declared to sol_flow_simple_c_type_new_full(). This is given as the last argument to the callback func as well as can be retrieved with sol_flow_node_get_private_data(). An example:

static int
const struct sol_flow_simple_c_type_event *ev,
void *data)
{
struct my_context *ctx = data;
if (ev->type == SOL_FLOW_SIMPLE_C_TYPE_EVENT_TYPE_OPEN) {
ctx->my_value = initial_value;
ctx->my_string = strdup("inital_string");
} else if (ev->type == SOL_FLOW_SIMPLE_C_TYPE_EVENT_TYPE_CLOSE) {
free(ctx->my_string);
// do not free(ctx), it's automatically deleted
} else {
printf("value=%d, string=%s\n", ctx->my_value, ctx->my_string);
}
}

Macro Definition Documentation

#define sol_flow_simple_c_type_new (   context_data_type,
  cb,
  ... 
)    sol_flow_simple_c_type_new_full(#cb, sizeof(context_data_type), sizeof(struct sol_flow_node_type), cb, ## __VA_ARGS__, NULL)

This macro will simplify usage of sol_flow_simple_c_type_new_full() by taking only a context data type and the callback, as well as the port information.

It will transform the callback (func) into the name of the simple_c_type as well as doing the sizeof(context_data_type) to specify the data size.

See Also
sol_flow_simple_c_type_new_full()
sol_flow_simple_c_type_new_nocontext()
#define sol_flow_simple_c_type_new_nocontext (   cb,
  ... 
)    sol_flow_simple_c_type_new_full(#cb, 0, sizeof(struct sol_flow_node_type), cb, ## __VA_ARGS__, NULL)

This macro will simplify usage of sol_flow_simple_c_type_new_full() by taking only the callback as well as the port information.

It will transform the callback (func) into the name of the simple_c_type and use context_data_size as 0.

See Also
sol_flow_simple_c_type_new_full()
sol_flow_simple_c_type_new()
Examples:
/src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

#define SOL_FLOW_SIMPLE_C_TYPE_PORT_IN (   name,
  type 
)
Value:
SOL_TYPE_CHECK(const char *, name), \
SOL_TYPE_CHECK(const struct sol_flow_packet_type *, type), \
#define SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_IN
Input port identifier.
Definition: sol-flow-simple-c-type.h:94
A packet type defines what's the content of a packet and how it's stored and retrieved.
Definition: sol-flow-packet.h:60
#define SOL_TYPE_CHECK(type, value)
Macro to check type of given value.
Definition: sol-types.h:95

Helper macro to declare an input port.

Parameters
namePort's name
typeData type of the packets that this port should receive
Examples:
/src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

#define SOL_FLOW_SIMPLE_C_TYPE_PORT_OUT (   name,
  type 
)
Value:
SOL_TYPE_CHECK(const char *, name), \
SOL_TYPE_CHECK(const struct sol_flow_packet_type *, type), \
#define SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_OUT
Output port identifier.
Definition: sol-flow-simple-c-type.h:99
A packet type defines what's the content of a packet and how it's stored and retrieved.
Definition: sol-flow-packet.h:60
#define SOL_TYPE_CHECK(type, value)
Macro to check type of given value.
Definition: sol-types.h:95

Helper macro to declare an output port.

Parameters
namePort's name
typeData type of the packets that this port will send
Examples:
/src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().

#define SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_IN   1

Input port identifier.

#define SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_OUT   2

Output port identifier.

Typedef Documentation

Simple C event structure.

Function Documentation

uint16_t sol_flow_simple_c_type_get_port_in_index ( const struct sol_flow_node_type type,
const char *  port_in_name 
)

Helper to retrieve the input port index from its name.

While the port index is defined by the declaration order given to sol_flow_simple_c_type_new_full(), sometimes it is desirable to find in the index given the string.

Note
Note that this needs a lookup, so avoid doing it in hot paths.
Parameters
typethe type to search the port index given its name.
port_in_namethe input port name to retrieve the index.
Returns
UINT16_MAX if not found, the index if found.
uint16_t sol_flow_simple_c_type_get_port_out_index ( const struct sol_flow_node_type type,
const char *  port_out_name 
)

Helper to retrieve the output port index from its name.

While the port index is defined by the declaration order given to sol_flow_simple_c_type_new_full(), sometimes it is desirable to find out the index given the string.

Note
Note that this needs a lookup, so avoid doing it in hot paths.
Parameters
typethe type to search the port index given its name.
port_out_namethe output port name to retrieve the index.
Returns
UINT16_MAX if not found, the index if found.
Examples:
/src/samples/flow/c-api/simple-c-type.c.

Referenced by on_timeout().

struct sol_flow_node_type* sol_flow_simple_c_type_new_full ( const char *  name,
size_t  context_data_size,
uint16_t  options_size,
int(*)(struct sol_flow_node *node, const struct sol_flow_simple_c_type_event *ev, void *data)  func,
  ... 
)

Creates a flow node type using a simple C function.

The newly returned type should be freed calling sol_flow_node_type_del().

The ports of the given type should be specified using the NULL-terminated variable arguments, each port takes a triple name, packet_type and direction. Name is the string and direction is either SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_IN or SOL_FLOW_SIMPLE_C_TYPE_PORT_TYPE_OUT. Consider using the macros SOL_FLOW_SIMPLE_C_TYPE_PORT_IN() and SOL_FLOW_SIMPLE_C_TYPE_PORT_OUT() to make it clear and future-proof.

Parameters
namethe type name, will be used in debug. Often this is the name of the function you're using.
context_data_sizethe amount of bytes to store for each node instance. This memory can be retrieved from a node with sol_flow_node_get_private_data() and is given to func as the last argument. If zero is given, then this node shouldn't store per-instance information and data shouldn't be used.
options_sizethe amount of bytes to store options used with this type. The options struct must contain a struct sol_flow_node_options as its first member.
functhe function to call for all events of this node such as opening (creating), closing (destroying), ports being connected or disconnected as well as incoming packets on input ports.
Returns
newly created node type, free using its sol_flow_node_type_del().
See Also
sol_flow_simple_c_type_new()
sol_flow_simple_c_type_new_nocontext()
sol_flow_node_type_del()
Examples:
/src/samples/flow/c-api/simple-c-type.c.

Referenced by startup().