示例#1
0
    def get_c_function(self):
        template1A = r"""// Callback function for {function_name_comment} callback
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""void cb_{function_name_under}({parameters}void *user_data) {{
	{unuseds}

{printfs}{extra_message}
}}
"""
        override_comment = self.get_formatted_override_comment(
            '// {0}', None, '\n// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        unuseds = []
        printfs = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_c_source())
            unuseds += parameter.get_c_unuseds()
            printfs += parameter.get_c_printfs()

        while None in unuseds:
            unuseds.remove(None)

        unuseds.append('(void)user_data;')

        unuseds = common.wrap_non_empty('', '<BP>'.join(unuseds),
                                        ' // avoid unused parameter warning')
        unuseds = common.break_string(unuseds, '').replace('\n', '\n\t')

        while None in printfs:
            printfs.remove(None)

        if len(printfs) > 1:
            printfs.append('\tprintf("\\n");')

        extra_message = self.get_formatted_extra_message(
            '\tprintf("{0}\\n");').replace('%', '%%')

        if len(extra_message) > 0 and len(printfs) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(function_name_under=self.get_name().under,
                                  parameters=common.wrap_non_empty('', ',<BP>'.join(parameters), ',<BP>'),
                                  unuseds=unuseds,
                                  printfs='\n'.join(printfs).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result,
                                   'cb_{}('.format(self.get_name().under))
    def get_c_function(self):
        template1A = r"""// Callback function for {function_name_comment} callback
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""void cb_{function_name_under}({parameters}void *user_data) {{
	{unuseds}

{printfs}{extra_message}
}}
"""
        override_comment = self.get_formatted_override_comment('// {0}', None, '\n// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        unuseds = []
        printfs = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_c_source())
            unuseds += parameter.get_c_unuseds()
            printfs += parameter.get_c_printfs()

        while None in unuseds:
            unuseds.remove(None)

        unuseds.append('(void)user_data;')

        unuseds = common.wrap_non_empty('', '<BP>'.join(unuseds), ' // avoid unused parameter warning')
        unuseds = common.break_string(unuseds, '').replace('\n', '\n\t')

        while None in printfs:
            printfs.remove(None)

        if len(printfs) > 1:
            printfs.append('\tprintf("\\n");')

        extra_message = self.get_formatted_extra_message('\tprintf("{0}\\n");').replace('%', '%%')

        if len(extra_message) > 0 and len(printfs) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(function_name_under=self.get_name().under,
                                  parameters=common.wrap_non_empty('', ',<BP>'.join(parameters), ',<BP>'),
                                  unuseds=unuseds,
                                  printfs='\n'.join(printfs).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result, 'cb_{}('.format(self.get_name().under))
    def get_vbnet_source(self):
        template1 = r"""        ' Register {function_name_comment}<BP>callback<BP>to<BP>subroutine<BP>{function_name_camel}CB
"""
        template2 = r"""        AddHandler {device_name}.{function_name_camel}Callback,<BP>AddressOf {function_name_camel}CB
"""

        result1 = template1.format(function_name_camel=self.get_name().camel,
                                   function_name_comment=self.get_comment_name())
        result2 = template2.format(device_name=self.get_device().get_initial_name(),
                                   function_name_camel=self.get_name().camel)

        return common.break_string(result1, "' ", indent_tail="' ") + \
               common.break_string(result2, 'AddHandler ', continuation=' _')
    def get_perl_source(self):
        template1 = r"""# Register {function_name_comment}<BP>callback<BP>to<BP>subroutine<BP>cb_{function_name_under}
"""
        template2 = r"""${device_name}->register_callback(${device_name}->CALLBACK_{function_name_upper},<BP>'cb_{function_name_under}');
"""

        result1 = template1.format(function_name_under=self.get_name().under,
                                   function_name_comment=self.get_comment_name())
        result2 = template2.format(device_name=self.get_device().get_initial_name(),
                                   function_name_under=self.get_name().under,
                                   function_name_upper=self.get_name().upper)

        return common.break_string(result1, '# ', indent_tail='# ') + \
               common.break_string(result2, 'register_callback(')
    def get_python_source(self):
        template1 = r"""    # Register {function_name_comment}<BP>callback<BP>to<BP>function<BP>cb_{function_name_under}
"""
        template2 = r"""    {device_name}.register_callback({device_name}.CALLBACK_{function_name_upper},<BP>cb_{function_name_under})
"""

        result1 = template1.format(function_name_under=self.get_name().under,
                                   function_name_comment=self.get_comment_name())
        result2 = template2.format(device_name=self.get_device().get_initial_name(),
                                   function_name_under=self.get_name().under,
                                   function_name_upper=self.get_name().upper)

        return common.break_string(result1, '# ', indent_tail='# ') + \
               common.break_string(result2, 'register_callback(')
    def get_vbnet_source(self):
        template1 = r"""        ' Register {function_name_comment}<BP>callback<BP>to<BP>subroutine<BP>{function_name_camel}CB
"""
        template2 = r"""        AddHandler {device_name}.{function_name_camel}Callback,<BP>AddressOf {function_name_camel}CB
"""

        result1 = template1.format(
            function_name_camel=self.get_name().camel,
            function_name_comment=self.get_comment_name())
        result2 = template2.format(
            device_name=self.get_device().get_initial_name(),
            function_name_camel=self.get_name().camel)

        return common.break_string(result1, "' ", indent_tail="' ") + \
               common.break_string(result2, 'AddHandler ', continuation=' _')
    def get_python_source(self):
        template = r"""{global_line_prefix}    # Get current {function_name_comment}
{global_line_prefix}    {variables} = {device_name}.{function_name_under}({arguments})
{prints}
"""
        variables = []
        prints = []

        for result in self.get_results():
            variables.append(result.get_python_variable())
            prints += result.get_python_prints()

        while None in prints:
            prints.remove(None)

        if len(prints) > 1:
            prints.insert(0, '\b')

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name_under=self.get_name().under,
                                 function_name_comment=self.get_comment_name(),
                                 variables=',<BP>'.join(variables),
                                 prints='\n'.join(prints).replace('\b\n\r', '\n').replace('\b', '').replace('\r\n\r', '\n\n').rstrip('\r').replace('\r', '\n'),
                                 arguments=', '.join(self.get_python_arguments()))

        return common.break_string(result, '    ', continuation=' \\', indent_suffix='  ')
    def get_go_source(self):        
        template = r"""{global_line_prefix}		// Get current {function_name_comment}.
{global_line_prefix}{result_name}, _ := {device_name_initials}.{function_name_camel}({arguments})
{write_lines}
"""
        result_name = self.get_go_result_prefix()
        
        write_lines = []
        for result in self.get_results():
            write_lines += result.get_go_write_lines()

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.insert(0, '\b')

        arguments = self.get_go_arguments()

        result = template.format(device_name_under=self.get_device().get_name().camel,
                                 device_name_initials=self.get_device().get_initial_name(),
                                 device_category_under = self.get_device().get_category().camel,
                                 result_name = result_name,                                 
                                 function_name_camel=self.get_name().camel,
                                 function_name_comment=self.get_comment_name(),                                 
                                 write_lines='\n'.join(write_lines).replace('\b\n\r', '\n').replace('\b', '').replace('\r\n\r', '\n\n').rstrip('\r').replace('\r', '\n'),
                                 arguments=',<BP>'.join(arguments),
                                 global_line_prefix=global_line_prefix)

        return common.break_string(result, '{}('.format(self.get_name().camel))
示例#9
0
    def get_java_source(self):
        template = r"""		// Configure threshold for {function_comment_name} "{option_comment}"{mininum_maximum_unit_comments}
		{device_initial_name}.set{function_camel_case_name}CallbackThreshold({arguments}'{option_char}',<BP>{mininum_maximums});
"""
        arguments = []

        for argument in self.get_arguments():
            arguments.append(argument.get_java_source())

        mininum_maximums = []
        mininum_maximum_unit_comments = []

        for mininum_maximum in self.get_minimum_maximums():
            mininum_maximums.append(mininum_maximum.get_java_source())
            mininum_maximum_unit_comments.append(mininum_maximum.get_unit_comment())

        if len(mininum_maximum_unit_comments) > 1 and len(set(mininum_maximum_unit_comments)) == 1:
            mininum_maximum_unit_comments = mininum_maximum_unit_comments[:1]

        result = template.format(device_initial_name=self.get_device().get_initial_name(),
                               function_camel_case_name=self.get_camel_case_name(),
                               function_comment_name=self.get_comment_name(),
                               arguments=common.wrap_non_empty('', ',<BP>'.join(arguments), ',<BP>'),
                               option_char=self.get_option_char(),
                               option_comment=self.get_option_comment(),
                               mininum_maximums=',<BP>'.join(mininum_maximums),
                               mininum_maximum_unit_comments=''.join(mininum_maximum_unit_comments))

        return common.break_string(result, 'CallbackThreshold(')
示例#10
0
    def get_go_source(self):
        template = r"""{global_line_prefix}		// Get current {function_name_comment}.
{global_line_prefix}{result_name}, _ := {device_name_initials}.{function_name_camel}({arguments})
{write_lines}
"""
        result_name = self.get_go_result_prefix()

        write_lines = []
        for result in self.get_results():
            write_lines += result.get_go_write_lines()

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.insert(0, '\b')

        arguments = self.get_go_arguments()

        result = template.format(
            device_name_under=self.get_device().get_name().camel,
            device_name_initials=self.get_device().get_initial_name(),
            device_category_under=self.get_device().get_category().camel,
            result_name=result_name,
            function_name_camel=self.get_name().camel,
            function_name_comment=self.get_comment_name(),
            write_lines='\n'.join(write_lines).replace('\b\n\r', '\n').replace(
                '\b', '').replace('\r\n\r',
                                  '\n\n').rstrip('\r').replace('\r', '\n'),
            arguments=',<BP>'.join(arguments),
            global_line_prefix=global_line_prefix)

        return common.break_string(result, '{}('.format(self.get_name().camel))
    def get_python_source(self):
        template = r"""    # Get current {function_name_comment}
    {variables} = {device_name}.{function_name_under}({arguments})
{prints}
"""
        variables = []
        prints = []

        for result in self.get_results():
            variables.append(result.get_python_variable())
            prints += result.get_python_prints()

        while None in prints:
            prints.remove(None)

        if len(prints) > 1:
            prints.insert(0, '')

        result = template.format(
            device_name=self.get_device().get_initial_name(),
            function_name_under=self.get_name().under,
            function_name_comment=self.get_comment_name(),
            variables=',<BP>'.join(variables),
            prints='\n'.join(prints),
            arguments=', '.join(self.get_python_arguments()))

        return common.break_string(result,
                                   '    ',
                                   continuation=' \\',
                                   indent_suffix='  ')
    def get_rust_source(self):
        template = '{comment1}{global_line_prefix}\t\t{device_name_initials}.{function_name}({arguments}){propagate_errors};{comment2}\n'

        has_high_level = [
            packet
            for packet in self.get_device().get_packets(type_='function')
            if (packet.get_name().under == self.get_name().under) or
            (len(packet.get_name().under.split("_")) > 2 and packet.get_name(
                skip=-2).under == self.get_name().under)
        ][0].has_high_level()

        result = template.format(
            global_line_prefix=global_line_prefix,
            device_name_under=self.get_device().get_name().under,
            device_name_initials=self.get_device().get_initial_name(),
            device_category_under=self.get_device().get_category().under,
            function_name=self.get_name().under,
            arguments=',<BP>'.join(self.get_rust_arguments()),
            propagate_errors='?' if has_high_level else '',
            comment1=self.get_formatted_comment1(
                global_line_prefix + '\t\t// {0}\n', '\r',
                '\n' + global_line_prefix + '\t\t// '),
            comment2=self.get_formatted_comment2(' // {0}', ''))

        return common.break_string(result,
                                   '{}('.format(self.get_name().camel_abbrv))
    def get_perl_source(self):
        template = r"""# Get current {function_name_comment}
{variables} = ${device_name}->{function_name_under}({arguments});
{prints}
"""
        variables = []
        prints = []

        for result in self.get_results():
            variables.append(result.get_perl_variable())
            prints += result.get_perl_prints()

        if len(variables) > 1:
            variables = common.break_string('my (' + ',<BP>'.join(variables) + ')', 'my (')
        else:
            variables = 'my ' + variables[0]

        while None in prints:
            prints.remove(None)

        if len(prints) > 1:
            prints.insert(0, '')

        return template.format(device_name=self.get_device().get_initial_name(),
                               function_name_under=self.get_name().under,
                               function_name_comment=self.get_comment_name(),
                               variables=variables,
                               prints='\n'.join(prints),
                               arguments=', '.join(self.get_perl_arguments()))
    def get_go_source(self):        
        template = r"""{device_name_initials}.Register{function_name_camel}Callback(func({params}) {{
        {write_lines}{extra_message}
    }})
"""
        write_lines = []
        params = []
        packet = [packet for packet in self.get_device().get_packets(type_='callback') if (packet.get_name().under == self.get_name().under) or (len(packet.get_name().under.split("_")) > 2 and packet.get_name(skip=-2).under == self.get_name().under)][0]
        
        for parameter in self.get_parameters():
            params.append(parameter.get_go_source())
            write_lines += parameter.get_go_write_lines()

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.append('\t\tfmt.Println();')

        extra_message = self.get_formatted_extra_message('\t\tfmt.Println("{0}");')

        if len(extra_message) > 0 and len(write_lines) > 0:
            extra_message = '\n' + extra_message

        result = template.format(device_name_initials=self.get_device().get_initial_name(),                                 
                                 params=", ".join(params),
                                 function_name_camel=self.get_name().camel,
                                 function_name_comment=self.get_comment_name(),
                                 write_lines='\n'.join(write_lines).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                 extra_message=extra_message)

        return common.break_string(result, '// ', indent_tail='// ')
示例#15
0
    def get_ruby_source(self):
        template = '{comment1}{global_line_prefix}{device_initial_name}.{function_underscore_name}{arguments}{comment2}\n'
        arguments = []

        for argument in self.get_arguments():
            arguments.append(argument.get_ruby_source())

        marker = '.{} '

        if len(arguments) > 0:
            arguments = ' ' + ',<BP>'.join(arguments)
        else:
            arguments = ''

        if arguments.strip().startswith('('):
            arguments = '({0})'.format(arguments.strip())
            marker = '.{}('

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_initial_name=self.get_device().get_initial_name(),
                                 function_underscore_name=self.get_underscore_name(),
                                 arguments=arguments,
                                 comment1=self.get_formatted_comment1(global_line_prefix + '# {0}\n', '\r', '\n' + global_line_prefix + '# '),
                                 comment2=self.get_formatted_comment2(' # {0}', ''))

        return common.break_string(result, marker.format(self.get_underscore_name()), continuation=' \\')
示例#16
0
    def get_c_source(self):
        template = '{comment1}{declarations}{global_line_prefix}\t{device_name_under}_{function_name}(&{device_name_initial}{arguments});{comment2}\n'

        arg_declarations, arguments = self.get_c_arguments()
        declarations = common.wrap_non_empty(
            '', '\n'.join([
                '{global_line_prefix}\t{decl}'.format(
                    global_line_prefix=global_line_prefix, decl=decl)
                for decl in arg_declarations
            ]), '\n')

        result = template.format(
            global_line_prefix=global_line_prefix,
            device_name_under=self.get_device().get_name().under,
            device_name_initial=self.get_device().get_initial_name(),
            function_name=self.get_name().under,
            declarations=declarations,
            arguments=common.wrap_non_empty(',<BP>', ',<BP>'.join(arguments),
                                            ''),
            comment1=self.get_formatted_comment1(
                global_line_prefix + '\t// {0}\n', '\r',
                '\n' + global_line_prefix + '\t// '),
            comment2=self.get_formatted_comment2(' // {0}', ''))

        return common.break_string(result,
                                   '_{}('.format(self.get_name().under))
示例#17
0
    def get_php_source(self):
        template1 = r"""// Register {function_name_comment}<BP>callback<BP>to<BP>function<BP>cb_{function_name_headless}
"""
        template2 = r"""${device_name_initial}->registerCallback({device_category}{device_name_camel}::CALLBACK_{function_name_upper},<BP>'cb_{function_name_headless}');
"""

        result1 = template1.format(function_name_headless=self.get_name().headless,
                                   function_name_comment=self.get_comment_name())
        result2 = template2.format(device_category=self.get_device().get_category().camel,
                                   device_name_camel=self.get_device().get_name().camel,
                                   device_name_initial=self.get_device().get_initial_name(),
                                   function_name_headless=self.get_name().headless,
                                   function_name_upper=self.get_name().upper)

        return common.break_string(result1, '// ', indent_tail='// ') + \
               common.break_string(result2, '->registerCallback(')
    def get_javascript_function(self):
        template1 = r"""// Register {function_name_comment} callback
{device_name_initial}.on(Tinkerforge.{device_category}{device_name_camel}.CALLBACK_{function_name_upper},
"""
        template2A = r"""    // Callback function for {function_name_comment} callback
"""
        template2B = r"""{override_comment}
"""
        template3 = r"""    function ({parameters}) {{
{outputs}{extra_message}{global_callback_output_suffix}
    }}
);
"""
        override_comment = self.get_formatted_override_comment(
            '    // {0}', None, '\n    // ')

        if override_comment == None:
            template2 = template2A
        else:
            template2 = template2B

        parameters = []
        outputs = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_javascript_source())
            outputs += parameter.get_javascript_outputs()

        while None in outputs:
            outputs.remove(None)

        if len(outputs) > 1:
            outputs.append(
                "        {global_output_prefix}''{global_output_suffix};".
                format(global_output_prefix=global_output_prefix,
                       global_output_suffix=global_output_suffix))

        extra_message = self.get_formatted_extra_message(
            "        {global_output_prefix}'{{0}}'{global_output_suffix};".
            format(global_output_prefix=global_output_prefix,
                   global_output_suffix=global_output_suffix))

        if len(extra_message) > 0 and len(outputs) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(device_category=self.get_device().get_category().camel,
                                  device_name_camel=self.get_device().get_name().camel,
                                  device_name_initial=self.get_device().get_initial_name(),
                                  function_name_upper=self.get_name().upper,
                                  function_name_comment=self.get_comment_name()) + \
                 template2.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template3.format(global_callback_output_suffix=global_callback_output_suffix,
                                  parameters=',<BP>'.join(parameters),
                                  outputs='\n'.join(outputs).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result, 'function (')
    def get_mathematica_source(self):
        template1A = r"""(*Callback function for {function_name_comment} callback*)
"""
        template1B = r"""{override_comment}
"""
        template2A = r"""{function_name_camel}CB[sender_{parameters}]:=
 Module[{{}},
{prints}{extra_message}
 ]

AddEventHandler[{device_name}@{function_name_camel}Callback,{function_name_camel}CB]
"""
        template2B = r"""{function_name_camel}CB[sender_{parameters}]:=
{prints}{extra_message}
AddEventHandler[{device_name}@{function_name_camel}Callback,{function_name_camel}CB]
"""
        override_comment = self.get_formatted_override_comment('(*{0}*)', None, '*)\n(*')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B
            override_comment = re.sub('\\(\\*[ ]+\\*\\)\n', '', override_comment)

        parameters = []
        prints = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_mathematica_source())
            prints += parameter.get_mathematica_prints()

        while None in prints:
            prints.remove(None)

        extra_message = self.get_formatted_extra_message(' Print["{0}"]')

        if len(prints) > 1 or (len(prints) == 1 and len(extra_message) > 0) or sum([1 for p in prints if '\n' in p]) > 0:
            template2 = template2A
            prints = [' ' + prints for prints in prints]

            if len(extra_message) > 0:
                extra_message = ' ' + extra_message
        else:
            template2 = template2B

        if len(extra_message) > 0 and len(prints) > 0:
            extra_message = ';\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(device_name=self.get_device().get_initial_name(),
                                  function_name_camel=self.get_name().camel,
                                  parameters=common.wrap_non_empty(',<BP>', ',<BP>'.join(parameters), ''),
                                  prints='\n'.join(prints).replace('\n', ';\n'),
                                  extra_message=extra_message)

        return common.break_string(result, '{}CB['.format(self.get_name().camel), space='')
示例#20
0
    def get_c_function(self):
        template1A = r"""// Callback function for {function_comment_name} callback{comments}
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""void cb_{function_underscore_name}({parameters}void *user_data) {{{unuseds}
	(void)user_data; // avoid unused parameter warning

{printfs}{extra_message}
}}
"""
        override_comment = self.get_formatted_override_comment('// {0}', None, '\n// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        comments = []
        parameters = []
        unuseds = []
        printfs = []

        for parameter in self.get_parameters():
            comments.append(parameter.get_formatted_comment())
            parameters.append(parameter.get_c_source())
            unuseds.append(parameter.get_c_unused())
            printfs.append(parameter.get_c_printf())

        if len(comments) > 1 and len(set(comments)) == 1:
            comments = [comments[0].replace('parameter has', 'parameters have')]

        while None in unuseds:
            unuseds.remove(None)

        while None in printfs:
            printfs.remove(None)

        if len(printfs) > 1:
            printfs.append('\tprintf("\\n");')

        extra_message = self.get_formatted_extra_message('\tprintf("{0}\\n");').replace('%', '%%')

        if len(extra_message) > 0 and len(printfs) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_comment_name=self.get_comment_name(),
                                  comments=''.join(comments),
                                  override_comment=override_comment) + \
                 template2.format(function_underscore_name=self.get_underscore_name(),
                                  parameters=common.wrap_non_empty('', ',<BP>'.join(parameters), ',<BP>'),
                                  unuseds=common.wrap_non_empty('\n', '\n'.join(unuseds), ''),
                                  printfs='\n'.join(printfs),
                                  extra_message=extra_message)

        return common.break_string(result, 'cb_{}('.format(self.get_underscore_name()))
    def get_delphi_source(self):
        template = r"""  {{ Register {function_name_comment}<BP>callback<BP>to<BP>procedure<BP>{function_name_camel}CB }}
  {device_name}.On{function_name_camel} := {{$ifdef FPC}}@{{$endif}}{function_name_camel}CB;
"""

        result = template.format(device_name=self.get_device().get_initial_name(),
                                 function_name_camel=self.get_name().camel,
                                 function_name_comment=self.get_comment_name())

        return common.break_string(result, '{ ')
    def get_csharp_source(self):
        template = r"""		// Register {function_name_comment}<BP>callback<BP>to<BP>function<BP>{function_name_camel}CB
		{device_name}.{function_name_camel}Callback += {function_name_camel}CB;
"""

        result = template.format(device_name=self.get_device().get_initial_name(),
                                 function_name_camel=self.get_name().camel,
                                 function_name_comment=self.get_comment_name())

        return common.break_string(result, '// ', indent_tail='// ')
    def get_javascript_source(self):
        template = '{comment1}{global_line_prefix}        {device_name}.{function_name}({arguments});{comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().headless,
                                 arguments=',<BP>'.join(self.get_javascript_arguments()),
                                 comment1=self.get_formatted_comment1(global_line_prefix + '        // {0}\n', '\r', '\n' + global_line_prefix + '        // '),
                                 comment2=self.get_formatted_comment2(' // {0}', ''))

        return common.break_string(result, '.{}('.format(self.get_name().headless))
    def get_delphi_source(self):
        template = r"""  {{ Register {function_name_comment}<BP>callback<BP>to<BP>procedure<BP>{function_name_camel}CB }}
  {device_name}.On{function_name_camel} := {{$ifdef FPC}}@{{$endif}}{function_name_camel}CB;
"""

        result = template.format(
            device_name=self.get_device().get_initial_name(),
            function_name_camel=self.get_name().camel,
            function_name_comment=self.get_comment_name())

        return common.break_string(result, '{ ')
示例#25
0
    def get_java_source(self):
        template1A = r"""		// Add {function_comment_name} listener{comments}
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""		{device_initial_name}.add{function_camel_case_name}Listener(new {device_camel_case_category}{device_camel_case_name}.{function_camel_case_name}Listener() {{
			public void {function_headless_camel_case_name}({parameters}) {{
{printlns}{extra_message}
			}}
		}});
"""
        override_comment = self.get_formatted_override_comment('\t\t// {0}', None, '\n\t\t// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        comments = []
        parameters = []
        printlns = []

        for parameter in self.get_parameters():
            comments.append(parameter.get_formatted_comment())
            parameters.append(parameter.get_java_source())
            printlns.append(parameter.get_java_println())

        if len(comments) > 1 and len(set(comments)) == 1:
            comments = [comments[0].replace('parameter has', 'parameters have')]

        while None in printlns:
            printlns.remove(None)

        if len(printlns) > 1:
            printlns.append('\t\t\t\tSystem.out.println("");')

        extra_message = self.get_formatted_extra_message('\t\t\t\tSystem.out.println("{0}");')

        if len(extra_message) > 0 and len(printlns) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_comment_name=self.get_comment_name(),
                                comments=''.join(comments),
                                override_comment=override_comment) + \
               template2.format(device_camel_case_category=self.get_device().get_camel_case_category(),
                                device_camel_case_name=self.get_device().get_camel_case_name(),
                                device_initial_name=self.get_device().get_initial_name(),
                                function_camel_case_name=self.get_camel_case_name(),
                                function_headless_camel_case_name=self.get_headless_camel_case_name(),
                                parameters=',<BP>'.join(parameters),
                                printlns='\n'.join(printlns),
                                extra_message=extra_message)

        return common.break_string(result, '{}('.format(self.get_headless_camel_case_name()))
示例#26
0
    def get_vbnet_source(self):
        templateA = r"""        ' Get current {function_comment_name}{comments}
{variable_declarations} = {device_initial_name}.{function_camel_case_name}({arguments})
{write_lines}
"""
        templateB = r"""        ' Get current {function_comment_name}{comments}
{variable_declarations}

        {device_initial_name}.{function_camel_case_name}({arguments})
{write_lines}
"""
        comments = []
        variable_declarations = []
        variable_references = []
        write_lines = []

        for result in self.get_results():
            comments.append(result.get_formatted_comment())
            variable_declarations.append(result.get_vbnet_variable_declaration())
            variable_references.append(result.get_vbnet_variable_reference())
            write_lines.append(result.get_vbnet_write_line())

        if len(comments) > 1 and len(set(comments)) == 1:
            comments = comments[:1]

        if len(variable_declarations) == 1:
            template = templateA
        else:
            template = templateB

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.insert(0, '')

        arguments = []

        for argument in self.get_arguments():
            arguments.append(argument.get_vbnet_source())

        if len(variable_references) > 1:
            arguments += variable_references

        result = template.format(device_initial_name=self.get_device().get_initial_name(),
                                 function_camel_case_name=self.get_camel_case_name(),
                                 function_headless_camel_case_name=self.get_headless_camel_case_name(),
                                 function_comment_name=self.get_comment_name(),
                                 comments=''.join(comments),
                                 variable_declarations='\n'.join(variable_declarations),
                                 write_lines='\n'.join(write_lines),
                                 arguments=',<BP>'.join(arguments))

        return common.break_string(result, '.{}('.format(self.get_camel_case_name()), continuation=' _')
示例#27
0
    def get_php_source(self):
        template = '{comment1}{global_line_prefix}${device_name}->{function_name}({arguments});{comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().headless,
                                 arguments=',<BP>'.join(self.get_php_arguments()),
                                 comment1=self.get_formatted_comment1(global_line_prefix + '// {0}\n', '\r', '\n' + global_line_prefix + '// '),
                                 comment2=self.get_formatted_comment2(' // {0}', ''))

        return common.break_string(result, '->{}('.format(self.get_name().headless))
示例#28
0
    def get_csharp_source(self):
        template = r"""		// Register {function_name_comment}<BP>callback<BP>to<BP>function<BP>{function_name_camel}CB
		{device_name}.{function_name_camel}Callback += {function_name_camel}CB;
"""

        result = template.format(
            device_name=self.get_device().get_initial_name(),
            function_name_camel=self.get_name().camel,
            function_name_comment=self.get_comment_name())

        return common.break_string(result, '// ', indent_tail='// ')
    def get_python_source(self):
        template = '{comment1}{global_line_prefix}    {device_name}.{function_name}({arguments}){comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().under,
                                 arguments=',<BP>'.join(self.get_python_arguments()),
                                 comment1=self.get_formatted_comment1(global_line_prefix + '    # {0}\n', '\r', '\n' + global_line_prefix + '    # '),
                                 comment2=self.get_formatted_comment2(' # {0}', ''))

        return common.break_string(result, '.{0}('.format(self.get_name().under))
    def get_vbnet_source(self):
        template = '{comment1}{global_line_prefix}        {device_name}.{function_name}({arguments}){comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().camel,
                                 arguments=',<BP>'.join(self.get_vbnet_arguments()),
                                 comment1=self.get_formatted_comment1(global_line_prefix + "        ' {0}\n", '\r', "\n" + global_line_prefix + "        ' "),
                                 comment2=self.get_formatted_comment2(" ' {0}", ''))

        return common.break_string(result, '.{}('.format(self.get_name().camel), continuation=' _')
示例#31
0
    def get_c_source(self):
        template = r"""	// Get current {function_comment_name}{comments}
	{variable_declarations};
	if({device_underscore_name}_{function_underscore_name}(&{device_initial_name}{arguments}{variable_references}) < 0) {{
		fprintf(stderr, "Could not get {function_comment_name}, probably timeout\n");
		return 1;
	}}

{printfs}
"""
        comments = []
        variable_declarations = []
        variable_references = []
        printfs = []

        for result in self.get_results():
            comments.append(result.get_formatted_comment())
            variable_declarations.append(result.get_c_variable_declaration())
            variable_references.append(result.get_c_variable_reference())
            printfs.append(result.get_c_printf())

        if len(comments) > 1 and len(set(comments)) == 1:
            comments = comments[:1]

        merged_variable_declarations = [' '.join(variable_declarations[0])]

        for i in range(len(variable_declarations) - 1):
            type0 = variable_declarations[i][0]
            type1 = variable_declarations[i + 1][0]

            if type0 != type1:
                merged_variable_declarations.append('; ' + ' '.join(variable_declarations[i + 1]))
            else:
                merged_variable_declarations.append(', ' + variable_declarations[i + 1][1])

        while None in printfs:
            printfs.remove(None)

        arguments = []

        for argument in self.get_arguments():
            arguments.append(argument.get_c_source())

        result = template.format(device_underscore_name=self.get_device().get_underscore_name(),
                                 device_initial_name=self.get_device().get_initial_name(),
                                 function_comment_name=self.get_comment_name(),
                                 function_underscore_name=self.get_underscore_name(),
                                 comments=''.join(comments),
                                 variable_declarations=''.join(merged_variable_declarations),
                                 variable_references=',<BP>' + ',<BP>'.join(variable_references),
                                 printfs='\n'.join(printfs),
                                 arguments=common.wrap_non_empty(',<BP>', ',<BP>'.join(arguments), ''))

        return common.break_string(result, '_{}('.format(self.get_underscore_name()))
    def get_delphi_source(self):
        template = '{comment1}{global_line_prefix}  {device_name}.{function_name}{arguments};{comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().camel,
                                 arguments=common.wrap_non_empty('(', ',<BP>'.join(self.get_delphi_arguments()), ')'),
                                 comment1=self.get_formatted_comment1(global_line_prefix + '  {{ {0} }}\n', '\r', '\n' + global_line_prefix + '    '),
                                 comment2=self.get_formatted_comment2(' {{ {0} }}', ''))

        return common.break_string(result, '{}('.format(self.get_name().camel))
    def get_javascript_function(self):
        template1 = r"""// Register {function_name_comment} callback
{device_name_initial}.on(Tinkerforge.{device_category}{device_name_camel}.CALLBACK_{function_name_upper},
"""
        template2A = r"""    // Callback function for {function_name_comment} callback
"""
        template2B = r"""{override_comment}
"""
        template3 = r"""    function ({parameters}) {{
{outputs}{extra_message}{global_callback_output_suffix}
    }}
);
"""
        override_comment = self.get_formatted_override_comment('    // {0}', None, '\n    // ')

        if override_comment == None:
            template2 = template2A
        else:
            template2 = template2B

        parameters = []
        outputs = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_javascript_source())
            outputs += parameter.get_javascript_outputs()

        while None in outputs:
            outputs.remove(None)

        if len(outputs) > 1:
            outputs.append("        {global_output_prefix}''{global_output_suffix};".format(global_output_prefix=global_output_prefix,
                                                                                            global_output_suffix=global_output_suffix))

        extra_message = self.get_formatted_extra_message("        {global_output_prefix}'{{0}}'{global_output_suffix};".format(global_output_prefix=global_output_prefix,
                                                                                                                               global_output_suffix=global_output_suffix))

        if len(extra_message) > 0 and len(outputs) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(device_category=self.get_device().get_category().camel,
                                  device_name_camel=self.get_device().get_name().camel,
                                  device_name_initial=self.get_device().get_initial_name(),
                                  function_name_upper=self.get_name().upper,
                                  function_name_comment=self.get_comment_name()) + \
                 template2.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template3.format(global_callback_output_suffix=global_callback_output_suffix,
                                  parameters=',<BP>'.join(parameters),
                                  outputs='\n'.join(outputs).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result, 'function (')
    def get_matlab_source(self):
        template1 = r"""    % Register {function_name_comment}<BP>callback<BP>to<BP>function<BP>cb_{function_name_under}
"""
        template2A = r"""    set({device_name}, '{function_name_camel}Callback',<BP>@(h, e) cb_{function_name_under}(e));
"""
        template2B = r"""    {device_name}.add{function_name_camel}Callback(@cb_{function_name_under});
"""

        if not global_is_octave:
            template2 = template2A
        else:
            template2 = template2B

        result1 = template1.format(function_name_under=self.get_name().under,
                                   function_name_comment=self.get_comment_name())
        result2 = template2.format(device_name=self.get_device().get_initial_name(),
                                   function_name_under=self.get_name().under,
                                   function_name_camel=self.get_name().camel)

        return common.break_string(result1, '% ', indent_tail='% ') + \
               common.break_string(result2, 'set(',)
    def get_mathematica_source(self):
        template = '{comment1}{global_line_prefix}{device_name}@{function_name}[{arguments}]{global_line_suffix}{comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 global_line_suffix=global_line_suffix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().camel,
                                 arguments=',<BP>'.join(self.get_mathematica_arguments()),
                                 comment1=re.sub('\\(\\*[ ]*\\*\\)\n', '', self.get_formatted_comment1(global_line_prefix + '(*{0}*)\n', '\r', '*)\n' + global_line_prefix + '(*')),
                                 comment2=self.get_formatted_comment2('(*{0}*)', ''))

        return common.break_string(result, '@{}['.format(self.get_name().camel), space='')
    def get_perl_source(self):
        template = '{comment1}{global_line_prefix}${device_name}->{function_name}({arguments});{comment2}\n'
        marker = '->{}('

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().under,
                                 arguments=',<BP>'.join(self.get_perl_arguments()),
                                 comment1=self.get_formatted_comment1(global_line_prefix + '# {0}\n', '\r', '\n' + global_line_prefix + '# '),
                                 comment2=self.get_formatted_comment2(' # {0}', ''))

        return common.break_string(result, marker.format(self.get_name().under))
    def get_matlab_source(self):
        template1 = r"""    % Register {function_name_comment}<BP>callback<BP>to<BP>function<BP>cb_{function_name_under}
"""
        template2A = r"""    set({device_name}, '{function_name_camel}Callback',<BP>@(h, e) cb_{function_name_under}(e));
"""
        template2B = r"""    {device_name}.add{function_name_camel}Callback(@cb_{function_name_under});
"""

        if not global_is_octave:
            template2 = template2A
        else:
            template2 = template2B

        result1 = template1.format(function_name_under=self.get_name().under,
                                   function_name_comment=self.get_comment_name())
        result2 = template2.format(device_name=self.get_device().get_initial_name(),
                                   function_name_under=self.get_name().under,
                                   function_name_camel=self.get_name().camel)

        return common.break_string(result1, '% ', indent_tail='% ') + \
               common.break_string(result2, 'set(',)
    def get_rust_source(self):
        #TODO: high level callback receivers send Option<Result>, so we need to match them here. OTOH streaming examples are incomplete anyway, so this can be done manually.
        template = r"""     let {function_name_under}_receiver = {device_name_initials}.get_{function_name_under}_callback_receiver();

        // Spawn thread to handle received callback messages.
        // This thread ends when the `{device_name_initials}` object
        // is dropped, so there is no need for manual cleanup.
        thread::spawn(move || {{
            for {function_name_under} in {function_name_under}_receiver {{{match_expr}
                {write_lines}{extra_message}
            {match_expr_end}}}
        }});
"""
        write_lines = []
        has_high_level = [packet for packet in self.get_device().get_packets(type_='callback') if (packet.get_name().under == self.get_name().under) or (len(packet.get_name().under.split("_")) > 2 and packet.get_name(skip=-2).under == self.get_name().under)][0].has_high_level()

        if has_high_level:
            match_expr = "match {function_name_under} {{\nSome((payload, result)) => {{\n".format(function_name_under = self.get_name().under)
            match_expr_end = '}\nNone => println!("Stream was out of sync.")\n}'
        else:
            match_expr = ""
            match_expr_end = ""

        if len(self.get_parameters()) > 1:
            for parameter in self.get_parameters():
                write_lines += parameter.get_rust_write_lines(parameter_struct_name=self.get_name().under if not has_high_level else "result")
        else:
            for parameter in self.get_parameters():
                write_lines += parameter.get_rust_write_lines(override_parameter_name=self.get_name().under if not has_high_level else "result")

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.append('\t\tprintln!();')

        extra_message = self.get_formatted_extra_message('\t\tprintln!("{0}");')

        if len(extra_message) > 0 and len(write_lines) > 0:
            extra_message = '\n' + extra_message

        result = template.format(match_expr = match_expr,
                                 match_expr_end = match_expr_end,
                                 device_name_under=self.get_device().get_name().under,
                                 device_name_initials=self.get_device().get_initial_name(),
                                 device_category_under=self.get_device().get_category().under,
                                 function_name_under=self.get_name().under,
                                 function_name_comment=self.get_comment_name(),
                                 write_lines='\n'.join(write_lines).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                 extra_message=extra_message)

        return common.break_string(result, '// ', indent_tail='// ')
示例#39
0
    def get_ruby_source(self):
        template1A = r"""# Register {function_comment_name} callback{comments}
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""{device_initial_name}.register_callback({device_camel_case_category}{device_camel_case_name}::CALLBACK_{function_upper_case_name}) do{parameters}
{puts}{extra_message}
end
"""
        override_comment = self.get_formatted_override_comment('# {0}', None, '\n# ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        comments = []
        parameters = []
        puts = []

        for parameter in self.get_parameters():
            comments.append(parameter.get_formatted_comment())
            parameters.append(parameter.get_ruby_source())
            puts.append(parameter.get_ruby_puts())

        if len(comments) > 1 and len(set(comments)) == 1:
            comments = [comments[0].replace('parameter has', 'parameters have')]

        while None in puts:
            puts.remove(None)

        if len(puts) > 1:
            puts.append("  puts ''")

        extra_message = self.get_formatted_extra_message("  puts '{0}'")

        if len(extra_message) > 0 and len(puts) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_comment_name=self.get_comment_name(),
                                  comments=''.join(comments),
                                  override_comment=override_comment) + \
                 template2.format(device_camel_case_category=self.get_device().get_camel_case_category(),
                                  device_camel_case_name=self.get_device().get_camel_case_name(),
                                  device_initial_name=self.get_device().get_initial_name(),
                                  function_underscore_name=self.get_underscore_name(),
                                  function_upper_case_name=self.get_upper_case_name(),
                                  parameters=common.wrap_non_empty(' |', ',<BP>'.join(parameters), '|'),
                                  puts='\n'.join(puts),
                                  extra_message=extra_message)

        return common.break_string(result, 'do |', continuation=' \\')
示例#40
0
    def get_delphi_prototype(self):
        template = '    procedure {function_camel_case_name}CB(sender: T{device_camel_case_category}{device_camel_case_name}{parameters});'
        parameters = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_delphi_source())

        result = template.format(device_camel_case_category=self.get_device().get_camel_case_category(),
                                 device_camel_case_name=self.get_device().get_camel_case_name(),
                                 function_camel_case_name=self.get_camel_case_name(),
                                 parameters=common.wrap_non_empty(';<BP>', ';<BP>'.join(parameters), ''))

        return common.break_string(result, '{}CB('.format(self.get_camel_case_name()))
    def get_go_source(self):
        template = '{comment1}{global_line_prefix}\t\t{device_name_initials}.{function_name}({arguments}){comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name_under=self.get_device().get_name().camel,
                                 device_name_initials=self.get_device().get_initial_name(),
                                 device_category_under = self.get_device().get_category().camel,
                                 function_name=self.get_name().camel,
                                 arguments=',<BP>'.join(self.get_go_arguments()),
                                 comment1=self.get_formatted_comment1(global_line_prefix + '\t\t// {0}\n', '\r', '\n' + global_line_prefix + '\t\t// '),
                                 comment2=self.get_formatted_comment2(' // {0}', ''))

        return common.break_string(result, '{}('.format(self.get_name().camel))
示例#42
0
    def get_php_source(self):
        template = r"""// Register {function_comment_name} callback to function cb_{function_headless_camel_case_name}
${device_initial_name}->registerCallback({device_camel_case_category}{device_camel_case_name}::CALLBACK_{function_upper_case_name},<BP>'cb_{function_headless_camel_case_name}');
"""

        result = template.format(device_camel_case_category=self.get_device().get_camel_case_category(),
                                 device_camel_case_name=self.get_device().get_camel_case_name(),
                                 device_initial_name=self.get_device().get_initial_name(),
                                 function_headless_camel_case_name=self.get_headless_camel_case_name(),
                                 function_upper_case_name=self.get_upper_case_name(),
                                 function_comment_name=self.get_comment_name())

        return common.break_string(result, '->registerCallback(')
    def get_rust_source(self):
        template = '{comment1}{global_line_prefix}\t\t{device_name_initials}.{function_name}({arguments});{comment2}\n'

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name_under=self.get_device().get_name().under,
                                 device_name_initials=self.get_device().get_initial_name(),
                                 device_category_under = self.get_device().get_category().under,
                                 function_name=self.get_name().under,
                                 arguments=',<BP>'.join(self.get_rust_arguments()),
                                 comment1=self.get_formatted_comment1(global_line_prefix + '\t\t// {0}\n', '\r', '\n' + global_line_prefix + '\t\t// '),
                                 comment2=self.get_formatted_comment2(' // {0}', ''))

        return common.break_string(result, '{}('.format(self.get_name().camel_abbrv))
示例#44
0
    def get_delphi_procedure(self):
        template1A = r"""{{ Callback procedure for {function_comment_name} callback{comments} }}
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""procedure TExample.{function_camel_case_name}CB(sender: T{device_camel_case_category}{device_camel_case_name}{parameters});
begin
{write_lns}{extra_message}
end;
"""
        override_comment = self.get_formatted_override_comment('{{ {0} }}', None, '\n  ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        comments = []
        parameters = []
        write_lns = []

        for parameter in self.get_parameters():
            comments.append(parameter.get_formatted_comment())
            parameters.append(parameter.get_delphi_source())
            write_lns.append(parameter.get_delphi_write_ln())

        if len(comments) > 1 and len(set(comments)) == 1:
            comments = [comments[0].replace('parameter has', 'parameters have')]

        while None in write_lns:
            write_lns.remove(None)

        if len(write_lns) > 1:
            write_lns.append("  WriteLn('');")

        extra_message = self.get_formatted_extra_message("  WriteLn('{0}');")

        if len(extra_message) > 0 and len(write_lns) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_comment_name=self.get_comment_name(),
                                  comments=''.join(comments),
                                  override_comment=override_comment) + \
                 template2.format(device_camel_case_category=self.get_device().get_camel_case_category(),
                                  device_camel_case_name=self.get_device().get_camel_case_name(),
                                  function_camel_case_name=self.get_camel_case_name(),
                                  parameters=common.wrap_non_empty(';<BP>', ';<BP>'.join(parameters), ''),
                                  write_lns='\n'.join(write_lns),
                                  extra_message=extra_message)

        return common.break_string(result, '{}CB('.format(self.get_camel_case_name()))
示例#45
0
    def get_java_source(self):
        template1A = r"""		// Add {function_name_comment} listener
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""		{device_name_initial}.add{function_name_camel}Listener(new {device_category}{device_name_camel}.{function_name_camel}Listener() {{
			public void {function_name_headless}({parameters}) {{
{printlns}{extra_message}
			}}
		}});
"""
        override_comment = self.get_formatted_override_comment(
            '\t\t// {0}', None, '\n\t\t// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        printlns = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_java_source())
            printlns += parameter.get_java_printlns()

        while None in printlns:
            printlns.remove(None)

        if len(printlns) > 1:
            printlns.append('\t\t\t\tSystem.out.println("");')

        extra_message = self.get_formatted_extra_message(
            '\t\t\t\tSystem.out.println("{0}");')

        if len(extra_message) > 0 and len(printlns) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(device_category=self.get_device().get_category().camel,
                                  device_name_camel=self.get_device().get_name().camel,
                                  device_name_initial=self.get_device().get_initial_name(),
                                  function_name_camel=self.get_name().camel,
                                  function_name_headless=self.get_name().headless,
                                  parameters=',<BP>'.join(parameters),
                                  printlns='\n'.join(printlns).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result,
                                   '{}('.format(self.get_name().headless))
示例#46
0
    def get_csharp_function(self):
        template1A = r"""	// Callback function for {function_comment_name} callback{comments}
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""	static void {function_camel_case_name}CB({device_camel_case_category}{device_camel_case_name} sender{parameters})
	{{
{write_lines}{extra_message}
	}}
"""
        override_comment = self.get_formatted_override_comment('\t// {0}', None, '\n\t// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        comments = []
        parameters = []
        write_lines = []

        for parameter in self.get_parameters():
            comments.append(parameter.get_formatted_comment())
            parameters.append(parameter.get_csharp_source())
            write_lines.append(parameter.get_csharp_write_line())

        if len(comments) > 1 and len(set(comments)) == 1:
            comments = [comments[0].replace('parameter has', 'parameters have')]

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.append('\t\tConsole.WriteLine("");')

        extra_message = self.get_formatted_extra_message('\t\tConsole.WriteLine("{0}");')

        if len(extra_message) > 0 and len(write_lines) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_comment_name=self.get_comment_name(),
                                  comments=''.join(comments),
                                  override_comment=override_comment) + \
                 template2.format(device_camel_case_category=self.get_device().get_camel_case_category(),
                                  device_camel_case_name=self.get_device().get_camel_case_name(),
                                  function_camel_case_name=self.get_camel_case_name(),
                                  parameters=common.wrap_non_empty(',<BP>', ',<BP>'.join(parameters), ''),
                                  write_lines='\n'.join(write_lines),
                                  extra_message=extra_message)

        return common.break_string(result, '{}CB('.format(self.get_camel_case_name()))
    def get_ruby_source(self):
        template = r"""{global_line_prefix}# Get current {function_name_comment}{array_content}
{global_line_prefix}{variables} = {device_name}.{function_name_under}{arguments}
{puts}
"""
        comments = []
        variables = []
        puts = []

        for result in self.get_results():
            variables.append(result.get_ruby_variable())
            puts += result.get_ruby_puts()

        if len(variables) > 1:
            array_content = ' as [{0}]'.format(',<BP>'.join(
                [variable.rstrip('_') for variable in variables]))
            variables = [self.get_name(skip=1).under]
        else:
            array_content = ''

        while None in puts:
            puts.remove(None)

        if len(puts) > 1:
            puts.insert(0, '\b')

        arguments = common.wrap_non_empty(' ',
                                          ', '.join(self.get_ruby_arguments()),
                                          '')

        if arguments.strip().startswith('('):
            arguments = '({0})'.format(arguments.strip())

        result = template.format(
            global_line_prefix=global_line_prefix,
            device_name=self.get_device().get_initial_name(),
            function_name_under=self.get_name().under,
            function_name_comment=self.get_comment_name(),
            array_content=array_content,
            variables=', '.join(variables),
            puts='\n'.join(puts).replace('\b\n\r', '\n').replace(
                '\b', '').replace('\r\n\r',
                                  '\n\n').rstrip('\r').replace('\r', '\n'),
            arguments=arguments)

        return common.break_string(result,
                                   '# Get current {0} as ['.format(
                                       self.get_comment_name()),
                                   indent_head='#')
    def get_delphi_source(self):
        template = '{comment1}{global_line_prefix}  {device_name}.{function_name}{arguments};{comment2}\n'

        result = template.format(
            global_line_prefix=global_line_prefix,
            device_name=self.get_device().get_initial_name(),
            function_name=self.get_name().camel,
            arguments=common.wrap_non_empty(
                '(', ',<BP>'.join(self.get_delphi_arguments()), ')'),
            comment1=self.get_formatted_comment1(
                global_line_prefix + '  {{ {0} }}\n', '\r',
                '\n' + global_line_prefix + '    '),
            comment2=self.get_formatted_comment2(' {{ {0} }}', ''))

        return common.break_string(result, '{}('.format(self.get_name().camel))
示例#49
0
    def get_csharp_function(self):
        template1A = r"""	// Callback function for {function_name_comment} callback
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""	static void {function_name_camel}CB({device_category}{device_name} sender{parameters})
	{{
{write_lines}{extra_message}
	}}
"""
        override_comment = self.get_formatted_override_comment(
            '\t// {0}', None, '\n\t// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        write_lines = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_csharp_source())
            write_lines += parameter.get_csharp_write_lines()

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.append('\t\tConsole.WriteLine("");')

        extra_message = self.get_formatted_extra_message(
            '\t\tConsole.WriteLine("{0}");')

        if len(extra_message) > 0 and len(write_lines) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(device_category=self.get_device().get_category().camel,
                                  device_name=self.get_device().get_name().camel,
                                  function_name_camel=self.get_name().camel,
                                  parameters=common.wrap_non_empty(',<BP>', ',<BP>'.join(parameters), ''),
                                  write_lines='\n'.join(write_lines).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result,
                                   '{}CB('.format(self.get_name().camel))
    def get_vbnet_subroutine(self):
        template1A = r"""    ' Callback subroutine for {function_name_comment} callback
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""    Sub {function_name_camel}CB(ByVal sender As {device_category}{device_name}{parameters})
{write_lines}{extra_message}
    End Sub
"""
        override_comment = self.get_formatted_override_comment(
            "    ' {0}", None, "\n    ' ")

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        write_lines = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_vbnet_source())
            write_lines += parameter.get_vbnet_write_lines()

        while None in write_lines:
            write_lines.remove(None)

        if len(write_lines) > 1:
            write_lines.append('        Console.WriteLine("")')

        extra_message = self.get_formatted_extra_message(
            '        Console.WriteLine("{0}")')

        if len(extra_message) > 0 and len(write_lines) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(device_category=self.get_device().get_category().camel,
                                  device_name=self.get_device().get_name().camel,
                                  function_name_camel=self.get_name().camel,
                                  parameters=common.wrap_non_empty(',<BP>', ',<BP>'.join(parameters), ''),
                                  write_lines='\n'.join(write_lines),
                                  extra_message=extra_message)

        return common.break_string(result,
                                   '{}CB('.format(self.get_name().camel),
                                   continuation=' _')
    def get_delphi_prototype(self):
        template = '    procedure {function_name}CB(sender: T{device_category}{device_name}{parameters});'
        parameters = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_delphi_source())

        result = template.format(
            device_category=self.get_device().get_category().camel,
            device_name=self.get_device().get_name().camel,
            function_name=self.get_name().camel,
            parameters=common.wrap_non_empty(';<BP>', ';<BP>'.join(parameters),
                                             ''))

        return common.break_string(result,
                                   '{}CB('.format(self.get_name().camel))
    def get_vbnet_source(self):
        template = '{comment1}{global_line_prefix}        {device_name}.{function_name}({arguments}){comment2}\n'

        result = template.format(
            global_line_prefix=global_line_prefix,
            device_name=self.get_device().get_initial_name(),
            function_name=self.get_name().camel,
            arguments=',<BP>'.join(self.get_vbnet_arguments()),
            comment1=self.get_formatted_comment1(
                global_line_prefix + "        ' {0}\n", '\r',
                "\n" + global_line_prefix + "        ' "),
            comment2=self.get_formatted_comment2(" ' {0}", ''))

        return common.break_string(result,
                                   '.{}('.format(self.get_name().camel),
                                   continuation=' _')
    def get_ruby_source(self):
        template1A = r"""# Register {function_name_comment} callback
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""{device_name_initial}.register_callback({device_category}{device_name_camel}::CALLBACK_{function_name_upper}) do{parameters}
{puts}{extra_message}
end
"""
        override_comment = self.get_formatted_override_comment(
            '# {0}', None, '\n# ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        puts = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_ruby_source())
            puts += parameter.get_ruby_puts()

        while None in puts:
            puts.remove(None)

        if len(puts) > 1:
            puts.append("  puts ''")

        extra_message = self.get_formatted_extra_message("  puts '{0}'")

        if len(extra_message) > 0 and len(puts) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(device_category=self.get_device().get_category().camel,
                                  device_name_camel=self.get_device().get_name().camel,
                                  device_name_initial=self.get_device().get_initial_name(),
                                  function_name_under=self.get_name().under,
                                  function_name_upper=self.get_name().upper,
                                  parameters=common.wrap_non_empty(' |', ',<BP>'.join(parameters), '|'),
                                  puts='\n'.join(puts).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result, ') do |')
    def get_delphi_procedure(self):
        template1A = r"""{{ Callback procedure for {function_name_comment} callback }}
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""procedure TExample.{function_name_camel}CB(sender: T{device_category}{device_name}{parameters});
begin
{write_lns}{extra_message}
end;
"""
        override_comment = self.get_formatted_override_comment(
            '{{ {0} }}', None, '\n  ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        write_lns = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_delphi_source())
            write_lns += parameter.get_delphi_write_lns()

        while None in write_lns:
            write_lns.remove(None)

        if len(write_lns) > 1:
            write_lns.append("  WriteLn('');")

        extra_message = self.get_formatted_extra_message("  WriteLn('{0}');")

        if len(extra_message) > 0 and len(write_lns) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(device_category=self.get_device().get_category().camel,
                                  device_name=self.get_device().get_name().camel,
                                  function_name_camel=self.get_name().camel,
                                  parameters=common.wrap_non_empty(';<BP>', ';<BP>'.join(parameters), ''),
                                  write_lns='\n'.join(write_lns).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result,
                                   '{}CB('.format(self.get_name().camel))
    def get_delphi_source(self):
        templateA = r"""{global_line_prefix}  {{ Get current {function_name_comment} }}
{global_line_prefix}  {variable_names} := {device_name}.{function_name_camel}{arguments};
{write_lns}
"""
        templateB = r"""{global_line_prefix}  {{ Get current {function_name_comment} }}
{global_line_prefix}  {device_name}.{function_name_camel}{arguments};
{write_lns}
"""
        variable_names = []
        write_lns = []

        for result in self.get_results():
            variable_names.append(result.get_delphi_variable_name())
            write_lns += result.get_delphi_write_lns()

        if len(variable_names) == 1:
            template = templateA
        else:
            template = templateB

        while None in write_lns:
            write_lns.remove(None)

        if len(write_lns) > 1:
            write_lns.insert(0, '\b')

        arguments = self.get_delphi_arguments()

        if len(variable_names) > 1:
            arguments += variable_names
            variable_names = []

        result = template.format(
            global_line_prefix=global_line_prefix,
            device_name=self.get_device().get_initial_name(),
            function_name_camel=self.get_name().camel,
            function_name_comment=self.get_comment_name(),
            variable_names=''.join(variable_names),
            write_lns='\n'.join(write_lns).replace('\b\n\r', '\n').replace(
                '\b', '').replace('\r\n\r',
                                  '\n\n').rstrip('\r').replace('\r', '\n'),
            arguments=common.wrap_non_empty('(', ',<BP>'.join(arguments), ')'))

        return common.break_string(result,
                                   '.{0}('.format(self.get_name().camel))
    def get_ruby_source(self):
        template = '{comment1}{global_line_prefix}{device_name}.{function_name}{arguments}{comment2}\n'
        arguments = common.wrap_non_empty(' ', ',<BP>'.join(self.get_ruby_arguments()), '')
        indent_marker = '.{} '

        if arguments.strip().startswith('('):
            arguments = '({0})'.format(arguments.strip())
            indent_marker = '.{}('

        result = template.format(global_line_prefix=global_line_prefix,
                                 device_name=self.get_device().get_initial_name(),
                                 function_name=self.get_name().under,
                                 arguments=arguments,
                                 comment1=self.get_formatted_comment1(global_line_prefix + '# {0}\n', '\r', '\n' + global_line_prefix + '# '),
                                 comment2=self.get_formatted_comment2(' # {0}', ''))

        return common.break_string(result, indent_marker.format(self.get_name().under), continuation=' \\')
    def get_php_subroutine(self):
        template1A = r"""// Callback function for {function_name_comment} callback
"""
        template1B = r"""{override_comment}
"""
        template2 = r"""function cb_{function_name_headless}({parameters})
{{
{echos}{extra_message}
}}
"""
        override_comment = self.get_formatted_override_comment(
            '// {0}', None, '\n// ')

        if override_comment == None:
            template1 = template1A
        else:
            template1 = template1B

        parameters = []
        echos = []

        for parameter in self.get_parameters():
            parameters.append(parameter.get_php_source())
            echos += parameter.get_php_echos()

        while None in echos:
            echos.remove(None)

        if len(echos) > 1:
            echos.append('    echo "\\n";')

        extra_message = self.get_formatted_extra_message('    echo "{0}\\n";')

        if len(extra_message) > 0 and len(echos) > 0:
            extra_message = '\n' + extra_message

        result = template1.format(function_name_comment=self.get_comment_name(),
                                  override_comment=override_comment) + \
                 template2.format(function_name_headless=self.get_name().headless,
                                  parameters=',<BP>'.join(parameters),
                                  echos='\n'.join(echos).replace('\r\n\r', '\n\n').strip('\r').replace('\r', '\n'),
                                  extra_message=extra_message)

        return common.break_string(result,
                                   'cb_{}('.format(self.get_name().headless))
示例#58
0
    def get_c_source(self):
        template = r"""	// Register {function_name_comment}<BP>callback<BP>to<BP>function<BP>cb_{function_name_under}
	{device_name_under}_register_callback(&{device_name_initial},
	{spaces}                   {device_name_upper}_CALLBACK_{function_name_upper},
	{spaces}                   (void (*)(void))cb_{function_name_under},
	{spaces}                   NULL);
"""

        result = template.format(
            device_name_under=self.get_device().get_name().under,
            device_name_upper=self.get_device().get_name().upper,
            device_name_initial=self.get_device().get_initial_name(),
            function_name_under=self.get_name().under,
            function_name_upper=self.get_name().upper,
            function_name_comment=self.get_comment_name(),
            spaces=' ' * len(self.get_device().get_name().under))

        return common.break_string(result, '// ', indent_tail='// ')