Пример #1
0
def generate_msg_handlers(func_list, plugin_name, inputfile):
    handlers = []
    for f in func_list:
        handler_name = f['name']
        dto_name = util.underscore_to_camelcase_upper(handler_name)
        ref_name = util.underscore_to_camelcase(handler_name)

        if is_manually_generated(handler_name,
                                 plugin_name) or util.is_ignored(handler_name):
            continue

        if not util.is_reply(dto_name) and not util.is_notification(
                handler_name):
            continue

        if util.is_notification(handler_name):
            dto_name = util.add_notification_suffix(dto_name)
            ref_name = util.add_notification_suffix(ref_name)

        dto_setters = ''
        err_handler = ''
        # dto setters
        for t in zip(f['types'], f['args'], f['lengths']):
            c_name = t[1]
            java_name = util.underscore_to_camelcase(c_name)
            field_length = t[2][0]
            is_variable_len_array = t[2][1]
            length_field_type = None
            if is_variable_len_array:
                length_field_type = f['types'][f['args'].index(field_length)]
            dto_setters += jni_gen.jni_reply_handler_for_type(
                handler_name=handler_name,
                ref_name=ref_name,
                field_type=t[0],
                c_name=t[1],
                field_reference_name=java_name,
                field_name=java_name,
                field_length=field_length,
                is_variable_len_array=is_variable_len_array,
                length_field_type=length_field_type)

            # for retval don't generate setters and generate retval check
            if util.is_retval_field(c_name):
                err_handler = callback_err_handler_template.substitute(
                    handler_name=handler_name)
                continue

        handlers.append(
            msg_handler_template.substitute(
                inputfile=inputfile,
                api_data=util.api_message_to_javadoc(f),
                handler_name=handler_name,
                plugin_name=plugin_name,
                dto_name=dto_name,
                class_ref_name=ref_name,
                dto_setters=dto_setters,
                err_handler=err_handler))

    return "\n".join(handlers)
Пример #2
0
def generate_jni_impl(func_list, inputfile):
    jni_impl = []
    for f in func_list:
        f_name = f['name']
        camel_case_function_name = util.underscore_to_camelcase(f_name)
        if is_manually_generated(f_name) or util.is_reply(camel_case_function_name) \
                or util.is_ignored(f_name) or util.is_notification(f_name):
            continue

        arguments = ''
        request_class = ''
        field_identifiers = ''
        struct_setters = ''
        f_name_uppercase = f_name.upper()

        if f['args']:
            arguments = ', jobject request'
            camel_case_function_name_upper = util.underscore_to_camelcase_upper(f_name)

            request_class = request_class_template.substitute(java_name_upper=camel_case_function_name_upper)

            # field identifiers
            for t in zip(f['types'], f['args']):
                jni_type = t[0]
                java_field_name = util.underscore_to_camelcase(t[1])
                jni_signature = util.jni_2_signature_mapping[jni_type]
                jni_getter = util.jni_field_accessors[jni_type]
                field_identifiers += request_field_identifier_template.substitute(
                        jni_type=jni_type,
                        java_name=java_field_name,
                        jni_signature=jni_signature,
                        jni_getter=jni_getter)

            # field setters
            for t in zip(f['c_types'], f['args']):
                c_type = t[0]
                c_name = t[1]
                java_field_name = util.underscore_to_camelcase(c_name)

                struct_setter_template = struct_setter_templates[c_type]

                struct_setters += struct_setter_template.substitute(
                        c_name=c_name,
                        java_name=java_field_name)

        jni_impl.append(jni_impl_template.substitute(
                inputfile=inputfile,
                api_data=util.api_message_to_javadoc(f),
                java_name=camel_case_function_name,
                c_name_uppercase=f_name_uppercase,
                c_name=f_name,
                request_class=request_class,
                field_identifiers=field_identifiers,
                struct_setters=struct_setters,
                args=arguments))

    return "\n".join(jni_impl)
Пример #3
0
def generate_msg_handlers(func_list, plugin_name, inputfile):
    handlers = []
    for f in func_list:
        handler_name = f['name']
        dto_name = util.underscore_to_camelcase_upper(handler_name)
        ref_name = util.underscore_to_camelcase(handler_name)

        if is_manually_generated(handler_name):
            # Skip control ping managed by jvpp registry.
            continue
        if util.is_dump(handler_name) or util.is_request(
                handler_name, func_list):
            continue

        # Generate msg handlers for all messages except for dumps and requests (handled by vpp, not client).
        dto_setters = ''
        err_handler = ''
        # dto setters
        for t in zip(f['types'], f['args'], f['lengths']):
            c_name = t[1]
            java_name = util.underscore_to_camelcase(c_name)
            field_length = t[2][0]
            is_variable_len_array = t[2][1]
            length_field_type = None
            if is_variable_len_array:
                length_field_type = f['types'][f['args'].index(field_length)]
            dto_setters += jni_gen.jni_reply_handler_for_type(
                handler_name=handler_name,
                ref_name=ref_name,
                field_type=t[0],
                c_name=t[1],
                field_reference_name=java_name,
                field_name=java_name,
                field_length=field_length,
                is_variable_len_array=is_variable_len_array,
                length_field_type=length_field_type)

            # for retval don't generate setters and generate retval check
            if util.is_retval_field(c_name):
                err_handler = callback_err_handler_template.substitute(
                    handler_name=handler_name)
                continue

        handlers.append(
            msg_handler_template.substitute(
                inputfile=inputfile,
                api_data=util.api_message_to_javadoc(f),
                handler_name=handler_name,
                plugin_name=plugin_name,
                dto_name=dto_name,
                class_ref_name=ref_name,
                dto_setters=dto_setters,
                err_handler=err_handler))

    return "\n".join(handlers)
Пример #4
0
def generate_jni_impl(func_list, plugin_name, inputfile):
    jni_impl = []
    for f in func_list:
        f_name = f['name']
        camel_case_function_name = util.underscore_to_camelcase(f_name)
        if is_manually_generated(f_name, plugin_name) or util.is_reply(camel_case_function_name) \
                or util.is_ignored(f_name) or util.is_just_notification(f_name):
            continue

        arguments = ''
        request_class = ''
        jni_identifiers = ''
        msg_initialization = ''
        f_name_uppercase = f_name.upper()
        msg_size = 'sizeof(*mp)'

        if f['args']:
            arguments = ', jobject request'
            camel_case_function_name_upper = util.underscore_to_camelcase_upper(f_name)

            request_class = request_class_template.substitute(
                    java_name_upper=camel_case_function_name_upper,
                    plugin_name=plugin_name)

            for t in zip(f['types'], f['args'], f['lengths'], f['arg_types']):
                field_name = util.underscore_to_camelcase(t[1])
                is_variable_len_array = t[2][1]
                if is_variable_len_array:
                    msg_size += jni_msg_size_template.substitute(array_length=util.underscore_to_camelcase(t[2][0]),
                                                                 element_type=t[3])
                jni_identifiers += jni_gen.jni_request_identifiers_for_type(field_type=t[0],
                                                                            field_reference_name=field_name,
                                                                            field_name=field_name)
                msg_initialization += jni_gen.jni_request_binding_for_type(field_type=t[0], c_name=t[1],
                                                                           field_reference_name=field_name,
                                                                           field_length=t[2][0],
                                                                           is_variable_len_array=is_variable_len_array)

        jni_impl.append(jni_impl_template.substitute(
                inputfile=inputfile,
                api_data=util.api_message_to_javadoc(f),
                field_reference_name=camel_case_function_name,
                field_name=camel_case_function_name,
                c_name_uppercase=f_name_uppercase,
                c_name=f_name,
                crc=f['crc'],
                plugin_name=plugin_name,
                java_plugin_name=plugin_name.title(),
                request_class=request_class,
                jni_identifiers=jni_identifiers,
                msg_size=msg_size,
                msg_initialization=msg_initialization,
                args=arguments))

    return "\n".join(jni_impl)
Пример #5
0
def generate_msg_handlers(func_list, inputfile):
    handlers = []
    for f in func_list:
        handler_name = f['name']
        dto_name = util.underscore_to_camelcase_upper(handler_name)
        ref_name = util.underscore_to_camelcase(handler_name)

        if is_manually_generated(handler_name) or not util.is_reply(
                dto_name) or util.is_ignored(
                    handler_name) or util.is_notification(handler_name):
            # TODO handle notifications
            continue

        dto_setters = ''
        # dto setters
        for t in zip(f['c_types'], f['types'], f['args'], f['lengths']):
            c_type = t[0]
            jni_type = t[1]
            c_name = t[2]
            field_length = t[3]

            java_field_name = util.underscore_to_camelcase(c_name)
            jni_signature = util.jni_2_signature_mapping[jni_type]
            jni_setter = util.jni_field_accessors[jni_type]

            dto_setters += dto_field_id_template.substitute(
                java_name=java_field_name,
                class_ref_name=ref_name,
                jni_signature=jni_signature)

            dto_setter_template = dto_field_setter_templates[c_type]

            dto_setters += dto_setter_template.substitute(
                java_name=java_field_name,
                jni_signature=jni_signature,
                c_name=c_name,
                jni_setter=jni_setter,
                field_length=field_length)

        handlers.append(
            msg_handler_template.substitute(
                inputfile=inputfile,
                api_data=util.api_message_to_javadoc(f),
                handler_name=handler_name,
                dto_name=dto_name,
                class_ref_name=ref_name,
                dto_setters=dto_setters))

    return "\n".join(handlers)
Пример #6
0
def generate_class_cache(func_list):
    class_references = []
    find_class_invocations = []
    for f in func_list:
        c_name = f['name']
        class_name = util.underscore_to_camelcase_upper(c_name)
        ref_name = util.underscore_to_camelcase(c_name)

        if util.is_ignored(c_name):
            continue

        if util.is_reply(class_name):
            class_references.append(class_reference_template.substitute(
                ref_name=ref_name))
            find_class_invocations.append(find_class_invocation_template.substitute(
                ref_name=ref_name,
                class_name=class_name))
        elif util.is_notification(c_name):
            class_references.append(class_reference_template.substitute(
                ref_name=util.add_notification_suffix(ref_name)))
            find_class_invocations.append(find_class_invocation_template.substitute(
                ref_name=util.add_notification_suffix(ref_name),
                class_name=util.add_notification_suffix(class_name)))

    # add exception class to class cache
    ref_name = 'callbackException'
    class_name = 'org/openvpp/jvpp/VppCallbackException'
    class_references.append(class_reference_template.substitute(
        ref_name=ref_name))
    find_class_invocations.append(find_class_template.substitute(
            ref_name=ref_name,
            class_name=class_name))
    return class_cache_template.substitute(
        class_references="".join(class_references), find_class_invocations="".join(find_class_invocations))
Пример #7
0
def jni_request_binding_for_type(field_type, c_name, field_reference_name,
                                 field_length, is_variable_len_array):
    """
    Generates jni code that initializes C structure that corresponds to a field of java object
    (dto or custom type). To be used in request message handlers.
    :param field_type: type of the field to be initialized (as defined in vpe.api)
    :param c_name: name of the message struct member to be initialized
    :param field_reference_name: name of the field reference in generated code
    :param field_length: integer or name of variable that stores field length
    """

    # field setter
    field_length_check = ""

    # check if we are processing variable length array:
    if is_variable_len_array:
        field_length = util.underscore_to_camelcase(field_length)

    # enforce max length if array has fixed length or uses variable length syntax
    if str(field_length) != "0":
        field_length_check = array_length_enforcement_template.substitute(
            field_length=field_length)

    struct_setter_template = struct_setter_templates[field_type]

    msg_initialization = struct_setter_template.substitute(
        c_name=c_name,
        field_reference_name=field_reference_name,
        field_length_check=field_length_check)

    return msg_initialization
Пример #8
0
def get_definitions():
    # Pass 1
    func_list = []
    func_name = {}
    for a in cfg.vppapidef:
        if not is_supported(a[0]):
            continue

        java_name = util.underscore_to_camelcase(a[0])

        # For replies include all the arguments except message_id
        if util.is_reply(java_name):
            types, c_types = get_types(a[1:], is_response_field)
            func_name[a[0]] = dict([('name', a[0]), ('java_name', java_name),
                                    ('args', get_args(a[1:],
                                                      is_response_field)),
                                    ('full_args',
                                     get_args(a[1:], lambda x: True)),
                                    ('types', types), ('c_types', c_types)])
        # For requests skip message_id, client_id and context
        else:
            types, c_types = get_types(a[1:], is_request_field)
            func_name[a[0]] = dict([('name', a[0]), ('java_name', java_name),
                                    ('args', get_args(a[1:],
                                                      is_request_field)),
                                    ('full_args',
                                     get_args(a[1:], lambda x: True)),
                                    ('types', types), ('c_types', c_types)])

        # Indexed by name
        func_list.append(func_name[a[0]])
    return func_list, func_name
Пример #9
0
def generate_dtos(func_list, base_package, plugin_package, plugin_name, dto_package, inputfile):
    """ Generates dto objects in a dedicated package """
    print "Generating DTOs"

    if not os.path.exists(dto_package):
        os.mkdir(dto_package)

    for func in func_list:
        camel_case_dto_name = util.underscore_to_camelcase_upper(func['name'])
        camel_case_method_name = util.underscore_to_camelcase(func['name'])
        dto_path = os.path.join(dto_package, camel_case_dto_name + ".java")

        if util.is_ignored(func['name']) or util.is_control_ping(camel_case_dto_name):
            continue

        fields = generate_dto_fields(camel_case_dto_name, func)
        methods = generate_dto_base_methods(camel_case_dto_name, func)
        base_type = ""

        # Generate request/reply or dump/dumpReply even if structure can be used as notification
        if not util.is_just_notification(func["name"]):
            if util.is_reply(camel_case_dto_name):
                description = "reply DTO"
                request_dto_name = get_request_name(camel_case_dto_name, func['name'])
                if util.is_details(camel_case_dto_name):
                    # FIXME assumption that dump calls end with "Dump" suffix. Not enforced in vpe.api
                    base_type += "JVppReply<%s.%s.%s>" % (plugin_package, dto_package, request_dto_name + "Dump")
                    generate_dump_reply_dto(request_dto_name, base_package, plugin_package, dto_package,
                                            camel_case_dto_name, camel_case_method_name, func)
                else:
                    base_type += "JVppReply<%s.%s.%s>" % (plugin_package, dto_package, request_dto_name)
            else:
                args = "" if fields is "" else "this"
                methods += send_template.substitute(method_name=camel_case_method_name,
                                                    base_package=base_package,
                                                    plugin_package=plugin_package,
                                                    plugin_name=plugin_name,
                                                    args=args)
                if util.is_dump(camel_case_dto_name):
                    base_type += "JVppDump"
                    description = "dump request DTO"
                else:
                    base_type += "JVppRequest"
                    description = "request DTO"

            write_dto_file(base_package, plugin_package, base_type, camel_case_dto_name, description, dto_package,
                           dto_path, fields, func, inputfile, methods)

        # for structures that are also used as notifications, generate dedicated notification DTO
        if util.is_notification(func["name"]):
            base_type = "JVppNotification"
            description = "notification DTO"
            camel_case_dto_name = util.add_notification_suffix(camel_case_dto_name)
            dto_path = os.path.join(dto_package, camel_case_dto_name + ".java")
            methods = generate_dto_base_methods(camel_case_dto_name, func)
            write_dto_file(base_package, plugin_package, base_type, camel_case_dto_name, description, dto_package,
                           dto_path, fields, func, inputfile, methods)

    flush_dump_reply_dtos(inputfile)
Пример #10
0
def generate_jvpp(func_list, base_package, dto_package, inputfile):
    """ Generates JVpp interface and JNI implementation """
    print "Generating JVpp"

    methods = []
    methods_impl = []
    for func in func_list:

        # Skip structures that are used only as notifications
        if util.is_just_notification(func['name']) or util.is_ignored(func['name']):
            continue

        camel_case_name = util.underscore_to_camelcase(func['name'])
        camel_case_name_upper = util.underscore_to_camelcase_upper(func['name'])
        if util.is_reply(camel_case_name):
            continue

        if len(func['args']) == 0:
            methods.append(no_arg_method_template.substitute(name=camel_case_name,
                                                             base_package=base_package,
                                                             dto_package=dto_package))
            methods_impl.append(
                no_arg_method_native_template.substitute(name=camel_case_name,
                                                         base_package=base_package,
                                                         dto_package=dto_package))
            methods_impl.append(no_arg_method_impl_template.substitute(name=camel_case_name,
                                                                       base_package=base_package,
                                                                       dto_package=dto_package))
        else:
            methods.append(method_template.substitute(name=camel_case_name,
                                                      request=camel_case_name_upper,
                                                      base_package=base_package,
                                                      dto_package=dto_package))
            methods_impl.append(method_native_template.substitute(name=camel_case_name,
                                                                  request=camel_case_name_upper,
                                                                  base_package=base_package,
                                                                  dto_package=dto_package))
            methods_impl.append(method_impl_template.substitute(name=camel_case_name,
                                                                request=camel_case_name_upper,
                                                                base_package=base_package,
                                                                dto_package=dto_package))

    jvpp_file = open("JVpp.java", 'w')
    jvpp_file.write(
        jvpp_ifc_template.substitute(inputfile=inputfile,
                                     methods="\n".join(methods),
                                     base_package=base_package,
                                     dto_package=dto_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open("JVppImpl.java", 'w')
    jvpp_file.write(jvpp_impl_template.substitute(inputfile=inputfile,
                                                  methods="\n".join(methods_impl),
                                                  base_package=base_package,
                                                  dto_package=dto_package))
    jvpp_file.flush()
    jvpp_file.close()
Пример #11
0
def generate_jvpp(func_list, base_package, plugin_package, plugin_name_underscore, control_ping_class, dto_package, inputfile):
    """ Generates JVpp interface and JNI implementation """
    print "Generating JVpp"
    plugin_name = util.underscore_to_camelcase_upper(plugin_name_underscore)

    methods = []
    methods_impl = []
    for func in func_list:

        # Skip structures that are used only as notifications
        if util.is_just_notification(func['name']) or util.is_ignored(func['name']):
            continue

        camel_case_name = util.underscore_to_camelcase(func['name'])
        camel_case_name_upper = util.underscore_to_camelcase_upper(func['name'])
        if util.is_reply(camel_case_name):
            continue

        if len(func['args']) == 0:
            methods.append(no_arg_method_template.substitute(name=camel_case_name))
            methods_impl.append(no_arg_method_native_template.substitute(name=camel_case_name))
            methods_impl.append(no_arg_method_impl_template.substitute(name=camel_case_name))
        else:
            methods.append(method_template.substitute(name=camel_case_name,
                                                      request=camel_case_name_upper,
                                                      plugin_package=plugin_package,
                                                      dto_package=dto_package))
            methods_impl.append(method_native_template.substitute(name=camel_case_name,
                                                                  request=camel_case_name_upper,
                                                                  plugin_package=plugin_package,
                                                                  dto_package=dto_package))
            methods_impl.append(method_impl_template.substitute(name=camel_case_name,
                                                                request=camel_case_name_upper,
                                                                plugin_package=plugin_package,
                                                                dto_package=dto_package))

    jvpp_file = open("JVpp%s.java" % plugin_name, 'w')
    jvpp_file.write(
        jvpp_ifc_template.substitute(inputfile=inputfile,
                                     methods="\n".join(methods),
                                     base_package=base_package,
                                     plugin_package=plugin_package,
                                     plugin_name=plugin_name,
                                     dto_package=dto_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open("JVpp%sImpl.java" % plugin_name, 'w')
    jvpp_file.write(jvpp_impl_template.substitute(inputfile=inputfile,
                                                  methods="\n".join(methods_impl),
                                                  base_package=base_package,
                                                  plugin_package=plugin_package,
                                                  plugin_name=plugin_name,
                                                  plugin_name_underscore=plugin_name_underscore,
                                                  dto_package=dto_package,
                                                  control_ping_class=control_ping_class))
    jvpp_file.flush()
    jvpp_file.close()
Пример #12
0
def generate_dtos(func_list, base_package, plugin_package, plugin_name,
                  dto_package, inputfile, logger):
    """ Generates dto objects in a dedicated package """
    logger.debug("Generating DTOs for %s" % inputfile)

    if not os.path.exists(dto_package):
        os.mkdir(dto_package)

    for func in func_list:
        camel_case_dto_name = util.underscore_to_camelcase_upper(func['name'])
        camel_case_method_name = util.underscore_to_camelcase(func['name'])
        dto_path = os.path.join(dto_package, camel_case_dto_name + ".java")

        if util.is_control_ping(camel_case_dto_name):
            continue

        fields = generate_dto_fields(camel_case_dto_name, func)
        methods = generate_dto_base_methods(camel_case_dto_name, func)
        base_type = ""

        if util.is_reply(camel_case_dto_name):
            description = "reply DTO"
            request_dto_name = util.remove_reply_suffix(camel_case_dto_name)
            if util.is_details(camel_case_dto_name):
                base_type += "JVppReply<%s.%s.%s>" % (
                    plugin_package, dto_package, request_dto_name + "Dump")
                generate_dump_reply_dto(request_dto_name, base_package,
                                        plugin_package, dto_package,
                                        camel_case_dto_name,
                                        camel_case_method_name, func)
            else:
                base_type += "JVppReply<%s.%s.%s>" % (
                    plugin_package, dto_package, request_dto_name)
        elif util.is_dump(camel_case_dto_name) or util.is_request(
                func['name'], func_list):
            args = "" if fields is "" else "this"
            methods += send_template.substitute(
                method_name=camel_case_method_name,
                base_package=base_package,
                plugin_package=plugin_package,
                plugin_name=plugin_name,
                args=args)
            if util.is_dump(camel_case_dto_name):
                base_type += "JVppDump"
                description = "dump request DTO"
            else:
                base_type += "JVppRequest"
                description = "request DTO"
        else:
            description = "event DTO"
            dto_path = os.path.join(dto_package, camel_case_dto_name + ".java")

        write_dto_file(base_package, plugin_package, base_type,
                       camel_case_dto_name, description, dto_package, dto_path,
                       fields, func, inputfile, methods)

    flush_dump_reply_dtos(inputfile)
Пример #13
0
def generate_dto_fields(camel_case_dto_name, func):
    fields = ""
    for t in zip(func['types'], func['args']):
        # for retval don't generate dto field in Reply
        field_name = util.underscore_to_camelcase(t[1])
        if util.is_reply(camel_case_dto_name) and util.is_retval_field(field_name):
            continue
        fields += field_template.substitute(type=util.jni_2_java_type_mapping[t[0]],
                                            name=field_name)
    return fields
Пример #14
0
def generate_dto_hash(func):
    hash_fields = ""

    # Special handling for hashCode in case just a single array field is present. Cannot use Objects.equals since the
    # array is mistaken for a varargs parameter. Instead use Arrays.hashCode in such case.
    if len(func['args']) == 1:
        single_type = func['types'][0]
        single_type_name = func['args'][0]
        if util.is_array(util.jni_2_java_type_mapping[single_type]):
            return hash_single_array_type_template.substitute(fields=util.underscore_to_camelcase(single_type_name))

    for t in zip(func['types'], func['args']):
        field_name = util.underscore_to_camelcase(t[1])
        # for retval don't generate dto field in Reply
        if util.is_retval_field(field_name):
            continue

        hash_fields += field_name + ", "

    return hash_template.substitute(fields=hash_fields[:-2])
Пример #15
0
def generate_type_fields(type_definition):
    """
    Generates fields for class representing typeonly definition
    :param type_definition: python representation of typeonly definition
    :return: string representing class fields
    """
    fields = ""
    for t in zip(type_definition['types'], type_definition['args']):
        field_name = util.underscore_to_camelcase(t[1])
        fields += field_template.substitute(
            type=util.jni_2_java_type_mapping[t[0]], name=field_name)
    return fields
Пример #16
0
def generate_struct_initialization(type_def, c_name_prefix, object_name, indent):
    struct_initialization = ""
    # field identifiers
    for t in zip(type_def['types'], type_def['args'], type_def['lengths']):
        field_reference_name = "${c_name}" + util.underscore_to_camelcase_upper(t[1])
        field_name = util.underscore_to_camelcase(t[1])
        struct_initialization += jni_gen.jni_request_binding_for_type(field_type=t[0], c_name=c_name_prefix + t[1],
                                                                     field_reference_name=field_reference_name,
                                                                     field_name=field_name,
                                                                     field_length=t[2][0],
                                                                     is_variable_len_array=t[2][1],
                                                                     object_name=object_name)
    return indent + struct_initialization.replace('\n', '\n' + indent)
Пример #17
0
def generate_class_cache(func_list, plugin_name):
    class_references = []
    find_class_invocations = []
    delete_class_invocations = []
    for f in func_list:
        c_name = f['name']
        class_name = util.underscore_to_camelcase_upper(c_name)
        ref_name = util.underscore_to_camelcase(c_name)

        if util.is_ignored(c_name) or util.is_control_ping(class_name):
            continue

        if util.is_reply(class_name):
            class_references.append(
                class_reference_template.substitute(ref_name=ref_name))
            find_class_invocations.append(
                find_class_invocation_template.substitute(
                    plugin_name=plugin_name,
                    ref_name=ref_name,
                    class_name=class_name))
            delete_class_invocations.append(
                delete_class_invocation_template.substitute(ref_name=ref_name))
        elif util.is_notification(c_name):
            class_references.append(
                class_reference_template.substitute(
                    ref_name=util.add_notification_suffix(ref_name)))
            find_class_invocations.append(
                find_class_invocation_template.substitute(
                    plugin_name=plugin_name,
                    ref_name=util.add_notification_suffix(ref_name),
                    class_name=util.add_notification_suffix(class_name)))
            delete_class_invocations.append(
                delete_class_invocation_template.substitute(
                    ref_name=util.add_notification_suffix(ref_name)))

    # add exception class to class cache
    ref_name = 'callbackException'
    class_name = 'io/fd/vpp/jvpp/VppCallbackException'
    class_references.append(
        class_reference_template.substitute(ref_name=ref_name))
    find_class_invocations.append(
        find_class_template.substitute(ref_name=ref_name,
                                       class_name=class_name))
    delete_class_invocations.append(
        delete_class_invocation_template.substitute(ref_name=ref_name))

    return class_cache_template.substitute(
        class_references="".join(class_references),
        find_class_invocations="".join(find_class_invocations),
        delete_class_invocations="".join(delete_class_invocations))
Пример #18
0
def generate_handler_registration(func_list):
    handler_registration = ["#define foreach_api_reply_handler \\\n"]
    for f in func_list:
        name = f['name']
        camelcase_name = util.underscore_to_camelcase(f['name'])

        if (not util.is_reply(camelcase_name) and not util.is_notification(name)) or util.is_ignored(name) \
                or util.is_control_ping(camelcase_name):
            continue

        handler_registration.append(
            handler_registration_template.substitute(name=name, crc=f['crc']))

    return "".join(handler_registration)
Пример #19
0
def generate_handler_registration(func_list):
    handler_registration = ["#define foreach_vpe_api_msg \\\n"]
    for f in func_list:
        name = f['name']
        camelcase_name = util.underscore_to_camelcase(f['name'])

        if (not util.is_reply(camelcase_name) and not util.is_notification(name)) or util.is_ignored(name):
            continue

        handler_registration.append(handler_registration_template.substitute(
            name=name,
            upercase_name=name.upper()))

    return "".join(handler_registration)
Пример #20
0
def generate_handler_registration(func_list):
    handler_registration = ["#define foreach_vpe_api_msg \\\n"]
    for f in func_list:
        name = f['name']
        camelcase_name = util.underscore_to_camelcase(f['name'])

        if not util.is_reply(camelcase_name) or util.is_ignored(name) or util.is_notification(name):
            # TODO handle notifications
            continue

        handler_registration.append(handler_registration_template.substitute(
                name=name,
                upercase_name=name.upper()))

    return "".join(handler_registration)
Пример #21
0
def generate_callback(func_list, base_package, plugin_package, plugin_name, dto_package, callback_package, notification_package, future_facade_package, inputfile):
    callbacks = []
    for func in func_list:
        camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name'])

        if util.is_control_ping(camel_case_name_with_suffix):
            # Skip control ping managed by jvpp registry.
            continue
        if util.is_dump(func['name']) or util.is_request(func['name'], func_list):
            continue

        # Generate callbacks for all messages except for dumps and requests (handled by vpp, not client).
        if util.is_details(camel_case_name_with_suffix):
            # Callbacks for detail messages that append replies to a list.
            camel_case_method_name = util.underscore_to_camelcase(func['name'])
            camel_case_reply_name = util.underscore_to_camelcase_upper(func['name'])
            callbacks.append(jvpp_facade_details_callback_method_template.substitute(base_package=base_package,
                                                                                     plugin_package=plugin_package,
                                                                                     dto_package=dto_package,
                                                                                     callback_dto=camel_case_name_with_suffix,
                                                                                     callback_dto_field=camel_case_method_name,
                                                                                     callback_dto_reply_dump=camel_case_reply_name + dto_gen.dump_dto_suffix,
                                                                                     future_package=future_facade_package))
        elif util.is_reply(camel_case_name_with_suffix):
            request_dto = util.remove_reply_suffix(util.underscore_to_camelcase_upper(func['name']))
            callbacks.append(jvpp_facade_callback_method_template.substitute(base_package=base_package,
                                                                             plugin_package=plugin_package,
                                                                             dto_package=dto_package,
                                                                             callback_dto=camel_case_name_with_suffix,
                                                                             request_dto=request_dto))
        else:
            callbacks.append(jvpp_facade_callback_notification_method_template.substitute(plugin_package=plugin_package,
                                                                                          dto_package=dto_package,
                                                                                          callback_dto=camel_case_name_with_suffix))

    jvpp_file = open(os.path.join(future_facade_package, "FutureJVpp%sFacadeCallback.java" % plugin_name), 'w')
    jvpp_file.write(jvpp_facade_callback_template.substitute(inputfile=inputfile,
                                                             base_package=base_package,
                                                             plugin_package=plugin_package,
                                                             plugin_name=plugin_name,
                                                             dto_package=dto_package,
                                                             notification_package=notification_package,
                                                             callback_package=callback_package,
                                                             methods="".join(callbacks),
                                                             future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()
Пример #22
0
def generate_handler_registration(func_list):
    handler_registration = ["#define foreach_api_reply_handler \\\n"]
    for f in func_list:
        name = f['name']
        camelcase_name = util.underscore_to_camelcase(name)

        if util.is_control_ping(camelcase_name):
            # Skip control ping managed by registry.
            continue
        if util.is_dump(name) or util.is_request(name, func_list):
            continue

        # Generate msg handler registration for all messages except for dumps and requests.
        handler_registration.append(
            handler_registration_template.substitute(name=name, crc=f['crc']))

    return "".join(handler_registration)
Пример #23
0
def generate_dto_tostring(camel_case_dto_name, func):
    tostring_fields = ""
    for t in zip(func['types'], func['args']):

        field_name = util.underscore_to_camelcase(t[1])
        # for retval don't generate dto field in Reply
        if util.is_retval_field(field_name):
            continue

        # handle array types
        if util.is_array(util.jni_2_java_type_mapping[t[0]]):
            tostring_fields += tostring_array_field_template.substitute(field_name=field_name)
        else:
            tostring_fields += tostring_field_template.substitute(field_name=field_name)

    return tostring_template.substitute(cls_name=camel_case_dto_name,
                                        fields_tostring=tostring_fields[:-8])
Пример #24
0
def generate_type_setter(handler_name, type_def, c_name_prefix, object_name, indent):
    type_initialization = ""
    for t in zip(type_def['types'], type_def['args'], type_def['lengths']):
        field_length = t[2][0]
        is_variable_len_array = t[2][1]
        length_field_type = None
        if is_variable_len_array:
            length_field_type = type_def['types'][type_def['args'].index(field_length)]
        type_initialization += jni_gen.jni_reply_handler_for_type(handler_name=handler_name,
                                                                  ref_name="${field_reference_name}",
                                                                  field_type=t[0], c_name=c_name_prefix + t[1],
                                                                  field_reference_name="${c_name}" + util.underscore_to_camelcase_upper(t[1]),
                                                                  field_name=util.underscore_to_camelcase(t[1]),
                                                                  field_length=field_length,
                                                                  is_variable_len_array=is_variable_len_array,
                                                                  length_field_type=length_field_type,
                                                                  object_name=object_name)
    return indent + type_initialization.replace('\n', '\n' + indent)
Пример #25
0
def generate_dto_equals(camel_case_dto_name, func):
    equals_fields = ""
    for t in zip(func['types'], func['args']):
        field_name = util.underscore_to_camelcase(t[1])
        # for retval don't generate dto field in Reply
        if util.is_retval_field(field_name):
            continue

        # handle array types
        if util.is_array(util.jni_2_java_type_mapping[t[0]]):
            equals_fields += equals_array_field_template.substitute(field_name=field_name)
        else:
            equals_fields += equals_field_template.substitute(field_name=field_name)

    if equals_fields != "":
        equals_fields = equals_other_template.substitute(cls_name=camel_case_dto_name) + equals_fields

    return equals_template.substitute(comparisons=equals_fields)
Пример #26
0
def generate_class_cache(func_list):
    class_references = []
    find_class_invocations = []
    for f in func_list:
        c_name = f['name']
        class_name = util.underscore_to_camelcase_upper(c_name)
        ref_name = util.underscore_to_camelcase(c_name)

        if not util.is_reply(class_name) or util.is_ignored(c_name) or util.is_notification(c_name):
            # TODO handle notifications
            continue

        class_references.append(class_reference_template.substitute(
                ref_name=ref_name))

        find_class_invocations.append(find_class_invocation_template.substitute(
                ref_name=ref_name,
                class_name=class_name))

    return class_cache_template.substitute(
            class_references="".join(class_references), find_class_invocations="".join(find_class_invocations))
Пример #27
0
def generate_jvpp(func_list, base_package, dto_package, inputfile):
    """ Generates JVpp interface and JNI implementation """
    print "Generating JVpp"

    methods = []
    methods_impl = []
    for func in func_list:

        if util.is_notification(func['name']) or util.is_ignored(func['name']):
            # TODO handle notifications
            continue

        camel_case_name = util.underscore_to_camelcase(func['name'])
        camel_case_name_upper = util.underscore_to_camelcase_upper(
            func['name'])
        if util.is_reply(camel_case_name):
            continue

        if len(func['args']) == 0:
            methods.append(
                no_arg_method_template.substitute(name=camel_case_name,
                                                  base_package=base_package,
                                                  dto_package=dto_package))
            methods_impl.append(
                no_arg_method_native_template.substitute(
                    name=camel_case_name,
                    base_package=base_package,
                    dto_package=dto_package))
            methods_impl.append(
                no_arg_method_impl_template.substitute(
                    name=camel_case_name,
                    base_package=base_package,
                    dto_package=dto_package))
        else:
            methods.append(
                method_template.substitute(name=camel_case_name,
                                           request=camel_case_name_upper,
                                           base_package=base_package,
                                           dto_package=dto_package))
            methods_impl.append(
                method_native_template.substitute(
                    name=camel_case_name,
                    request=camel_case_name_upper,
                    base_package=base_package,
                    dto_package=dto_package))
            methods_impl.append(
                method_impl_template.substitute(name=camel_case_name,
                                                request=camel_case_name_upper,
                                                base_package=base_package,
                                                dto_package=dto_package))

    jvpp_file = open("JVpp.java", 'w')
    jvpp_file.write(
        jvpp_ifc_template.substitute(inputfile=inputfile,
                                     methods="\n".join(methods),
                                     base_package=base_package,
                                     dto_package=dto_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open("JVppImpl.java", 'w')
    jvpp_file.write(
        jvpp_impl_template.substitute(inputfile=inputfile,
                                      methods="\n".join(methods_impl),
                                      base_package=base_package,
                                      dto_package=dto_package))
    jvpp_file.flush()
    jvpp_file.close()
Пример #28
0
def generate_msg_handlers(func_list, plugin_name, inputfile):
    handlers = []
    for f in func_list:
        handler_name = f['name']
        dto_name = util.underscore_to_camelcase_upper(handler_name)
        ref_name = util.underscore_to_camelcase(handler_name)

        if is_manually_generated(handler_name,
                                 plugin_name) or util.is_ignored(handler_name):
            continue

        if not util.is_reply(dto_name) and not util.is_notification(
                handler_name):
            continue

        if util.is_notification(handler_name):
            dto_name = util.add_notification_suffix(dto_name)
            ref_name = util.add_notification_suffix(ref_name)

        dto_setters = ''
        err_handler = ''
        # dto setters
        for t in zip(f['c_types'], f['types'], f['args'], f['lengths']):
            c_type = t[0]
            jni_type = t[1]
            c_name = t[2]
            field_length = t[3][0]

            if jni_type.endswith('Array') and field_length == '0':
                raise Exception(
                    'Variable array \'%s\' defined in message \'%s\' '
                    'should have defined length (e.g. \'%s[%s_length]\'' %
                    (c_name, handler_name, c_name, c_name))

            # check if we are processing variable length array
            if t[3][1]:
                length_var_name = t[3][0]
                length_field_type = f['c_types'][f['args'].index(
                    length_var_name)]
                field_length = variable_length_array_value_template.substitute(
                    length_var_name=length_var_name)
                if length_field_type != 'u8':  # we need net to host conversion:
                    field_length = variable_length_array_template.substitute(
                        length_field_type=length_field_type,
                        value=field_length)

            # for retval don't generate setters and generate retval check
            if util.is_retval_field(c_name):
                err_handler = callback_err_handler_template.substitute(
                    handler_name=handler_name)
                continue

            java_field_name = util.underscore_to_camelcase(c_name)
            jni_signature = util.jni_2_signature_mapping[jni_type]
            jni_setter = util.jni_field_accessors[jni_type]

            dto_setters += dto_field_id_template.substitute(
                java_name=java_field_name,
                class_ref_name=ref_name,
                jni_signature=jni_signature)

            dto_setter_template = dto_field_setter_templates[c_type]

            dto_setters += dto_setter_template.substitute(
                java_name=java_field_name,
                jni_signature=jni_signature,
                c_name=c_name,
                jni_setter=jni_setter,
                field_length=field_length)

        handlers.append(
            msg_handler_template.substitute(
                inputfile=inputfile,
                api_data=util.api_message_to_javadoc(f),
                handler_name=handler_name,
                plugin_name=plugin_name,
                dto_name=dto_name,
                class_ref_name=ref_name,
                dto_setters=dto_setters,
                err_handler=err_handler))

    return "\n".join(handlers)
Пример #29
0
def generate_jvpp(func_list, base_package, plugin_package,
                  plugin_name_underscore, dto_package, inputfile, logger):
    """ Generates JVpp interface and JNI implementation """
    logger.debug("Generating JVpp interface implementation for %s" % inputfile)
    plugin_name = util.underscore_to_camelcase_upper(plugin_name_underscore)

    methods = []
    methods_impl = []
    for func in func_list:
        camel_case_name = util.underscore_to_camelcase(func['name'])
        camel_case_name_upper = util.underscore_to_camelcase_upper(
            func['name'])
        if util.is_reply(camel_case_name):
            continue

        if len(func['args']) == 0:
            methods.append(
                no_arg_method_template.substitute(name=camel_case_name))
            methods_impl.append(
                no_arg_method_native_template.substitute(name=camel_case_name))
            methods_impl.append(
                no_arg_method_impl_template.substitute(name=camel_case_name))
        else:
            methods.append(
                method_template.substitute(name=camel_case_name,
                                           request=camel_case_name_upper,
                                           plugin_package=plugin_package,
                                           dto_package=dto_package))
            methods_impl.append(
                method_native_template.substitute(
                    name=camel_case_name,
                    request=camel_case_name_upper,
                    plugin_package=plugin_package,
                    dto_package=dto_package))
            methods_impl.append(
                method_impl_template.substitute(name=camel_case_name,
                                                request=camel_case_name_upper,
                                                plugin_package=plugin_package,
                                                dto_package=dto_package))

    jvpp_file = open("JVpp%s.java" % plugin_name, 'w')
    jvpp_file.write(
        jvpp_ifc_template.substitute(inputfile=inputfile,
                                     methods="\n".join(methods),
                                     base_package=base_package,
                                     plugin_package=plugin_package,
                                     plugin_name=plugin_name,
                                     dto_package=dto_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open("JVpp%sImpl.java" % plugin_name, 'w')
    jvpp_file.write(
        jvpp_impl_template.substitute(
            inputfile=inputfile,
            methods="\n".join(methods_impl),
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            plugin_name_underscore=plugin_name_underscore,
            dto_package=dto_package))
    jvpp_file.flush()
    jvpp_file.close()
Пример #30
0
def generate_msg_handlers(func_list, inputfile):
    handlers = []
    for f in func_list:
        handler_name = f['name']
        dto_name = util.underscore_to_camelcase_upper(handler_name)
        ref_name = util.underscore_to_camelcase(handler_name)

        if is_manually_generated(handler_name) or util.is_ignored(handler_name):
            continue

        if not util.is_reply(dto_name) and not util.is_notification(handler_name):
            continue

        if util.is_notification(handler_name):
            dto_name = util.add_notification_suffix(dto_name)
            ref_name = util.add_notification_suffix(ref_name)

        dto_setters = ''
        err_handler = ''
        # dto setters
        for t in zip(f['c_types'], f['types'], f['args'], f['lengths']):
            c_type = t[0]
            jni_type = t[1]
            c_name = t[2]
            field_length = t[3][0]

            # check if we are processing variable length array
            if t[3][1]:
                length_var_name = t[3][0]
                length_field_type = f['c_types'][f['args'].index(length_var_name)]
                field_length = variable_length_array_value_template.substitute(length_var_name=length_var_name)
                if length_field_type != 'u8':  # we need net to host conversion:
                    field_length = variable_length_array_template.substitute(
                        length_field_type=length_field_type, value=field_length)

            # for retval don't generate setters and generate retval check
            if util.is_retval_field(c_name):
                err_handler = callback_err_handler_template.substitute(
                    handler_name=handler_name
                )
                continue

            java_field_name = util.underscore_to_camelcase(c_name)
            jni_signature = util.jni_2_signature_mapping[jni_type]
            jni_setter = util.jni_field_accessors[jni_type]

            dto_setters += dto_field_id_template.substitute(
                    java_name=java_field_name,
                    class_ref_name=ref_name,
                    jni_signature=jni_signature)

            dto_setter_template = dto_field_setter_templates[c_type]

            dto_setters += dto_setter_template.substitute(
                    java_name=java_field_name,
                    jni_signature=jni_signature,
                    c_name=c_name,
                    jni_setter=jni_setter,
                    field_length=field_length)

        handlers.append(msg_handler_template.substitute(
            inputfile=inputfile,
            api_data=util.api_message_to_javadoc(f),
            handler_name=handler_name,
            dto_name=dto_name,
            class_ref_name=ref_name,
            dto_setters=dto_setters,
            err_handler=err_handler))

    return "\n".join(handlers)
Пример #31
0
def generate_jvpp(func_list, base_package, plugin_package, plugin_name,
                  dto_package, callback_package, notification_package,
                  future_facade_package, inputfile):
    """ Generates JVpp interface and JNI implementation """
    print "Generating JVpp future facade"

    if not os.path.exists(future_facade_package):
        os.mkdir(future_facade_package)

    methods = []
    methods_impl = []
    callbacks = []
    for func in func_list:
        camel_case_name_with_suffix = util.underscore_to_camelcase_upper(
            func['name'])

        if util.is_ignored(func['name']) or util.is_control_ping(
                camel_case_name_with_suffix):
            continue

        if not util.is_reply(camel_case_name_with_suffix
                             ) and not util.is_notification(func['name']):
            continue

        camel_case_method_name = util.underscore_to_camelcase(func['name'])

        if not util.is_notification(func["name"]):
            camel_case_request_method_name = util.remove_reply_suffix(
                util.underscore_to_camelcase(func['name']))
            if util.is_details(camel_case_name_with_suffix):
                camel_case_reply_name = get_standard_dump_reply_name(
                    util.underscore_to_camelcase_upper(func['name']),
                    func['name'])
                callbacks.append(
                    jvpp_facade_details_callback_method_template.substitute(
                        base_package=base_package,
                        plugin_package=plugin_package,
                        dto_package=dto_package,
                        callback_dto=camel_case_name_with_suffix,
                        callback_dto_field=camel_case_method_name,
                        callback_dto_reply_dump=camel_case_reply_name +
                        dto_gen.dump_dto_suffix,
                        future_package=future_facade_package))

                methods.append(
                    future_jvpp_method_template.substitute(
                        plugin_package=plugin_package,
                        dto_package=dto_package,
                        method_name=camel_case_request_method_name +
                        util.underscore_to_camelcase_upper(util.dump_suffix),
                        reply_name=camel_case_reply_name +
                        dto_gen.dump_dto_suffix,
                        request_name=util.remove_reply_suffix(
                            camel_case_reply_name) +
                        util.underscore_to_camelcase_upper(util.dump_suffix)))
                methods_impl.append(
                    future_jvpp_dump_method_impl_template.substitute(
                        plugin_package=plugin_package,
                        dto_package=dto_package,
                        method_name=camel_case_request_method_name +
                        util.underscore_to_camelcase_upper(util.dump_suffix),
                        reply_name=camel_case_reply_name +
                        dto_gen.dump_dto_suffix,
                        request_name=util.remove_reply_suffix(
                            camel_case_reply_name) +
                        util.underscore_to_camelcase_upper(util.dump_suffix)))
            else:
                request_name = util.underscore_to_camelcase_upper(util.unconventional_naming_rep_req[func['name']]) \
                    if func['name'] in util.unconventional_naming_rep_req else util.remove_reply_suffix(camel_case_name_with_suffix)

                methods.append(
                    future_jvpp_method_template.substitute(
                        plugin_package=plugin_package,
                        dto_package=dto_package,
                        method_name=camel_case_request_method_name,
                        reply_name=camel_case_name_with_suffix,
                        request_name=request_name))
                methods_impl.append(
                    future_jvpp_method_impl_template.substitute(
                        plugin_package=plugin_package,
                        dto_package=dto_package,
                        method_name=camel_case_request_method_name,
                        reply_name=camel_case_name_with_suffix,
                        request_name=request_name))

                callbacks.append(
                    jvpp_facade_callback_method_template.substitute(
                        base_package=base_package,
                        plugin_package=plugin_package,
                        dto_package=dto_package,
                        callback_dto=camel_case_name_with_suffix))

        if util.is_notification(func["name"]):
            callbacks.append(
                jvpp_facade_callback_notification_method_template.substitute(
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    callback_dto=util.add_notification_suffix(
                        camel_case_name_with_suffix)))

    jvpp_file = open(
        os.path.join(future_facade_package,
                     "FutureJVpp%sFacadeCallback.java" % plugin_name), 'w')
    jvpp_file.write(
        jvpp_facade_callback_template.substitute(
            inputfile=inputfile,
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            dto_package=dto_package,
            notification_package=notification_package,
            callback_package=callback_package,
            methods="".join(callbacks),
            future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open(
        os.path.join(future_facade_package, "FutureJVpp%s.java" % plugin_name),
        'w')
    jvpp_file.write(
        future_jvpp_template.substitute(
            inputfile=inputfile,
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            notification_package=notification_package,
            methods="".join(methods),
            future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open(
        os.path.join(future_facade_package,
                     "FutureJVpp%sFacade.java" % plugin_name), 'w')
    jvpp_file.write(
        future_jvpp_facade_template.substitute(
            inputfile=inputfile,
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            dto_package=dto_package,
            notification_package=notification_package,
            methods="".join(methods_impl),
            future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()
Пример #32
0
def generate_jvpp(func_list, base_package, dto_package, callback_package, notification_package, callback_facade_package, inputfile):
    """ Generates callback facade """
    print "Generating JVpp callback facade"

    if os.path.exists(callback_facade_package):
        util.remove_folder(callback_facade_package)

    os.mkdir(callback_facade_package)

    methods = []
    methods_impl = []
    for func in func_list:

        if util.is_notification(func['name']) or util.is_ignored(func['name']):
            # TODO handle notifications
            continue

        camel_case_name = util.underscore_to_camelcase(func['name'])
        camel_case_name_upper = util.underscore_to_camelcase_upper(func['name'])
        if util.is_reply(camel_case_name):
            continue

        # Strip suffix for dump calls
        callback_type = get_request_name(camel_case_name_upper, func['name']) + callback_gen.callback_suffix

        if len(func['args']) == 0:
            methods.append(no_arg_method_template.substitute(name=camel_case_name,
                                                             base_package=base_package,
                                                             dto_package=dto_package,
                                                             callback_package=callback_package,
                                                             callback=callback_type))
            methods_impl.append(no_arg_method_impl_template.substitute(name=camel_case_name,
                                                                       base_package=base_package,
                                                                       dto_package=dto_package,
                                                                       callback_package=callback_package,
                                                                       callback=callback_type))
        else:
            methods.append(method_template.substitute(name=camel_case_name,
                                                      request=camel_case_name_upper,
                                                      base_package=base_package,
                                                      dto_package=dto_package,
                                                      callback_package=callback_package,
                                                      callback=callback_type))
            methods_impl.append(method_impl_template.substitute(name=camel_case_name,
                                                                request=camel_case_name_upper,
                                                                base_package=base_package,
                                                                dto_package=dto_package,
                                                                callback_package=callback_package,
                                                                callback=callback_type))

    join = os.path.join(callback_facade_package, "CallbackJVpp.java")
    jvpp_file = open(join, 'w')
    jvpp_file.write(
        jvpp_ifc_template.substitute(inputfile=inputfile,
                                     methods="\n".join(methods),
                                     base_package=base_package,
                                     dto_package=dto_package,
                                     notification_package=notification_package,
                                     callback_facade_package=callback_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open(os.path.join(callback_facade_package, "CallbackJVppFacade.java"), 'w')
    jvpp_file.write(jvpp_impl_template.substitute(inputfile=inputfile,
                                                  methods="\n".join(methods_impl),
                                                  base_package=base_package,
                                                  dto_package=dto_package,
                                                  notification_package=notification_package,
                                                  callback_package=callback_package,
                                                  callback_facade_package=callback_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    generate_callback(func_list, base_package, dto_package, callback_package, notification_package, callback_facade_package, inputfile)
Пример #33
0
def generate_jvpp(func_list, base_package, plugin_package, plugin_name,
                  dto_package, callback_package, notification_package,
                  callback_facade_package, inputfile):
    """ Generates callback facade """
    print "Generating JVpp callback facade"

    if os.path.exists(callback_facade_package):
        util.remove_folder(callback_facade_package)

    os.mkdir(callback_facade_package)

    methods = []
    methods_impl = []
    for func in func_list:

        if util.is_notification(func['name']) or util.is_ignored(func['name']):
            continue

        camel_case_name = util.underscore_to_camelcase(func['name'])
        camel_case_name_upper = util.underscore_to_camelcase_upper(
            func['name'])
        if util.is_reply(camel_case_name) or util.is_control_ping(
                camel_case_name):
            continue

        # Strip suffix for dump calls
        callback_type = get_request_name(
            camel_case_name_upper, func['name']) + callback_gen.callback_suffix

        if len(func['args']) == 0:
            methods.append(
                no_arg_method_template.substitute(
                    name=camel_case_name,
                    base_package=base_package,
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    callback_package=callback_package,
                    callback=callback_type))
            methods_impl.append(
                no_arg_method_impl_template.substitute(
                    name=camel_case_name,
                    base_package=base_package,
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    callback_package=callback_package,
                    callback=callback_type))
        else:
            methods.append(
                method_template.substitute(name=camel_case_name,
                                           request=camel_case_name_upper,
                                           base_package=base_package,
                                           plugin_package=plugin_package,
                                           dto_package=dto_package,
                                           callback_package=callback_package,
                                           callback=callback_type))
            methods_impl.append(
                method_impl_template.substitute(
                    name=camel_case_name,
                    request=camel_case_name_upper,
                    base_package=base_package,
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    callback_package=callback_package,
                    callback=callback_type))

    join = os.path.join(callback_facade_package,
                        "CallbackJVpp%s.java" % plugin_name)
    jvpp_file = open(join, 'w')
    jvpp_file.write(
        jvpp_ifc_template.substitute(
            inputfile=inputfile,
            methods="\n".join(methods),
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            dto_package=dto_package,
            notification_package=notification_package,
            callback_facade_package=callback_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open(
        os.path.join(callback_facade_package,
                     "CallbackJVpp%sFacade.java" % plugin_name), 'w')
    jvpp_file.write(
        jvpp_impl_template.substitute(
            inputfile=inputfile,
            methods="\n".join(methods_impl),
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            dto_package=dto_package,
            notification_package=notification_package,
            callback_package=callback_package,
            callback_facade_package=callback_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    generate_callback(func_list, base_package, plugin_package, plugin_name,
                      dto_package, callback_package, notification_package,
                      callback_facade_package, inputfile)
Пример #34
0
def generate_jvpp(func_list, base_package, dto_package, callback_package, notification_package, future_facade_package, inputfile):
    """ Generates JVpp interface and JNI implementation """
    print "Generating JVpp future facade"

    if not os.path.exists(future_facade_package):
        raise Exception("%s folder is missing" % future_facade_package)

    methods = []
    methods_impl = []
    callbacks = []
    for func in func_list:

        if util.is_ignored(func['name']):
            continue

        camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name'])
        if not util.is_reply(camel_case_name_with_suffix) and not util.is_notification(func['name']):
            continue

        camel_case_method_name = util.underscore_to_camelcase(func['name'])

        if not util.is_notification(func["name"]):
            camel_case_request_method_name = util.remove_reply_suffix(util.underscore_to_camelcase(func['name']))
            if util.is_details(camel_case_name_with_suffix):
                camel_case_reply_name = get_standard_dump_reply_name(util.underscore_to_camelcase_upper(func['name']),
                                                                     func['name'])
                callbacks.append(jvpp_facade_details_callback_method_template.substitute(base_package=base_package,
                                                                                         dto_package=dto_package,
                                                                                         callback_dto=camel_case_name_with_suffix,
                                                                                         callback_dto_field=camel_case_method_name,
                                                                                         callback_dto_reply_dump=camel_case_reply_name + dto_gen.dump_dto_suffix,
                                                                                         future_package=future_facade_package))

                methods.append(future_jvpp_method_template.substitute(base_package=base_package,
                                                                      dto_package=dto_package,
                                                                      method_name=camel_case_request_method_name +
                                                                                  util.underscore_to_camelcase_upper(util.dump_suffix),
                                                                      reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix,
                                                                      request_name=util.remove_reply_suffix(camel_case_reply_name) +
                                                                                   util.underscore_to_camelcase_upper(util.dump_suffix)))
                methods_impl.append(future_jvpp_method_impl_template.substitute(base_package=base_package,
                                                                                dto_package=dto_package,
                                                                                method_name=camel_case_request_method_name +
                                                                                            util.underscore_to_camelcase_upper(util.dump_suffix),
                                                                                reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix,
                                                                                request_name=util.remove_reply_suffix(camel_case_reply_name) +
                                                                                             util.underscore_to_camelcase_upper(util.dump_suffix)))
            else:
                request_name = util.underscore_to_camelcase_upper(util.unconventional_naming_rep_req[func['name']]) \
                    if func['name'] in util.unconventional_naming_rep_req else util.remove_reply_suffix(camel_case_name_with_suffix)

                methods.append(future_jvpp_method_template.substitute(base_package=base_package,
                                                                      dto_package=dto_package,
                                                                      method_name=camel_case_request_method_name,
                                                                      reply_name=camel_case_name_with_suffix,
                                                                      request_name=request_name))
                methods_impl.append(future_jvpp_method_impl_template.substitute(base_package=base_package,
                                                                                dto_package=dto_package,
                                                                                method_name=camel_case_request_method_name,
                                                                                reply_name=camel_case_name_with_suffix,
                                                                                request_name=request_name))

                # Callback handler is a bit special and a different template has to be used
                if util.is_control_ping(camel_case_name_with_suffix):
                    callbacks.append(jvpp_facade_control_ping_method_template.substitute(base_package=base_package,
                                                                                         dto_package=dto_package,
                                                                                         callback_dto=camel_case_name_with_suffix,
                                                                                         future_package=future_facade_package))
                else:
                    callbacks.append(jvpp_facade_callback_method_template.substitute(base_package=base_package,
                                                                                     dto_package=dto_package,
                                                                                     callback_dto=camel_case_name_with_suffix))

        if util.is_notification(func["name"]):
            callbacks.append(jvpp_facade_callback_notification_method_template.substitute(base_package=base_package,
                                                                                          dto_package=dto_package,
                                                                                          callback_dto=util.add_notification_suffix(camel_case_name_with_suffix)))

    jvpp_file = open(os.path.join(future_facade_package, "FutureJVppFacadeCallback.java"), 'w')
    jvpp_file.write(jvpp_facade_callback_template.substitute(inputfile=inputfile,
                                                             base_package=base_package,
                                                             dto_package=dto_package,
                                                             notification_package=notification_package,
                                                             callback_package=callback_package,
                                                             methods="".join(callbacks),
                                                             future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open(os.path.join(future_facade_package, "FutureJVpp.java"), 'w')
    jvpp_file.write(future_jvpp_template.substitute(inputfile=inputfile,
                                                    base_package=base_package,
                                                    methods="".join(methods),
                                                    future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open(os.path.join(future_facade_package, "FutureJVppFacade.java"), 'w')
    jvpp_file.write(future_jvpp_facade_template.substitute(inputfile=inputfile,
                                                           base_package=base_package,
                                                           dto_package=dto_package,
                                                           methods="".join(methods_impl),
                                                           future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()
Пример #35
0
def generate_dtos(func_list, base_package, dto_package, inputfile):
    """ Generates dto objects in a dedicated package """
    print "Generating DTOs"

    if not os.path.exists(dto_package):
        raise Exception("%s folder is missing" % dto_package)

    for func in func_list:
        camel_case_dto_name = util.underscore_to_camelcase_upper(func['name'])
        camel_case_method_name = util.underscore_to_camelcase(func['name'])
        dto_path = os.path.join(dto_package, camel_case_dto_name + ".java")

        if util.is_ignored(func['name']):
            continue

        fields = ""
        for t in zip(func['types'], func['args']):
            # for retval don't generate dto field in Reply
            field_name = util.underscore_to_camelcase(t[1])
            if util.is_reply(camel_case_dto_name) and util.is_retval_field(field_name):
                continue
            fields += field_template.substitute(type=util.jni_2_java_type_mapping[t[0]],
                                                name=field_name)
        methods = ""
        base_type = ""

        # Generate request/reply or dump/dumpReply even if structure can be used as notification
        if not util.is_just_notification(func["name"]):
            if util.is_reply(camel_case_dto_name):
                description = "vpe.api reply DTO"
                request_dto_name = get_request_name(camel_case_dto_name, func['name'])
                if util.is_details(camel_case_dto_name):
                    # FIXME assumption that dump calls end with "Dump" suffix. Not enforced in vpe.api
                    base_type += "JVppReply<%s.%s.%s>" % (base_package, dto_package, request_dto_name + "Dump")
                    generate_dump_reply_dto(request_dto_name, base_package, dto_package, camel_case_dto_name,
                                            camel_case_method_name, func)
                else:
                    base_type += "JVppReply<%s.%s.%s>" % (base_package, dto_package, request_dto_name)
            else:
                args = "" if fields is "" else "this"
                methods = send_template.substitute(method_name=camel_case_method_name,
                                                   base_package=base_package,
                                                   args=args)
                if util.is_dump(camel_case_dto_name):
                    base_type += "JVppDump"
                    description = "vpe.api dump request DTO"
                else:
                    base_type += "JVppRequest"
                    description = "vpe.api request DTO"

            write_dto_file(base_package, base_type, camel_case_dto_name, description, dto_package, dto_path, fields, func,
                           inputfile, methods)

        # for structures that are also used as notifications, generate dedicated notification DTO
        if util.is_notification(func["name"]):
            base_type = "JVppNotification"
            description = "vpe.api notification DTO"
            camel_case_dto_name = util.add_notification_suffix(camel_case_dto_name)
            methods = ""
            dto_path = os.path.join(dto_package, camel_case_dto_name + ".java")
            write_dto_file(base_package, base_type, camel_case_dto_name, description, dto_package, dto_path, fields, func,
                           inputfile, methods)

    flush_dump_reply_dtos(inputfile)
Пример #36
0
def generate_dtos(func_list, base_package, dto_package, inputfile):
    """ Generates dto objects in a dedicated package """
    print "Generating DTOs"

    if not os.path.exists(dto_package):
        raise Exception("%s folder is missing" % dto_package)

    for func in func_list:
        camel_case_dto_name = util.underscore_to_camelcase_upper(func['name'])
        camel_case_method_name = util.underscore_to_camelcase(func['name'])
        dto_path = os.path.join(dto_package, camel_case_dto_name + ".java")

        if util.is_notification(func['name']) or util.is_ignored(func['name']):
            # TODO handle notifications
            continue

        fields = ""
        for t in zip(func['types'], func['args']):
            fields += field_template.substitute(
                type=util.jni_2_java_type_mapping[t[0]],
                name=util.underscore_to_camelcase(t[1]))
        methods = ""
        base_type = ""
        if util.is_reply(camel_case_dto_name):
            description = "vpe.api reply DTO"
            request_dto_name = get_request_name(camel_case_dto_name,
                                                func['name'])
            if util.is_details(camel_case_dto_name):
                # FIXME assumption that dump calls end with "Dump" suffix. Not enforced in vpe.api
                base_type += "JVppReply<%s.%s.%s>" % (
                    base_package, dto_package, request_dto_name + "Dump")
                generate_dump_reply_dto(request_dto_name, base_package,
                                        dto_package, camel_case_dto_name,
                                        camel_case_method_name, func)
            else:
                base_type += "JVppReply<%s.%s.%s>" % (
                    base_package, dto_package, request_dto_name)
        else:
            args = "" if fields is "" else "this"
            methods = send_template.substitute(
                method_name=camel_case_method_name,
                base_package=base_package,
                args=args)
            if util.is_dump(camel_case_dto_name):
                base_type += "JVppDump"
                description = "vpe.api dump request DTO"
            else:
                base_type += "JVppRequest"
                description = "vpe.api request DTO"

        dto_file = open(dto_path, 'w')
        dto_file.write(
            dto_template.substitute(inputfile=inputfile,
                                    description=description,
                                    docs=util.api_message_to_javadoc(func),
                                    cls_name=camel_case_dto_name,
                                    fields=fields,
                                    methods=methods,
                                    base_package=base_package,
                                    base_type=base_type,
                                    dto_package=dto_package))
        dto_file.flush()
        dto_file.close()

    flush_dump_reply_dtos(inputfile)
Пример #37
0
def generate_jni_impl(func_list, inputfile):
    jni_impl = []
    for f in func_list:
        f_name = f['name']
        camel_case_function_name = util.underscore_to_camelcase(f_name)
        if is_manually_generated(f_name) or util.is_reply(camel_case_function_name) \
                or util.is_ignored(f_name) or util.is_just_notification(f_name):
            continue

        arguments = ''
        request_class = ''
        field_identifiers = ''
        struct_setters = ''
        f_name_uppercase = f_name.upper()

        if f['args']:
            arguments = ', jobject request'
            camel_case_function_name_upper = util.underscore_to_camelcase_upper(f_name)

            request_class = request_class_template.substitute(java_name_upper=camel_case_function_name_upper)

            # field identifiers
            for t in zip(f['types'], f['args']):
                jni_type = t[0]
                java_field_name = util.underscore_to_camelcase(t[1])
                jni_signature = util.jni_2_signature_mapping[jni_type]
                jni_getter = util.jni_field_accessors[jni_type]
                field_identifiers += request_field_identifier_template.substitute(
                        jni_type=jni_type,
                        java_name=java_field_name,
                        jni_signature=jni_signature,
                        jni_getter=jni_getter)

            # field setters
            for t in zip(f['c_types'], f['args'], f['lengths']):
                c_type = t[0]
                c_name = t[1]
                field_length = t[2][0]

                # check if we are processing variable length array:
                if t[2][1]:
                    field_length = util.underscore_to_camelcase(t[2][0])

                java_field_name = util.underscore_to_camelcase(c_name)

                struct_setter_template = struct_setter_templates[c_type]

                struct_setters += struct_setter_template.substitute(
                        c_name=c_name,
                        java_name=java_field_name,
                        field_length=field_length)

        jni_impl.append(jni_impl_template.substitute(
                inputfile=inputfile,
                api_data=util.api_message_to_javadoc(f),
                java_name=camel_case_function_name,
                c_name_uppercase=f_name_uppercase,
                c_name=f_name,
                request_class=request_class,
                field_identifiers=field_identifiers,
                struct_setters=struct_setters,
                args=arguments))

    return "\n".join(jni_impl)
Пример #38
0
def generate_jvpp(func_list, base_package, plugin_package, plugin_name,
                  dto_package, callback_package, notification_package,
                  future_facade_package, inputfile):
    """ Generates JVpp interface and JNI implementation """
    print "Generating JVpp future facade"

    if not os.path.exists(future_facade_package):
        os.mkdir(future_facade_package)

    methods = []
    methods_impl = []

    # Generate methods for sending messages.
    for func in func_list:
        camel_case_name_with_suffix = util.underscore_to_camelcase_upper(
            func['name'])

        if util.is_control_ping(camel_case_name_with_suffix):
            # Skip control ping managed by jvpp registry.
            continue

        # Process replies instead of requests (optimization).
        if not util.is_reply(camel_case_name_with_suffix):
            # Do not generate send methods for messages that do not have replies.
            continue

        camel_case_request_method_name = util.remove_reply_suffix(
            util.underscore_to_camelcase(func['name']))
        if util.is_details(camel_case_name_with_suffix):
            camel_case_reply_name = util.underscore_to_camelcase_upper(
                func['name'])
            methods.append(
                future_jvpp_method_template.substitute(
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    method_name=camel_case_request_method_name +
                    util.underscore_to_camelcase_upper(util.dump_suffix),
                    reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix,
                    request_name=util.remove_reply_suffix(
                        camel_case_reply_name) +
                    util.underscore_to_camelcase_upper(util.dump_suffix)))
            methods_impl.append(
                future_jvpp_dump_method_impl_template.substitute(
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    method_name=camel_case_request_method_name +
                    util.underscore_to_camelcase_upper(util.dump_suffix),
                    reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix,
                    request_name=util.remove_reply_suffix(
                        camel_case_reply_name) +
                    util.underscore_to_camelcase_upper(util.dump_suffix)))
        else:
            request_name = util.remove_reply_suffix(
                camel_case_name_with_suffix)

            methods.append(
                future_jvpp_method_template.substitute(
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    method_name=camel_case_request_method_name,
                    reply_name=camel_case_name_with_suffix,
                    request_name=request_name))
            methods_impl.append(
                future_jvpp_method_impl_template.substitute(
                    plugin_package=plugin_package,
                    dto_package=dto_package,
                    method_name=camel_case_request_method_name,
                    reply_name=camel_case_name_with_suffix,
                    request_name=request_name))

    jvpp_file = open(
        os.path.join(future_facade_package, "FutureJVpp%s.java" % plugin_name),
        'w')
    jvpp_file.write(
        future_jvpp_template.substitute(
            inputfile=inputfile,
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            notification_package=notification_package,
            methods="".join(methods),
            future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    jvpp_file = open(
        os.path.join(future_facade_package,
                     "FutureJVpp%sFacade.java" % plugin_name), 'w')
    jvpp_file.write(
        future_jvpp_facade_template.substitute(
            inputfile=inputfile,
            base_package=base_package,
            plugin_package=plugin_package,
            plugin_name=plugin_name,
            dto_package=dto_package,
            notification_package=notification_package,
            methods="".join(methods_impl),
            future_package=future_facade_package))
    jvpp_file.flush()
    jvpp_file.close()

    generate_callback(func_list, base_package, plugin_package, plugin_name,
                      dto_package, callback_package, notification_package,
                      future_facade_package, inputfile)