int runner_run(struct runner *r) { r->root = sol_flow_node_new(NULL, r->filename, r->root_type, NULL); if (!r->root) return -1; return 0; }
static void startup(void) { struct sol_flow_builder *builder; 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 */ sol_flow_builder_del(builder); }
static void startup(void) { /* you can give your simplectype custom arguments, just give it * the struct and remember to fill its "base" with the API fields. * the 'api_version' is checked by sol-flow calls, while sub_api * is checked at mytype_func when handling the * SOL_FLOW_SIMPLECTYPE_EVENT_TYPE_OPEN. */ struct mytype_options mystuff_opts = { .base = { #ifndef SOL_NO_API_VERSION .api_version = SOL_FLOW_NODE_OPTIONS_API_VERSION, .sub_api = MYTYPE_OPTIONS_SUB_API, #endif }, .someint = 12, .somebool = true, }; builder = sol_flow_builder_new(); /* declare 'isodd' without private data and with ports: * input: IN (index: 0) * output: OUT (index: 0) */ isoddtype = sol_flow_simplectype_new_nocontext( isodd, SOL_FLOW_SIMPLECTYPE_PORT_IN("IN", SOL_FLOW_PACKET_TYPE_IRANGE), SOL_FLOW_SIMPLECTYPE_PORT_OUT("OUT", SOL_FLOW_PACKET_TYPE_BOOLEAN), NULL); /* declare mytype with 'struct mytype_context' private data and with ports: * input: IRANGE (index: 0), BOOLEAN (index: 1) * output: STRING (index: 0, as input and output have separate arrays) */ mytype = sol_flow_simplectype_new_full( "mytype", sizeof(struct mytype_context), sizeof(struct mytype_options), mytype_func, SOL_FLOW_SIMPLECTYPE_PORT_IN("IRANGE", SOL_FLOW_PACKET_TYPE_IRANGE), SOL_FLOW_SIMPLECTYPE_PORT_IN("BOOLEAN", SOL_FLOW_PACKET_TYPE_BOOLEAN), SOL_FLOW_SIMPLECTYPE_PORT_OUT("STRING", SOL_FLOW_PACKET_TYPE_STRING), NULL); /* for types declared as builtin or external modules, add by type name */ sol_flow_builder_add_node_by_type(builder, "timer", "timer", NULL); sol_flow_builder_add_node_by_type(builder, "booltoggle", "boolean/toggle", NULL); sol_flow_builder_add_node_by_type(builder, "intacc", "int/accumulator", NULL); sol_flow_builder_add_node_by_type(builder, "debug", "console", NULL); sol_flow_builder_add_node_by_type(builder, "console_mystuff", "console", NULL); sol_flow_builder_add_node_by_type(builder, "console_isodd", "console", NULL); /* use our types as we'd use any custom type: given its handle */ sol_flow_builder_add_node(builder, "isodd", isoddtype, NULL); sol_flow_builder_add_node(builder, "mystuff", mytype, &mystuff_opts.base); /* setup connections */ sol_flow_builder_connect(builder, "timer", "OUT", -1, "booltoggle", "IN", -1); sol_flow_builder_connect(builder, "timer", "OUT", -1, "intacc", "INC", -1); /* intacc OUT -> IN isodd OUT -> IN console_isodd */ sol_flow_builder_connect(builder, "intacc", "OUT", -1, "isodd", "IN", -1); sol_flow_builder_connect(builder, "isodd", "OUT", -1, "console_isodd", "IN", -1); /* booltoggle OUT -> BOOLEAN mystuff * intacc OUT -> IRANGE mystuff * mystuff STRING -> IN console_mystuff */ sol_flow_builder_connect(builder, "booltoggle", "OUT", -1, "mystuff", "BOOLEAN", -1); sol_flow_builder_connect(builder, "intacc", "OUT", -1, "mystuff", "IRANGE", -1); sol_flow_builder_connect(builder, "mystuff", "STRING", -1, "console_mystuff", "IN", -1); /* also print out values from boolean toggle and integer * accumulator so we can double check the results. */ sol_flow_builder_connect(builder, "booltoggle", "OUT", -1, "debug", "IN", -1); sol_flow_builder_connect(builder, "intacc", "OUT", -1, "debug", "IN", -1); /* this creates a static flow using the low-level API that will * actually run the flow. Note that its memory is bound to * builder, then keep builder alive. */ flow_node_type = sol_flow_builder_get_node_type(builder); /* create and run the flow */ flow = sol_flow_node_new(NULL, "simplectype", flow_node_type, NULL); }