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 jvpp_model import is_request, is_dump, is_event
21 def generate_java_ifc(work_dir, model, logger):
22 logger.debug("Generating JVpp interface for %s" % model.json_api_files)
23 messages = filter(_jvpp_ifc_filter, model.messages)
24 plugin_package = model.plugin_package
28 methods.append(_JVPP_IFC_METHOD_TEMPLATE.substitute(
29 name=msg.java_name_lower,
30 plugin_package=plugin_package,
31 type=msg.java_name_upper))
33 methods.append(_JVPP_IFC_NO_ARG_METHOD_TEMPLATE.substitute(name=msg.java_name_lower))
35 plugin_name = model.plugin_java_name
36 jvpp_interface = _JVPP_IFC_TEMPLATE.substitute(
37 plugin_package=plugin_package,
38 json_filename=model.json_api_files,
39 plugin_name=plugin_name,
40 methods="\n".join(methods)
42 with open("%s/JVpp%s.java" % (work_dir, plugin_name), "w") as f:
43 f.write(jvpp_interface)
46 def _jvpp_ifc_filter(msg):
47 return is_request(msg) or is_dump(msg) or is_event(msg)
50 _JVPP_IFC_METHOD_TEMPLATE = Template(
51 """ int $name($plugin_package.dto.$type request) throws io.fd.vpp.jvpp.VppInvocationException;""")
53 _JVPP_IFC_NO_ARG_METHOD_TEMPLATE = Template(""" int $name() throws io.fd.vpp.jvpp.VppInvocationException;""")
55 _JVPP_IFC_TEMPLATE = Template("""package $plugin_package;
58 * <p>Java representation of plugin's api file.
59 * <br>It was generated by jvpp_impl_gen.py based on $json_filename.
60 * <br>(python representation of api file generated by vppapigen)
62 public interface JVpp${plugin_name} extends io.fd.vpp.jvpp.JVpp {
64 * Generic dispatch method for sending requests to VPP
66 * @throws io.fd.vpp.jvpp.VppInvocationException if send request had failed
68 int send(io.fd.vpp.jvpp.dto.JVppRequest request) throws io.fd.vpp.jvpp.VppInvocationException;