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 | Functions
custom-node-types.c File Reference

This file contains the implementation of 3 custom node types. More...

#include <errno.h>
#include <stdio.h>
#include "custom-node-types-gen.h"
#include <sol-log.h>
#include <sol-mainloop.h>
#include "custom-node-types-gen.c"

Data Structures

struct  reader_data
 Reader: More...
 
struct  writer_data
 Writer: More...
 

Macros

#define SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options, expected,...)
 

Functions

static int logic_process (struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
 Logic: More...
 
static void reader_close (struct sol_flow_node *node, void *data)
 This destructor method is called when the node is finished. More...
 
static bool reader_on_timeout (void *data)
 
static int reader_open (struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
 this constructor method is called when the node is created. More...
 
static void writer_close (struct sol_flow_node *node, void *data)
 
static int writer_in_process (struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
 
static int writer_open (struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
 

Detailed Description

This file contains the implementation of 3 custom node types.

It does not contain the full implementation in C, rather it leverages soletta's tooling to generate boilerplate from JSON. Even this file was initially created using a tool:

To create the initial version (stub) file from JSON:

$ sol-flow-node-type-stub-gen.py \
        custom-node-types.c \
        custom-node-types-spec.json

To create the dependencies from JSON:

$ sol-flow-node-type-gen.py \
       ${top_srcdir}/data/schemas/node-type.schema \
       custom-node-types-spec.json \
       custom-node-types-gen.h \
       custom-node-types-gen.c

This file contains 3 custom node types:

Macro Definition Documentation

#define SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK (   options,
  expected,
  ... 
)
Value:
do { \
SOL_NULL_CHECK(options, __VA_ARGS__); \
if (((const struct sol_flow_node_options *)options)->sub_api != (expected)) { \
SOL_WRN("" # options "(%p)->sub_api(%" PRIu16 ") != " \
"" # expected "(%" PRIu16 ")", \
(options), \
((const struct sol_flow_node_options *)options)->sub_api, \
(expected)); \
return __VA_ARGS__; \
} \
} while (0)
#define SOL_NULL_CHECK(ptr,...)
Convenience macro to check for NULL pointer.
Definition: sol-log.h:223
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
Node options are a set of attributes defined by the Node Type that can change the behavior of a Node...
Definition: sol-flow.h:552
Examples:
/src/samples/flow/c-api/custom-node-types.c.

Referenced by reader_open(), and writer_open().

Function Documentation

static int logic_process ( struct sol_flow_node node,
void *  data,
uint16_t  port,
uint16_t  conn_id,
const struct sol_flow_packet packet 
)
static

Logic:

The logic is a node type simulates business logic, it will receive some information and deliver another. Here the logic is pretty simple, we receive an integer and deliver a boolean packet as true if the integer is even or false if it is odd.

this node contains no data, it will recompute everything based on the last received packet, thus there is no node private data, open or close methods.

Examples:
/src/samples/flow/c-api/custom-node-types.c, and /src/samples/flow/tilt-angle/arctan-node.c.

References sol_flow_packet_get_irange(), sol_flow_send_bool_packet(), SOL_INT_CHECK, and sol_irange::val.

static void reader_close ( struct sol_flow_node node,
void *  data 
)
static

This destructor method is called when the node is finished.

When this method returns the memory pointed by 'data' is released and should stop being referenced.

Examples:
/src/samples/flow/c-api/custom-node-types.c.

References sol_timeout_del(), and reader_data::timer.

static bool reader_on_timeout ( void *  data)
static
static int reader_open ( struct sol_flow_node node,
void *  data,
const struct sol_flow_node_options options 
)
static

this constructor method is called when the node is created.

The options are checked to see if it conforms to our api by using the 'sub_api' field.

The private data is guaranteed to be of size 'struct reader_data'.

Never send packets from this function as the node is still being created and there are no connections.

Examples:
/src/samples/flow/c-api/custom-node-types.c.

References reader_on_timeout(), SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK, sol_flow_send_irange_value_packet(), sol_timeout_add(), reader_data::timer, and reader_data::val.

static void writer_close ( struct sol_flow_node node,
void *  data 
)
static
static int writer_in_process ( struct sol_flow_node node,
void *  data,
uint16_t  port,
uint16_t  conn_id,
const struct sol_flow_packet packet 
)
static
static int writer_open ( struct sol_flow_node node,
void *  data,
const struct sol_flow_node_options options 
)
static