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.
21 def generate_enums(enum_list, inputfile, logger):
23 Generates Java representation of enum types defined in the provided JSON file.
27 logger.debug("Skipping enum generation (%s does not define enum types)." % inputfile)
30 logger.debug("Generating enums for %s" % inputfile)
32 for enum in enum_list:
36 if isinstance(e, basestring):
38 elif type(e) is dict and 'enumtype' in e:
39 enum_type = e['enumtype']
42 logger.warn("%s enum is missing name. Skipping" % enum)
46 logger.warn("%s enum is missing value type. Skipping" % enum)
49 # TODO(VPP-1153): add real enum support.
50 # But first refactor java api generation
51 # (either VPP-1154 or VPP-1155, see also VPP-480).
53 # As a workaround we just update all the mappings
54 # used for VPP API definitions to JAVA and C/JNI translation.
55 enum_array_type = enum_type + "[]"
56 type_name = "vl_api_" + enum_name + "_t"
57 array_type_name = type_name + "[]"
58 util.vpp_2_jni_type_mapping[type_name] = util.vpp_2_jni_type_mapping[enum_type]
59 util.vpp_2_jni_type_mapping[array_type_name] = util.vpp_2_jni_type_mapping[enum_array_type]
60 util.jni_2_java_type_mapping[type_name] = util.jni_2_java_type_mapping[enum_type]
61 util.jni_2_java_type_mapping[array_type_name] = util.jni_2_java_type_mapping[enum_array_type]
62 util.jni_2_signature_mapping[type_name] = util.jni_2_signature_mapping[enum_type]
63 util.jni_2_signature_mapping[array_type_name] = util.jni_2_signature_mapping[enum_array_type]
64 util.jni_field_accessors[type_name] = util.jni_field_accessors[enum_type]
65 util.jni_field_accessors[array_type_name] = util.jni_field_accessors[enum_array_type]
66 jni_gen.struct_setter_templates[type_name] = jni_gen.struct_setter_templates[enum_type]
67 jni_gen.struct_setter_templates[array_type_name] = jni_gen.struct_setter_templates[enum_array_type]
68 jni_gen.dto_field_setter_templates[type_name] = jni_gen.dto_field_setter_templates[enum_type]
69 jni_gen.dto_field_setter_templates[array_type_name] = jni_gen.dto_field_setter_templates[enum_array_type]