Ejemplo n.º 1
0
def make_callbacks():
    cb = {
    'en': """
.. csharp:function:: public event {0}::{1}({2})

{3}
""",
    'de': """
.. csharp:function:: public event {0}::{1}({2})

{3}
"""
    }

    cbs = ''
    cls = device.get_camel_case_name()
    for packet in device.get_packets('callback'):
        desc = format_doc(packet, 2)
        params = csharp_common.make_parameter_list(packet)

        cbs += common.select_lang(cb).format(device.get_category() + device.get_camel_case_name(),
                                             packet.get_camel_case_name(),
                                             params,
                                             desc)

    return cbs
Ejemplo n.º 2
0
def make_callbacks():
    cb = {
    'en': """
.. csharp:function:: public delegate void {0}::{1}({2})

{3}
""",
    'de': """
.. csharp:function:: public delegate void {0}::{1}({2})

{3}
"""
    }

    cbs = ''
    cls = device.get_camel_case_name()
    for packet in device.get_packets('callback'):
        desc = fix_links(common.shift_right(packet.get_doc()[1][lang], 2))
        params = csharp_common.make_parameter_list(packet)

        cbs += cb[lang].format(device.get_category() + device.get_camel_case_name(),
                               packet.get_camel_case_name(),
                               params,
                               desc)

    return cbs
Ejemplo n.º 3
0
def make_obsolete_methods():
    methods = ''
    method = """
\t\t/// <summary>
\t\t///  Obsolete. Use overloaded version instead that returns the result.
\t\t/// </summary>
\t\t[Obsolete()]
\t\tpublic void {0}({1})
\t\t{{
\t\t\t{2} = {0}({3});
\t\t}}
"""

    cls = device.get_camel_case_name()
    for packet in device.get_packets('function'):
        ret_count = len(packet.get_elements('out'))
        if ret_count != 1:
            continue

        name = packet.get_camel_case_name()
        sigParams = csharp_common.make_parameter_list(packet, True)
        outParam = common.underscore_to_headless_camel_case(packet.get_elements('out')[0][0])
        callParams = ", ".join(map(lambda e: common.underscore_to_headless_camel_case(e[0]), packet.get_elements('in')))
        doc = '\n\t\t///  '.join(fix_links(packet.get_doc()[1][lang]).strip().split('\n'))

        methods += method.format(name,
                                 sigParams,
                                 outParam,
                                 callParams,
                                 doc)

    return methods
def make_callbacks():
    cbs = ''
    cb = """
\t\t/// <summary>
\t\t/// </summary>
\t\tprotected void On{0}(byte[] data_)
\t\t{{
{1}\t\t\tvar handler = {0};
\t\t\tif(handler != null)
\t\t\t{{
\t\t\t\thandler(this{3});
\t\t\t}}
\t\t}}
"""
    cls = device.get_camel_case_name()
    for packet in device.get_packets('callback'):
        name = packet.get_camel_case_name()
        name_upper = packet.get_upper_case_name()
        eles = []
        for element in packet.get_elements('out'):
            eles.append(common.underscore_to_headless_camel_case(element[0]))
        callParams = ", ".join(eles)
        signatureParams = csharp_common.make_parameter_list(packet)
        size = str(get_data_size(packet))

        convs = ''
        conv = '\t\t\t{0} {1} = LEConverter.{2}({3}, data_{4});\n'

        pos = 8
        for element in packet.get_elements('out'):
            csharp_type = csharp_common.get_csharp_type(element)
            cname = common.underscore_to_headless_camel_case(element[0])
            from_type = get_from_type(element)
            length = ''
            if element[2] > 1:
                length = ', ' + str(element[2])
            convs += conv.format(csharp_type, 
                                 cname, 
                                 from_type,
                                 pos,
                                 length)

            pos += common.get_element_size(element)

        if convs != '':
            convs += '\n'

        if callParams != '':
            callParams = ', ' + callParams
        
        cbs += cb.format(name, convs, name_upper, callParams, pos, signatureParams)

    return cbs + "\t}\n}"
Ejemplo n.º 5
0
def make_delegates():
    cbs = '\n'
    cb = """
\t\t/// <summary>
\t\t///  {2}
\t\t/// </summary>
\t\tpublic delegate void {0}({1});
"""
    for packet in device.get_packets('callback'):
        name = packet.get_camel_case_name()
        parameter = csharp_common.make_parameter_list(packet)
        doc = '\n\t\t///  '.join(fix_links(packet.get_doc()[1][lang]).strip().split('\n'))
        cbs += cb.format(name, parameter, doc)
    return cbs
def make_delegates():
    cbs = '\n'
    cb = """
\t\t/// <summary>
\t\t///  {2}
\t\t/// </summary>
\t\tpublic event {0}EventHandler {0};
\t\tpublic delegate void {0}EventHandler(object sender{1});
"""
    for packet in device.get_packets('callback'):
        name = packet.get_camel_case_name()
        parameter = csharp_common.make_parameter_list(packet)
        doc = format_doc(packet)
        if parameter != '':
            parameter = ', ' + parameter
        cbs += cb.format(name, parameter, doc)
    return cbs