Commit f747545c authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add input/output 'add' functions

parent 7e561e46
......@@ -23,6 +23,7 @@
#include <math.h>
#include <pthread.h>
#include <dlfcn.h>
#include <errno.h>
#include "controller_block.h"
#include "controller_sample.h"
......@@ -572,3 +573,201 @@ void controller_block_free(struct controller_block *blk)
free(blk);
}
struct controller_block_interm *controller_block_add_input(
struct controller_block *blk, char *name,
enum controller_block_term_type type)
{
int inputs;
int idx;
struct controller_block_interm *input;
inputs = blk->inputs + 1;
if (inputs == 1) {
input = malloc(sizeof(struct controller_block_interm));
} else {
input = realloc(blk->input, inputs *
sizeof(struct controller_block_interm));
}
if (input == NULL)
return NULL;
blk->inputs = inputs;
blk->input = input;
idx = inputs - 1;
input[idx].name = name;
input[idx].type = type;
input[idx].ghostof = NULL;
return &input[idx];
}
int controller_block_add_float_input(struct controller_block *blk,
char *name, float **ptr)
{
struct controller_block_interm *input;
input = controller_block_add_input(blk, name,
CONTROLLER_BLOCK_TERM_FLOAT);
if (input == NULL)
return ENOMEM;
input->value.f = ptr;
return 0;
}
int controller_block_add_bool_input(struct controller_block *blk,
char *name, bool **ptr)
{
struct controller_block_interm *input;
input = controller_block_add_input(blk, name,
CONTROLLER_BLOCK_TERM_BOOL);
if (input == NULL)
return ENOMEM;
input->value.b = ptr;
return 0;
}
int controller_block_add_sint16_input(struct controller_block *blk,
char *name, int16_t **ptr)
{
struct controller_block_interm *input;
input = controller_block_add_input(blk, name,
CONTROLLER_BLOCK_TERM_SINT16);
if (input == NULL)
return ENOMEM;
input->value.v = (void **)ptr;
return 0;
}
int controller_block_add_sint32_input(struct controller_block *blk,
char *name, int32_t **ptr)
{
struct controller_block_interm *input;
input = controller_block_add_input(blk, name,
CONTROLLER_BLOCK_TERM_SINT32);
if (input == NULL)
return ENOMEM;
input->value.v = (void **)ptr;
return 0;
}
struct controller_block_outterm *controller_block_add_output(
struct controller_block *blk, char *name,
enum controller_block_term_type type)
{
int outputs;
int idx;
struct controller_block_outterm *output;
outputs = blk->outputs + 1;
if (outputs == 1) {
output = malloc(sizeof(struct controller_block_outterm));
} else {
output = realloc(blk->output, outputs *
sizeof(struct controller_block_outterm));
}
if (output == NULL)
return NULL;
blk->outputs = outputs;
blk->output = output;
idx = outputs - 1;
output[idx].name = name;
output[idx].type = type;
output[idx].source = blk;
return &output[idx];
}
int controller_block_add_float_output(struct controller_block *blk,
char *name, float *ptr)
{
struct controller_block_outterm *output;
output = controller_block_add_output(blk, name,
CONTROLLER_BLOCK_TERM_FLOAT);
if (output == NULL)
return ENOMEM;
output->value.f = ptr;
return 0;
}
int controller_block_add_bool_output(struct controller_block *blk,
char *name, bool *ptr)
{
struct controller_block_outterm *output;
output = controller_block_add_output(blk, name,
CONTROLLER_BLOCK_TERM_BOOL);
if (output == NULL)
return ENOMEM;
output->value.b = ptr;
return 0;
}
int controller_block_add_uint16_output(struct controller_block *blk,
char *name, uint16_t *ptr)
{
struct controller_block_outterm *output;
output = controller_block_add_output(blk, name,
CONTROLLER_BLOCK_TERM_UINT16);
if (output == NULL)
return ENOMEM;
output->value.v = ptr;
return 0;
}
int controller_block_add_sint32_output(struct controller_block *blk,
char *name, int32_t *ptr)
{
struct controller_block_outterm *output;
output = controller_block_add_output(blk, name,
CONTROLLER_BLOCK_TERM_SINT32);
if (output == NULL)
return ENOMEM;
output->value.v = ptr;
return 0;
}
int controller_block_add_sint16_output(struct controller_block *blk,
char *name, int16_t *ptr)
{
struct controller_block_outterm *output;
output = controller_block_add_output(blk, name,
CONTROLLER_BLOCK_TERM_SINT16);
if (output == NULL)
return ENOMEM;
output->value.v = ptr;
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment