Esempio n. 1
0
def create_args(parameters):
    result = ''
    is_twist_mechanism = common_helpers.has_ivi_dance_with_a_twist_param(
        parameters)
    if is_twist_mechanism:
        twist_value = common_helpers.get_twist_value(parameters)
        twist_value_name = common_helpers.camel_to_snake(twist_value)
    for parameter in parameters:
        parameter_name = common_helpers.camel_to_snake(parameter['cppName'])
        is_array = common_helpers.is_array(parameter['type'])
        is_output = common_helpers.is_output_parameter(parameter)
        if is_output and common_helpers.is_string_arg(parameter):
            type_without_brackets = common_helpers.get_underlying_type_name(
                parameter['type'])
            result = f'{result}({type_without_brackets}*){parameter_name}.data(), '
        elif parameter['type'] in {"ViBoolean[]", "ViSession[]", "ViInt16[]"}:
            result = f'{result}{parameter_name}.data(), '
        elif parameter.get('is_size_param', False) and is_twist_mechanism:
            result = f'{result}{twist_value_name}, '
        else:
            if is_array and common_helpers.is_struct(parameter):
                parameter_name = parameter_name + ".data()"
            elif not is_array and is_output:
                result = f'{result}&'
            result = f'{result}{parameter_name}, '
    return result[:-2]
Esempio n. 2
0
def create_args_for_ivi_dance(parameters):
    result = ''
    for parameter in parameters:
        if parameter.get('is_size_param', False):
            result = f'{result}0, '
        elif common_helpers.is_output_parameter(parameter):
            result = f'{result}nullptr, '
        else:
            result = result + \
                common_helpers.camel_to_snake(parameter['cppName']) + ', '
    return result[:-2]
Esempio n. 3
0
def create_args(parameters):
    result = ''
    is_twist_mechanism = common_helpers.has_ivi_dance_with_a_twist_param(
        parameters)
    if is_twist_mechanism:
        twist_value = common_helpers.get_twist_value(parameters)
        twist_value_name = common_helpers.camel_to_snake(twist_value)
    have_expanded_varargs = False
    for parameter in parameters:
        if parameter.get('repeating_argument', False):
            continue
        parameter_name = common_helpers.camel_to_snake(parameter['cppName'])
        is_array = common_helpers.is_array(parameter['type'])
        is_output = common_helpers.is_output_parameter(parameter)
        if common_helpers.is_repeated_varargs_parameter(parameter):
            # Some methods have both input and output repeated varargs parameters,
            # so only expand them once.
            if have_expanded_varargs:
                continue
            have_expanded_varargs = True
            repeated_parameters = [
                p for p in parameters if common_helpers.is_repeating_parameter(p)]
            # We need to pass one extra set of arguments because the last parameters have to be nullptr's
            # so the callee knows we're done passing arguments.
            max_length = parameter['max_length'] + 1
            for i in range(max_length):
                for parameter in repeated_parameters:
                    if common_helpers.is_input_parameter(parameter):
                        result += f'get_{parameter["name"]}_if({parameter_name}, {i}), '
                    else:
                        result += f'get_{parameter["name"]}_if({parameter["name"]}Vector, {i}), '
        elif is_output and common_helpers.is_string_arg(parameter):
            type_without_brackets = common_helpers.get_underlying_type_name(
                parameter['type'])
            result = f'{result}({type_without_brackets}*){parameter_name}.data(), '
        elif parameter['type'] in {"ViBoolean[]", "ViSession[]", "ViInt16[]"}:
            result = f'{result}{parameter_name}.data(), '
        elif parameter.get('is_size_param', False) and is_twist_mechanism:
            result = f'{result}{twist_value_name}, '
        elif 'callback_params' in parameter:
            result = f'{result}CallbackRouter::handle_callback, '
        elif 'callback_token' in parameter:
            result = f'{result}handler->token(), '
        else:
            if is_array and common_helpers.is_struct(parameter):
                parameter_name = parameter_name + ".data()"
            elif not is_array and is_output:
                result = f'{result}&'
            elif get_c_element_type_for_array_that_needs_coercion(parameter) is not None:
                parameter_name = parameter_name + ".data()"
            result = f'{result}{parameter_name}, '
    return result[:-2]
Esempio n. 4
0
def create_param(parameter):
    type = parameter['type']
    name = parameter['cppName']
    if common_helpers.is_struct(parameter):
        type = type.replace("struct ", "")
    if common_helpers.is_array(type):
        is_fixed = parameter['size']['mechanism'] == 'fixed'
        array_size = parameter['size']['value'] if is_fixed else ''
        return f'{type[:-2]} {name}[{array_size}]'
    elif common_helpers.is_output_parameter(parameter):
        return f'{type}* {name}'
    else:
        return f'{type} {name}'
Esempio n. 5
0
def create_args_for_ivi_dance_with_a_twist(parameters):
    result = ''
    for parameter in parameters:
        name = common_helpers.camel_to_snake(parameter['cppName'])
        is_array = common_helpers.is_array(parameter['type'])
        if parameter.get('is_size_param', False):
            result = f'{result}0, '
        elif common_helpers.is_output_parameter(parameter):
            if is_array:
                result = f'{result}nullptr, '
            else:
                result = result + f'&{name}' + ', '
        else:
            result = result + common_helpers.camel_to_snake(name) + ', '
    return result[:-2]
Esempio n. 6
0
def get_parameters(function):
    parameter_array = common_helpers.filter_parameters_for_grpc_fields(
        function['parameters'])
    input_parameters = [
        p for p in parameter_array if common_helpers.is_input_parameter(p)
    ]
    if common_helpers.is_init_method(function):
        has_session_input = any(
            is_session_name(param) for param in input_parameters)
        if not has_session_input:
            session_name_param = {
                'direction': 'in',
                'name': 'session_name',
                'type': 'ViString',
                'grpc_type': 'string'
            }
            input_parameters.insert(0, session_name_param)

    default_status_param = {
        'name': 'status',
        'type': 'int32',
        'grpc_type': 'int32'
    }
    output_parameters = [default_status_param]

    callback_parameters = get_callback_output_params(function)

    if callback_parameters:
        if any((p for p in callback_parameters if p['name'] == 'status')):
            # if the callback provides a status, it can override default_status_param.
            output_parameters = callback_parameters
        else:
            output_parameters.extend(callback_parameters)
    else:
        output_parameters.extend([
            p for p in parameter_array if common_helpers.is_output_parameter(p)
        ])

    return (input_parameters, output_parameters)
Esempio n. 7
0
def is_output_array_that_needs_coercion(parameter):
    return common_helpers.is_output_parameter(parameter) and get_c_element_type_for_array_that_needs_coercion(parameter) is not None