Beispiel #1
0
def _generate_class(model, t, type_handlers):
    ref_name = t.java_name_lower
    jni_identifiers = generate_j2c_identifiers(t,
                                               class_ref_name="%sClass" %
                                               ref_name,
                                               object_ref_name="_host")
    type_handlers.append(
        _TYPE_NET_TO_HOST_TEMPLATE.substitute(
            c_name=t.name,
            json_filename=model.json_api_files,
            json_definition=t.doc,
            type_reference_name=ref_name,
            class_FQN=t.jni_name,
            jni_identifiers=jni_identifiers,
            type_swap=generate_j2c_swap(t, struct_ref_name="_net")))

    type_handlers.append(
        _TYPE_HOST_TO_NET_TEMPLATE.substitute(
            c_name=t.name,
            json_filename=model.json_api_files,
            json_definition=t.doc,
            type_reference_name=ref_name,
            class_FQN=t.jni_name,
            jni_identifiers=jni_identifiers,
            type_swap=generate_c2j_swap(t,
                                        object_ref_name="_host",
                                        struct_ref_name="_net")))
Beispiel #2
0
def _generate_class(model, t, type_handlers):
    ref_name = t.java_name_lower
    is_alias = t.name in model._aliases

    if t.name == "ip6_address_with_prefix":
        is_alias = True

    type_handlers.append(
        _TYPE_HOST_TO_NET_TEMPLATE.substitute(
            c_name=t.name,
            json_filename=model.json_api_files,
            json_definition=t.doc,
            type_reference_name=ref_name,
            class_FQN=t.jni_name,
            jni_identifiers=generate_j2c_identifiers(t,
                                                     class_ref_name="%sClass" %
                                                     ref_name,
                                                     object_ref_name="_host"),
            type_swap=generate_j2c_swap(t,
                                        struct_ref_name="_net",
                                        is_alias=is_alias)))

    type_handlers.append(
        _TYPE_NET_TO_HOST_TEMPLATE.substitute(
            c_name=t.name,
            json_filename=model.json_api_files,
            json_definition=t.doc,
            type_reference_name=ref_name,
            class_FQN=t.jni_name,
            type_swap=generate_c2j_swap(t,
                                        object_ref_name="_host",
                                        struct_ref_name="_net",
                                        is_alias=is_alias)))
Beispiel #3
0
def generate_jni_impl(model):
    """
    Generates JNI bindings for sending dump and request messages.
    :param model: meta-model of VPP API used for jVPP generation.
    """
    jni_impl = []
    for msg in model.messages:
        if is_control_ping(msg) or is_control_ping_reply(msg):
            # Skip control ping managed by jvpp registry.
            continue
        if not (is_dump(msg) or is_request(msg)):
            continue
        arguments = ""
        request_class = ""
        jni_identifiers = ""
        msg_initialization = ""

        if msg.has_fields:
            arguments = ", jobject request"
            request_class = _REQUEST_CLASS_TEMPLATE.substitute(
                plugin_name=model.plugin_name,
                java_dto_name=msg.java_name_upper)
            jni_identifiers = generate_j2c_identifiers(
                msg, class_ref_name="requestClass", object_ref_name="request")
            msg_initialization = generate_j2c_swap(msg,
                                                   struct_ref_name="mp",
                                                   is_alias=False)

        jni_impl.append(
            _JNI_IMPL_TEMPLATE.substitute(
                c_name=msg.name,
                json_filename=model.json_api_files,
                json_definition=msg.doc,
                plugin_name=model.plugin_name,
                plugin_java_name=model.plugin_java_name,
                java_method_name=msg.java_name_lower,
                arguments=arguments,
                request_class=request_class,
                jni_identifiers=jni_identifiers,
                msg_size=_generate_msg_size(msg),
                crc=msg.crc,
                msg_initialization=msg_initialization))
    return "".join(jni_impl)
def generate_type_handlers(model):
    """
    Generates msg handlers for all messages except for dumps and requests (handled by vpp, not client).
    :param model: meta-model of VPP API used for jVPP generation.
    """
    type_handlers = []
    for t in model.types:
        if not isinstance(t, Class):
            continue
        ref_name = t.java_name_lower
        jni_identifiers = generate_j2c_identifiers(t,
                                                   class_ref_name="%sClass" %
                                                   ref_name,
                                                   object_ref_name="_host")
        type_handlers.append(
            _TYPE_NET_TO_HOST_TEMPLATE.substitute(
                c_name=t.name,
                json_filename=model.json_api_files,
                json_definition=t.doc,
                type_reference_name=ref_name,
                class_FQN=t.jni_name,
                jni_identifiers=jni_identifiers,
                type_swap=generate_j2c_swap(t, struct_ref_name="_net")))

        type_handlers.append(
            _TYPE_HOST_TO_NET_TEMPLATE.substitute(
                c_name=t.name,
                json_filename=model.json_api_files,
                json_definition=t.doc,
                type_reference_name=ref_name,
                class_FQN=t.jni_name,
                jni_identifiers=jni_identifiers,
                type_swap=generate_c2j_swap(t,
                                            object_ref_name="_host",
                                            struct_ref_name="_net")))

    return "\n".join(type_handlers)