3 # Copyright (c) 2016 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.
22 import notification_gen
24 import jvpp_callback_facade_gen
25 import jvpp_future_facade_gen
31 # ~/Projects/vpp/vpp-api/jvpp/gen$ mkdir -p java/org/openvpp/jvpp && cd java/org/openvpp/jvpp
32 # ~/Projects/vpp/vpp-api/jvpp/gen/java/org/openvpp/jvpp$ ../../../../jvpp_gen.py -idefs_api_vpp_papi.py
35 # ~/Projects/vpp/vpp-api/jvpp/gen/java/org/openvpp/jvpp$ javac *.java dto/*.java callback/*.java
38 # defs_api_vpp_papi.py - vpe.api in python format (generated by vppapigen)
39 from util import vpp_2_jni_type_mapping
41 parser = argparse.ArgumentParser(description='VPP Java API generator')
42 parser.add_argument('-i', action="store", dest="inputfile")
43 args = parser.parse_args()
47 inputfile = args.inputfile.replace('.py', '')
48 cfg = importlib.import_module(inputfile, package=None)
51 # FIXME: functions unsupported due to problems with vpe.api
52 def is_supported(f_name):
53 return f_name not in {'vnet_ip4_fib_counters', 'vnet_ip6_fib_counters'}
56 def is_request_field(field_name):
57 return field_name not in {'_vl_msg_id', 'client_index', 'context'}
60 def is_response_field(field_name):
61 return field_name not in {'_vl_msg_id'}
64 def get_args(t, filter):
73 def get_types(t, filter):
80 if len(i) is 3: # array type
81 types_list.append(vpp_2_jni_type_mapping[i[0]] + 'Array')
82 c_types_list.append(i[0] + '[]')
83 lengths_list.append((i[2], False))
84 elif len(i) is 4: # variable length array type
85 types_list.append(vpp_2_jni_type_mapping[i[0]] + 'Array')
86 c_types_list.append(i[0] + '[]')
87 lengths_list.append((i[3], True))
88 else: # primitive type
89 types_list.append(vpp_2_jni_type_mapping[i[0]])
90 c_types_list.append(i[0])
91 lengths_list.append((0, False))
92 return types_list, c_types_list, lengths_list
95 def get_definitions():
99 for a in cfg.vppapidef:
100 if not is_supported(a[0]):
103 java_name = util.underscore_to_camelcase(a[0])
105 # For replies include all the arguments except message_id
106 if util.is_reply(java_name):
107 types, c_types, lengths = get_types(a[1:], is_response_field)
108 func_name[a[0]] = dict(
109 [('name', a[0]), ('java_name', java_name),
110 ('args', get_args(a[1:], is_response_field)), ('full_args', get_args(a[1:], lambda x: True)),
111 ('types', types), ('c_types', c_types), ('lengths', lengths)])
112 # For requests skip message_id, client_id and context
114 types, c_types, lengths = get_types(a[1:], is_request_field)
115 func_name[a[0]] = dict(
116 [('name', a[0]), ('java_name', java_name),
117 ('args', get_args(a[1:], is_request_field)), ('full_args', get_args(a[1:], lambda x: True)),
118 ('types', types), ('c_types', c_types), ('lengths', lengths)])
121 func_list.append(func_name[a[0]])
122 return func_list, func_name
125 func_list, func_name = get_definitions()
127 base_package = 'org.openvpp.jvpp'
129 callback_package = 'callback'
130 notification_package = 'notification'
131 future_package = 'future'
132 # TODO find better package name
133 callback_facade_package = 'callfacade'
135 dto_gen.generate_dtos(func_list, base_package, dto_package, args.inputfile)
136 jvpp_impl_gen.generate_jvpp(func_list, base_package, dto_package, args.inputfile)
137 callback_gen.generate_callbacks(func_list, base_package, callback_package, dto_package, args.inputfile)
138 notification_gen.generate_notification_registry(func_list, base_package, notification_package, callback_package, dto_package, args.inputfile)
139 jvpp_c_gen.generate_jvpp(func_list, args.inputfile)
140 jvpp_future_facade_gen.generate_jvpp(func_list, base_package, dto_package, callback_package, notification_package, future_package, args.inputfile)
141 jvpp_callback_facade_gen.generate_jvpp(func_list, base_package, dto_package, callback_package, notification_package, callback_facade_package, args.inputfile)