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
/src/samples/flow/c-api/highlevel.c
/*
* This file is part of the Soletta (TM) Project
*
* Copyright (C) 2015 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
/* we include custom-node-types-gen.h but are not building a module,
* disregard log_init */
#include "sol-macros.h"
#include "soletta.h"
#include "custom-node-types-gen.h"
static struct sol_flow_node *flow;
static void
startup(void)
{
struct sol_flow_node_type_custom_node_types_reader_options reader_opts =
SOL_FLOW_NODE_TYPE_CUSTOM_NODE_TYPES_READER_OPTIONS_DEFAULTS(
.intopt = 1
);
struct sol_flow_node_type_custom_node_types_writer_options writer_opts =
SOL_FLOW_NODE_TYPE_CUSTOM_NODE_TYPES_WRITER_OPTIONS_DEFAULTS(
.prefix = "writer prefix from options"
);
builder = sol_flow_builder_new();
/* use our custom node types */
sol_flow_builder_add_node(builder, "reader",
SOL_FLOW_NODE_TYPE_CUSTOM_NODE_TYPES_READER,
&reader_opts.base);
sol_flow_builder_add_node(builder, "logic",
SOL_FLOW_NODE_TYPE_CUSTOM_NODE_TYPES_LOGIC,
NULL);
sol_flow_builder_add_node(builder, "writer",
SOL_FLOW_NODE_TYPE_CUSTOM_NODE_TYPES_WRITER,
&writer_opts.base);
sol_flow_builder_connect(builder, "reader", "OUT", -1, "logic", "IN", -1);
sol_flow_builder_connect(builder, "logic", "OUT", -1, "writer", "IN", -1);
/* Also output to console using soletta's console node type. If
* console is builtin libsoletta, it is used, otherwise a module
* console.so is looked up and if exists will be added. If nothing
* can be found (ie: module is disabled) it will keep going as we
* are not checking the return value of
* sol_flow_builder_add_node().
*/
sol_flow_builder_add_node_by_type(builder, "console", "console", NULL);
sol_flow_builder_connect(builder, "reader", "OUT", -1, "console", "IN", -1);
sol_flow_builder_connect(builder, "logic", "OUT", -1, "console", "IN", -1);
/* this creates a static flow using the low-level API that will
* actually run the flow.
*/
flow_node_type = sol_flow_builder_get_node_type(builder);
/* create and run the flow */
flow = sol_flow_node_new(NULL, "highlevel", flow_node_type, NULL);
/* builder is not necessary anymore, so delete it */
}
static void
shutdown(void)
{
/* stop the flow, disconnect ports and close children nodes */
/* delete the node type we've created with builder */
sol_flow_node_type_del(flow_node_type);
}