bool
sml_matrix_equals(struct sml_matrix *m1, struct sml_matrix *m2, struct
    sol_vector *changed,
    sml_cmp_cb cmp_cb)
{
    uint16_t i, j, len_i, len_j, *idx;
    struct sol_vector *vec1, *vec2;
    bool r = false;

    len_i = max(m1->data.len, m2->data.len);
    for (i = 0; i < len_i; i++) {
        vec1 = sol_vector_get(&m1->data, i);
        vec2 = sol_vector_get(&m2->data, i);
        len_j = max((vec1 ? vec1->len : 0), (vec2 ? vec2->len : 0));
        for (j = 0; j < len_j; j++) {
            if (!cmp_cb(sol_vector_get(vec1, j),
                sol_vector_get(vec2, j))) {
                if (changed) {
                    idx = sol_vector_append(changed);
                    if (!idx) {
                        sml_critical("Could not append the index:%d to the" \
                            " changed vector", i);
                        return false;
                    }
                    *idx = i;
                }
                r = true;
                break;
            }
        }
    }

    return r;
}
示例#2
0
static inline const void *
sol_mavlink_parse_addr_protocol(const char *str, struct sol_str_slice *addr, int *port)
{
    struct sol_vector tokens;
    struct sol_str_slice slice = sol_str_slice_from_str(str);
    const void *init;

    tokens = sol_str_slice_split(slice, ":", 0);
    if (tokens.len <= 1) {
        SOL_ERR("Invalid addr string, it must specify at least <prot>:<addr>");
        return NULL;
    }

    init = sol_str_table_ptr_lookup_fallback
            (protocol_table, STR_SLICE_VAL(sol_vector_get(&tokens, 0)),
            sol_mavlink_init_tcp);
    if (!init) {
        SOL_ERR("Invalid protocol");
        goto err;
    }

    *addr = STR_SLICE_VAL(sol_vector_get(&tokens, 1));

    if (tokens.len >= 3)
        sol_str_slice_to_int(STR_SLICE_VAL(sol_vector_get(&tokens, 2)), port);

    sol_vector_clear(&tokens);

    return init;

err:
    sol_vector_clear(&tokens);
    return NULL;
}
void *
sml_matrix_get(struct sml_matrix *m, uint16_t i, uint16_t j)
{
    struct sol_vector *line = sol_vector_get(&m->data, i);

    if (!line)
        return NULL;
    return sol_vector_get(line, j);
}
struct terms_width*
_get_terms_width(struct sml_fuzzy *fuzzy, struct sml_variable *var)
{
    uint16_t i;

    if (sml_fuzzy_is_input(fuzzy, var, &i))
        return (struct terms_width *)sol_vector_get(&fuzzy->input_terms_width,
            i);
    if (sml_fuzzy_is_output(fuzzy, var, &i))
        return (struct terms_width *)sol_vector_get(&fuzzy->output_terms_width,
            i);

    return NULL;
}
static int
http_composed_client_open(struct sol_flow_node *node, void *data,
    const struct sol_flow_node_options *options)
{
    struct http_composed_client_data *cdata = data;
    const struct http_composed_client_type *self;
    const struct http_composed_client_options *opts;
    const struct http_composed_client_port_out *out;

    opts = (struct http_composed_client_options *)options;

    if (opts->url) {
        cdata->url = strdup(opts->url);
        SOL_NULL_CHECK(cdata->url, -ENOMEM);
    }

    self = (const struct http_composed_client_type *)
        sol_flow_node_get_type(node);

    sol_ptr_vector_init(&cdata->pending_conns);

    cdata->inputs_len = self->ports_in.len - INPUT_FIXED_PORTS_LEN;
    cdata->inputs = calloc(cdata->inputs_len, sizeof(struct sol_flow_packet *));
    SOL_NULL_CHECK_GOTO(cdata->inputs, err);

    out = sol_vector_get(&self->ports_out, 0);
    cdata->composed_type = out->base.packet_type;

    return 0;

err:
    free(cdata->url);
    return -ENOMEM;
}
示例#6
0
int
byte_validator_process(
    struct sol_flow_node *node,
    void *data,
    uint16_t port,
    uint16_t conn_id,
    const struct sol_flow_packet *packet)
{
    struct byte_validator_data *mdata = data;
    unsigned char *op;
    int r;
    unsigned char val;
    bool match;

    if (mdata->done) {
        sol_flow_send_error_packet(node, ECANCELED,
            "Input stream already deviated from expected data, ignoring packets.");
        return 0;
    }
    r = sol_flow_packet_get_byte(packet, &val);
    SOL_INT_CHECK(r, < 0, r);
    op = sol_vector_get(&mdata->values, mdata->next_index);
    match = val == *op;
    mdata->next_index++;

    if (mdata->next_index == mdata->values.len || !match) {
        sol_flow_send_boolean_packet(node,
            SOL_FLOW_NODE_TYPE_TEST_INT_VALIDATOR__OUT__OUT, match);
        mdata->done = true;
    }
    return 0;
}
void
sml_matrix_debug(struct sml_matrix *m, sml_matrix_convert_cb convert)
{
    struct sml_string *str = sml_string_new("\t");
    uint16_t i, len_i, j, len_j;
    struct sol_vector *vec;
    char buf[BUF_LEN];

    sml_string_append(str, "{");
    len_i = m->data.len;
    for (i = 0; i < len_i; i++) {
        vec = sol_vector_get(&m->data, i);
        if (i > 0)
            sml_string_append(str, ", ");

        sml_string_append(str, "{");
        len_j = vec ? vec->len : 0;
        for (j = 0; j < len_j; j++) {
            if (j > 0)
                sml_string_append(str, ", ");

            convert(buf, BUF_LEN, sml_matrix_get(m, i, j));
            sml_string_append_printf(str, "%s", buf);
        }
        sml_string_append(str, "}");
    }
    sml_string_append(str, "}");
    sml_debug("%s", sml_string_get_string(str));

    sml_string_free(str);
}
int
float_validator_process(
    struct sol_flow_node *node,
    void *data,
    uint16_t port,
    uint16_t conn_id,
    const struct sol_flow_packet *packet)
{
    struct float_validator_data *mdata = data;
    struct sol_drange input;
    double *op;
    bool match;

    if (mdata->done) {
        sol_flow_send_error_packet(node, ECANCELED,
            "Input stream already deviated from expected data, ignoring packets.");
        return 0;
    }

    sol_flow_packet_get_drange(packet, &input);
    op = sol_vector_get(&mdata->values, mdata->next_index);
    match = sol_drange_val_equal(input.val, *op);
    mdata->next_index++;

    if (mdata->next_index == mdata->values.len || !match) {
        sol_flow_send_boolean_packet(node, SOL_FLOW_NODE_TYPE_TEST_FLOAT_VALIDATOR__OUT__OUT,
            match);
        mdata->done = true;
    }
    return 0;
}
uint16_t
sml_matrix_cols(struct sml_matrix *m, uint16_t i)
{
    struct sol_vector *line = sol_vector_get(&m->data, i);

    if (!line)
        return 0;

    return line->len;
}
inline static struct sol_vector *
_get_line(struct sol_vector *v, uint16_t pos, uint16_t elem_size)
{
    uint16_t i;

    for (i = v->len; i <= pos; i++) {
        struct sol_vector *line = sol_vector_append(v);
        sol_vector_init(line, elem_size);
    }
    return sol_vector_get(v, pos);
}
void
sml_matrix_remove_col(struct sml_matrix *m, uint16_t line_num, uint16_t col_num)
{
    struct sol_vector *line;

    line = sol_vector_get(&m->data, line_num);
    if (!line)
        return;

    sol_vector_del(line, col_num);
}
void
sml_matrix_remove_line(struct sml_matrix *m, uint16_t line_num)
{
    struct sol_vector *line;

    line = sol_vector_get(&m->data, line_num);
    if (!line)
        return;

    sol_vector_clear(line);
    sol_vector_del(&m->data, line_num);
}
inline static void *
_get_column(struct sol_vector *line, uint16_t pos, uint16_t elem_size)
{
    uint16_t i;

    for (i = line->len; i <= pos; i++) {
        void *c = sol_vector_append(line);
        if (!c)
            return NULL;
        memset(c, 0, elem_size);
    }
    return sol_vector_get(line, pos);
}
示例#14
0
static bool
timer_tick(void *data)
{
    struct sol_flow_node *node = data;
    struct string_generator_data *mdata = sol_flow_node_get_private_data(node);
    struct sol_str_slice *val;

    val = sol_vector_get(&mdata->values, mdata->next_index);
    sol_flow_send_string_slice_packet
        (node, SOL_FLOW_NODE_TYPE_TEST_STRING_GENERATOR__OUT__OUT, *val);
    mdata->next_index++;

    return mdata->next_index != mdata->values.len;
}
示例#15
0
static int
counter_disconnect(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id)
{
    struct counter_data *mdata = data;
    enum state *s;

    s = sol_vector_get(&mdata->map, conn_id);
    if (*s == TRUE)
        mdata->true_count--;
    if (*s == FALSE)
        mdata->false_count--;

    *s = NA;
    return 0;
}
示例#16
0
static bool
timer_tick(void *data)
{
    struct sol_flow_node *node = data;
    struct int_generator_data *mdata = sol_flow_node_get_private_data(node);
    struct sol_irange output = { };
    int32_t *val;

    val = sol_vector_get(&mdata->values, mdata->next_index);
    output.val = *val;
    output.step = 1;
    sol_flow_send_irange_packet(node, SOL_FLOW_NODE_TYPE_TEST_INT_GENERATOR__OUT__OUT, &output);
    mdata->next_index++;

    return mdata->next_index != mdata->values.len;
}
示例#17
0
static int
send_regexp_substring(struct string_regexp_search_data *mdata)
{
    struct sol_str_slice *sub_slice;
    int len;

    len = mdata->substrings.len;
    if (!len)
        return 0;

    if (mdata->index >= len) {
        SOL_WRN("Index (%d) greater than substrings "
            "length (%d).", mdata->index, len);
        return -EINVAL;
    }

    sub_slice = sol_vector_get(&mdata->substrings, mdata->index);

    return sol_flow_send_string_slice_packet(mdata->node,
        SOL_FLOW_NODE_TYPE_STRING_REGEXP_SEARCH__OUT__OUT, *sub_slice);
}
示例#18
0
static int
out_write(struct subprocess_data *mdata)
{
    int ret = 0;
    struct timespec start = sol_util_timespec_get_current();

    while (mdata->write_data.len) {
        struct timespec now = sol_util_timespec_get_current();
        struct timespec elapsed;
        struct write_data *w = sol_vector_get(&mdata->write_data, 0);
        ssize_t r;

        sol_util_timespec_sub(&now, &start, &elapsed);
        if (elapsed.tv_sec > 0 ||
            elapsed.tv_nsec > (time_t)CHUNK_MAX_TIME_NS)
            break;

        r = write(mdata->pipes.out[1], (uint8_t *)w->blob->mem + w->offset, w->blob->size - w->offset);
        if (r > 0) {
            w->offset += r;
        } else if (r < 0) {
            if (errno == EINTR)
                continue;
            else if (errno == EAGAIN)
                break;
            else {
                ret = -errno;
                break;
            }
        }

        if (w->blob->size <= w->offset) {
            sol_blob_unref(w->blob);
            sol_vector_del(&mdata->write_data, 0);
        }
    }

    return ret;
}
示例#19
0
static int
counter_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id,
    const struct sol_flow_packet *packet)
{
    struct sol_irange val = { 0, 0, INT32_MAX, 1 };
    struct counter_data *mdata = data;
    enum state *s;
    bool packet_val;
    int r;

    r = sol_flow_packet_get_boolean(packet, &packet_val);
    SOL_INT_CHECK(r, < 0, r);
    s = sol_vector_get(&mdata->map, conn_id);

    if (*s == packet_val)
        return 0;

    if (packet_val) {
        mdata->true_count++;
        if (*s != NA)
            mdata->false_count--;
    } else {
        mdata->false_count++;
        if (*s != NA)
            mdata->true_count--;
    }
    *s = packet_val;

    val.val = mdata->true_count;
    sol_flow_send_irange_packet(node, SOL_FLOW_NODE_TYPE_BOOLEAN_COUNTER__OUT__TRUE, &val);

    val.val = mdata->false_count;
    sol_flow_send_irange_packet(node, SOL_FLOW_NODE_TYPE_BOOLEAN_COUNTER__OUT__FALSE, &val);

    return 0;
}