Beispiel #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]
Beispiel #2
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]
Beispiel #3
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]
Beispiel #4
0
def create_client_param(param: dict) -> ClientParam:
    name = common_helpers.camel_to_snake(param["name"])
    param_type = get_cpp_client_param_type(param)
    param_type = const_ref_t(param_type)
    param_mechanism = get_param_mechanism(param)

    return ClientParam(name, param_type, param_mechanism)
Beispiel #5
0
def get_message_parameter_definitions(parameters):
    """Get simplified list of all parameters that can be used for defining request/respones messages in proto file."""
    parameter_definitions = []
    used_indexes = []
    for parameter in parameters:
        is_array = common_helpers.is_array(parameter["type"])
        parameter_name = common_helpers.camel_to_snake(parameter["name"])
        parameter_type = get_parameter_type(parameter)
        if is_decomposable_enum(parameter):
            is_request_message = common_helpers.is_input_parameter(parameter)
            enum_parameters = get_enum_parameters(parameter, parameter_name,
                                                  parameter_type, is_array,
                                                  used_indexes)
            if is_request_message:
                # use oneof for enums in request messages
                parameter_definitions.append({
                    "name": f"{parameter_name}_enum",
                    "use_oneof": True,
                    "parameters": enum_parameters
                })
            else:
                # we define all enum fields in response messages
                parameter_definitions.extend(enum_parameters)
        else:
            grpc_field_number = generate_parameter_field_number(
                parameter, used_indexes)
            parameter_definitions.append({
                "name": parameter_name,
                "type": parameter_type,
                "grpc_field_number": grpc_field_number
            })
    return parameter_definitions
Beispiel #6
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]