API: Use string type instead of u8.
[vpp.git] / extras / japi / java / jvpp / gen / jvppgen / jvpp_ifc_gen.py
1 #!/usr/bin/env python2
2 #
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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 #
16 from string import Template
17
18 from jvpp_model import is_request, is_dump, is_event
19
20
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
25     methods = []
26     for msg in messages:
27         if msg.has_fields:
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))
32         else:
33             methods.append(_JVPP_IFC_NO_ARG_METHOD_TEMPLATE.substitute(name=msg.java_name_lower))
34
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)
41     )
42     with open("%s/JVpp%s.java" % (work_dir, plugin_name), "w") as f:
43         f.write(jvpp_interface)
44
45
46 def _jvpp_ifc_filter(msg):
47     return is_request(msg) or is_dump(msg) or is_event(msg)
48
49
50 _JVPP_IFC_METHOD_TEMPLATE = Template(
51     """    int $name($plugin_package.dto.$type request) throws io.fd.vpp.jvpp.VppInvocationException;""")
52
53 _JVPP_IFC_NO_ARG_METHOD_TEMPLATE = Template("""    int $name() throws io.fd.vpp.jvpp.VppInvocationException;""")
54
55 _JVPP_IFC_TEMPLATE = Template("""package $plugin_package;
56
57 /**
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)
61  */
62 public interface JVpp${plugin_name} extends io.fd.vpp.jvpp.JVpp {
63     /**
64      * Generic dispatch method for sending requests to VPP
65      *
66      * @throws io.fd.vpp.jvpp.VppInvocationException if send request had failed
67      */
68     int send(io.fd.vpp.jvpp.dto.JVppRequest request) throws io.fd.vpp.jvpp.VppInvocationException;
69 $methods
70 }
71 """)