3 # Copyright (c) 2018 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from string import Template
18 from jni_common_gen import generate_j2c_swap, generate_j2c_identifiers, generate_c2j_swap
19 from jvpp_model import Class
22 def generate_type_handlers(model):
24 Generates msg handlers for all messages except for dumps and requests (handled by vpp, not client).
25 :param model: meta-model of VPP API used for jVPP generation.
29 if not isinstance(t, Class):
31 ref_name = t.java_name_lower
32 jni_identifiers = generate_j2c_identifiers(t, class_ref_name="%sClass" % ref_name, object_ref_name="_host")
33 type_handlers.append(_TYPE_NET_TO_HOST_TEMPLATE.substitute(
35 json_filename=model.json_api_files,
36 json_definition=t.doc,
37 type_reference_name=ref_name,
39 jni_identifiers=jni_identifiers,
40 type_swap=generate_j2c_swap(t, struct_ref_name="_net")
43 type_handlers.append(_TYPE_HOST_TO_NET_TEMPLATE.substitute(
45 json_filename=model.json_api_files,
46 json_definition=t.doc,
47 type_reference_name=ref_name,
49 jni_identifiers=jni_identifiers,
50 type_swap=generate_c2j_swap(t, object_ref_name="_host", struct_ref_name="_net")
53 return "\n".join(type_handlers)
55 _TYPE_NET_TO_HOST_TEMPLATE = Template("""
57 * Host to network byte order conversion for ${c_name} type.
58 * Generated based on $json_filename:
61 static inline void _host_to_net_${c_name}(JNIEnv * env, jobject _host, vl_api_${c_name}_t * _net)
63 jclass ${type_reference_name}Class = (*env)->FindClass(env, "${class_FQN}");
68 _TYPE_HOST_TO_NET_TEMPLATE = Template("""
70 * Network to host byte order conversion for ${c_name} type.
71 * Generated based on $json_filename:
74 static inline void _net_to_host_${c_name}(JNIEnv * env, vl_api_${c_name}_t * _net, jobject _host)
76 jclass ${type_reference_name}Class = (*env)->FindClass(env, "${class_FQN}");