예제 #1
0
/**
 * Callback function for each component
 * @param sca  Stream callback argument
 */
void tlm_stream_one(tlm_component *comp, stream_callback_type stream, void *print_ascii, void *sca)
{
    if (NULL == comp || NULL == stream) {
        return;
    }

    /* sca : stream callback argument */
    char buff[16] = { 0 };
    sprintf(buff, "%u\n", (unsigned int)c_list_node_count((comp->var_list)));

    /* Send: "START:<name>:<#>\n" */
    stream("START:", sca);
    stream(comp->name, sca);
    stream(":", sca);
    stream(buff, sca);

    /* Now for each variable list of this component, make a call-back to our
     * component for each function that will stream data of each variable
     */
    c_list_for_each_elm((comp->var_list), tlm_stream_for_each_component_var,
                        stream,     /* arg1 */
                        sca,        /* arg2 */
                        print_ascii /* arg3 */
                        );

    /* Send: "END:<name>\n" */
    stream("END:", sca);
    stream((comp->name), sca);
    stream("\n", sca);
}
예제 #2
0
bool tlm_variable_register(tlm_component *comp_ptr,
                             const char *name,
                             const void *data_ptr,
                             const uint16_t data_size,
                             const uint16_t arr_size,
                             tlm_type type)
{
    if(NULL == comp_ptr || NULL == name || NULL == data_ptr || 0 == data_size) {
        return false;
    }

    tlm_reg_var_type *new_var = malloc(sizeof(tlm_reg_var_type));
    if(NULL == new_var) {
        return false;
    }

    /* If not an array, a single var still has size of 1 array element
     * This is make it easier to calculate bytes of the variable
     */
    new_var->name = name;
    new_var->data_ptr = data_ptr;
    new_var->elm_size_bytes = data_size;
    new_var->elm_arr_size = 0 == arr_size ? 1 : arr_size;
    new_var->elm_type = type;

    if (!c_list_for_each_elm(comp_ptr->var_list, tlm_variable_check_dup,
                             (void*)new_var, NULL, NULL)) {
        free(new_var);
        return false;
    }

    if (!c_list_insert_elm_end(comp_ptr->var_list, new_var)) {
        free(new_var);
        return false;
    }

    return true;
}